Saturday, 9 June 2007

Blogger & Google Code Prettify

I wanted to improve the look of my java source code examples that i have in my blog posts. I came across the google-code-prettify project. The main hassel is the java script and css files need to be included in the blog template. A bit of investigation and i noticed i could link the two required files from the project web site. [Granted, if they change the location of the files we're screwed.]

1: Add the java script file to the blog template.

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


The complete java script src file path : http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js

2: Link the css file to the blog template.

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


The complete css src file path : http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css

3: Update the blog template to call the prettyPrint() function when loaded.

In the blog template file add the call to the prettyPrint() function to the body onload tag.

<body onload="prettyPrint();">


4: Use the prettyprint command in your blog post.

<pre class="prettyprint" id="xml">
your code
<pre>


Links

Duffblog 2.0: Google Code Prettify

No comments: