Jump to >

reviewboard.reviews.markdown_utils

markdown_escape(text)[source]

Escapes text for use in Markdown.

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

This is deprecated. Please use djblets.markdown.markdown_escape instead.

markdown_unescape(escaped_text)[source]

Unescapes Markdown-escaped text.

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

This is deprecated. Please use djblets.markdown.markdown_unescape instead.

markdown_escape_field(obj, field_name)[source]

Escapes Markdown text in a model or dictionary’s field.

This is a convenience around markdown_escape to escape the contents of a particular field in a model or dictionary.

markdown_unescape_field(obj, field_name)[source]

Unescapes Markdown text in a model or dictionary’s field.

This is a convenience around markdown_unescape to unescape the contents of a particular field in a model or dictionary.

normalize_text_for_edit(user, text, rich_text, escape_html=True)[source]

Normalizes text, converting it for editing.

This will normalize text for editing based on the rich_text flag and the user settings.

If the text is not in Markdown and the user edits in Markdown by default, this will return the text escaped for edit. Otherwise, the text is returned as-is.

markdown_render_conditional(text, rich_text)[source]

Return the escaped HTML content based on the rich_text flag.

is_rich_text_default_for_user(user)[source]

Returns whether the user edits in Markdown by default.

markdown_set_field_escaped(obj, field, escaped)[source]

Escapes or unescapes the specified field in a model or dictionary.

iter_markdown_lines(markdown_html)[source]

Iterates 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.

This is deprecated. Please use djblets.markdown.iter_markdown_lines instead.

get_markdown_element_tree(markdown_html)[source]

Returns an XML element tree for Markdown-generated HTML.

This will build the tree and return all nodes representing the rendered Markdown content.

This is deprecated. Please use djblets.markdown.get_markdown_element_tree instead.

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.

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

This is deprecated. Please use djblets.markdown.sanitize_illegal_chars_for_xml instead.

render_markdown(text)[source]

Renders Markdown text to HTML.

The Markdown text will be sanitized to prevent injecting custom HTML. It will also enable a few plugins for code highlighting and sane lists.

render_markdown_from_file(f)[source]

Renders Markdown text to HTML.

The Markdown text will be sanitized to prevent injecting custom HTML. It will also enable a few plugins for code highlighting and sane lists.