> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiIzOGU0MDRmOS02MTFiLTRjN2EtYTYwYi0wYjdhODVkMDk5ZDkiLCJleHAiOjE3NzgyNTg4OTYsImlhdCI6MTc3ODI1ODU5Nn0.Y1-oS_PxxXQ6ZSiT5eWJ7_crkB9sQKdSqXIN5LLk5HE
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# Markdown 基础

> 使用 Markdown 和 MDX 在 Fern 文档网站中添加内容，包括标题、组件、链接和 API 端点链接。

学习如何使用 Markdown 和 MDX 在文档中添加内容，包括标题、组件和链接。

<Note title="术语说明">
  在本文档中，"Markdown" 指代 Markdown 和 MDX。[MDX](https://mdxjs.com/) 是 Markdown 的扩展版本，允许使用 JSX 组件。
</Note>

## 添加 Markdown 或 MDX 页面

通过创建 Markdown（`.md`）或 MDX（`.mdx`）文件手动向文档添加页面。初次接触 Markdown？请参阅 [Markdown Guide: Getting started](https://www.markdownguide.org/getting-started/)。

将页面放置在 `fern/` 文件夹内，并在 `docs.yml` 文件的[导航设置](/learn/docs/configuration/navigation)中链接到它们。

在下面的示例中，MDX 文件位于名为 `pages/` 的文件夹内。

<CodeBlock title="示例文件夹结构">
  ```bash
  fern/
  ├─ fern.config.json
  ├─ docs.yml
  └─ pages/
    ├─ welcome.mdx
    └─ quickstart.mdx
  ```
</CodeBlock>

<CodeBlock title="docs.yml">
  ```yml
  navigation:
    - section: 概述
      contents:
        - page: 欢迎
          path: ./pages/welcome.mdx
        - page: 快速开始
          path: ./pages/quickstart.mdx
  ```
</CodeBlock>

## 页面标题

Fern 使用 `docs.yml` 中的 `page` 值自动为每个页面生成 `<h1>` 页面标题。例如，以下条目将此页面的页面标题设置为"Markdown basics"：

```yml docs.yml
- page: Markdown basics
  path: ./pages/component-library/writing-content/markdown-basics.mdx
```

因为 `<h1>` 是自动生成的，您应该从 `<h2>` 标题开始页面内容，而不是 `<h1>`。

## Markdown 中的链接

### 链接格式

使用 `/` 字符开始一个指向文档网站上另一个页面的相对 URL。这会路由到 `docs.yml` 文件中定义的 `url`，例如 `example-docs.buildwithfern.com`。例如，如果您想链接到 `https://example-docs.buildwithfern.com/overview/introduction`，您可以在 Markdown 中这样写链接：

<CodeBlock title="相对链接示例">
  ```mdx
  阅读[介绍](/learn/sdks/overview/introduction)。
  ```
</CodeBlock>

### API 链接语法

Use `api:` link syntax to link to API endpoints or API Reference sections in any Markdown content. Fern resolves these links at build time, so you don't need to hardcode slugs.

<AccordionGroup>
  <Accordion title="Link to an endpoint">
    Use `api:METHOD/path`, where `METHOD` is an HTTP method (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`) and `/path` is the endpoint path from your API definition. Path parameters use curly braces, such as `api:GET/v2/payments/{paymentId}`.

    For projects with [multiple APIs](/learn/docs/api-references/generate-api-ref#include-more-than-one-api-reference), prefix with the API name: `api:API-NAME:METHOD/path`.

    ```mdx Markdown
    View the [Current user information](api:mcp-tools:GET/api/fern-docs/whoami) endpoint.
    ```
  </Accordion>

  <Accordion title="Link to the root of an API Reference section">
    Use `api:apiName`, where `apiName` matches the API name in your `generators.yml` file. This is useful when your project has multiple APIs and you want to link to the root landing page of a specific API Reference.

    ```mdx Markdown
    Explore the [Plant Store API](api:plant-store) reference.
    ```
  </Accordion>
</AccordionGroup>

### 链接目标

Control where links open with the `target` property. Available for product, tab, navbar, and page links. For typical documentation sites, links can open in the same tab (`_self`) or new tab (`_blank`). For documentation embedded in a dashboard or iframe, links can open in the parent frame (`_parent`) or topmost frame (`_top`).

```yaml title="docs.yml" {8}
navigation:
  - section: Home
    contents:
      - page: Introduction
        path: ./intro.mdx
      - link: Our YouTube channel
        href: https://www.youtube.com/
        target: _blank
```

[了解更多](/learn/docs/configuration/navigation)关于链接和其他导航元素的信息。

## 表格

使用标准 Markdown 语法通过管道（`|`）和连字符（`-`）创建表格：

```markdown
| 列 1 | 列 2 | 列 3 |
|----------|----------|----------|
| 行 1    | 数据     | 数据     |
| 行 2    | 数据     | 数据     |
```

对于更高级的表格功能，如较长数据集的粘性标题，请参阅[表格组件](/learn/docs/writing-content/components/tables)文档。

## Fern 组件

Fern 具有内置组件库，您可以在 Markdown 中使用。[探索组件。](/learn/docs/content/components/overview)