> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/creating-content/reusable-content.md).

# 可复用内容

{% hint style="info" %}
此功能适用于 [专业版和企业版方案](https://www.gitbook.com/pricing).
{% endhint %}

可复用内容让你可以在多个页面和章节之间同步内容，因此你可以同时编辑该块的所有实例。

<figure><img src="/files/04929e36cedac0101f0b5177f8945147b5261639" alt="A GitBook screenshot showing reusable content"><figcaption><p>在某个章节内创建可复用内容。</p></figcaption></figure>

## 基础知识

可复用内容的工作方式与其他内容完全相同——你可以通过变更请求对其进行修改，将其纳入审阅工作流，并且它会在任何已发布站点上正确呈现。

虽然可复用内容可以在多个章节中被引用，但它隶属于一个单独的 *父章节*.

### “父章节”概念

父章节是拥有该可复用内容的章节。只有在这里才能编辑该内容。

尽管对可复用内容的更新会立即出现在所有实例中，但所有更改都必须源自父章节——无论是直接编辑还是通过变更请求。

章节同时支持编辑工作流和安全性。由于 GitBook 基于权限进行编辑控制，可复用内容只能从其父章节中更改。这样可以确保编辑权限得到尊重，即使内容在整个组织中被重复使用也是如此。

### 已知限制

#### 集成

由集成提供的块不支持用于可复用内容。这是因为 GitBook 中的集成是按章节安装的，限制访问可确保第三方集成仅拥有你授予的权限。在多个章节之间引用可复用内容会破坏这一安全边界。

#### 搜索

目前，可复用内容只会出现在其父章节内的搜索结果中。我们正在积极努力取消这一限制，以便可复用内容在其被引用的任何位置都能出现在搜索结果中。

## 在应用中

### **创建可复用内容**

要创建可复用内容，请选择一个或多个块，然后打开 **操作菜单** <picture><source srcset="/files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="/files/d05670ba93b683794fb3fe95a9fc7ab5c7fceafd" alt="The Actions menu icon in GitBook"></picture> ，选择 **转换为**，并选择 **可复用内容**。你也可以为你的块命名，这样以后更容易找到和重复使用。

或者，你也可以选择一个或多个块，然后按下 **Cmd + C** 以打开一个提示，询问你是否要创建可复用内容。

### **插入可复用内容**

你可以像插入任何其他块一样插入可复用内容。按 `/` 在空白行上打开 **插入面板**。你也可以点击任何块或空白行旁边的 `+` 。

页面侧边栏中的可复用内容面板会列出当前章节中之前创建的内容块。

要从当前章节或另一个章节插入可复用内容，你可以访问：

1. 从 **插入面板** 或 `+` 菜单。
2. 使用顶部的章节选择器来选择源章节。
3. 按名称搜索可复用块，然后选择它将其插入。

从另一个章节插入内容不会转移所有权。只有父章节才能编辑可复用内容。来自该父章节的更新会继续同步到每个实例。

### **编辑可复用内容**

可复用内容就像其他任何内容一样——如果已启用实时编辑，你可以直接编辑任一实例；如果没有启用，则可以通过变更请求进行编辑。你所做的任何更改都会同步到该内容被使用的所有位置。

如果你是在变更请求中进行更改，那么一旦该变更请求合并，内容就会同步到所有其他实例。

### **分离可复用内容**

你可以通过打开 **操作菜单** <picture><source srcset="/files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="/files/d05670ba93b683794fb3fe95a9fc7ab5c7fceafd" alt="The Actions menu icon in GitBook"></picture> 并选择 **分离**来分离可复用内容。分离后会将内容转换回普通块。

一旦分离，你对该块的更改将不会反映到其他实例中，而你在那些实例中所做的更改也不会反映到已分离的块中。可复用内容的所有其他实例仍会彼此保持同步。

### 删除可复用内容

如果你愿意，可以完全从你的章节中删除可复用内容。在页面的目录中找到该可复用内容，然后打开 **操作菜单** <picture><source srcset="/files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="/files/d05670ba93b683794fb3fe95a9fc7ab5c7fceafd" alt="The Actions menu icon in GitBook"></picture> 在你想删除的内容旁边，选择 **删除**.

删除可复用内容将会 **将其从所有使用它的页面中删除**。此操作无法撤销。

## 与 GitHub 和 GitLab 同步

同步到 GitHub 和 GitLab 时完全支持可复用内容。你的可复用内容将被导出到一个专用的 `包含` 文件夹，其中每个内容都是一个单独的 Markdown 文件。

然后，你的内容会通过 `包含` 指令在其他页面中被引用。

{% hint style="info" %}
同步时， `.gitbook/includes` 目录会在每个已同步章节的根目录中创建（这可能并不是整个仓库的根目录）。如果你的 `.gitbook/includes` 文件夹或其文件出现在你章节的目录中，你可能需要手动将它们从 TOC 中隐藏。
{% endhint %}

#### 示例

{% hint style="success" %}
如果你是在 GitHub 端编写，请确保 include 的路径是相对于包含引用的文件，而不是仓库根目录。
{% endhint %}

```markdown
{% include "../../.gitbook/includes/reusable-block.md" %}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/creating-content/reusable-content.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
