Repository navigation
0.7.0
This release replaces the HTML pretty-printer with a new rendering-preserving serializer, tightens how generated HTML is escaped, and validates the whole thing against browser-accurate standards.
Highlights
- New HTML pretty-printer.
prettify_htmlwas rewritten from a BeautifulSoup pass to a purpose-built lxml serializer that re-indents
document structure while preserving exactly how the page renders:- Inline elements are never broken across lines, and significant inline whitespace is kept.
pre,textarea,script, andstylecontent is emitted verbatim (byte for byte).- It is idempotent. Prettifying already-pretty output changes nothing.
- Body-level fragments are emitted as-is, never wrapped in a synthetic
<div>/<span>; whole documents get an HTML5 doctype, fragments don't. - Compact elements (e.g. table rows) are handled.
- Correct, minimal attribute escaping. Attribute values escape only what a parser could misread. The
"delimiter and reference-starting ampersands. CSS/Tailwind values likeclass="[&>p]:prose"survive verbatim instead of being mangled to[&>p]:prose, while genuine ampersands (Q&A) are correctly writtenQ&A.
Correctness & standards
- Validated against an independent, browser-accurate oracle. Every transformation is checked to preserve rendering using html5lib (a WHATWG-conformant parser) that shares no code with the serializer, so a bug surfaces as a mismatch instead of being masked.
- Property-based tests. Render-invariance and idempotence are fuzzed with Hypothesis over generated documents and fragments.
- Conformance corpus. The same invariants run over the html5lib test corpus (the WHATWG test suite), not just hand-written cases.
- Spec-based escaping. Attribute escaping follows the WHATWG HTML character-reference rules and is confirmed to round-trip identically under both lxml and html5lib.
Behavior changes
Upgrading from 0.6.x, your generated HTML may differ (how it renders does not):
- Ampersands in attribute values are escaped correctly. 0.6.x (BeautifulSoup) left some ambiguous ampersands raw; they are now
&. - Attribute order follows the source; 0.6.x alphabetized attributes.
- Whitespace-sensitive and inline content is preserved verbatim. The old BeautifulSoup pass could reflow it.
Requirements
- Requires Python 3.11+ (the config loader uses the stdlib
tomllib, added in 3.11). Tested on 3.11–3.13.