djblets.markdown¶
- markdown_escape(text)[source]¶
Escape text for use in Markdown.
This will escape the provided text so that none of the characters will be rendered specially by Markdown.
- markdown_unescape(escaped_text)[source]¶
Unescape Markdown-escaped text.
This will unescape the provided Markdown-formatted text so that any escaped characters will be unescaped.
- iter_markdown_lines(markdown_html)[source]¶
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.
- get_markdown_element_tree(markdown_html)[source]¶
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
.
- sanitize_illegal_chars_for_xml(s)[source]¶
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
- render_markdown_from_file(f, **markdown_kwargs)[source]¶
Render Markdown text from a file stream to HTML.
- Parameters:
f (
file
orio.BytesIO
) – The byte stream to read from.**markdown_kwargs (
dict
) – Keyword arguments to pass tomarkdown.markdownFromFile()
.
- Returns:
The resulting Markdown-rendered HTML.
- Return type: