Skip to content


Subversion checkout URL

You can clone with
Download ZIP
markdown2: A fast and complete implementation of Markdown in Python
Python HTML Tcl Perl PHP Makefile
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Markdown is a light text markup format and a processor to convert that to HTML. The originator describes it as follows:

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).


This is a fast and complete Python implementation of Markdown. It was written to closely match the behaviour of the original Perl-implemented There is another Python However, at least at the time this project was started, was faster (see the Performance Notes) and, to my knowledge, more correct (see Testing Notes). That was a while ago though, so you should still consider Python-markdown for your usage.


To install it in your Python installation run one of the following:

pypm install markdown2      # if you use ActivePython (
pip install markdown2
python install

However, everything you need to run this is in "lib/". If it is easier for you, you can just copy that file to somewhere on your PythonPath (to use as a module) or executable path (to use as a script).

Quick Usage

As a module:

>>> import markdown2
>>> markdown2.markdown("*boo!*")  # or use `html = markdown_path(PATH)`

>>> markdowner = Markdown()
>>> markdowner.convert("*boo!*")
>>> markdowner.convert("**boom!**")

As a script (CLI):

$ python > foo.html

I think pip-based installation will enable this as well:

$ markdown2 > foo.html

See the project wiki, lib/ docstrings and/or python --help for more details.

Extra Syntax (aka extensions)

Many Markdown processors include support for additional optional syntax (often called "extensions") and markdown2 is no exception. With markdown2 these are called "extras". Using the "footnotes" extra as an example, here is how you use an extra ... as a module:

$ python --extras footnotes > foo.html

as a script:

>>> import markdown2
>>> markdown2.markdown("*boo!*", extras=["footnotes"])

There are a number of currently implemented extras for tables, footnotes, syntax coloring of <pre>-blocks, auto-linking patterns, table of contents, Smarty Pants (for fancy quotes, dashes, etc.) and more. See the Extras wiki page for full details.


The python-markdown2 project lives at (Note: On Mar 6, 2011 this project was moved from Google Code to here on Github.) See also, markdown2 on the Python Package Index (PyPI).

The change log:

To report a bug:

Test Suite

This markdown implementation passes a fairly extensive test suite. To run it:

cd test && python

If you have the mk tool installed you can run the test suite with all available Python versions by running:

mk test

The crux of the test suite is a number of "cases" directories -- each with a set of matching .text (input) and .html (expected output) files. These are:

tm-cases/                   Tests authored for python-markdown2 (tm=="Trent Mick")
markdowntest-cases/         Tests from the 3rd-party MarkdownTest package
php-markdown-cases/         Tests from the 3rd-party MDTest package
php-markdown-extra-cases/   Tests also from MDTest package

See the Testing Notes wiki page for full details.

Something went wrong with that request. Please try again.