Monday, February 6, 2012

Syntax highlighter for my blog posts

Adding a syntax highlighter to a blog is so much simpler than use to be. Since I am planning on posting a lot of code on this blog I wanted to make sure I have this in place as soon as possible. Fortunately this is as simple as adding css and js to the Blogger template and wrap the code around with <pre class="prettyprint"> tag. After testing a few of them I ended up using Google Prettify. I like how simple it is to integrate it and it auto picks up most of the languages, so I don't have to reference it. Yes I know I am lazy, but lazy programmer is good.:)
So here is the first test:
$(document).ready(function() {
   var syntaxHighlighting = 'Super Simple';
});

And a second one:
class Test(object):
    def __init__(self):
        self.test = True

And a third one:
- (void)sayIt
{
    NSString *str1 = @"Syntax highlight";
    NSString *str2 = @"Super Simple";
    NSLog(@"%@ %@", str1, str2);
}

I chose the desert style even though my IDEs have light background, but it helps to make it standout in a post.