mdast-util-from-markdown is a foundational utility in the syntax-tree ecosystem, designed to parse Markdown input into an mdast (Markdown Abstract Syntax Tree) syntax tree. It leverages the micromark tokenizer internally and transforms its output into a tree structure. The current stable version is 2.0.3, with frequent patch and minor releases, while major versions like 2.0.0 introduce significant breaking changes such as the shift to ESM-only and a minimum Node.js 16 requirement. This package provides a lower-level API for direct AST manipulation, making it suitable for developers who need fine-grained control over the parsing process or wish to integrate custom syntax extensions like GFM, MDX, Math, or Frontmatter. It is distinct from micromark (which focuses on direct HTML output) and remark-parse (which offers a higher-level, more abstracted content processing experience within the remark ecosystem).
npm install mdast-util-from-markdownVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to asynchronously read a Markdown file and parse its content into an mdast syntax tree using the `fromMarkdown` utility.
Upgrade your Node.js environment to version 16 or newer. Use nvm or your preferred Node.js version manager.
Migrate your codebase to use ES module `import` syntax. Ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions. For mixed CJS/ESM projects, consider dynamic `import()`.
If you are passing raw buffers, ensure they are converted to `Uint8Array` instances before passing them to `fromMarkdown`. For example, `new Uint8Array(myBuffer)`.
If you have custom markdown extensions that interact deeply with `mdast-util-from-markdown`'s internals, you will need to update them according to the `micromark@4` and `mdast-util-from-markdown@2` migration guides. Review `Extension` and `CompileContext` types for changes.
Choose the right tool for the job: `micromark` for direct HTML, `remark` for plugin-based content transformation, `mdast-util-from-markdown` for direct AST manipulation.
Update your import statements to use `import { fromMarkdown } from 'mdast-util-from-markdown'` and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).Convert your `Buffer` instances to `Uint8Array` before passing them. Example: `fromMarkdown(new Uint8Array(myBuffer))`.
Upgrade your Node.js version to 16 or newer. Also, verify your project's `package.json` correctly specifies `"type": "module"` if you're using explicit ESM in your files.
Ensure you are using a named import: `import { fromMarkdown } from 'mdast-util-from-markdown'`. The package has no default export.