webhelpers.html.converters

Functions that convert from text markup languages to HTML and back.

webhelpers.html.converters.format_paragraphs(text, preserve_lines=False)

Convert text to HTML paragraphs.

text:
the text to convert. Split into paragraphs at blank lines (i.e., wherever two or more consecutive newlines appear), and wrap each paragraph in a <p>.
preserve_lines:
If true, add <br /> before each single line break
webhelpers.html.converters.markdown(text, markdown=None, **kwargs)

Format the text to HTML with Markdown formatting.

Markdown is a wiki-like text markup language, originally written by John Gruber for Perl. The helper converts Markdown text to HTML.

There are at least two Python implementations of Markdown. Markdown <http://www.freewisdom.org/projects/python-markdown/>`_is the original port, and version 2.x contains extensions for footnotes, RSS, etc. Markdown2 is another port which claims to be faster and to handle edge cases better.

You can pass the desired Markdown module as the markdown argument, or the helper will try to import markdown. If neither is available, it will fall back to webhelpers.markdown, which is Freewisdom’s Markdown 1.7 without extensions.

IMPORTANT: If your source text is untrusted and may contain malicious HTML markup, pass safe_mode="escape" to escape it, safe_mode="replace" to replace it with a scolding message, or safe_mode="remove" to strip it.

webhelpers.html.converters.nl2br(text)
Insert a <br /> before each newline.
webhelpers.html.converters.textilize(text, sanitize=False)

Format the text to HTML with Textile formatting.

This function uses the PyTextile library which is included with WebHelpers.

Additionally, the output can be sanitized which will fix tags like <img />, <br /> and <hr /> for proper XHTML output.

Previous topic

webhelpers.html.builder

Next topic

webhelpers.html.grid