Skip to content

0.7.0

Choose a tag to compare

@jdeanwallace jdeanwallace released this 23 Jul 16:36
· 2 commits to master since this release
61b4665

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_html was 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, and style content 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 like class="[&>p]:prose" survive verbatim instead of being mangled to [&amp;&gt;p]:prose, while genuine ampersands (Q&A) are correctly written Q&amp;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
    &amp;.
  • 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.

Tooling

  • Migrated to uv for dependency management and builds.
  • Code formatting on black 26.