@qezor/livehtmlrewriter
v1.0.1
Published
Low-memory HTML rewriting on top of streaming tokenization.
Maintainers
Readme
@qezor/livehtmlrewriter
@qezor/livehtmlrewriter is a low-memory HTML rewriter built on streaming tokenization.
It does not materialize a full DOM just to change a few attributes or text nodes.
Install
npm install @qezor/livehtmlrewriterMain API
createLiveHtmlRewriter(options?)new LiveHtmlRewriter(options?)onElement(selector, handler)onText(selector?, handler)onComment(selector?, handler)rewrite(source, options?)rewriteString(html, options?)rewriteFile(chunkySystem, sourcePath, destinationPath, options?)
Example
const { createLiveHtmlRewriter } = require("@qezor/livehtmlrewriter")
const rewriter = createLiveHtmlRewriter()
.onElement(".hero", (element) => {
element.setAttribute("data-ready", "1")
})
.onText(".hero", (text) => {
text.replace(text.text.toUpperCase())
})
const html = await rewriter.rewriteString("<section class='hero'><p>Hello</p></section>")Notes
- element rewrites are applied on the live start-tag state
- text rewrites operate on coalesced contiguous text within the same parent context
- selector matching uses the same selector engine as
@qezor/livedomparser - element controls now include:
addClass(...)removeClass(...)toggleClass(name, force?)setInnerText(text)setOuterText(text)before(html)after(html)prepend(html)append(html)remove()replace(html)replaceChildren(html)skipSubtree()
- current scope stays intentionally honest:
- start-tag mutation
- class helper mutation
- text-safe inner or outer text replacement
- outer-boundary insertion
- inner-boundary insertion
- whole-element removal/replacement
- child-subtree replacement
- subtree pass-through skipping
- text mutation
- comment mutation
- streamed file rewriting
onText(...) and onComment(...) mutations now also support before(...) and after(...) around the node result.
Versioning
@qezor/livehtmlrewriter follows practical semver:
- patch: safe fixes, docs, selector-alignment work, and low-risk rewrite correctness improvements
- minor: additive rewrite controls and handler capabilities that preserve existing behavior
- major: breaking changes to rewrite ordering, handler contracts, or control semantics
Release notes live in CHANGELOG.md.
