Tuesday, September 27, 2011

Syntaxhighlightning 3.0

I like blogger, it allows me to change the html template which in turn allows me to add custom javascript. I looked for a way to highlight code in a blog. For me the obvious way is to use the client i.e. javascript to do the job to highlight code. And of course there are dedicated folks that has done the job -  alex.gorbatchev@gmail.com is one of them that has created SyntaxHighlighter. Thanx to him this task is a peace of cake to achieve.

An example, I have imported CSS and javascript that Alex so kindly shared on Amazon S3, use and donate, it is worth it. Then wrap the code in PRE tags with a style that define the language in use. Following code example actually uses Alexs syntax highlighting for Javascript:

    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }

1 comment:

  1. Nice! I use http://coderay.rubychan.de/ on my blog but I think I will switch to embedded gists instead. https://gist.github.com/

    ReplyDelete