Monday, August 8, 2011

Code highlight in Blog

The most simple solution may be using googe-code-pretifier. It will load a javascript library when your blog is rendered and it's able to automatically detect the programming language and highlight your code properly.
  1. add following two lines in your blog template:
  2. <link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' rel='stylesheet' type='text/css'/>
    <script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'></script>
    
  3. Add the javascript library to the 'body' tag in your blog template:
  4. <body onload='prettyPrint()'>
    
  5. wrap the code with pre tag:
  6. <pre class="prettyprint"> ... # Your code goes here </pre> 
    

No comments:

Post a Comment