html5parser is a highly performant and compact JavaScript library designed for parsing HTML5 documents. Currently at version 2.0.2, it provides functionalities to tokenize and parse HTML strings into a structured Abstract Syntax Tree (AST). It distinguishes itself through its speed, tiny bundle size (under 5kb), and cross-platform compatibility, running effectively in both modern browsers and Node.js environments. A key design principle is its strict adherence to the HTML5 specification; any content not compliant with HTML5 will be ignored. The library offers both low-level tokenization (`tokenize`) and higher-level AST generation (`parse`), along with utilities like `walk` for traversing the AST and `safeHtml` for sanitization. It ships with TypeScript types, promoting better developer experience and type safety. The release cadence appears to be driven by dependency updates and bug fixes, with `2.0.2` specifically noting dependency updates, suggesting a focus on stability and maintenance.
npm install html5parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing an HTML string into an Abstract Syntax Tree (AST) and then traversing it using `walk` to extract the content of the `<title>` tag and other elements. It includes a browser-specific DOM update with a Node.js console fallback.
Ensure that all input HTML conforms to the official HTML5 specification. For parsing non-standard, malformed, or highly custom HTML, consider alternative parsers that offer more lenient parsing options.
Use ES Module import syntax: `import { parse } from 'html5parser';`Ensure code interacting with the `document` object is executed in a browser environment, or use a library like JSDOM to simulate a browser DOM in Node.js for testing or server-side rendering.
No dependency data recorded yet.