HTML parser with visible-text extraction, fragment parsing, and structural traversal.
Supports Node, Deno, Bun, and browsers with explicit resource budgets.
No runtime dependencies: this package ships with zero runtime dependencies.
- You need deterministic parse and serialize output.
- You need explicit resource budgets for untrusted input.
- You need consistent behavior across Node, Deno, Bun, and browser smoke paths.
- You need HTML sanitization.
- You need a full browser engine with script execution.
- You need DOM mutation semantics beyond deterministic parse utilities.
npm install @ismail-elkorchi/html-parserdeno add jsr:@ismail-elkorchi/html-parserimport { parse } from "@ismail-elkorchi/html-parser";import { parse } from "jsr:@ismail-elkorchi/html-parser";import { parse } from "@ismail-elkorchi/html-parser";
const tree = parse("<main><h1>Hello</h1></main>");
console.log(tree.kind);import { parseStream } from "@ismail-elkorchi/html-parser";
const stream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode("<p>streamed</p>"));
controller.close();
}
});
const tree = await parseStream(stream, { budgets: { maxInputBytes: 4096, maxBufferedBytes: 512 } });
console.log(tree.kind);import { parse, visibleText } from "@ismail-elkorchi/html-parser";
const tree = parse("<article><h1>Title</h1><p>Hello world.</p></article>");
console.log(visibleText(tree).trim());import { applyPatchPlan, computePatch } from "@ismail-elkorchi/html-parser";
const plan = computePatch("<p>Draft</p>", []);
const patched = applyPatchPlan("<p>Draft</p>", plan);
console.log(patched);Run packaged examples:
npm run examples:runRuntime compatibility matrix:
| Runtime | Status |
|---|---|
| Node.js | Supported |
| Deno | Supported |
| Bun | Supported |
| Browser (evergreen) | Supported |
The Node.js package surface is verified against Node 20, 22, and 24.
Parsing is not sanitization. For untrusted input:
- set strict budgets,
- handle
BudgetExceededErrorexplicitly, - sanitize separately before rendering.