Functions
escape_html
Escape HTML special characters for use in attributes.
Escapes: & < > " '
escape_html
def escape_html(text: str) -> str
Escape HTML special characters for use in attributes.
Escapes: & < > " '
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— | Raw text to escape |
Returns
HTML-escaped text safe for use in attributesstr
—
build_class_string
Build CSS class string from multiple class sources.
Filters out empty strings and joins with space.
build_class_string
def build_class_string(*classes: str) -> str
Build CSS class string from multiple class sources.
Filters out empty strings and joins with space.
Returns
Space-joined class stringstr
—
bool_attr
Return HTML boolean attribute string.
bool_attr
def bool_attr(name: str, value: bool) -> str
Return HTML boolean attribute string.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
name |
str |
— | Attribute name (e.g., "open", "disabled") |
value |
bool |
— | Whether to include the attribute |
Returns
" name" if value is True, "" otherwisestr
—
data_attrs
Build data-* attribute string from keyword arguments.
Converts underscore names to hyphenated (dat…
data_attrs
def data_attrs(**attrs: Any) -> str
Build data-* attribute string from keyword arguments.
Converts underscore names to hyphenated (data_foo -> data-foo). Skips None and empty string values.
Returns
Space-joined data attribute stringstr
—
attr_str
Return HTML attribute string if value is truthy.
attr_str
def attr_str(name: str, value: str | None) -> str
Return HTML attribute string if value is truthy.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
name |
str |
— | Attribute name |
value |
str | None |
— | Attribute value (may be None or empty) |
Returns
' name="value"' if value is truthy, "" otherwisestr
—
class_attr
Build class attribute string.
Convenience wrapper combining build_class_string with attribute form…
class_attr
def class_attr(base_class: str, *extra_classes: str) -> str
Build class attribute string.
Convenience wrapper combining build_class_string with attribute formatting.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
base_class |
str |
— | Primary class (always included if non-empty) *extra_classes: Additional classes to add |
Returns
' class="..."' string or "" if no classesstr
—