hast-util-from-html is a utility within the unifiedjs ecosystem that transforms serialized HTML strings into a HAST (Hypertext Abstract Syntax Tree) representation. The current stable version is 2.0.3. It maintains a relatively active release cadence, with recent patch releases addressing type issues and a major version bump (2.0.0) introducing significant changes like ESM-only support and Node.js 16+ requirement. This package is designed for scenarios where developers need to manually manipulate HTML syntax trees, offering granular control over parsing. It differentiates itself from `parse5` (a low-level HTML parser) by directly producing HAST nodes, and from higher-level abstractions like `rehype-parse`. For browser environments, `hast-util-from-html-isomorphic` offers a lighter, albeit less feature-rich, alternative.
npm install hast-util-from-htmlVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse a simple HTML string into a HAST (Hypertext Abstract Syntax Tree) using the `fromHtml` function, showcasing both fragment and full document parsing.
Upgrade your Node.js environment to version 16 or newer.
Migrate your codebase to use ES module `import` syntax (e.g., `import { fromHtml } from 'hast-util-from-html'`) and ensure your project is configured for ESM.Only use the public API as exported from the main package entry point (`import { ... } from 'hast-util-from-html'`).For parsing HTML fragments, use `fromHtml(value, { fragment: true })`.Review the API documentation for `OnError`, `ErrorCode`, and `ErrorSeverity` to customize how parse errors are reported or handled via the `onerror` option.
Switch to ES module `import` syntax: `import { fromHtml } from 'hast-util-from-html'` and ensure your project is configured to run ESM.Verify that your project is using `import { fromHtml } from 'hast-util-from-html'` and that your environment (Node.js version, bundler config) supports ESM correctly.For ESM, ensure you use `import { fromHtml } from 'hast-util-from-html'`. If you are using an older version (pre-v2) with CommonJS, ensure you're accessing the correct export property if it wasn't the default.No dependency data recorded yet.