Sunday, 13 June 2010

Hello World

Is the Google pretty printer working? Will my code samples come out looking rather nice?

class HelloWorld{
public static void main(String[] args){
String hw="Hello World";

Looks like it is. Thanks to Luka Marinko's post on how to set it up.

I modified Luka's recipe slightly, as I found that setting the onload attribute on the body worked for the blog, but was giving me Javascript errors when I tried to use the blogger layout/design tools. All I did was move the onload up to a script tag in the head of the page, and check for the presence of the function before calling it. So, my template looks like this:

<link href=''
rel='stylesheet' type='text/css'/>
<style type='text/css'>
font-size: 0.9em;
padding: 4px; background-color:#adf;
border-radius: 8px; -webkit-border-radius: 8px; -moz-border-radius: 8px;
pre.lang-html{ background-color: #afd; }
<script src=''
<script type='text/javascript'>
if (prettyPrint){ prettyPrint(); }

which has the added advantage of keeping all the changes in one place.

In sequence, what I'm doing is:

  1. Importing the prettyprint CSS stylesheet

  2. Adding a few extra styles to put the text in funky rounded boxes (where the browser supports it), and make the text a bit smaller so I have to worry less about truncating lines

  3. Import the prettyprint library code from google code

  4. Add a script to safely invoke the pretty printer

1 comment:

  1. I really enjoyed reading your post.
    Thanks for this post. It Very nice Blog.
    It was a very good Blog. I like it. Thanks for sharing knowledge.
    Ask you to share good Blog again.............
    excel interpolation function