Module

postprocess.html_output

HTML output processing and minification utilities.

Provides HTML minification with whitespace preservation for sensitive tags. Handles HTML minification while preserving whitespace in code blocks, scripts, and other whitespace-sensitive content.

Key Concepts:

  • HTML minification: Remove unnecessary whitespace and comments
  • Whitespace preservation: Preserve whitespace in sensitive tags
  • Protected regions: Code blocks, scripts, styles protected from minification
  • Void tags: Self-closing tags that don't need closing tags

Related Modules:

  • bengal.postprocess: Post-processing orchestration
  • bengal.config.defaults: HTML output configuration

See Also:

  • bengal/postprocess/html_output.py: minify_html() for HTML minification

Functions

_split_protected_regions
Split HTML into segments, marking whitespace-sensitive regions to preserve. Returns list of tuples…
1 list[tuple[str, bool]]
def _split_protected_regions(html: str) -> list[tuple[str, bool]]

Split HTML into segments, marking whitespace-sensitive regions to preserve.

Returns list of tuples: (segment_text, is_protected)

Parameters 1

Name Type Default Description
html str

Returns

list[tuple[str, bool]]

_pretty_indent_html
Indent non-protected HTML lines with two spaces per nesting level. Depth carries across protected …
1 str
def _pretty_indent_html(html: str) -> str

Indent non-protected HTML lines with two spaces per nesting level.

Depth carries across protected segments, but protected content is left untouched.

Parameters 1

Name Type Default Description
html str

Returns

str

format_html_output
Format HTML to produce pristine output, preserving whitespace-sensitive regions.
3 str
def format_html_output(html: str, mode: str = 'raw', options: dict[str, Any] | None = None) -> str

Format HTML to produce pristine output, preserving whitespace-sensitive regions.

Parameters 3

Name Type Default Description
html str

Input HTML string

mode str 'raw'

"raw" (no-op), "pretty" (stable whitespace), or "minify" (compact inter-tag spacing)

options dict[str, Any] | None None

optional flags, e.g., {"remove_comments": True, "collapse_blank_lines": True}

Returns

str

Formatted HTML string