Friday, September 10, 2010

JavaScript: best code highlighter I have seen

I needed JavaScript code highlighter for my recent project and having a gut feeling that someone has done it already, I decided to do a search rather than develop it myself. Not so much as a surprise it turned out to be good feeling and soon enough I ended up testing a dozen of different highlighters. I had spent good couple of hours before I found the one. Sharing is caring so here we go.

That beauty is called hightlight.js. You won't be disappointed especially if you are using jQuery, although it's a standalone library. It was created by talented Russian programmer Ivan Sagalaev who claims to be Software Maniac. He put together very simple documentation page which contains everything you need to know. It took me literally 5 minutes to download it, unpack it and get it working. Why do I think highlight.js is the best JavaScript highlighter?
  • supports 32 different types of syntax, including exotic ones like Lua, Lisp or Nginx
  • is a standalone library but is very easy to use with mootools, jQuery, prototype or any other JS library
  • can be used to highlight code injected to the DOM with JS (for some reason that didn't work for me with quite a few other libraries)
  • allows user to choose which nodes should be processed and does not force parsing the whole document
  • does not require being called upon document load event
  • is quite simplistic and is not trying to do 1000 things except from the one that you need; instead it does one thing and does it well: highlights code
Damn it, now I'm tempted to use it on my own old blog pages with code examples. Respect, Ivan!

2 comments:

  1. Wow... Thank you!
    Though I always keep saying that highlight.js is nothing without all its contributions from many good people: http://bazaar.launchpad.net/~isagalaev/%2Bjunk/highlight/annotate/head%3A/src/AUTHORS.en.txt

    ReplyDelete
  2. That's all right. I didn't want to keep the knowlege to myself. And thank you for the highlighter. Seriously, it made my day!

    ReplyDelete