I'm looking for something I can use within django to display preformatted code. Ideally this would include out-of-the-box syntax highlighting for various programming languages, although just starting with something that displayed html and xml well would be a good starting point.

Does something like this exist?

Basically I am looking for something like the widget dpaste (and also stack overflow) use to display code.



<?xml version="1.0" encoding='UTF-8'?>
  <img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/>
  <caption>This is Raphael's "Foligno" Madonna, painted in

I'm aware of this question, but mine is not about the mechanics of escaping the code, it's about the UI.

+6  A: 

You could use Pygments to do the syntax highlighting and get HTML to display.

Example code :

from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter

highlighted = highlight('# Some Python code', PythonLexer(), HtmlFormatter())

Also see the official documentation.

Pierre Bourdon
+1  A: 

I have found SyntaxHighlighter ( to work well within the Django part of my site.