Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

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
share|improve this answer
    
The only problem I had with this method is that it expect you to mark your code tags with a specific class, which is not nice if you are using Markdown syntax. Luckily, it's not a problem to do it using JS on page load. –  Mladen Jablanović Dec 12 '10 at 7:48
add comment

You can use hilite.me

hilite.me converts your code snippets into pretty-printed HTML format, easily embeddable into blog posts, emails and websites.
Just copy the source code to the left pane, select the language and the color scheme, and click "Highlight!". The HTML from the right pane can now be pasted to your blog or email, no external CSS or Javascript files are required.
share|improve this answer
add comment

I use Github's gist to do this. Paste in and create the gist and you can then embed them in any web page including tumblr.

share|improve this answer
    
There's a problem here, it needs JS so if a user doesn't have it activated, or if a user is a search bot, your code stays invisible. –  Mladen Jablanović Dec 12 '10 at 7:52
    
I wish I could upvote this more than once. @MladenJablanović You can't use the majority of the web without JavaScript nowadays. I think that is not really an issue. –  Octavian Damiean Jan 21 '12 at 21:40
    
Can you give more detail on how to do this? I just tried it and gist renders the embed as script elements - Tumblr escapes these, even if you use HTML mode. Any ideas? –  cottsak Aug 16 '12 at 8:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.