So I was playing around with the rather nice SyntaxHighlighter WordPress plugin. It worked pretty nicely. But it had some issues, IMO:
- It repurposes the
classattribute to act like a pseudo-CSS ruleset with custom rules. To me that’s just ugly.
- It does all its work client-side. For some things that’s a nice touch, but for a blog with mostly static content it’s wasted time.
- It’s LGPLv3. I prefer less restrictive licenses for OSS.
On the other hand, I know the Pygments syntax highlighter pretty well, and I already had a written style plugin for it to get the syntax coloring I like. But there’s no mature Pygments plugin for WordPress that I could find. So I did what any good programmer would do and set out to write my own. I have the working knowledge of PHP (I’m a core dev, for mercy’s sake) and Python to do it with, after all. Not so much WordPress’ plugin API, though, so I took the SyntaxHighlighter plugin as a starting point.
So in I dug… ripped out all the JS, rewrote it to use the modern Settings API, tore out the backwards-compat stuff, added the ability to call out to Pygments (using the
pygmentize commandline interface), cleaned up the shortcode parser a little… well, long story short, I got it to work decently okay. Not quite as elegant as the original, but it works. I still don’t know how much of the remaining code from the original plugin is nothing but cruft, since there are too many WordPress features I just don’t use (such as the visual post editor)!
I also added an option to disable the automatic use of the
wpautop filter in WordPress. This means that finally I’m writing truly raw HTML in the HTML editor. No more creating paragraph and line break tags for me instead of letting me do it myself. Ha! Of course, this meant that a couple of hacks the code does to avoid
wpautop processing were making things worse instead of better, but that was easily fixed.
I am not releasing this plugin’s code in any form whatsoever until I can contact the author of the SyntaxHighlighter plugin and resolve any potential licensing issues. There’s enough of his code left in the plugin for there to be a significant issue; I didn’t use his code as an example, I took his code and heavily modified it. If by some strange coincidence Alex Gorbatchev, Andrew Ozz, or Viper007Bond, the original authors named by the plugin, are reading this, I invite comment from them.
Here are some screenshots of the plugin’s settings screen: