Skip to main content

Module text

Module text 

Source
Expand description

Text utilities — slugify, html_escape, truncate. Text utilities — slug generation, HTML escaping, truncation.

Small zero-dep helpers for the common bits of text-handling boilerplate every web app needs.

Functions§

html_escape
Escape a string for safe insertion into HTML element content or double-quoted HTML attributes.
slugify
Convert a string into a URL-safe slug.
slugify_unicode
Like slugify but preserves Unicode letters/digits (lowercased). Useful when your URL infrastructure handles UTF-8 paths.
truncate
Truncate s to at most max_chars characters. If truncation happens, append suffix (typically "…" or "...").
unique_slug
Generate a unique slug by appending -2, -3, … until is_taken returns false. Useful for URL slugs where the natural slugify(title) might collide with an existing row.
unique_slug_async
Async variant of unique_slug for DB-backed uniqueness checks.