I came across a link today that would allow you to post “pretty” code in any HTML page. I’ve had plenty of problems (as have others) posting well-formatted source code to my Blogger-based blog. I’ve wanted to correct this problem for some time, and this project appears to be a decent solution. Here’s an example:
function chooseWinner() { $('p3').removeClassName('winner'); participantBo.chooseWinnerForEvent(eventId, function(data) { people = $A(data); updateDivs(); intervalId = setInterval(doShift, 500); });}
Now that isn’t too bad is it? There seems to be a bit of a delay as the Javascript is loaded, but I think that’s more a symptom of my connection than it is a problem with the script.
Here’s how you can take advantage of this solution (quoted from http://google-code-prettify.googlecode.com/svn/trunk/README.html):
- Download a distribution
- Include the script and stylesheets in your document
(you will need to make sure the css and js file are on your server, and
adjust the paths in the script and link tag)
<link href="prettify.css" type="text/css" rel="stylesheet" /><script type="text/javascript" src="prettify.js"></script>
- Add
onload="prettyPrint()"to your
document’s body tag.
- Modify the stylesheet to get the coloring you prefer
- Put code snippets in
<pre class="prettyprint">...</pre>
or <code class="prettyprint">...</code>
and it will automatically be pretty printed.








Posted by Shane on February 6, 2008 at 10:17 pm
I found this blog entry that generates formatted code:http://formatmysourcecode.blogspot.com/