The `htmljs-parser` is a specialized HTML parser designed to understand and process both standard HTML elements and embedded JavaScript expressions, particularly within attribute values and placeholders. It forms a core component of the Marko framework. The current stable version is `5.10.2`, with a consistent release cadence of frequent patch updates and minor versions introducing new validation APIs and parsing refinements. Its primary differentiator lies in its ability to deeply integrate JavaScript expression parsing directly into the HTML parsing stream, enabling advanced templating and reactive UI paradigms that extend beyond traditional HTML parsing capabilities. It is well-suited for environments requiring the compilation or processing of HTML containing dynamic JavaScript logic.
npm install htmljs-parserVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a parser instance and register handlers for various parsing events, including text, placeholders, comments, CDATA sections, and tag names. It showcases how to read the raw content of a parsed range and access additional metadata.
Thoroughly test parsing output after upgrading to ensure whitespace rendering aligns with expectations. Consult release notes for specific changes related to concise mode.
Upgrade to the latest v5 patch release to benefit from fixes in JavaScript/TypeScript expression parsing. Ensure your embedded JavaScript adheres to standard syntax to avoid unexpected interpretations.
Understand that `htmljs-parser` provides a stream of parsing events and `Range` objects. To get the actual string content of a range, use `parser.read(range)`. If a DOM-like structure is required, an additional layer of abstraction would need to be built on top of these events.
Either configure your project to use ECMAScript Modules (ESM) by setting `"type": "module"` in `package.json` or by using `.mjs` file extensions, or use CommonJS `require()` syntax: `const { createParser } = require('htmljs-parser');`Ensure that the `range` object passed to your event handlers is always valid before attempting to access its properties. Add checks like `if (range) { /* ... */ }` or ensure your parser configuration is robust.Review the specific patch and minor release notes for v5.9.0 and v5.10.x regarding 'concise mode' and whitespace handling. Update your parsing logic or expectations to accommodate these changes, or adjust the input HTML/concise blocks accordingly.
No dependency data recorded yet.