So you’ve got a Tumblr blog. And you craft code. From time to time, you might want to show that code off to the world. May I submit to you Google Code Prettify? This is the dogfood that Google uses to power code.google.com, so it has to be good, right? (You better say yes lest all your email, documents, and TV channels go bye-bye.) Here’s what you’ll want to do.
Customize your Tumblr blog’s theme and enable custom HTML. At the bottom of the head section, add the prettify css and js files. You’ll also need to call the prettyPrint method when the body’s onload event fires. Additionally, you might want to spruce up the default pre.prettyprint styles to match your theme.
Now, all you’ll need to do is get your code into your post. Just fire up the HTML editor, and wrap your code in pre and code tags. If you’re working with an XMLish language, you’ll need to escape the angle brackets. Instead of doing this by hand, you can paste it into the WYSIWYG editor and it will do it for you.
Here’s an example of what the above snippet looks like in the Tumblr HTML editor:
Well, now I’ve gone and done it. I’ve started blogging. I mean, give me a break. How can can any self-respecting programmer not have some form of online presence? I don’t have a Facebook account and my tweets are lame and spaced about 6 months apart.