discount is a ctypes binding of David Loren's Discount, a C implementation of John Gruber's Markdown.
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).
The discount Python module contains two things of interest:
* libmarkdown, a submodule that provides access to the public C functions defined by Discount.
* Markdown, a helper class built on top of libmarkdown, providing a more familiar Pythonic interface
Using the Markdown class
The Markdown class wraps the c functions exposed in the libmarkdown submodule and handles the ctypes leg work for you. If you want to use the Discount functions directly, skip to the next section about libmarkdown.
Let's take a look at a simple example:
mkd = discount.Markdown(sys.stdin)
Markdown takes one required argument, input_file_or_string, the markdown formatted data. If this argument is a file-like object, the file must be a real OS file descriptor, i.e. sys.stdin yes, a StringIO object, no. The argument is otherwise assumed to be a string-like object. The same is true for Markdown methods that write HTML output to files.
Otherwise, the data is assumed to be string-like. Markdown also has methods for getting the output as a string, instead of writing to a file-like object. Let's look at a modified version of the first example, this time using strings:
mkd = discount.Markdown('`test`')
The Markdown class constructor also takes optional boolean keyword arguments.
Generate table-of-contents headers (each generated < h1 >, < h2 >, etc will include a id="name" argument.) Use get_html_toc() or write_html_toc() to generate the table-of-contents itself.
Disable relaxed emphasis and superscripts.
Greedily expand links; if a url is encountered, convert it to a hyperlink even if it isn't surrounded with < >s.
Be paranoid about how  is expanded into a link - if the url isn't a local reference, http://, https://, ftp://, or news://, it will not be converted into a hyperlink.
Do not process the pandoc document header, but treat it like regular text.
Do not allow < a or expand  into a link.
Do not allow < img or expand ! into a image.
Don't process PHP Markdown Extra tables.
Disable SmartyPants processing.
Disable all embedded HTML by replacing all
What's New in This Release: [ read full changelog ]
· version 2.1.2 tweaks table handling so that tables with leading |’s won’t end up generating empty false s, and that tables with trailing |’s won’t end up getting those pipes included in the output.