Fumadocs

标题

处理文档中的标题

Remark Heading

为标题应用 ID。

MDX Compiler
import { compile } from '@mdx-js/mdx';
import { remarkHeading } from 'fumadocs-core/mdx-plugins';

await compile('...', {
  remarkPlugins: [remarkHeading],
});

此插件默认包含在 Fumadocs MDX 中。

Extract TOC

默认情况下,它会将文档的标题(目录)提取到 vfile.data.toc 中。 您可以使用以下方式禁用它:

import { remarkHeading } from 'fumadocs-core/mdx-plugins';

export default {
  remarkPlugins: [[remarkHeading, { generateToc: false }]],
};

Custom Ids

您可以使用 [#slug] 来自定义标题 ID。

# heading [#slug]

Output

一个 TOCItemType 数组。

Prop

Type

Rehype TOC

导出目录(一个 TOCItemType 数组),它允许使用 JSX 节点,这是 Remark 插件无法实现的。

它需要 MDX.js。

Usage

import { rehypeToc } from 'fumadocs-core/mdx-plugins';

export default {
  rehypePlugins: [rehypeToc],
};

Output

对于 Markdown 文档:

## Hello `code`

将创建一个导出:

export const toc = [
  {
    title: (
      <>
        Hello <code>code</code>
      </>
    ),
    depth: 2,
    url: '#hello-code',
  },
];

How is this guide?

Last updated on