« django-lastfm More Feeds »
.

A BeautifulSoup with Django and Pygments

Just 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 }}

Comment

  1. 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
  2. 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. :-)

New comment

Required
Required, but not displayed
Optional
Format using ReStructuredText (Quickref)
  • *emphasis*, **strong**, ``inline code``
  • Blockquotes: indent each line to be quoted
  • Links w/ description: `Description <URL>`_
  • Highlighted code blocks: See here