{"library":"mdast-util-to-hast","title":"Markdown AST to HTML AST Transformer","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mdast-util-to-hast"],"cli":null},"imports":["import { toHast } from 'mdast-util-to-hast'","import { defaultFootnoteBackLabel } from 'mdast-util-to-hast'","import type { Options } from 'mdast-util-to-hast'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { promises as fs } from 'node:fs';\nimport { toHtml } from 'hast-util-to-html';\nimport { fromMarkdown } from 'mdast-util-from-markdown';\nimport { toHast } from 'mdast-util-to-hast';\n\nasync function convertMarkdownToHtml(markdownFilePath: string): Promise<string> {\n  try {\n    const markdown = String(await fs.readFile(markdownFilePath));\n    const mdast = fromMarkdown(markdown);\n    const hast = toHast(mdast);\n    const html = toHtml(hast);\n    return html;\n  } catch (error) {\n    console.error(`Error converting markdown: ${error instanceof Error ? error.message : String(error)}`);\n    throw error;\n  }\n}\n\n// Example usage:\nconst exampleFilePath = './example.md';\nconst exampleMarkdown = `## Hello **World**!\\n\\nThis is a [link](https://example.com) and some *italic* text.\\n\\n1. Item one\\n2. Item two`;\n\nfs.writeFile(exampleFilePath, exampleMarkdown)\n  .then(() => convertMarkdownToHtml(exampleFilePath))\n  .then(html => console.log('Generated HTML:\\n', html))\n  .catch(error => console.error('Overall process failed:', error));","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}