on syntax highlighting: a brief public service announcement
¶ by Rob FrieselIn preparation for an up-coming post 1, 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 colors 3. 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 versions 4 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 changes 5 in the code samples already posted 6 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…
- Quite likely the next post…[↩]
- Which I’ve been using for a few months now.[↩]
- Meaning that it was only coloring the hash and the first six characters of
#container
.[↩] - Though neither was using the most recent version.[↩]
- I.e., it more gracefully relented to my efforts to kludge in the AppleScript and Sass support.[↩]
- I.e., -Pro recognized the
<pre>
formatted blocks whereas Evolved was going to require changing all those to use BBCode-style[bracket]
syntax. Ick.[↩]
Leave a Reply