Expand description
Thin wrapper around Cloudflare’s [lol_html] streaming HTML rewriter.
Replaces the previous fragile str::find / str::rfind rewriting
that lived in the image, search, CSP, and html-fix plugins (issue
#525). Compared to the old approach lol_html:
- Skips HTML comments.
<!-- <img …> -->is byte-identical in the output rather than being half-rewritten. - Preserves character entities.
alt="Café & bar"round-trips verbatim — no double-encoding, no entity decoding inside attribute values. - Streams. Peak RSS stays flat regardless of input size; there is no full-document DOM materialised in memory.
§API
The crate-private functions rewrite_html and
extract_text_with_filter cover every call site inside SSG.
Plugins pass closure-based [ElementContentHandlers] or write to a
&mut String aggregator and let the wrapper deal with feeding
chunks through lol_html::HtmlRewriter.
Functions§
- collapse_
whitespace - Collapses runs of ASCII whitespace into a single space and trims.
- decode_
html_ entities - Minimal HTML entity decoder for text-extraction call sites.
- extract_
text_ with_ filter - Extract concatenated text content from every element matching
selector, separating successive elements with a single space. - inject_
before_ body_ close - Rewrites every element with its attributes in name order.
- inject_
before_ body_ close_ or_ append - Injects
payloadbefore</body>, appending it when there is none. - rewrite_
html - Run
lol_htmloverhtmlwith the supplied(selector, handlers)pairs and return the rewritten document. - sort_
attributes - Returns
SsgError::Ioiflol_htmlfails to parse or rewrite.