mdast-util-from-markdown

Parses markdown into a fully spec-compliant mdast syntax tree using the micromark tokenizer.

Library
npm
v2.1.0
295 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
62 /100 Good
Development Activity 60
Maintenance 56
Community 52
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 88
Code Quality 92
Innovation 78
Learning Curve 75

mdast-util-from-markdown is the low-level utility that converts markdown into an mdast syntax tree, used when you need to work with the parsed tree directly instead of going straight to HTML. It delegates tokenization to micromark’s CommonMark-compliant parser, then compiles the resulting token events into mdast nodes (headings, lists, links, code, emphasis, and more) via a stack-based compiler with dedicated enter/exit handlers for every token type.

Its extension system is what makes it foundational to the wider syntax-tree ecosystem: passing micromark extensions adds new markdown syntax (GFM, MDX, math, directives, frontmatter), while mdastExtensions register the enter/exit handlers and post-parse transforms needed to turn those new tokens into mdast nodes. Packages like mdast-util-gfm, mdast-util-mdx, and remark-parse all build on this exact mechanism rather than reimplementing markdown parsing themselves.

What You Get

  • A single fromMarkdown(value, encoding?, options?) function that returns a complete mdast Root node
  • Support for micromark extensions (syntax) and mdastExtensions (tree-building) so ecosystem plugins like GFM, MDX, and frontmatter can be layered in without forking the parser
  • Exported TypeScript types (CompileContext, CompileData, Extension, Handle, Options, Token, Transform) for building your own extensions
  • A CommonMark fixture-backed test suite enforcing 100% line/branch/function coverage, run against both development and production build conditions

Common Use Cases

  • Parsing markdown files into an inspectable, transformable AST instead of straight to HTML
  • Building a custom remark/unified plugin that needs to add or rewrite mdast nodes
  • Powering MDX, frontmatter, GFM, or math syntax extensions across the syntax-tree ecosystem
  • Writing markdown linters or static-analysis tools that need positional/token-level detail

Under The Hood

Architecture

The public fromMarkdown(value, encoding, options) in dev/lib/index.js is a thin composition: it feeds value through micromark’s preprocess(), parse().document().write(), and postprocess() to get a token event stream, then hands that stream to an internal compiler(options). The compiler builds a default config object mapping every micromark token name (atxHeading, codeFenced, link, listItem, etc.) to enter/exit handler functions produced by opener()/closer() factories, merges in any user-supplied mdastExtensions via a configure() step, then walks the events maintaining a node stack, a tokenStack (to detect unclosed tokens and raise OnEnterError/OnExitError), and a buffer()/resume() pair that captures raw text for constructs like link destinations before they are finalized into node fields. This gives the whole ecosystem one pluggable seam — new syntax registers handlers here instead of forking the compiler.

Tech Stack

The package is plain, dependency-light JavaScript (ESM only, "type": "module") with no build step for source — only type declarations are emitted via tsc --build with checkJs/declaration/emitDeclarationOnly, so the codebase is fully typed through JSDoc alone. Runtime dependencies are all narrowly scoped micromark/unist/mdast utilities (micromark, micromark-util-decode-string, micromark-util-normalize-identifier, mdast-util-to-string, unist-util-stringify-position) plus devlop for dev-only assertions and decode-named-character-reference for entity decoding. The package exports map exposes a development condition (dev/index.js) alongside the production index.js, letting consumers opt into extra runtime assertions during testing.

Code Quality

A single 1200+ line test/index.js runs the full CommonMark fixture set (test/fixtures/*.md paired with *.json) plus targeted extension and error-path tests, executed once under the development condition and once under production. CI (test-coverage) enforces 100% line, branch, and function coverage via Node’s built-in test runner and coverage flags, and the whole repo is linted with xo (ESLint preset) with Prettier-compatible formatting and a type-coverage check requiring 100% typed code. No test files were skipped or found missing — this is one of the most rigorously tested packages in the unified ecosystem.

What Makes It Unique

Rather than parsing markdown directly into HTML or a bespoke tree shape, this package’s entire value is the clean separation between tokenizing (delegated to micromark) and compiling tokens into a standard, spec-defined tree (mdast). The extensions/mdastExtensions/transforms seams are deliberately narrow and composable, which is why a dozen-plus sibling packages (GFM, MDX, math, directives, frontmatter) can each add markdown syntax independently without touching this package’s internals — a plugin architecture pattern other markdown parsers in the ecosystem have converged on rather than reinvented.

Used by 15 apps in this directory

TypeScript
90%
MIT

OpenClaw

AI Agents · AI Assistants

392,894

An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.

View details
88
Repo Health
88
Technical
66
Dependency
Built with
TypeScript 90%
Updated 1 weeks ago
TypeScript
96%
MIT

Payload CMS

Blogging · CMS · Developer Tools

45,458

The open-source, Next.js-native headless CMS that lives inside your /app folder and gives you a full TypeScript backend instantly.

View details
92
Repo Health
88
Technical
65
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

113,827

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript 72%
MDX 26%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

TinaCMS

CMS

13,845

An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.

View details
92
Repo Health
74
Technical
59
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Python
73%
Apache 2.0

Unsloth

AI Assistants · AI Development

78,493

Run and fine-tune LLMs, diffusion, audio and embedding models on your own hardware, from a native desktop app, a browser UI, or a Python library.

View details
89
Repo Health
83
Technical
70
Dependency
Built with
Python 73%
TypeScript 22%
Updated 1 weeks ago
TypeScript
99%
AGPL 3.0

Webstudio

Design Tools · No Code Platforms

9,103

Open source visual development platform with complete CSS control, headless CMS integration, and full infrastructure ownership

View details
91
Repo Health
79
Technical
60
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers