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=”http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js” type=”text/javascript”>
</pre>

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.

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

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.

<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
<pre>
</pre>

Links

Duffblog 2.0: Google Code Prettify

Categories:

Updated:

Leave a Comment