module documentation

HTML utilities suitable for global use.

Class MLStripper Undocumented
Class Urlizer Convert any URLs in text into clickable links.
Function avoid_wrapping Avoid text wrapping in the middle of a phrase by adding non-breaking spaces where there previously were normal spaces.
Function conditional_escape Similar to escape(), except that it doesn't operate on pre-escaped strings.
Function escape Return the given text with ampersands, quotes and angle brackets encoded for use in HTML.
Function escapejs Hex encode characters for use in JavaScript strings.
Function format_html Similar to str.format, but pass all arguments through conditional_escape(), and call mark_safe() on the result. This function should be used instead of str.format or % interpolation to build up small HTML fragments.
Function format_html_join A wrapper of format_html, for the common case of a group of arguments that need to be formatted using the same format string, and then joined using 'sep'. 'sep' is also passed through conditional_escape.
Function html_safe A decorator that defines the __html__ method. This helps non-Django templates to detect classes whose __str__ methods return SafeString.
Function json_script Escape all the HTML/XML special characters with their unicode escapes, so value is safe to be output anywhere except for inside a tag attribute. Wrap the escaped JSON in a script tag.
Function linebreaks Convert newlines into <p> and <br>s.
Function smart_urlquote Quote a URL if it isn't already quoted.
Function strip_spaces_between_tags Return the given HTML with spaces between tags removed.
Function strip_tags Return the given HTML with all tags stripped.
Function urlize Undocumented
Variable urlizer Undocumented
Function _strip_once Internal tag stripping utility used by strip_tags.
Variable _js_escapes Undocumented
Variable _json_script_escapes Undocumented
def avoid_wrapping(value): (source)

Avoid text wrapping in the middle of a phrase by adding non-breaking spaces where there previously were normal spaces.

def conditional_escape(text): (source)

Similar to escape(), except that it doesn't operate on pre-escaped strings. This function relies on the __html__ convention used both by Django's SafeData class and by third-party libraries like markupsafe.

Return the given text with ampersands, quotes and angle brackets encoded for use in HTML. Always escape input, even if it's already escaped and marked as such. This may result in double-escaping. If this is a concern, use conditional_escape() instead.

@keep_lazy(SafeString)
def escapejs(value): (source)

Hex encode characters for use in JavaScript strings.

def format_html(format_string, *args, **kwargs): (source)

Similar to str.format, but pass all arguments through conditional_escape(), and call mark_safe() on the result. This function should be used instead of str.format or % interpolation to build up small HTML fragments.

def format_html_join(sep, format_string, args_generator): (source)

A wrapper of format_html, for the common case of a group of arguments that need to be formatted using the same format string, and then joined using 'sep'. 'sep' is also passed through conditional_escape. 'args_generator' should be an iterator that returns the sequence of 'args' that will be passed to format_html. Example: format_html_join(' ', "<li>{} {}</li>", ((u.first_name, u.last_name) for u in users))

def html_safe(klass): (source)

A decorator that defines the __html__ method. This helps non-Django templates to detect classes whose __str__ methods return SafeString.

def json_script(value, element_id=None): (source)

Escape all the HTML/XML special characters with their unicode escapes, so value is safe to be output anywhere except for inside a tag attribute. Wrap the escaped JSON in a script tag.

@keep_lazy_text
def linebreaks(value, autoescape=False): (source)

Convert newlines into <p> and <br>s.

def smart_urlquote(url): (source)

Quote a URL if it isn't already quoted.

@keep_lazy_text
def strip_spaces_between_tags(value): (source)

Return the given HTML with spaces between tags removed.

@keep_lazy_text
def strip_tags(value): (source)

Return the given HTML with all tags stripped.

@keep_lazy_text
def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): (source)

Undocumented

Undocumented

def _strip_once(value): (source)

Internal tag stripping utility used by strip_tags.

_js_escapes = (source)

Undocumented

_json_script_escapes = (source)

Undocumented