Setting up Pygments with Markdown

November 21, 2009

There's some confusion out there about how to set up Pygments with Markdown. The Pygments website suggests that you add a text preprocessor, but it's simpler than that.

This code takes a markdown formatted file and converts it to HTML formatted text including pygments based source code. When formatting code in the pygments file, use four leading spaces and prefix the code with :::lexer, for example :::python.

self.body_html = markdown(lMarkdownSource, ['codehilite'])