found drama

get oblique

on syntax highlighting: a brief public service announcement

by Rob Friesel

In preparation for an up-coming post1, I did a bit of extra legwork on syntax highlighting plugins for WordPress and wound up switching from Google Syntax Highlighter for WordPress (GSHW)2 to SyntaxHighlighterPro. Both of them are backed by Alex Gorbatchev’s Syntax Highlighter library. But more on that in a moment.

What prompted the switch was the fact that I noticed that GSHW was mangling some CSS syntax highlighting operations. The regex used to grab hex colors was getting greedy and highlighting #id-selectors as if they were colors3. After a little digging, I came to discover that GSHW was using a quite-out-of-date version of Gorbatchev’s library.

Exploring the Syntax Highlighter site a bit, I found a couple of other plugins that appeared to be more up-to-date. I gave a crack at SyntaxHighlighter Evolved and the above mentioned SyntaxHighlighterPro. Both had more recent versions4 of the library baked in. Both seemed a step up in that regard, but I went with -Pro because it was going to require the fewest tweaks and changes5 in the code samples already posted6 and also because its control panel offered the ability to toggle specific syntaxes at will.

That said, the “Evolved” plugin has a nice suite of options.

This is likely just a temporary stop-gap measure, however. I may pull the plug on the plugins and just drop in Gorbatchev’s script directly—the latest version appears to offer on-demand loading of the “brush” scripts. Combine that with a minified version of the script and that may prove a better overall solution than the plugins can offer.

Nevertheless, the problem remains that the CSS highlighter “brush” script needs some work. It doesn’t really seem to recognize common selectors (#id and .class selectors, I’m looking at you)… and this bugs me.

But until then…

  1. Quite likely the next post… []
  2. Which I’ve been using for a few months now. []
  3. Meaning that it was only coloring the hash and the first six characters of #container. []
  4. Though neither was using the most recent version. []
  5. I.e., it more gracefully relented to my efforts to kludge in the AppleScript and Sass support. []
  6. I.e., -Pro recognized the <pre> formatted blocks whereas Evolved was going to require changing all those to use BBCode-style [bracket] syntax. Ick. []

About Rob Friesel

Software engineer by day, science fiction writer by night; weekend homebrewer. Author of The PhantomJS Cookbook and a short story in Please Do Not Remove. View all posts by Rob Friesel →

Leave a Reply

Your email address will not be published.