Battling WordPress: Displaying source code

You would think adding source code to a blog would be easy, or maybe I am just getting old… Anyway it all started with trying to make use of the HTML pre tag - except that line breaks and spacing weren’t being preserved. I then moved onto the HTML code tag - same problem. In my travels I came across the following:

The first uses the Google Syntax Highlighter plugin for WordPress - and looks great - except I can’t seem to get the name attribute of the HTML pre tag to stick (I figure because it is deprecated in XHTML), and the alternative HTML textarea method - well I haven’t had much more luck with the line break and spacing preservation and it mucks up the editor having form elements in it. Not only that, but adding HTML form tags seems to have stopped my ability to Save changes…

The second, from WordPress themselves, just rementions the HTML pre and code tag variations I tried first :(.

Further investigation led me to:

Which has been helpful in hacking the HTML pre tags to work - but still hasn’t overcome the issue of entering the code in the first place. Even resorting to constructing it externally and pasting it in (editing it resets all of the escaping), I am still having difficulties with RedDot markup being confused for HTML comments, missing HTML body tags, using HTML br tags for line breaks, non-breaking spaces for indenting and having to re-enter all of the escaping everytime I edit the post.

Conclusion - I think it is the text editor that is the main problem, which is most likely linked to my not using the latest version of WordPress, currently 2.6. (I am using the auto-install version provided by my hosting provider - probably my first mistake - which is 2.0.2) So I will investigate upgrading first. I have noticed in my searching that there are quite a few different code viewing plugins, so regardless of whether an upgrade solves my issue I will probably take a closer look at some of these too.

I will record my final solution when I finally obtain it!

2 Responses to “Battling WordPress: Displaying source code”

  1. Paul Says:

    Not sure upgrading the wordpress installation will fix it. But… there is a plugin that looks like it will help : http://www.thunderguy.com/semicolon/wordpress/code-markup-wordpress-plugin/

    Not sure how it will cope with reddot stuff, but I’m sure you’re keen enough to work out a fix :)

  2. Leo Says:

    Good post. Your posts are really interesting. To have a good resource you should not only to post something, but do it from the heart. You cope with it.

Leave a Reply