跳至正文
Wener Notes

MDX

约 1 分钟阅读
    • Markdown+JSX
    • remark, rehype, recma
  • 参考
    • mdxjs.com/playground
      • mdxast 插件,添加 mermaid 支持
      • 可以支持直接渲染 svg - 需要 puppeteer
      • {type:mermaidCodeBlock, data:{hName, hProperties:{config:{}, chart:""}}}
input.mdx
export const Thing = () => <>World</>;

# Hello <Thing />
output-outline.jsx
/* @jsxRuntime automatic @jsxImportSource react */

export const Thing = () => <>World</>;

export default function MDXContent() {
  return (
    <h1>
      Hello <Thing />
    </h1>
  );
}
  • 默认 export MDXContent
    • props
      • components: Record<string,ComponentType> | ()=>Record<string,ComponentType>
  • export default function Layout - 同 components.wrapper
  • <MDXProvider components={components}></MDXProvider>
    • 上下文配置好组件

Notes

Version

MDX v3

  • 支持 await
  • 支持 ES2024 语法 - 更新 Acorn
  • Adjacent block JSX and expressions in MDX
MDX
<style>{`

  h1 {
    color: blue;
  }

`}</style>

MDX v2

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

GitHub9 条
其他外链4 条
最近更新commit 3d5e006编辑