MDX(Markdown + JSX)是一种文件格式,它允许你在 Markdown 文档中嵌入 JSX 代码(即带有 XML 语法的 JavaScript)。这种组合使得 MDX 成为了一个强大的工具,特别适合用于编写包含交互式组件和富文本内容的文档或教程。MDX 文件通常以 .mdx 为扩展名。
@mdx-js/react 和 remark-mdx。下面是一个简单的 MDX 文件示例,展示了如何混合使用 Markdown 和 JSX:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# Welcome to My MDX Document This is a regular paragraph of text. ## Interactive Example Here's an interactive button component: import Button from '../components/Button'; <Button onClick={() => alert('Hello, world!')}>Click me</Button> ## Code Blocks You can also include code blocks with syntax highlighting: ```js function add(a, b) { return a + b; } |
And even inline JSX expressions:
{The sum of 2 and 3 is ${2 + 3}.}
.mdx 文件,并开始编写结合了 Markdown 和 JSX 的内容。通过 MDX,你可以轻松创建既美观又功能丰富的文档和网页,同时保持开发效率和灵活性。
from:https://www.cnblogs.com/longmo666/p/18646184