Published on

18 Feb 2008

Updated on

22 Feb 2008,

26 Oct 2008,

13 May 2009,

5 Jul 2009

Markdown extensions

John Grubers’s Markdown is a specification and a program for turning plain text into HTML. This is already very convenient, but sometimes you would like to automate a little more.

This site is written in Python, so it makes sense to use the Python port of John Gruber’s original implementation. In addition to integrating better with a Python-based site, it is comparatively easy to extend this particular implementation. Quite a few extensions are available – and it’s easy to write additional extensions.

I have written an extension that adds several typographic niceties – “smart” quotes, en– and em—dashes, and ellipses… This is mostly automated (en- and em-dashes must be manually specified by -- or ---). The specific rules used can be configured (although that interface is not particularly user-friendly), and backslash-escaped characters will not be considered (-- becomes –, but \-\- becomes --). Most concepts were stolen from SmartyPants or Typogrify, but the implementation is my own.

I also have a rather trivial extension that turns headers into tags. Note that it does not generate the required images – PIL or another imaging library may be helpful.

At some point in the past, these extensions worked with Python-Markdown 1.x (the above extensions work with 2.x). This page also included something akin to 2.x’ block parsers in 1.x. It also included an extension that basically implemented the CSS selectors :first-child and + using classes, which may be useful if trying to support IE≤6. Finally, the version of the typography extension that worked with 1.x had some additional features (making CAPS stand out slightly less by making them smaller and preventing widows). All of this is available from the repository, in the directory webpy/mdx/. However, there is a reason I stopped using it…