# 在 Confluence 中嵌入 GitHub 文件 要在 Confluence 中嵌入 GitHub 文件,请将 **Github file (Capable)** 宏添加到页面,连接您的 GitHub 账户,然后选择仓库和文件,并选择 **Add to page**。或者,也可以直接将文件的 GitHub 链接粘贴到编辑器中。文件会保持实时更新:代码会高亮显示,Markdown 会被格式化,图表也会被绘制出来。 --- ## 开始之前 | **您需要** | **原因** | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | 拥有编辑页面的权限 | 该宏在 Confluence 编辑器中添加。 | | 可读取该仓库的 GitHub 账户 | 选择器仅列出您已连接的账户可见的仓库。以链接形式粘贴的公开文件无需连接。 | | 私有文件的读者需要拥有自己的访问权限 | 每位读者需连接自己的 GitHub 账户,不会借用您的账户。请参阅 [私有文件路径](https://help.gocapable.com/zh-hans/git/private-file-path.html)。 | --- ## 步骤 1. 打开 Confluence 页面并选择 **Edit**。 2. 输入 **/Github** 并选择 **Github file (Capable)**。 3. 在宏上选择 **Select File**,打开 **Browse Git Repositories** 窗口。 4. 如果尚未连接 GitHub,请选择 **Connect**,并在打开的 GitHub 窗口中授权该应用。 5. 在 **Search repositories or paste URL...** 中输入仓库名称的一部分,或粘贴 GitHub 文件链接并按 Enter 键。 6. 打开仓库,逐级进入文件夹直到找到该文件,然后选择它进行预览。 7. 选择 **Add to page**,然后发布页面。 📝 **更快捷的方式:**将 github.com `/blob/` 链接或 raw.githubusercontent.com 链接粘贴到编辑器中,它会自动转换为该宏,并从链接中获取仓库、分支和路径。请参阅 [自动转换粘贴的 GitHub 链接](https://help.gocapable.com/zh-hans/git/auto-convert-pasted-github-links.html)。 --- ## 后续会发生什么 文件显示在包含 `owner/repo/path` 的标题下方。当分支不是 `main` 时,分支名称会显示在括号中。读者可以选择**在 GitHub 上打开**跳转到该文件,已登录的读者还可以使用**刷新内容**。页面署名栏会统计文件数量,例如**1 个文件**。 每次查看页面时,该宏都会从 GitHub 读取文件,因此始终显示分支上的最新内容。无需同步。 --- ## 如果仍然无法解决 * 该宏会提示读者**连接 GitHub**:该文件为私有文件,且该读者没有已连接且有访问权限的账号。请参阅[读者看到“请连接有权访问此仓库的 GitHub 账号以查看此文件”](https://help.gocapable.com/zh-hans/git/readers-see-connect-a-github-account-with-access-to-this-repository-to-view-this-file.html)。 * 选择器显示**无法渲染此文件类型**:不支持该文件类型,例如 PDF 或 zip 文件。 * 粘贴的链接仍然是链接:请参阅[粘贴了 GitHub URL 但没有变成宏](https://help.gocapable.com/zh-hans/git/pasted-a-github-url-and-it-did-not-turn-into-a-macro.html)。 --- ## 相关内容 ### [Github 文件](https://help.gocapable.com/zh-hans/git/github-file.html) 所有设置项以及宏的显示内容。 ### [自动转换粘贴的 GitHub 链接](https://help.gocapable.com/zh-hans/git/auto-convert-pasted-github-links.html) 粘贴链接,即可获得宏。 ### [将您的 GitHub 账户连接到 Confluence](https://help.gocapable.com/zh-hans/git/connect-your-github-account-to-confluence.html) 请先关联您的 GitHub 账号。 ### [在 Confluence 中显示 GitHub README](https://help.gocapable.com/zh-hans/git/show-a-github-readme-in-confluence.html) README 同样适用。 ### [故障排查](https://help.gocapable.com/zh-hans/git/troubleshooting.html) 文件未显示时的处理方法。 --- _一个宏,显示文件的当前内容。_