HTML utilities suitable for global use.
Class |
|
Undocumented |
Class |
|
Convert any URLs in text into clickable links. |
Function | avoid |
Avoid text wrapping in the middle of a phrase by adding non-breaking spaces where there previously were normal spaces. |
Function | conditional |
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 |
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 |
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 |
A decorator that defines the __html__ method. This helps non-Django templates to detect classes whose __str__ methods return SafeString. |
Function | json |
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 |
Quote a URL if it isn't already quoted. |
Function | strip |
Return the given HTML with spaces between tags removed. |
Function | strip |
Return the given HTML with all tags stripped. |
Function | urlize |
Undocumented |
Variable | urlizer |
Undocumented |
Function | _strip |
Internal tag stripping utility used by strip_tags. |
Variable | _js |
Undocumented |
Variable | _json |
Undocumented |
Avoid text wrapping in the middle of a phrase by adding non-breaking spaces where there previously were normal spaces.
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.
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.
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))
A decorator that defines the __html__ method. This helps non-Django templates to detect classes whose __str__ methods return SafeString.
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.