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?
If you have too many, I would say go for google-code-prettify.
Check some examples and here is the setup:
- 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"/>
- Add onload="prettyPrint()" to your document's body tag.
- Modify the stylesheet to get the coloring you prefer
The only problem I had with this method is that it expect you to mark your
codetags 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. Dec 12, 2010 at 7:48
You can use hilite.me
hilite.me converts your code snippets into pretty-printed HTML format, easily embeddable into blog posts, emails and websites.
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.
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. Dec 12, 2010 at 7:52
Can you give more detail on how to do this? I just tried it and gist renders the embed as
scriptelements - Tumblr escapes these, even if you use HTML mode. Any ideas?– cottsakAug 16, 2012 at 8:38