A BeautifulSoup with Django and Pygments
Saturday, October 24, 2009Just added syntax highlighting using BeautifulSoup and Pygments. I took the SaltyCrane Blog for inspiration, but in contrast to it, I implemented it as a template filter in a separate application. This is surely not the most performant way, but I’m planning to use memcache, so I think this is ok.
Here an example how to use the filter:
{% load highlight_code %}
{{ my_var_with_code|highlight|safe }}
2 Comments on «A BeautifulSoup with Django and Pygments»
nfo on January 13, 2010 at 11:17:
Hi, why not share the filter code..?
At moment i despair adding syntax highlighting to my django test blog. In special when code in mixed up like php+html+javascrip.
best regards nfo
Stefan on January 13, 2010 at 19:27:
I switched from HTML markup to ReST and thus forgot about this. I’ll post something on this later. :-)