Code Highlighting

Back in Drupal 4.x days I used some GeSHi module, I slapped together with dp. A few weeks later an offical module popped up and I stopped caring about our one.

However, that project is now abandoned and there is no GeSHi module for 5.x anymore. There are some patches for 5.x, but it actually crashed Apache. No idea how that's supposed to work, but it seems to be reproducible. Making a proper test case out of those zillion files was too much work tho.

GeSHi is sorta heavy, therefore I looked at a few client side alternatives.

star-light
The first one was star-light, which uses HTML Components (an ancient concept I never heard of before). The performance was pretty good for a JS highlighter, but it doesn't work with Opera. Meh.

dp.SyntaxHighlighter
The next one, I checked out was another JS highlighter called dp.SyntaxHighlighter. It works across browsers, it's also rather compact and modular, and it has fancy features such as view as plain and copy to clipboard (via some swf cheat). However, the performance is a downright horrible and sort of random. Around 50 lines of code is the maximum you should put on a single page. Putting it into a test module was pretty easy tho.

In it's current state the dp.SyntaxHighlighter is a bit crap, since I need highlighting for up to 100 lines. Sure, many snippets are shorter than that, but I really need some buffer zone. Always testing how much (and which kind of) lines are acceptable and adjusting the code/explanations accordingly is a bit too much trouble.

SHJS
The last one, I took a closer look at, was SHJS. It uses definitions from GNU Source-Highlight and it comes with support for 24 languages in minimal and full variations. And it's pretty fast to boot. Highlighting 400 lines of code isn't a problem (even with a 500mhz CPU).

Unfortunately there is no copy to clipboard function and it lacks other fancy features such as line numbers, but it's quite neat, fast and easy to integrate.

I choose you SHJS! :V

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options