I’ve always wanted a cool syntax highlighter for source code on my blog, so when performing the latest revamp of my blog I decided to go hunting for a solution that would fit my needs.
After installing and converting over several posts I started to notice two main issues that were effectively show stoppers:
- Anything that looked like an XML tag was being made lowercase
- Anything that looked like a start tag of an XML element that didn’t have a corresponding end tag was having one automatically inserted
This may not sound like a huge deal, but the second point was especially painful when using non-XML-based languages. Take generics in C#, for instance. If I wanted to write a line of code like this:
IList<Customer> listOfActiveCustomers = customerService.GetActiveCustomers();
SyntaxHighlighter MT would spit out the following:
IList<customer> listOfActiveCustomers = customerService.GetActiveCustomers(); </customer>
Not only did it mess up the casing on the Customer type, it thought that the generic type parameter to IList was the start of an XML tag and thus needed to be closed.
Now, I’m guessing this has something to do with how WordPress in general processes text inside a <pre> tag and is probably not the fault of the plugin author, but that still didn’t change the fact that I needed a solution.
The WordPress.com guide to posting source code noted that WordPress.com blogs have access to the “sourcecode” WordPress shortcode to accomplish the very same thing. Now I’m not using WordPress.com, I self-host my blog using the WordPress.org code, but they do mention at the bottom of the post also indicates that the same functionality is available through the SyntaxHighlighter Evolved plugin.
This plugin also uses Alex Gorbatchev’s SyntaxHighlighter, but it uses WordPress shortcodes just like the functionality available through WordPress.com. I’ve now installed the new plugin and started converting old posts over to the new format with no issues whatsoever.