Archive for the 'WordPress' Category

Battling WordPress: Displaying source code, Part II

Monday, August 18th, 2008

Its amazing what you can achieve when you upgrade - this blog is now on the latest version of WordPress - version 2.6.1. General observations (compared to version 2.0.2):

  • The editor now remembers formatting (line breaks, indenting) within HTML pre tags.
  • The editor now handles HTML entities properly - I can enter code AND modify it later, without screwing everything up.
  • Consequently, HTML body tags and RedDot markup within HTML pre tags is working properly.
  • Upgrade hasn’t affected my Google Syntax Highlighter plugin.
  • The editor is still removing the deprecated name attribute from the HTML pre tags - so my Javascript hack mentioned in the previous post is still required. 
  • The update wasn’t difficult, but I thought the update instructions could have been clearer.

I will post my blog entry with code and you can be the judge!

Battling WordPress: Displaying source code

Wednesday, August 13th, 2008

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!