Functions
register
Register advanced string functions with Jinja2 environment.
register
def register(env: Environment, site: Site) -> None
Register advanced string functions with Jinja2 environment.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
env |
Environment |
— | |
site |
Site |
— |
camelize
Convert string to camelCase.
camelize
def camelize(text: str) -> str
Convert string to camelCase.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— | Text to convert |
Returns
camelCase textstr
—
underscore
Convert string to snake_case.
underscore
def underscore(text: str) -> str
Convert string to snake_case.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— | Text to convert |
Returns
snake_case textstr
—
titleize
Convert string to Title Case (proper title capitalization).
More sophisticated than str.title() - …
titleize
def titleize(text: str) -> str
Convert string to Title Case (proper title capitalization).
More sophisticated than str.title() - handles articles, conjunctions, and prepositions correctly.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— | Text to convert |
Returns
Properly title-cased textstr
—
wrap_text
Wrap text to specified width.
wrap_text
def wrap_text(text: str, width: int = 80) -> str
Wrap text to specified width.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— | Text to wrap |
width |
int |
80 |
Maximum line width (default: 80) |
Returns
Wrapped text with newlinesstr
—
indent_text
Indent text by specified number of spaces.
indent_text
def indent_text(text: str, spaces: int = 4, first_line: bool = True) -> str
Indent text by specified number of spaces.
Parameters 3
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— | Text to indent |
spaces |
int |
4 |
Number of spaces to indent (default: 4) |
first_line |
bool |
True |
Indent first line too (default: True) |
Returns
Indented textstr
—
softwrap_identifier
Insert soft wrap opportunities into API identifiers and dotted paths.
Adds zero-width space () af…
softwrap_identifier
def softwrap_identifier(text: str) -> str
Insert soft wrap opportunities into API identifiers and dotted paths.
Adds zero-width space () after sensible breakpoints like dots, underscores, and before uppercase letters in camelCase/PascalCase to allow titles like "cache.dependency_tracker" to wrap nicely.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— |
Returns
str
last_segment
Return the last segment of a dotted or path-like identifier.
last_segment
def last_segment(text: str) -> str
Return the last segment of a dotted or path-like identifier.
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
text |
str |
— |
Returns
str