Showing posts with label bloging. Show all posts
Showing posts with label bloging. Show all posts

Saturday, October 11, 2008

Code highlighting on blogger

Ok lets see if new highlighter works.


#! /bin/env python

def python_funct():
a = a + b
print "Hello Highlighted code"

class Foo(Bar):
pass


So how to do it?
Simply use googles own client side code highlighting library .


Its easy. Just include this two lines at top of your blogger template:

<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"> </script>



And change body tag in your template to include onload="prettyPrint()":
>
...
<body onload='prettyPrint()'>
...


And thats it. Now all you have to do when you want highlighted piece of code in your blog is to use.


<pre class="prettyprint">
... # Your code goes here
</pre>
EDIT: Urls to prettyfy.js and prettyfy.css were wrong. They are fixed now.