Skip to main content

Module strings

Module strings 

Source

Statics§

HTML_TAG_REGEX
One HTML tag, < to the next >.
IETF_LANGUAGE_CODE_REGEX 🔒

Functions§

decode_html_entities
Decodes the entities rich text commonly holds: &amp;, &lt;, &gt;, &quot;, &#39; and &nbsp; (as a space). Decodes once, so &amp;lt; becomes &lt;. Borrows the input when it has no &.
escape 🔒
escape_html
text safe both as HTML text content and inside a quoted attribute value.
escape_html_text
text as HTML text content: &, < and > as entities. Leaves quotes as they are, so it isn’t safe inside attribute values; see escape_html.
generate_easily_writable_random_string
generate_random_string
is_ietf_language_code_like
Checks whether the string is IETF language code where subtags are separated with underscore.
non_empty_trimmed
Trims the string and returns None if the trimmed result is empty.
slugify
A URL path segment made of a title: its letters and digits, of any script, in lowercase, with each run of other characters as one - and none at either end. Empty when the title has no letters or digits, so the caller picks a fallback.
strip_html_tags
Removes all HTML tags from the input, leaving only the text content. Borrows the input when it has no tags.
truncate_utf8_at_boundary
Truncates UTF-8 text to a max byte length at a valid char boundary.