Jump to >

This documentation covers the in-development release of Djblets. You can see the latest stable docs or all previous versions.



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.


markdown_html (bytes or unicode) – The Markdown-generated HTML to parse.


The list of nodes representing the Markdown-generated HTML.

Return type



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


s (unicode) – The string to sanitize.


The resulting sanitized HTML.

Return type


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