Module

rendering.template_functions.content

Content transformation functions for templates.

Provides 6 functions for HTML/content manipulation and transformation.

Functions

register
Register content transformation functions with Jinja2 environment.
2 None
def register(env: Environment, site: Site) -> None

Register content transformation functions with Jinja2 environment.

Parameters 2

Name Type Default Description
env Environment
site Site
safe_html
Mark HTML as safe (prevents auto-escaping). This is a marker function - Jinja2's 'safe' filter sho…
1 str
def safe_html(text: str) -> str

Mark HTML as safe (prevents auto-escaping).

This is a marker function - Jinja2's 'safe' filter should be used instead. Included for compatibility with other SSGs.

Parameters 1

Name Type Default Description
text str

HTML text to mark as safe

Returns

str

Same text (use with Jinja2's |safe filter)

html_escape
Escape HTML entities. Converts special characters to HTML entities: - < becomes &lt; - > becomes &…
1 str
def html_escape(text: str) -> str

Escape HTML entities.

Converts special characters to HTML entities:

  • < becomes &lt;
  • becomes &gt;

  • & becomes &amp;
  • " becomes &quot;
  • ' becomes &#x27;

Parameters 1

Name Type Default Description
text str

Text to escape

Returns

str

Escaped HTML text

html_unescape
Unescape HTML entities. Converts HTML entities back to characters: - &lt; becomes < - &gt; becomes…
1 str
def html_unescape(text: str) -> str

Unescape HTML entities.

Converts HTML entities back to characters:

  • &lt; becomes <
  • &gt; becomes >
  • &amp; becomes &
  • &quot; becomes "

Parameters 1

Name Type Default Description
text str

HTML text with entities

Returns

str

Unescaped text

nl2br
Convert newlines to HTML <br> tags. Replaces with <br> to preserve both HTML and text formatting.
1 str
def nl2br(text: str) -> str

Convert newlines to HTML <br> tags.

Replaces 

with <br> to preserve both HTML and text formatting.

Parameters 1

Name Type Default Description
text str

Text with newlines

Returns

str

HTML with <br> tags

smartquotes
Convert straight quotes to smart (curly) quotes. Converts: - " to " and " - ' to ' and ' - -- to –…
1 str
def smartquotes(text: str) -> str

Convert straight quotes to smart (curly) quotes.

Converts:

  • " to " and "
  • ' to ' and '
  • -- to –
  • --- to —

Parameters 1

Name Type Default Description
text str

Text with straight quotes

Returns

str

Text with smart quotes

emojify
Convert emoji shortcodes to Unicode emoji. Converts :emoji_name: to actual emoji characters.
1 str
def emojify(text: str) -> str

Convert emoji shortcodes to Unicode emoji.

Converts :emoji_name: to actual emoji characters.

Parameters 1

Name Type Default Description
text str

Text with emoji shortcodes

Returns

str

Text with Unicode emoji

extract_content
Extract content portion from full rendered HTML page. Removes the page wrapper (html, head, body, …
1 str
def extract_content(html: str) -> str

Extract content portion from full rendered HTML page.

Removes the page wrapper (html, head, body, navigation, footer) and extracts just the main content area. This is useful for embedding page content within other pages (e.g., track pages).

Tries multiple strategies to find content:

  1. Look for <article class="prose"> or <div class="docs-content">
  2. Look for <main> content (excluding nav/footer)
  3. Fall back to empty string if no content area found

Parameters 1

Name Type Default Description
html str

Full rendered HTML page

Returns

str

Extracted content HTML (or empty string if extraction fails)