This package, `hast-util-raw`, provides a utility for re-parsing HAST (Hypertext Abstract Syntax Tree) documents, specifically targeting 'raw' nodes which contain unprocessed HTML strings. Leveraging the `parse5` HTML parser, it transforms these raw HTML strings into a proper HAST syntax tree, crucial for applications that require a fully-formed, inspectable, and transformable tree rather than mere HTML serialization. This is particularly vital when working with markdown that includes embedded HTML (often enabled via `allowDangerousHtml: true` in converters like `mdast-util-to-hast`), where the initial conversion preserves the HTML as raw strings. The utility ensures that all original data and positional information from the source HTML are meticulously retained during the reparsing process. Currently in stable version 9.1.0, the library maintains an active release cadence, frequently delivering bug fixes and minor features, with major versions introducing breaking changes, often related to Node.js version support or API enhancements. Its core differentiator lies in enabling robust processing of mixed markdown/HTML content by integrating raw HTML into the HAST ecosystem as manipulable nodes, supporting various output formats beyond simple HTML, such as React or MDX.
npm install hast-util-rawVerified import paths — ran on the pinned version, not inferred.
Demonstrates processing a HAST tree containing a `type: 'raw'` node with an HTML string, converting it into a fully structured HAST tree with parsed elements.
Upgrade your Node.js environment to version 16 or later.
Ensure your project uses native ES Modules. Update import paths to use the documented public API. If you need the `Raw` type, import it from `mdast-util-to-hast`.
Update calls to `raw(tree, { file })` instead of `raw(tree, file)`.Always sanitize untrusted input before passing it to `hast-util-raw` or related utilities that enable dangerous HTML. Avoid `allowDangerousHtml: true` or `passThrough` with untrusted sources.
If specific tags are unexpectedly filtered, review the GFM tagfilter rules and consider setting `tagfilter: false` in the options if you explicitly need to process these tags and trust their content.
Change `const { raw } = require('hast-util-raw')` to `import { raw } from 'hast-util-raw'`.Ensure SVG element tags are consistently lowercase. This issue was specifically addressed in version 9.0.3, so upgrading may resolve it.
Ensure that the HTML content within `raw` nodes is well-formed. This issue received a fix for certain cases in version 9.0.4, so upgrading might help, but manual correction of malformed input is often required.