19th February
2009
Let’s say you would like to post some XML in a blog post about, for example, XML in a Django template. There’s a great plugin called WP-Syntax that adds syntax highlighting to code samples in your blog. Once installed, you can use some code like this in your templates:
<xml>Hello</xml>
Then switch over to HTML mode and wrap that code in a pre tag like this:
<pre lang="xml" escaped="true"> <xml>Hello</xml> </pre>
But there’s a small catch
If you switch back and forth between HTML and Visual mode, you’ll lose that ‘escaped=”true”‘ attribute (probably a bug). Then you’ll end up with double escaped code on you page like this:
<xml>Hello</xml>
Solution?
- Only work in HTML mode, so your code doesn’t get escaped in the first place (Then you won’t need the escaped=”true” attribute either. I think you can even disable Visual mode).
- Write you post in Visual mode, then switch HTML mode, add your pre tags with escaped=”true” attribute, and then don’t switch back to Visual mode (that’s how I wrote this post).
I don’t like either solution, but I prefer the second.