Skills2026年5月16日·1 分钟阅读

MDX — Markdown for the Component Era

MDX lets you use JSX components directly inside Markdown documents, enabling interactive and dynamic content in documentation sites, blogs, and design systems.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
MDX
直接安装命令
npx -y tokrepo@latest install 08b5e23d-5166-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

MDX is an authoring format that combines the simplicity of Markdown with the power of JSX. It allows you to import and render React (or other framework) components directly within Markdown content, making it the standard for interactive documentation, blogs, and content-heavy applications.

What MDX Does

  • Parses Markdown with embedded JSX expressions and component imports
  • Compiles MDX files into framework components (React, Preact, Vue, Svelte)
  • Supports standard Markdown syntax including GFM (tables, task lists, footnotes)
  • Allows passing props and data to embedded components at render time
  • Integrates with remark and rehype plugin ecosystems for content transformation

Architecture Overview

MDX uses a pipeline: the MDX compiler parses source into an AST using micromark (Markdown) and acorn (JavaScript), then applies remark/rehype plugins for transformations, and finally serializes the AST into a JavaScript module that exports a component function. This pipeline runs at build time, producing static or server-rendered output with no client runtime cost for static content.

Self-Hosting & Configuration

  • Add @mdx-js/loader to webpack or use the Vite plugin @mdx-js/rollup
  • Configure via mdx options in your bundler (remarkPlugins, rehypePlugins)
  • Use next.config.mjs with @next/mdx for Next.js integration
  • Set providerImportSource to customize the component provider
  • Add TypeScript types with @types/mdx for editor autocompletion

Key Features

  • Full interop with any component framework via JSX
  • remark/rehype plugin system for syntax extensions and transformations
  • Compiles to static output with zero client JS for non-interactive content
  • Supports expressions, imports, and exports inside Markdown
  • Works with content layers like Contentlayer, Velite, or Fumadocs

Comparison with Similar Tools

  • Markdoc — Stripe's Markdoc uses custom tag syntax; MDX uses standard JSX familiar to React developers
  • Astro Components — Astro's .astro files mix HTML and JS; MDX focuses specifically on Markdown-first content
  • remark-html — remark outputs static HTML; MDX produces interactive component trees
  • Docusaurus Markdown — Docusaurus uses MDX under the hood for its documentation features
  • reStructuredText — RST is powerful but Python-ecosystem-only; MDX works across JS frameworks

FAQ

Q: Does MDX add runtime overhead? A: No. MDX compiles at build time. Static content ships as plain HTML with zero additional JavaScript.

Q: Can I use MDX with Vue or Svelte? A: Yes. MDX v3 supports multiple JSX runtimes. Configure the jsxImportSource option for your framework.

Q: How do I add syntax highlighting to code blocks? A: Use rehype plugins like rehype-shiki or rehype-prism-plus in your MDX pipeline configuration.

Q: Is MDX compatible with standard Markdown files? A: Yes. Any valid Markdown file is valid MDX. You can rename .md to .mdx and add components incrementally.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产