Tumblr – How to Show Color-Coded Python Snippets

tumblr

I have a Tumblr-managed blog, on which I post a lot of Python-related posts. How do I make the Python snippets in my posts show color-coded?

Best Answer

If you have too many, I would say go for google-code-prettify.

All you have to do is to include some javascript, css and then you're done.

Check some examples and here is the setup:

  1. Download a distribution
  2. 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>
  3. Add onload="prettyPrint()" to your document's body tag.
  4. Modify the stylesheet to get the coloring you prefer