mdast-util-to-hast is a foundational utility within the unified (syntax-tree) ecosystem, designed to convert an mdast (Markdown Abstract Syntax Tree) into a hast (HTML Abstract Syntax Tree). It is currently stable at version 13.2.1 and receives frequent patch and minor updates, with major versions occurring less often but bringing significant breaking changes, such as the recent v13.0.0. This package is crucial for developers building tools that process Markdown and render it to HTML, acting as the bridge between the two AST formats. Key differentiators include its tight integration with the broader unified ecosystem, offering a programmatic way to transform content, and serving as the inverse to `hast-util-to-mdast`. It is also the underlying engine for higher-level plugins like `remark-rehype`, which provides an easier abstraction for similar conversion tasks. Its focus is purely on AST transformation, providing granular control over the conversion process.
npm install mdast-util-to-hastVerified import paths — ran on the pinned version, not inferred.
This example demonstrates the full workflow from reading a Markdown file to converting it to an HTML string using mdast-util-to-hast and related utilities.
Migrate your project to use ES Modules, update your `package.json` with `"type": "module"` or use `.mjs` files, and update `require()` calls to `import` statements.
Upgrade your Node.js runtime environment to version 16 or newer. Use `nvm` or your preferred Node.js version manager.
If customizing footnote back labels, ensure you are passing a function to the `footnoteBackLabel` option, taking `referenceIndex` and `rereferenceIndex` as arguments. Consult `defaultFootnoteBackLabel` for an example.
Update your code to expect a `Node` object, potentially an empty `root` (`{ type: 'root', children: [] }`), instead of `null` or `undefined` for empty inputs.Upgrade to mdast-util-to-hast version 12.2.4 or newer to ensure correct URL encoding.
Switch to using ES module `import` syntax and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Ensure consistent ESM usage throughout your project. If using TypeScript, check `tsconfig.json` for `module` and `moduleResolution` settings (e.g., `"module": "node16", "moduleResolution": "node16"`).
Run `npm install mdast-util-to-hast`. Ensure Node.js 16+ is used if on v13+ of the library, and that your `tsconfig.json` (if applicable) aligns with ESM resolution.
Update `@types/mdast` and `@types/hast` to match the major version used by `mdast-util-to-hast` (v13 requires compatible types). Ensure the input `tree` adheres to the `MdastNode` interface.
No dependency data recorded yet.