Skip to main content

Module rewrite

Module rewrite 

Available on crate features html and http only.
Expand description

Selector-driven HTML rewriting.

The public entry point is HtmlRewriter (and the rewrite_str one-shot). Internally, a streaming selector matcher is fed start/end tags as they are tokenized and reports, at each start tag, which registered selectors match the element being opened — without building a DOM. It maintains an open-element stack and, per selector, two bitmasks:

  • completed — which compound-prefixes are matched ending at this element (a child combinator reads its parent’s completed);
  • desc_ready — which prefixes are available to descendants (a descendant combinator reads its ancestor’s desc_ready).

It underpins the selector-driven HtmlRewriter.

Structs§

AttributeName
A validated HTML attribute name.
Element
A matched element, for inspection and mutation by a handler.
ElementContentHandlers
A builder bundling (selector, closure) pairs — the closure-based escape hatch over the ElementContentHandler trait, for one-off rewrites that don’t need a dedicated state struct.
HtmlRewriter
A streaming, selector-driven HTML rewriter.

Enums§

InvalidAttributeName
Why a string is not a valid AttributeName.

Traits§

ElementContentHandler
Handles matched elements during a rewrite.

Functions§

rewrite_str
One-shot rewrite of a complete HTML string.

Type Aliases§

HandlerResult
The result of an element content handler. An error aborts the rewrite.