包含
从其他文件中重用内容。
使用
内容
要显示来自另一个 Markdown/MDX 文件的内容,请在 <include> 标签中指定相对于文件本身的路径。
<include>./another.mdx</include>针对 Markdown
Markdown (.md) 文件不支持 JSX 语法。要使用 <include />,您需要配置 remark-directive。
import { defineConfig } from 'fumadocs-mdx/config';
import remarkDirective from 'remark-directive';
export default defineConfig({
mdxOptions: {
remarkPlugins: [remarkDirective],
},
});您可能还需要 rehype-raw 来处理 HTML 注释和内容。
代码块
对于其他类型的文件,它将变成代码块:
<include>./script.ts</include>
<include lang="md" meta='title="lib.md"'>
page.md
</include>cwd
从 cwd 而非当前文件解析相对路径:
<include cwd lang="tsx" meta='title="lib.ts"'>
./script.ts
</include>提取
在引用内容文件时,您只能包含文档的特定部分。
部分
通过 <section /> 标签封装:
## Hello World
<section id="test">This is included</section>
This is not included.在 Markdown 中:
## Hello World
:::section{#test}
This is included
:::
This is not included.标题
包含某个标题下的内容
## Included Section
I'm here!
## Not Included
Some random text.在 Markdown 中:
## Included Section
I'm here!
## Not Included
Some random text.How is this guide?
Last updated on
