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.
e.g. http://dpaste.com/hold/102141/
or
<?xml version="1.0" encoding='UTF-8'?>
<painting>
<img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/>
<caption>This is Raphael's "Foligno" Madonna, painted in
<date>1511</date>-<date>1512</date>.</caption>
</painting>
I'm aware of this question, but mine is not about the mechanics of escaping the code, it's about the UI.
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.
I have found SyntaxHighlighter (http://alexgorbatchev.com) to work well within the Django part of my site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With