mdast-util-mdx-jsx

Parses and serializes MDX JSX syntax within mdast syntax trees for markdown processing pipelines.

Library
npm
v3.2.0
32 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
31 /100 Needs Attention
Development Activity 0
Maintenance 32
Community 20
Maturity 60
Momentum 12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
70 /100 Good
Architecture 80
Code Quality 92
Innovation 62
Learning Curve 45

mdast-util-mdx-jsx is a pair of extensions that teach the mdast ecosystem how to read and write MDX JSX (<Component prop="x" />) inside markdown. mdxJsxFromMarkdown() plugs into mdast-util-from-markdown to turn JSX tokens produced by micromark-extension-mdx-jsx into mdxJsxFlowElement (block-level) and mdxJsxTextElement (inline) nodes, while mdxJsxToMarkdown() plugs into mdast-util-to-markdown to serialize those nodes back into markdown text, including attributes, expression values, and self-closing tags.

It is a low-level building block maintained by the syntax-tree/unified organization rather than something most developers install directly — it underlies higher-level packages like mdast-util-mdx and remark-mdx, which compose it with sibling extensions to give remark and unified pipelines full MDX support. Expression and spread attributes are parsed with acorn and exposed as ESTree Program nodes under data.estree, so tools built on top of it can statically inspect or transform JSX prop expressions rather than treating them as opaque strings.

What You Get

  • A mdxJsxFromMarkdown() extension that converts JSX tokens into mdxJsxFlowElement/mdxJsxTextElement mdast nodes
  • A mdxJsxToMarkdown() extension that serializes those nodes back to markdown text
  • ESTree-typed expression and spread attributes via data.estree, parsed with acorn
  • Configurable serialization: quote style, quote-smart selection, tight self-closing tags, and print-width-based attribute wrapping
  • Structured, position-aware parse errors (VFileMessage) for malformed JSX in markdown

Common Use Cases

  • Composing MDX support into a remark/unified pipeline alongside micromark-extension-mdx-jsx and mdast-util-mdx
  • Building static-site generators or doc tools that need to read or rewrite JSX embedded in markdown content
  • Writing linting or codemod tooling that visits mdxJsxFlowElement/mdxJsxTextElement nodes to validate JSX usage in MDX files
  • Implementing custom MDX compilers that need direct control over the JSX AST, separate from React/Babel’s JSX runtime

Under The Hood

Architecture The library is organized as two independent codecs assembled around mdast/unist token streams: lib/index.js exports mdxJsxFromMarkdown(), an extension object of enter/exit handler maps keyed by micromark token names (mirrored for mdxJsxFlowTag* and mdxJsxTextTag* variants) that build up a tag accumulator on the compile context’s data bag as the parser walks tokens, and mdxJsxToMarkdown(options), a handle map keyed by mdast node type that serializes back through internal containerFlow/inferDepth/createIndent helpers to respect indentation and print-width wrapping. There is no class hierarchy or dependency injection here — state flows entirely through the CompileContext/State objects handed in by mdast-util-from-markdown and mdast-util-to-markdown, so the package is purely a plugin/extension surface with no standalone entry point of its own; changing the shared tag shape or enter/exit key names would ripple into every sibling mdast-util-mdx-* package relying on the same token contract.

Tech Stack It’s pure ESM (Node 16+, single exports field), authored in typed JSDoc compiled to .d.ts declarations via tsc --build with type-coverage enforcing full type coverage, with runtime dependencies limited to mdast-util-from-markdown, mdast-util-to-markdown, devlop (assertions), ccount, parse-entities/stringify-entities (HTML entity handling), unist-util-stringify-position, and vfile-message for structured errors. Dev tooling adds micromark-extension-mdx-jsx/micromark-extension-mdx-md for parser-level fixtures, acorn for expression parsing in tests, xo plus prettier for linting/formatting, and c8 for coverage — a standard syntax-tree package in the unified/remark ecosystem with no runtime framework dependency beyond its sibling mdast-util packages.

Code Quality The test suite is a single large file run twice under different Node module conditions to exercise both development-only and production assertion paths, gated by a coverage threshold that requires full statement and branch coverage. Assertions rely on Node’s built-in assertion module rather than a separate test framework, keeping the dependency surface minimal. Error handling is explicit and typed: invalid syntax states throw structured, position-aware errors with stable error identifiers rather than silently coercing bad input, and internal invariant checks guard states that should be unreachable if the token stream is well-formed. Naming is consistent and verbose, mirroring token names one-to-one with handler function names, and the build pipeline chains type-checking, formatting, linting, and coverage into a single test script.

What Makes It Unique The library’s real contribution is a precise, reversible mapping between micromark’s low-level JSX tokens and mdast’s tree shape, correctly distinguishing block-level from inline JSX placement and serializing both back to markdown without losing fidelity — a round-trip guarantee most ad hoc JSX-in-markdown handling doesn’t attempt. It also exposes parsed expression attributes as real ESTree nodes so downstream tools can statically analyze JSX prop expressions instead of treating them as opaque strings. This isn’t novel in a research sense — it’s foundational infrastructure — but its round-trip rigor and estree bridging exceed typical regex-based JSX-in-markdown approaches.

Used by 5 apps in this directory

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 1 weeks 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 1 weeks ago
TypeScript
96%
MIT

Payload CMS

Blogging · CMS · Developer Tools

44,995

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
TypeScript 96%
Updated 1 weeks ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

110,828

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,811

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

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