Efficient syntax highlighting in your blog
May 12, 2010
Dick Brouwer
1 minute read

Many blogs seems to use alexgorbatchev’s scripts, but I found those a little sluggish in use. Code.google.com uses Google Code Prettify. It works great and simpler to install (plus has nice features like auto language detection).

You basically add the following js files to your blog’s custom HTML <head> section:

And add onload=“prettyPrint()” to your document’s <body> tag. Wrap your code in pre tags to colorize <pre class=“prettyprint”></pre>

(if you can’t store the files on your own server, use the hosted version at: http://google-code-prettify.googlecode.com/svn/trunk/src/)

Another cool option is to use the :TOhtml function in Vim (if you use vim). This will create html with appropriate color tags. If you like CSS better, set :let html_use_css = 1.

UPDATE: Nevermind, I switched to Github’s Gists instead. Much nicer.



comments powered by Disqus