format-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFormat Docs
格式化文档
Prepare markdown documents for clean Confluence publishing via . This skill analyzes and transforms markdown files — individually or as a directory tree — to follow the conventions that Confluence expects.
orbit confluence publish通过工具为Markdown文档进行格式化,使其能干净利落地发布到Confluence。此技能会分析并转换Markdown文件(单个文件或整个目录树),使其符合Confluence的规范。
orbit confluence publishWhen to Use
使用场景
- Before running for the first time on a docs directory
orbit confluence publish - When adding new markdown files to an existing published docs tree
- When docs render poorly in Confluence and need structural fixes
- When migrating docs from another system (GitHub wiki, Notion export, etc.)
- 首次对文档目录运行之前
orbit confluence publish - 向已发布的文档树中添加新Markdown文件时
- 文档在Confluence中渲染效果不佳,需要结构修复时
- 从其他系统(GitHub wiki、Notion导出文件等)迁移文档时
Process
处理流程
1. Assess the Scope
1. 评估处理范围
Determine whether the user is asking about a single file or a directory.
- Single file: Read it and apply the file-level checks below.
- Directory: List the full tree, then work through both directory-level and file-level checks.
确定用户的需求是处理单个文件还是整个目录。
- 单个文件:读取文件并应用下文的文件级检查规则。
- 目录:列出完整的目录树,然后依次执行目录级和文件级检查。
2. Directory-Level Checks
2. 目录级检查
If formatting a directory, verify and fix these structural issues:
INDEX.md files — Every directory that contains markdown files needs an . This file becomes the parent page in Confluence for all sibling files.
INDEX.md.mddocs/
INDEX.md ← Required: parent page for docs/
overview.md
api/
INDEX.md ← Required: parent page for api/
endpoints.mdIf an is missing, create one with:
INDEX.md- Frontmatter (title from directory name, today's date)
- A brief intro line
- A properties report directive (see below)
- Child page tables wrapped in confluence ignore blocks
INDEX.md structure — Every INDEX.md must follow this pattern:
markdown
---
title: "Section Title"如果格式化的是目录,需验证并修复以下结构问题:
INDEX.md文件 —— 每个包含Markdown文件的目录都需要一个文件。该文件会成为Confluence中所有同级文件的父页面。
INDEX.md.mddocs/
INDEX.md ← 必填:docs/的父页面
overview.md
api/
INDEX.md ← 必填:api/的父页面
endpoints.md如果缺少文件,需创建一个包含以下内容的文件:
INDEX.md- 前置元数据(frontmatter):标题来自目录名称,日期为当天日期
- 简短的介绍语句
- 属性报告指令(见下文)
- 包裹在confluence忽略块中的子页面表格
INDEX.md结构 —— 每个INDEX.md必须遵循以下格式:
markdown
---
title: "Section Title"... full frontmatter ...
... 完整前置元数据 ...
confluence_labels:
- my-label
confluence_labels:
- my-label
Section Title
Section Title
Brief intro summarizing the section.
<!-- confluence:properties-report cql="ancestor = currentContent() AND label = 'my-label'" firstcolumn="Title" headings="Owner,Status,Version,Reviewed on" --> <!-- confluence:ignore-start -->
概述该章节的简短介绍。
<!-- confluence:properties-report cql="ancestor = currentContent() AND label = 'my-label'" firstcolumn="Title" headings="Owner,Status,Version,Reviewed on" --> <!-- confluence:ignore-start -->
Subsection Name
子章节名称
| Document | Version | Summary |
|---|---|---|
| Child Page | v1.0 | Brief description |
Key rules for INDEX.md files:
1. **Properties report directive** — Add a `<!-- confluence:properties-report -->` directive after the intro content. This generates a dynamic table on Confluence that pulls metadata from all child pages sharing the same label. Use `ancestor = currentContent()` to scope to child pages, and match the label from `confluence_labels`.
2. **Confluence ignore blocks** — Wrap **all child page listing content** (section headings, tables, links) between `<!-- confluence:ignore-start -->` and `<!-- confluence:ignore-end -->`. This content is only visible in markdown viewers (GitHub, local); on Confluence, the properties report replaces it.
3. **Label alignment** — The `label` value in the CQL query must match one of the `confluence_labels` defined in the child pages' frontmatter. Use the same label across all siblings so the report captures them all.
4. **Report headings** — Include at minimum: `Owner,Status,Version,Reviewed on`. These must match field names in the children's `confluence_properties`.
**File naming** — Rename files that would cause URL issues:
- Use lowercase with hyphens: `api-reference.md` not `API Reference.md`
- No spaces, underscores, or special characters in filenames
- No version numbers in filenames — track versions in frontmatter instead
**Flat nesting** — Confluence page trees work best with one level of topic directories under the root. If the directory has deeply nested subdirectories (3+ levels), suggest flattening.| 文档 | 版本 | 摘要 |
|---|---|---|
| 子页面 | v1.0 | 简短描述 |
INDEX.md文件的核心规则:
1. **属性报告指令** —— 在介绍内容后添加`<!-- confluence:properties-report -->`指令。该指令会在Confluence中生成一个动态表格,从所有带有相同标签的子页面中提取元数据。使用`ancestor = currentContent()`限定为子页面范围,并与`confluence_labels`中的标签保持一致。
2. **Confluence忽略块** —— 将**所有子页面列表内容**(章节标题、表格、链接)包裹在`<!-- confluence:ignore-start -->`和`<!-- confluence:ignore-end -->`之间。这些内容仅在Markdown查看器(GitHub、本地)中可见;在Confluence中,属性报告会替代这些内容。
3. **标签对齐** —— CQL查询中的`label`值必须与子页面前置元数据中`confluence_labels`定义的标签之一匹配。在所有同级页面中使用相同的标签,以便报告能捕获所有子页面。
4. **报告标题** —— 至少包含:`Owner,Status,Version,Reviewed on`。这些必须与子页面`confluence_properties`中的字段名称匹配。
**文件命名** —— 重命名可能导致URL问题的文件:
- 使用小写字母加连字符:`api-reference.md`而非`API Reference.md`
- 文件名中不能有空格、下划线或特殊字符
- 文件名中不能包含版本号——版本号需在前置元数据中跟踪
**扁平化嵌套** —— Confluence页面树在根目录下仅保留一层主题目录时效果最佳。如果目录存在深度嵌套的子目录(3层及以上),建议进行扁平化处理。3. File-Level Checks
3. 文件级检查
For each markdown file, check and fix the following. Read the formatting reference for detailed rules on each item.
对每个Markdown文件,检查并修复以下问题。详细规则请参阅格式化参考文档。
Frontmatter
前置元数据(Frontmatter)
Every file needs YAML frontmatter with all standard fields populated. Frontmatter is the single source of truth for document metadata — any metadata that exists in the frontmatter must NOT be duplicated in the document body.
Always use the full frontmatter template:
yaml
---
title: API Reference
subtitle: "Reference — Project Docs v1.0"
date: "2026-03-09"
author: "Engineering Team"
confluence_ignore: false
confluence_labels:
- api
- reference
confluence_properties:
- id: status
fields:
Owner: "Engineering Team"
Classification: Internal
Status: "{status:Green|Published}"
Version: v1.0
Reviewed on: 2026-03-05
---When adding or completing frontmatter:
- Derive from the first
titleif present, otherwise from the filename# heading - Set to today's date
date - Derive from inline metadata if present, otherwise from existing sibling files or ask the user
author - Derive from document context (e.g.,
subtitle,"ADR — Project v1.0")"Guide — Team Docs" - Suggest based on the directory name and content
confluence_labels - Always include with at minimum:
confluence_properties,Owner,Classification,Status, andVersionReviewed on - Populate property values from inline metadata found in the document body when available
- Set by default. Only set to
confluence_ignore: falsewhen the user explicitly wants to exclude a file from Confluence publishing (previously published pages will be deleted on next sync)true - Never overwrite existing or
confluence_page_idconfluence_url
每个文件都需要包含完整标准字段的YAML前置元数据。前置元数据是文档元数据的唯一来源——任何已在前置元数据中捕获的信息,不得在文档正文中重复。
请始终使用完整的前置元数据模板:
yaml
---
title: API Reference
subtitle: "Reference — Project Docs v1.0"
date: "2026-03-09"
author: "Engineering Team"
confluence_ignore: false
confluence_labels:
- api
- reference
confluence_properties:
- id: status
fields:
Owner: "Engineering Team"
Classification: Internal
Status: "{status:Green|Published}"
Version: v1.0
Reviewed on: 2026-03-05
---添加或完善前置元数据时:
- 如果文件中有标题,
#字段取自该标题;否则取自文件名title - 字段设置为当天日期
date - 字段取自文档中的内嵌元数据;否则取自现有同级文件,或询问用户
author - 字段取自文档上下文(例如:
subtitle、"ADR — Project v1.0")"Guide — Team Docs" - 根据目录名称和内容建议标签
confluence_labels - 必须包含,至少包含:
confluence_properties,Owner,Classification,Status, 和VersionReviewed on - 如果文档正文中有内嵌元数据,将其值填充到对应字段中
- 默认设置。仅当用户明确希望将文件排除在Confluence发布之外时才设置为
confluence_ignore: false(已发布的页面会在下次同步时被删除)true - 切勿覆盖已有的或
confluence_page_idconfluence_url
Remove Redundant Inline Metadata
移除冗余的内嵌元数据
After populating the frontmatter, remove any inline metadata blocks from the document body that duplicate information already captured in the frontmatter or . These blocks typically appear near the top of the document as bold-key/value lines or small tables.
confluence_propertiesPatterns to detect and remove:
markdown
**Document Version**: 1.0
**Status**: Draft (Proposal)
**Classification**: Internal
**Last Updated**: March 7, 2026
**Author**: Engineering Team
**Owner**: Platform TeamAlso detect and remove metadata presented as:
- Key-value lines: or
Version: 1.0Status: Draft - Small two-column tables with metadata-like headers (e.g., )
| Field | Value | - Blockquote metadata:
> **Version**: 1.0
Rules for removal:
- Only remove metadata lines/blocks where the information is already captured in frontmatter fields or fields
confluence_properties - If an inline metadata block contains values not yet in frontmatter, absorb them into frontmatter first, then remove the block
- Preserve any surrounding content — only strip the metadata lines themselves
- If the metadata block is followed by a blank line or horizontal rule, remove the separator too to avoid orphaned whitespace
填充完前置元数据后,删除文档正文中所有与前置元数据或重复的内嵌元数据块。这些块通常出现在文档顶部,格式为加粗键/值行或小型表格。
confluence_properties需要检测并移除的格式:
markdown
**文档版本**: 1.0
**状态**: 草稿(提案)
**分类**: 内部
**最后更新**: 2026年3月7日
**作者**: 工程团队
**所有者**: 平台团队还需检测并移除以下格式呈现的元数据:
- 键值行:或
Version: 1.0Status: Draft - 带有元数据类表头的小型两列表格(例如:)
| 字段 | 值 | - 引用块元数据:
> **Version**: 1.0
移除规则:
- 仅移除已在前置元数据字段或字段中捕获的元数据行/块
confluence_properties - 如果内嵌元数据块包含前置元数据中尚未有的值,先将其合并到前置元数据中,再移除该块
- 保留周围的内容——仅删除元数据行本身
- 如果元数据块后有空白行或水平分隔线,也需删除该分隔符,避免出现孤立的空白
Heading Hierarchy
标题层级
The converter skips the first (Confluence uses the page title instead), so the document body should use as the top-level section heading.
# heading##Fix these issues:
- Multiple headings — Keep only the first one (it becomes the title). Convert subsequent
#to#.## - Heading gaps — Don't jump from to
##. Fill in the hierarchy.#### - No heading — If the file has no
#heading but has a#in frontmatter, that's fine. If it has neither, add atitleheading derived from the filename.#
转换器会跳过第一个标题(Confluence使用页面标题替代),因此文档正文应使用作为顶级章节标题。
###修复以下问题:
- 多个标题 —— 仅保留第一个(作为页面标题)。将后续的
#转换为#。## - 标题层级断层 —— 不要从直接跳到
##。补充完整层级。#### - 无标题 —— 如果文件没有
#标题但前置元数据中有#字段,无需处理。如果两者都没有,添加一个从文件名衍生的title标题。#
Document Structure
文档结构
Well-structured documents follow this pattern:
markdown
undefined结构良好的文档应遵循以下格式:
markdown
undefinedTitle
标题
<!-- confluence:toc-start -->One-line summary of what this document covers.
<!-- confluence:toc-start -->该文档内容的单行摘要。
Table of Contents
目录
<!-- confluence:toc-end -->
Section One
章节一
Content...
内容...
Section Two
章节二
Content...
Apply these structural improvements:
- **Add a TOC** if the document has 3+ sections (`##` headings). Wrap the TOC section (heading + list) with `<!-- confluence:toc-start -->` / `<!-- confluence:toc-end -->` directives so it gets replaced with the Confluence TOC macro on publish. The markdown TOC remains visible in GitHub/local renderers.
- **Add horizontal rules** (`---`) between major sections for visual separation.
- **Add a summary blockquote** after the title if the document jumps straight into content without context.内容...
应用以下结构优化:
- **添加目录(TOC)**:如果文档包含3个及以上章节(`##`标题),需添加目录。将目录章节(标题+列表)包裹在`<!-- confluence:toc-start -->` / `<!-- confluence:toc-end -->`指令中,这样发布时会被Confluence的TOC宏替代。Markdown格式的目录在GitHub/本地渲染器中仍可见。
- **添加水平分隔线**(`---`):在主要章节之间添加水平分隔线,用于视觉区分。
- **添加摘要引用块**:如果文档直接进入内容而无上下文说明,需在标题后添加单行摘要引用块。Cross-References
交叉引用
If the file is part of a directory being formatted, add a Cross-References section near the bottom linking to related sibling documents:
markdown
undefined如果文件属于正在格式化的目录的一部分,需在文档底部附近添加“交叉引用”章节,链接到相关的同级文档:
markdown
undefinedCross-References
交叉引用
| Document | Relevance |
|---|---|
| Related Doc | Brief note on why it's relevant |
Use relative paths so links resolve correctly both locally and in Confluence.| 文档 | 相关性 |
|---|---|
| 相关文档 | 说明相关性的简短注释 |
使用相对路径,确保链接在本地和Confluence中都能正确解析。Revision History
修订历史
For documents that will be actively maintained, add a revision history table at the bottom:
markdown
undefined对于需要持续维护的文档,需在底部添加修订历史表格:
markdown
undefinedRevision History
修订历史
| Version | Date | Changes |
|---|---|---|
| 1.0 | 2026-03-09 | Initial document |
Only add this if the document doesn't already have one.| 版本 | 日期 | 变更内容 |
|---|---|---|
| 1.0 | 2026-03-09 | 初始文档 |
仅当文档尚未包含修订历史时才添加。4. Content Formatting
4. 内容格式化
Fix markdown patterns that don't convert well to Confluence:
| Issue | Fix |
|---|---|
Inline metadata blocks ( | Absorb into frontmatter/ |
| Raw HTML tags | Replace with markdown equivalents |
| Use blank lines instead |
| Deeply nested lists (3+ levels) | Flatten to 2 levels max |
| Tables with multi-line cells | Split into simpler tables |
| Inline images with relative paths | Verify paths are correct relative to the file |
GitHub-flavored alerts ( | Keep as-is — the converter handles these |
MkDocs admonitions ( | Keep as-is — the converter handles these |
修复无法良好转换为Confluence格式的Markdown模式:
| 问题 | 修复方案 |
|---|---|
内嵌元数据块( | 将内容合并到前置元数据/ |
| 原始HTML标签 | 替换为Markdown等效格式 |
| 使用空白行替代 |
| 深度嵌套列表(3层及以上) | 扁平化至最多2层 |
| 包含多行单元格的表格 | 拆分为更简单的表格 |
| 使用相对路径的内嵌图片 | 验证路径相对于文件是否正确 |
GitHub风格的提示框( | 保留原样——转换器会处理这些内容 |
MkDocs警告框( | 保留原样——转换器会处理这些内容 |
5. Confluence-Specific Enhancements
5. Confluence专属增强
These are optional improvements that use Confluence features:
- Status badges — Use syntax in property fields (e.g.,
{status:Color|Text}){status:Green|Published} - Confluence ignore blocks — Wrap sections that should only appear in markdown (not Confluence) with and
<!-- confluence:ignore-start -->. In INDEX.md files, all child page tables must be wrapped (see Directory-Level Checks above).<!-- confluence:ignore-end --> - Properties report — Every INDEX.md must include a properties report directive. See the INDEX.md structure in Directory-Level Checks for the exact pattern.
以下是可选的优化,利用Confluence的功能:
- 状态徽章 —— 在属性字段中使用语法(例如:
{status:Color|Text}){status:Green|Published} - Confluence忽略块 —— 将仅需在Markdown中显示(无需在Confluence中显示)的内容包裹在和
<!-- confluence:ignore-start -->之间。在INDEX.md文件中,所有子页面表格必须包裹在此块中(见上文目录级检查)。<!-- confluence:ignore-end --> - 属性报告 —— 每个INDEX.md必须包含属性报告指令。具体格式见上文目录级检查中的INDEX.md结构部分。
6. Dry Run
6. 试运行
After making changes, suggest the user verify with:
bash
orbit confluence publish <directory> --space <SPACE> --parent <PAGE_ID> --dry-run -p <profile>This previews what would be published without making changes.
完成修改后,建议用户使用以下命令进行验证:
bash
orbit confluence publish <directory> --space <SPACE> --parent <PAGE_ID> --dry-run -p <profile>此命令会预览即将发布的内容,而不会实际进行修改。
Rules
规则
- Never delete content — only restructure and add metadata.
- Never overwrite or
confluence_page_id— these are managed byconfluence_url.orbit confluence publish - Preserve existing frontmatter fields — add missing ones, don't remove existing ones.
- When in doubt about a title, derive it from the first, then from the filename.
# heading - Keep changes minimal — don't rewrite prose, don't reorganize sections unless the heading hierarchy is broken.
- Show the user a summary of changes before applying them to a large directory.
- 切勿删除内容——仅进行结构调整和添加元数据。
- 切勿覆盖或
confluence_page_id——这些由confluence_url管理。orbit confluence publish - 保留已有的前置元数据字段——仅添加缺失的字段,不要删除现有字段。
- 若对标题不确定,优先从标题衍生,其次从文件名衍生。
# - 尽量减少修改——不要重写正文内容,除非标题层级混乱,否则不要重新组织章节。
- 对大型目录进行修改前,需向用户展示修改摘要。