备注结构
从你的文档中提取信息,有助于实现文档搜索
使用
🌐 Usage
将其添加为 remark 插件。
🌐 Add it as a remark plugin.
import { compile } from '@mdx-js/mdx';
import { remarkStructure } from 'fumadocs-core/mdx-plugins';
const vfile = await compile('...', {
remarkPlugins: [remarkStructure],
});这个插件默认包含在 Fumadocs MDX 中。
提取的信息可以在 vfile.data.structuredData 中找到,你可以编写自己的插件将其转换为 MDX 导出。
🌐 Extracted information could be found in vfile.data.structuredData, you may
write your own plugin to convert it into a MDX export.
选项
🌐 Options
Prop
Type
输出
🌐 Output
标题和内容的列表。段落将被提取到 contents 数组中,每个项目包含一个 heading 属性,表示段落的标题。
🌐 A list of headings and contents. Paragraphs will be extracted to the contents
array, each item contains a heading prop indicating the heading of paragraph.
注意
一个标题可以有多段文字。
标题
🌐 Heading
| 属性 | |
|---|---|
id | 标题的唯一标识符或别名 |
content | 文本内容 |
内容
🌐 Content
| 属性 | |
|---|---|
heading | 段落标题(可为空) |
content | 文本内容 |
作为函数
🌐 As a Function
接受 MDX/Markdown 内容并返回结构化数据。
🌐 Accepts MDX/markdown content and return structurized data.
import { structure } from 'fumadocs-core/mdx-plugins';
structure(page.body.raw);提示
如果你启用了自定义 remark 插件,例如 remark-math,你必须将这些插件传递给该函数。这可以避免段落内容难以阅读。
import { structure } from 'fumadocs-core/mdx-plugins';
import remarkMath from 'remark-math';
structure(page.body.raw, [remarkMath]);参数
🌐 Parameters
| 参数 | |
|---|---|
content | MDX/Markdown 内容 |
remarkPlugins | 备注插件列表 |
options | 自定义选项 |
Last updated on
