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

匯出文件的 Markdown，供 LLM 使用。

`remarkLLMs` 外掛會將文件的 Markdown 匯出為 `_markdown`，供 LLM 使用，並保留您原本撰寫的 Markdown。產生方式請參閱[字串化](/docs/headless/mdx/stringification)。

```mdx tab="Input"
import { Callout } from 'fumadocs-ui/components/callout';

## Getting Started

<Callout>Hello **world**.</Callout>
```

```md tab="Output"
## Getting Started [#getting-started]

<Callout>Hello **world**.</Callout>
```

ESM 會被移除，標題會加上各自的 ID (請參閱 `headingIds`) ，而透過 Fumadocs MDX 引入的內容也會展開。

## 使用方式 [#usage]

`remarkLLMs` 是一個 remark 外掛。您可以在 Fumadocs MDX 中透過 `includeProcessedMarkdown` 啟用它，unified 與 Sätteri 皆適用：

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

export const docs = defineDocs({
  docs: {
    postprocess: {
      // `true`，或 `remarkLLMs` 的選項
      includeProcessedMarkdown: true,
    },
  },
});
```

在頁面中使用 `getText('processed')` 讀取內容，它會搭配頁面的 props 算繪 Markdown：

```ts
const markdown = await page.data.getText('processed');
```

## 圖片 [#images]

與頁面放在一起、由 [Remark Image](/docs/headless/mdx/remark-image) 匯入的圖片，會使用打包工具提供這些圖片時的 URL：

```md tab="Input"
![How a calculation flows](./flow.png)
```

```md tab="Output"
![How a calculation flows](/assets/flow-Dxg6sAyC.png)
```

public 目錄中的圖片會保留原本的位址。小於 [`build.assetsInlineLimit`](https://vite.dev/config/build-options#build-assetsinlinelimit) 的圖片會由 Vite 內嵌為 `data:` URL。

## 輸出 [#output]

`output` 選項用於設定 `_markdown` 的形式：

* `function`：`_markdown` 是一個元件，請使用 [`renderToMarkdown()`](/docs/headless/utils/markdown) 加以算繪。Markdown 會依據頁面 props 產生：[`<show>`](/docs/next/markdown#show) 中未算繪的內容會被省略，表達式會替換為其值，JSX 元素則會替換為對應的 [Markdown 形式](#jsx-elements)。
* `string`：`_markdown` 是一個字串。表達式與 JSX 元素會以原始文字保留，而包含 `<show>` 的文件則會編譯失敗。

在 Fumadocs MDX 與 `@fumadocs/astro` 中，預設值為 `function`，其他情況則為 `string`。自訂內容來源若使用[執行階段輸出](/docs/headless/source-api/source#runtime-outputs)，則會得到 `function`。

## JSX 元素 [#jsx-elements]

使用 [`output: 'function'`](#output) 時，元件的查找方式與 MDX 相同：先查找檔案中的匯入與宣告，再查找[頁面 props](/docs/headless/source-api#custom-props) 中的 MDX 元件。請透過 `getPage()` 將 MDX 元件傳入頁面：

```ts
const page = source.getPage(slugs, { props: { components } });
```

元件可透過 [`asMarkdown()`](/docs/headless/utils/markdown#asmarkdown) 定義其 Markdown 形式，未定義的元件則會保留為 JSX。若要移除元素，或改以其子元素取代，請使用 `filterElement` (Sätteri 不支援) 。

### 預留位置 [#placeholders]

若要自行算繪 JSX 元素，請將它們列為預留位置：

```ts
import type { LLMsOptions } from 'fumadocs-core/mdx-plugins/remark-llms';

const llmsOptions: LLMsOptions = {
  mdxAsPlaceholder: ['Callout'],
};
```

接著將它們算繪出來，必要時可使用執行階段的資料：

```ts
import { renderPlaceholder } from 'fumadocs-core/mdx-plugins/remark-llms.runtime';

const markdown = await renderPlaceholder(await page.data.getText('processed'), {
  // `children` 為元素內容的 Markdown
  Callout: ({ attributes, children }) => `> **${attributes.title}**\n>\n> ${children}`,
});
```

使用 Sätteri 時，無法使用 `mdxAsPlaceholder`。

## 選項 [#options]

### $Fumadocs

| Prop                | Type                                                         | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `as?`               | `string \| undefined`                                        | export name for output Markdown. Default: `_markdown`                                                                                                                                                                                                                                                                                                                                                                                                       |
| `headingIds?`       | `boolean \| undefined`                                       | Explicit heading IDs in output. Default: `true`                                                                                                                                                                                                                                                                                                                                                                                                             |
| `filterElement?`    | `((node: Nodes) => boolean \| 'children-only') \| undefined` | Filter the elements to be included in the output: - `true`: include element & its children. - `children-only`: exclude element but keep its children. - `false`: exclude element & its children. ESM nodes are always excluded.                                                                                                                                                                                                                             |
| `mdxAsPlaceholder?` | `string[] \| undefined`                                      | Tag names of MDX components to be output as placeholders, render them with `renderPlaceholder()`.                                                                                                                                                                                                                                                                                                                                                           |
| `output?`           | `"function" \| "string" \| undefined`                        | Form of the export: - `string`: the output Markdown, authored expressions keep their source. - `function`: a component, render it with `renderToMarkdown` from `fumadocs-core/server`: JSX elements are kept as JSX, receiving their original props and resolving like in the content, a component can call `asMarkdown()` to define its own Markdown form. Default: `` `function` for a content source that renders pages for props, otherwise `string` `` |