Module

rendering.template_functions.advanced_strings

Advanced string manipulation functions for templates.

Provides 5 advanced string transformation functions.

Functions

register
Register advanced string functions with Jinja2 environment.
2 None
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.
1 str
def camelize(text: str) -> str

Convert string to camelCase.

Parameters 1

Name Type Default Description
text str

Text to convert

Returns

str

camelCase text

underscore
Convert string to snake_case.
1 str
def underscore(text: str) -> str

Convert string to snake_case.

Parameters 1

Name Type Default Description
text str

Text to convert

Returns

str

snake_case text

titleize
Convert string to Title Case (proper title capitalization). More sophisticated than str.title() - …
1 str
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

str

Properly title-cased text

wrap_text
Wrap text to specified width.
2 str
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

str

Wrapped text with newlines

indent_text
Indent text by specified number of spaces.
3 str
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

str

Indented text

softwrap_identifier
Insert soft wrap opportunities into API identifiers and dotted paths. Adds zero-width space (​) af…
1 str
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.
1 str
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