In an earlier post a commenter asked for something other than grey-on-black syntax highlighting for source code.

I originally tried using the sourcecode macro at wordpress.com but it didn't work with my theme. I then turned to TextMate but didn't find an immediate solution but fortunately stumbled upon Pygments which was exactly what I wanted. Here's the highlighted source for the highlight script itself:

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

code = open(__file__).read()
print highlight(code, PythonLexer(), HtmlFormatter(
  full=False,
  style="native",
  noclasses=True))

I have not upgraded to use non-standard CSS so all the color is in-lined with the tags making for a bigger page download and an ugly entry in MarsEdit — I can live with this for now.

Categories: development 
Tags: pygments  python 
comments powered by Disqus