Module

utils.text

Text processing utilities for Patitas.

Provides canonical implementations for common text operations like slugification.

Example:

>>> from patitas.utils.text import slugify
>>> slugify("Hello World!")
'hello-world'

Functions

slugify 4 str
Convert text to URL-safe slug with Unicode support. Preserves Unicode word cha…
def slugify(text: str, unescape_html: bool = True, max_length: int | None = None, separator: str = '-') -> str

Convert text to URL-safe slug with Unicode support.

Preserves Unicode word characters (letters, digits, underscore) to support international content. Modern web browsers and servers handle Unicode URLs.

Parameters
Name Type Description
text str

Text to slugify

unescape_html bool

Whether to decode HTML entities first (e.g., & -> &)

Default:True
max_length int | None

Maximum slug length (None = unlimited)

Default:None
separator str

Character to use between words (default: '-')

Default:'-'
Returns
str
escape_html 1 str
Escape HTML special characters for safe use in attributes. **Converts special …
def escape_html(text: str) -> str

Escape HTML special characters for safe use in attributes.

Converts special characters to HTML entities:

  • & becomes &
  • < becomes <
  • becomes >

  • " becomes "
  • ' becomes '
Parameters
Name Type Description
text str

Text to escape

Returns
str