ZZajaly.dev

Remark Structure

Extract information from your documents, useful for implementing document search

Usage

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],
});

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

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.

Note

A heading can have multiple paragraphs.

Heading

Prop
idunique identifier or slug of heading
contentText content (Markdown)

Content

Prop
headingHeading of paragraph (nullable)
contentText content (Markdown)

The content is stringified as Markdown text, you can customise it using the stringify option.

As a Function

Accepts MDX/markdown content and return structurized data.

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

structure(page.body.raw);

Tip

If you have custom remark plugins enabled, such as remark-math, you have to pass these plugins to the function. This avoids unreadable content on paragraphs.

import { structure } from 'fumadocs-core/mdx-plugins';
import remarkMath from 'remark-math';

structure(page.body.raw, [remarkMath]);

Parameters

Parameter
contentMDX/markdown content
remarkPluginsList of remark plugins
optionsCustom options

How is this guide?

Last updated on

On this page