# Fumadocs Core (the core library of Fumadocs): Remark Structure
URL: /docs/headless/mdx/structure
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/headless/mdx/structure.mdx

Extract search records from your documents.

The `remarkStructure` plugin extracts the headings and contents of a document as records for [search](/docs/headless/search). Records keep the Markdown you wrote. See [Stringification](/docs/headless/mdx/stringification) for how it's generated.

```mdx tab="Input"
## Installation

Run the [command](/docs/cli) below.

<Callout>Restart the **server** after it.</Callout>

| Option | Default |
| ------ | ------- |
| `dir`  | `docs`  |
```

```json tab="Output"
{
  "headings": [{ "id": "installation", "content": "Installation" }],
  "contents": [
    { "heading": "installation", "content": "Run the command below." },
    { "heading": "installation", "content": "<Callout>Restart the **server** after it.</Callout>" },
    {
      "heading": "installation",
      "content": "| Option | Default |\n| --- | --- |\n| `dir` | `docs` |",
      "table": "table-0"
    }
  ]
}
```

## Usage [#usage]

Remark Structure is a remark plugin. Fumadocs MDX enables it by default and exports the records as `structuredData`. Pass options with `remarkStructureOptions`.

In Fumadocs MDX, the records are generated with the page props: content inside a [`<show>`](/docs/next/markdown#show) that isn't rendered is left out, and expressions are replaced by their values. Outside Fumadocs MDX, expressions are kept as source text.

## Records [#records]

Headings, paragraphs, blockquotes, tables and JSX elements are recorded (see `types`):

- Links are replaced by their text, images are removed.
- A table has a record per row, as a table of its header and that row. The rows share a `table` field.
- JSX elements are replaced by their content, except those that `filterElement` keeps (see [Components](#components)).
- A JSX element is a record when it has no children (see `mdxTypes`), or fits on one line.
- Content inside a record isn't recorded again.

In Fumadocs MDX, the plugin keeps the elements of components by default, like `<Callout>` but not `<div>`. Outside Fumadocs MDX, it keeps `File`, `TypeTable`, `Callout` and `Card`. Change it with `filterElement`:

```ts tab="unified" title="source.config.ts"
import { defineConfig } from 'fumadocs-mdx/config';

export default defineConfig({
  mdxOptions: {
    remarkStructureOptions: {
      filterElement: (node) => node.name === 'Callout' || node.name === 'Banner',
    },
  },
});
```

```ts tab="Sätteri" title="source.config.ts"
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';

export const docs = defineDocs({
  docs: { compiler: 'satteri' },
});

export default defineConfig({
  satteriOptions: {
    remarkStructureOptions: {
      filterElement: (node) => node.name === 'Callout' || node.name === 'Banner',
    },
  },
});
```

## Components [#components]

In Fumadocs MDX, a kept JSX element is recorded in one of two forms, depending on how you read the records:

- `page.data.structuredData`: components aren't rendered. The element is kept as an HTML tag, which search dialogs render as a component. With `async` or `dynamic` collections, read it from the loaded page.
- `await page.data.structuredData()`: components are rendered for the [`search` target](/docs/headless/utils/markdown#targets), and the element is replaced by its Markdown form. Only `async` and `dynamic` collections have this function.

When rendering, a component is looked up like in MDX: first in the imports and declarations of the file, then in the MDX components of the [page props](/docs/headless/source-api#custom-props).

Search reads pages from `getPages()`, which have no custom props. Import or declare a component in the file if search should render it.

A component defines its text for search with [`asMarkdown()`](/docs/headless/utils/markdown#asmarkdown):

```tsx
import { asMarkdown } from 'fumadocs-core/server';

export function ProductName() {
  if (asMarkdown()) return 'Fumadocs';
  return <span className="font-semibold">Fumadocs</span>;
}
```

A component without a Markdown form is kept as JSX syntax, like an MDX component that is missing from the page props.

## Plugins [#plugins]

Nodes inserted by plugins aren't recorded. A plugin adds the records of its node with `data.structuredData`:

```ts
node.data = {
  ...node.data,
  structuredData: {
    // `heading` defaults to the current heading
    contents: [{ heading: undefined, content: 'Generated **content**' }],
  },
};
```

To change the Markdown of authored content in records only, edit the `search` namespace with [`replaceSource()`](/docs/headless/mdx/stringification#editing-the-output).

## As a Function [#as-a-function]

On unified, `structure()` extracts the records from a string:

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

// with the remark plugins your content needs
const data = structure(content, [remarkMath], options);
```

## Options [#options]

### StructureOptions

| Prop             | Type                                                  | Description                                                                                                                                                                                                                                                                                                                                        |
| ---------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `types?`         | `string[] \| ((node: Nodes) => boolean) \| undefined` | MDAST node types to be scanned as a content block. If a node's type is listed in this array, it will be converted into a single content block, except tables which become a content block per row, along with the header row. Default: `['heading', 'paragraph', 'blockquote', 'table', 'mdxJsxFlowElement']`                                      |
| `mdxTypes?`      | `((node: JsxElement) => boolean) \| undefined`        | Whether the MDX element should be treated as a single content block, only effective if `types` has `mdxJsxFlowElement`. Default: return `true` if the element is a leaf node, otherwise `false`.                                                                                                                                                   |
| `filterElement?` | `((node: JsxElement) => boolean) \| undefined`        | Return `true` to keep a JSX element, other elements are replaced by their content. Kept elements are HTML tags, or render into Markdown like processed Markdown when the export is a function of the props. Default: `File`, `TypeTable`, `Callout` and `Card` elements, or the elements of components when the export is a function of the props. |
| `exportAs?`      | `string \| boolean \| undefined`                      | export as `structuredData` (if true) or specified variable name.                                                                                                                                                                                                                                                                                   |