Blogger & Google Code Prettify

less than 1 minute read

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.

<pre class="prettyprint" id="javascript"><script src=”” type=”text/javascript”>

The complete java script src file path :

2: Link the css file to the blog template.

<pre class="prettyprint" id="javascript"><link rel=”stylesheet” type=”text/css” ref=””/>

The complete css src file path :

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.

<pre class="prettyprint" id="xml"><body onload=”prettyPrint();”></pre>

4: Use the prettyprint command in your blog post.

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


Duffblog 2.0: Google Code Prettify



Leave a Comment