Pygments is cool…

Pygments has been on my radar for a while, but I hadn’t looked closely at it until the other day, when I had a need to highlight some code fragments in a reST document that I’m writing. Hacking rst2html.py to do the necessary work was easy - just a copy-and-paste from some sample code in the docs. But then I hit a problem; my document includes code fragments written for both Python 2.5 and Python 3.0, and Pygments can handle the former but not the latter.

I delved into the source code with some trepidation, wondering how long it would take to hack a solution of some kind. I needn’t have worried. Pygments has good docs and a very clean design, so it took just a few minutes of study to figure out what was required. Less than fifteen minutes later, I had a Python3Lexer class plugged in and working!

If you want the code, it’s now been merged into Pygments’ Mercurial repository, courtesy of Pygments lead developer, Georg Brandl (Cheers, Georg!) Check it out with

  hg clone http://dev.pocoo.org/hg/pygments-main

Leave a Reply