« Back

Easy Syntax Highlighting

by Andrew Zeneski  •  published February 13, 2011
 

My blog was looking pretty good, but while thinking about finishing touches I felt it would be nice to add syntax highlighting to the code blocks.

The fact that I am using markdown2 for text formatting I assumed this task would not be trivial. I was wrong...

I added 3 lines to my template:

    <link rel="stylesheet" href="http://yandex.st/highlightjs/5.16/styles/github.min.css"/>
    <script src="http://yandex.st/highlightjs/5.16/highlight.min.js" type="text/javascript"></script>
    <script>hljs.initHighlightingOnLoad();</script>

Then all of a sudden, I had syntax highlighting. The highlight.js library handles everything and even works with content generated using markdown like text formatters.

« Back