mdast-util-from-markdown

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

Library
npm
v2.0.3
290stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity16
Maintenance32
Community52
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture88
Code Quality92
Innovation78
Learning Curve75

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 10 apps in this directory

TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,772

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript75%
Updated yesterday
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,969

The superpowered headless CMS for developers built with GraphQL and React

View details
91
Repo Health
81
Technical
64
Dependency
Built with
TypeScript99%
Updated 5 days ago
Rust
47%
MIT

Kuku

Note Taking

219

A local-first, open-source Markdown knowledge workspace for macOS — plain files, personal wiki and Second Brain workflows, AI-assisted diffs, and encrypted sync, built as an Obsidian alternative.

View details
81
Repo Health
67
Technical
67
Dependency
Built with
Rust47%
TypeScript40%
Updated yesterday
TypeScript
81%
MIT

LibreChat

Developer Tools · AI Assistants

42,871

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
65
Dependency
Built with
TypeScript81%
JavaScript18%
Updated today
TypeScript
97%
MIT

likec4

Developer Tools · Devops

5,634

Define your software architecture as code and get always up-to-date, interactive C4 diagrams generated automatically from a DSL.

View details
89
Repo Health
83
Technical
77
Dependency
Built with
TypeScript97%
Updated yesterday
Go
51%
MIT

memos

Note Taking

62,805

Open-source, self-hosted note-taking built for quick capture — Markdown-native, lightweight, and fully yours.

View details
91
Repo Health
78
Technical
66
Dependency
Built with
Go51%
TypeScript48%
Updated yesterday
TypeScript
96%
MIT

Payload CMS

Developer Tools · Blogging · CMS

44,600

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

View details
91
Repo Health
88
Technical
65
Dependency
Built with
TypeScript96%
Updated 3 days ago
TypeScript
71%
Apache 2.0

Supabase

Developer Tools · Databases · Search

108,912

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
TypeScript71%
MDX26%
Updated today
TypeScript
98%
Apache 2.0

TinaCMS

CMS

13,780

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
TypeScript98%
Updated today

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

Search