duck.html.html_minify

Non-destructive HTML minifier — trims payload size without ever changing what the HTML displays or means. Built on Python’s stdlib HTMLParser so it handles real-world, occasionally malformed markup the way a browser would, rather than guessing with regex over the whole document.

Module Contents

Classes

InnerHTMLMinifier

Streams HTML through HTMLParser and reconstructs it with whitespace collapsed and comments stripped, while leaving tags, attributes, entities, and whitespace-sensitive content untouched.

Functions

minify_inner_html

Minifies an HTML string without changing how it renders.

Data

WHITESPACE_RUN

WHITESPACE_SENSITIVE_TAGS

API

class duck.html.html_minify.InnerHTMLMinifier(keep_comments: bool = False)[source]

Bases: html.parser.HTMLParser

Streams HTML through HTMLParser and reconstructs it with whitespace collapsed and comments stripped, while leaving tags, attributes, entities, and whitespace-sensitive content untouched.

Non-destructive by design: nothing that could change how the HTML renders — attribute values, entity encoding, the content of

/