Remark LLMs
Export the Markdown of your documents for LLMs.
The remarkLLMs plugin exports the Markdown of a document as _markdown, for LLMs. It keeps the Markdown you wrote. See Stringification for how it's generated.
import { Callout } from 'fumadocs-ui/components/callout';
## Getting Started
<Callout>Hello **world**.</Callout>ESM is removed, headings get their IDs (see headingIds), and included content is expanded with Fumadocs MDX.
Usage
remarkLLMs is a remark plugin. Enable it in Fumadocs MDX with includeProcessedMarkdown, on both unified and Sätteri:
import { defineDocs } from 'fumadocs-mdx/config';
export const docs = defineDocs({
docs: {
postprocess: {
// `true`, or the options of `remarkLLMs`
includeProcessedMarkdown: true,
},
},
});Read it from your pages with getText('processed'), which renders the Markdown with the page props:
const markdown = await page.data.getText('processed');Images
Images beside your pages, imported by Remark Image, get the URLs your bundler serves them at:
Images in the public directory keep their address. Vite inlines images smaller than build.assetsInlineLimit as data: URLs.
Output
The output option sets the form of _markdown:
function:_markdownis a component, which you render withrenderToMarkdown(). The Markdown is generated with the page props: content inside a<show>that isn't rendered is left out, expressions are replaced by their values, and JSX elements by their Markdown form.string:_markdownis a string. Expressions and JSX elements are kept as source text, and a document with<show>fails to compile.
The default is function in Fumadocs MDX and @fumadocs/astro, and string elsewhere. A custom content source gets function with runtime outputs.
JSX Elements
With output: 'function', 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. Pass MDX components to a page with getPage():
const page = source.getPage(slugs, { props: { components } });A component defines its Markdown form with asMarkdown(). A component without one is kept as JSX. To remove elements, or replace them with their children, use filterElement (unavailable on Sätteri).
Placeholders
To render JSX elements yourself, list them as placeholders:
import type { LLMsOptions } from 'fumadocs-core/mdx-plugins/remark-llms';
const llmsOptions: LLMsOptions = {
mdxAsPlaceholder: ['Callout'],
};Then render them, from runtime data if needed:
import { renderPlaceholder } from 'fumadocs-core/mdx-plugins/remark-llms.runtime';
const markdown = await renderPlaceholder(await page.data.getText('processed'), {
// `children` is the Markdown of its content
Callout: ({ attributes, children }) => `> **${attributes.title}**\n>\n> ${children}`,
});On Sätteri, mdxAsPlaceholder is unavailable.
Options
Prop
Type
How is this guide?
