created by Brian LeRoux & Andrew Lunny. sparodically uncurated by David Trejo.

2010 04 31 syntax highlighting serverside with google prettyfy

This is much more awesome. I have to thank the guys at HowToNode.org for the idea in their WheatJS static site blog engine. Essentially, it all boils down to running the rather awesome Google Code Prettyfy serverside.

The only remaining problem with the syntax highlighting is now nested <code> elements have to be escaped to display correctly in the final render.

    // replace the raw code blocks with prettyfied html
    t = t.replace(/&lt;code&gt;[^&lt;]+&lt;\/code&gt;/g, function(code) {
        return prettyfy(code.match(/&lt;code&gt;([\s\S]+)&lt;\/code&gt;/)[1]);
    });    

Perhaps, in the future, a quick routine to fetch only the root code elements rather than blinding fetching all of them. Problem: more solved than before!

Fork me on GitHub