Jump to >



Escape text for use in Markdown.

This will escape the provided text so that none of the characters will be rendered specially by Markdown.


Unescape Markdown-escaped text.

This will unescape the provided Markdown-formatted text so that any escaped characters will be unescaped.


Iterate over lines of Markdown, normalizing for individual display.

Generated Markdown HTML cannot by itself be handled on a per-line-basis. Code blocks, for example, will consist of multiple lines of content contained within a <pre> tag. Likewise, lists will be a bunch of <li> tags inside a <ul> tag, and individually do not form valid lists.

This function iterates through the Markdown tree and generates self-contained lines of HTML that can be rendered individually.


Return an XML element tree for Markdown-generated HTML.

This will build the tree and return all nodes representing the rendered Markdown content. The element tree is generated using Python’s xml.dom.minidom.

Parameters:markdown_html (bytes or unicode) – The Markdown-generated HTML to parse.
Returns:The list of nodes representing the Markdown-generated HTML.
Return type:xml.dom.minicompat.NodeList

Sanitize a string, removing characters illegal in XML.

This will remove a number of characters that would break the XML parser. They may be in the string due to a copy/paste.

Note that this will not perform any security-related sanitization of the HTML. It’s purely a parsing aid for dealing with illegal characters.

This code is courtesy of the XmlRpcPlugin developers, as documented here: http://stackoverflow.com/a/22273639

Parameters:s (unicode) – The string to sanitize.
Returns:The resulting sanitized HTML.
Return type:unicode
render_markdown_from_file(f, **markdown_kwargs)[source]

Render Markdown text from a file stream to HTML.

  • f (file or io.BytesIO) – The byte stream to read from.
  • **markdown_kwargs (dict) – Keyword arguments to pass to markdown.markdownFromFile().

The resulting Markdown-rendered HTML.

Return type: