mdast-util-from-markdown

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

Library
npm
v2.0.3
290 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
59 /100 Fair
Development Activity 60
Maintenance 44
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
96%
MIT

deepseek-harness

AI Agents · AI Development · Developer Tools

237,945

An open-source, plugin-based agent harness from DeepSeek AI that runs coding and automation agents across web, desktop, CLI, and SDK surfaces.

View details
81
Repo Health
89
Technical
74
Dependency
Built with
TypeScript 96%
Updated 6 days ago
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,787

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
TypeScript 75%
Updated 5 days ago
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,982

The superpowered headless CMS for developers built with GraphQL and React

View details
92
Repo Health
81
Technical
64
Dependency
Built with
TypeScript 99%
Updated 5 days ago
Rust
47%
MIT

Kuku

Note Taking

225

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
52
Repo Health
67
Technical
67
Dependency
Built with
Rust 47%
TypeScript 40%
Updated 3 weeks ago
TypeScript
82%
MIT

LibreChat

AI Assistants · Developer Tools

45,009

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
TypeScript 82%
JavaScript 17%
Updated 5 days ago
TypeScript
97%
MIT

likec4

Developer Tools · Devops

5,756

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
TypeScript 97%
Updated 6 days ago
Rust
56%
Apache 2.0

Magnitude

AI Development · Developer Tools

5,285

An open source inference engine that profiles your hardware, recommends the best local models, and tunes them for the coding agent you already use.

View details
78
Repo Health
83
Technical
71
Dependency
Built with
Rust 56%
TypeScript 18%
Python 11%
Updated 5 days ago
Go
51%
MIT

memos

Note Taking

63,382

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

View details
91
Repo Health
78
Technical
65
Dependency
Built with
Go 51%
TypeScript 48%
Updated 6 days ago
TypeScript
97%
GPL 3.0

OpenKnowledge

Code Editors · Knowledge Management · Note Taking

4,337

A beautiful, local-first markdown IDE that turns any git repo into a live collaborative workspace for humans and AI coding agents like Claude, Codex, and OpenCode.

View details
79
Repo Health
89
Technical
64
Dependency
Built with
TypeScript 97%
Updated 5 days 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