What Javascript libraries can you recommend for syntax highlighting <code> blocks in HTML?
(One suggestion per answer please).
What Javascript libraries can you recommend for syntax highlighting <code> blocks in HTML?
(One suggestion per answer please).
I recently developed one called rainbow.
The main design goal was to make the core library really small and make it really easy for developers to extend.
See http://rainbowco.de.
If you're using jQuery there's Chilli:
http://code.google.com/p/jquery-chili-js/
All you have to do is include the jquery-chili.js and recipes.js, and do the highlight with
$("code").chili();
It should figure out the language by itself.
I'm very happy with SHJS. It supports a bevy of languages and seems pretty fast and accurate.
Here's an example where I use it on my blog. I'm using my own custom CSS file that simulates Coda's syntax highlighting. Email me if you'd like to use it.
jQuery.Syntax is an extremely fast and lightweight syntax highlighter. It has dynamic loading of syntax source files and integrates cleanly using CSS or modelines.
It was developed specifically to fill a gap - that is: a fast, clean, client-side syntax parser.
I'm not being argumentative but just thought it worth mentioning that if you're using a CMS or blog platform then using a backend highlighter is better for obvious reasons — Have a look at Geshi(http://qbnz.com/highlighter/) if you're interested. Actually you could set up your server to parse HTML content through a backend technology — so there is no need for the JS highlighters at all. (The only functionality they add is the ability to print/copy[using swf].)
This article at the Web Resources Depot lists a bunch of options for highlighting code, some of which use Javascript. It was published on 4th May 2009.