Google Code Prettify

So tonight I became insanely jealous of StackOverflow's syntax highlighting. When you post a question that contains code. the site formats it all nice and colorizes the text, fairly closely to how the IDE actually color codes it. I went hunting and I actually found what SO actually uses to do it.

http://code.google.com/p/google-code-prettify/

Google Code Prettify sets up in minutes. All you do is drop in the script, the css, and call prettyPrint() in the DOM ready.

You will have to add a CSS class ("prettyprint") to your <pre> or <code> tags and then all text inside will automatically be pretty-printed!

Like this:

if (GoogleCode.Prettify.IsAwesome)  
{
    MessageBox.Show("The Cake Is a Lie!");
}

Pretty slick.

Chev

Read more posts by this author.

comments powered by Disqus