Monday, October 20, 2008

Syntax Highlighting via Javascript with SHJS

After doing my own code syntax highlighting for the web by injecting span tags into code snippets using lisp functions inside emacs, I realized it's not the way to go. The right way to do this would be a javascript function that would decorate the code after it's been sent to the browser. I ran across SHJS, Syntax Highlighting in JavaScript on sourceforge. SHJS is very easy to set up and gives great results in many languages.
I've attached two graphics, one using Watir in Ruby and the other a little C#.
If you publish code on the internet you should use SHJS or something like it. It's just too easy not to use and it leaves your HTML very clean.
You can see my results for Ruby, C#, Java, Perl, JavaScript.

No comments: