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