baoyu-format-markdown by jimliu/baoyu-skills
npx skills add https://github.com/jimliu/baoyu-skills --skill baoyu-format-markdown将纯文本或 Markdown 转换为结构良好、易于阅读的 Markdown。目标是帮助读者快速掌握要点、亮点和结构,同时不改变任何原始内容。
核心原则:仅调整格式并修正明显的拼写错误。绝不添加、删除或重写内容。
脚本位于 scripts/ 子目录。{baseDir} = 此 SKILL.md 文件的目录路径。解析 ${BUN_X} 运行时:如果已安装 bun → bun;如果 npx 可用 → npx -y bun;否则建议安装 bun。将 {baseDir} 和 ${BUN_X} 替换为实际值。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 脚本 | 用途 |
|---|---|
scripts/main.ts | 主入口点,包含 CLI 选项(使用 remark-cjk-friendly 处理 CJK 强调) |
scripts/quotes.ts | 将 ASCII 引号替换为全角引号 |
scripts/autocorrect.ts | 通过 autocorrect 添加 CJK/英文间距 |
检查 EXTEND.md 是否存在(优先级顺序):
# macOS, Linux, WSL, Git Bash
test -f .baoyu-skills/baoyu-format-markdown/EXTEND.md && echo "project"
test -f "${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-format-markdown/EXTEND.md" && echo "xdg"
test -f "$HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md" && echo "user"
# PowerShell (Windows)
if (Test-Path .baoyu-skills/baoyu-format-markdown/EXTEND.md) { "project" }
$xdg = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { "$HOME/.config" }
if (Test-Path "$xdg/baoyu-skills/baoyu-format-markdown/EXTEND.md") { "xdg" }
if (Test-Path "$HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md") { "user" }
┌──────────────────────────────────────────────────────────┬───────────────────┐ │ 路径 │ 位置 │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ .baoyu-skills/baoyu-format-markdown/EXTEND.md │ 项目目录 │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ $HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md │ 用户主目录 │ └──────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐ │ 结果 │ 操作 │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ 找到 │ 读取、解析、应用设置 │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ 未找到 │ 使用默认值 │ └───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md 支持:
| 设置 | 值 | 默认值 | 描述 |
|---|---|---|---|
auto_select | true/false | false | 跳过标题和摘要选择,自动选取最佳 |
auto_select_title | true/false | false | 仅跳过标题选择 |
auto_select_summary | true/false | false | 仅跳过摘要选择 |
| 其他 | — | — | 默认格式化选项、排版偏好 |
工作流程分为两个阶段:分析(理解内容)然后格式化(应用格式)。Claude 执行内容分析和格式化(步骤 1-5),然后运行脚本进行排版修正(步骤 6)。
读取用户指定的文件,然后检测内容类型:
| 指示器 | 分类 |
|---|---|
包含 --- YAML 前言 | Markdown |
包含 #、##、### 标题 | Markdown |
包含 **粗体**、*斜体*、列表、代码块、引用块 | Markdown |
| 以上皆无 | 纯文本 |
如果检测到 Markdown,使用 AskUserQuestion 询问:
检测到现有的 Markdown 格式。您希望做什么?
1. 优化格式(推荐)
- 分析内容,改进标题、粗体、列表以提高可读性
- 运行排版脚本(间距、强调修正)
- 输出:{filename}-formatted.md
2. 保持原始格式
- 保留现有的 Markdown 结构
- 仅运行排版脚本
- 输出:{filename}-formatted.md
3. 仅进行排版修正
- 在原文件上直接运行排版脚本
- 不创建副本,直接修改原文件
根据用户选择:
仔细阅读全部内容。从读者角度思考:什么能帮助他们快速理解和记住关键信息?
生成涵盖以下维度的分析:
2.1 亮点与关键见解
2.2 结构评估
2.3 对读者重要的信息
2.4 格式问题
将分析保存到文件:{original-filename}-analysis.md
分析文件将作为步骤 3 的蓝图。使用以下格式:
# 内容分析:{filename}
## 亮点与关键见解
- [列出发现]
## 结构评估
- 当前流程:[描述]
- 建议的章节:[列出标题候选及其简要理由]
## 对读者重要的信息
- [列出可操作项、关键概念、隐藏的列表、潜在的表格]
## 格式问题
- [列出具体问题及位置引用]
## 发现的拼写错误
- [列出任何明显的拼写错误及更正,或"未发现"]
检查是否存在 YAML 前言(--- 块)。如果缺失则创建。
| 字段 | 处理 |
|---|---|
title | 参见下面的标题生成 |
slug | 从文件路径推断或根据标题生成 |
summary | 一句话简洁摘要(参见下面的摘要生成) |
description | 更长的描述性摘要(参见下面的摘要生成) |
coverImage | 检查同一目录下是否存在 imgs/cover.png;如果存在,使用相对路径 |
标题生成:
无论标题是否已存在,始终运行标题优化流程(除非设置了 auto_select_title)。
准备 — 阅读全文并提取:
使用 references/title-formulas.md 中的公式生成标题:
使用 AskUserQuestion 展示候选标题:
请选择一个标题:
1. [钩子标题 A] — (推荐) [公式名称]
2. [钩子标题 B] — [公式名称]
3. [钩子标题 C] — [公式名称]
4. [直白标题 D] — 直白
5. [直白标题 E] — 直白
输入编号,或键入自定义标题:
将最强的钩子放在首位并标记为(推荐)。有关标题原则和禁止模式,请参见 references/title-formulas.md。
如果第一行是 H1,则提取到前言中并从正文中移除。如果前言中已有 title,将其作为上下文包含,但仍生成新的候选标题。
摘要生成:
直接生成两个版本(无需用户选择),两者都存储在前言中:
| 字段 | 长度 | 用途 |
|---|---|---|
summary | 1 句话,约 50-80 字符 | 简洁的钩子 — 用于信息流、社交分享、SEO 元数据 |
description | 2-3 句话,约 100-200 字符 | 更丰富的上下文 — 用于文章预览、新闻简报摘要 |
原则:
summary 应简洁有力且自成一体;description 可以扩展更多支持性细节summary 或 description,则保留现有内容,仅生成缺失的部分禁止模式:
EXTEND.md 跳过行为:如果在 EXTEND.md 中设置了 auto_select: true 或 auto_select_title: true,则跳过标题选择 — 直接生成最佳候选标题,无需询问。
一旦标题在前言中,正文中不应有 H1(避免重复)。
根据步骤 2 的分析指导应用格式化。目标是使内容易于浏览,关键点一目了然。
格式化工具包:
| 元素 | 何时使用 | 格式 |
|---|---|---|
| 标题 | 自然的主题边界、章节分隔 | ##、### 层级 |
| 粗体 | 关键结论、重要术语、核心要点 | **粗体** |
| 无序列表 | 平行项目、功能列表、示例 | - 项目 |
| 有序列表 | 顺序步骤、排名项目、流程 | 1. 项目 |
| 表格 | 比较、结构化数据、选项矩阵 | Markdown 表格 |
| 代码 | 命令、文件路径、技术术语、变量名 | 行内代码 或围栏代码块 |
| 引用块 | 重要引语、重要警告、引用文本 | > 引语 |
| 分隔符 | 主要主题转换 | --- |
格式化原则 — 不要做的事:
格式化原则 — 要做的事:
保存为 {original-filename}-formatted.md
备份现有文件:
if [ -f "{filename}-formatted.md" ]; then
mv "{filename}-formatted.md" "{filename}-formatted.backup-$(date +%Y%m%d-%H%M%S).md"
fi
在输出文件上运行格式化脚本:
${BUN_X} {baseDir}/scripts/main.ts {output-file-path} [options]
脚本选项:
| 选项 | 简写 | 描述 | 默认值 |
|---|---|---|---|
--quotes | -q | 将 ASCII 引号替换为全角引号 "..." | false |
--no-quotes | 不替换引号 | ||
--spacing | -s | 通过 autocorrect 添加 CJK/英文间距 | true |
--no-spacing | 不添加 CJK/英文间距 | ||
--emphasis | -e | 修正 CJK 强调标点问题 | true |
--no-emphasis | 不修正 CJK 强调问题 |
示例:
# 默认:启用间距 + 强调,禁用引号替换
${BUN_X} {baseDir}/scripts/main.ts article.md
# 启用所有功能,包括引号替换
${BUN_X} {baseDir}/scripts/main.ts article.md --quotes
# 仅修正强调问题,跳过间距调整
${BUN_X} {baseDir}/scripts/main.ts article.md --no-spacing
脚本执行(基于选项):
显示一份总结所有更改的报告:
**格式化完成**
**文件:**
- 分析:{filename}-analysis.md
- 格式化:{filename}-formatted.md
**内容分析摘要:**
- 发现的亮点:X 个关键见解
- 金句:X 个令人难忘的句子
- 修正的格式问题:X 项
**应用的更改:**
- 前言:[添加/更新] (标题、slug、摘要)
- 添加的标题:X 个 (##: N, ###: N)
- 添加的粗体标记:X 个
- 创建的列表:X 个 (从散文转换而来)
- 创建的表格:X 个
- 添加的代码标记:X 个
- 添加的引用块:X 个
- 修正的拼写错误:X 个 [列出每个:"原词" → "更正词"]
**排版脚本:**
- CJK 间距:[已应用/已跳过]
- 强调修正:[已应用/已跳过]
- 引号替换:[已应用/已跳过]
调整报告以反映实际更改 — 对于未做更改的类别,请省略。
python、javascript)通过 EXTEND.md 进行自定义配置。有关路径和支持的选项,请参见偏好设置部分。
每周安装数
10.2K
代码仓库
GitHub 星标数
11.3K
首次出现
2026年1月29日
安全审计
安装于
opencode9.6K
codex9.3K
gemini-cli9.3K
github-copilot9.0K
cursor8.9K
kimi-cli8.9K
Transforms plain text or markdown into well-structured, reader-friendly markdown. The goal is to help readers quickly grasp key points, highlights, and structure — without changing any original content.
Core principle : Only adjust formatting and fix obvious typos. Never add, delete, or rewrite content.
Scripts in scripts/ subdirectory. {baseDir} = this SKILL.md's directory path. Resolve ${BUN_X} runtime: if bun installed → bun; if npx available → npx -y bun; else suggest installing bun. Replace {baseDir} and ${BUN_X} with actual values.
| Script | Purpose |
|---|---|
scripts/main.ts | Main entry point with CLI options (uses remark-cjk-friendly for CJK emphasis) |
scripts/quotes.ts | Replace ASCII quotes with fullwidth quotes |
scripts/autocorrect.ts | Add CJK/English spacing via autocorrect |
Check EXTEND.md existence (priority order):
# macOS, Linux, WSL, Git Bash
test -f .baoyu-skills/baoyu-format-markdown/EXTEND.md && echo "project"
test -f "${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-format-markdown/EXTEND.md" && echo "xdg"
test -f "$HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md" && echo "user"
# PowerShell (Windows)
if (Test-Path .baoyu-skills/baoyu-format-markdown/EXTEND.md) { "project" }
$xdg = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { "$HOME/.config" }
if (Test-Path "$xdg/baoyu-skills/baoyu-format-markdown/EXTEND.md") { "xdg" }
if (Test-Path "$HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md") { "user" }
┌──────────────────────────────────────────────────────────┬───────────────────┐ │ Path │ Location │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ .baoyu-skills/baoyu-format-markdown/EXTEND.md │ Project directory │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ $HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md │ User home │ └──────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐ │ Result │ Action │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ Found │ Read, parse, apply settings │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ Not found │ Use defaults │ └───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md Supports :
| Setting | Values | Default | Description |
|---|---|---|---|
auto_select | true/false | false | Skip both title and summary selection, auto-pick best |
auto_select_title | true/false | false |
The workflow has two phases: Analyze (understand the content) then Format (apply formatting). Claude performs content analysis and formatting (Steps 1-5), then runs the script for typography fixes (Step 6).
Read the user-specified file, then detect content type:
| Indicator | Classification |
|---|---|
Has --- YAML frontmatter | Markdown |
Has #, ##, ### headings | Markdown |
Has **bold**, *italic*, lists, code blocks, blockquotes | Markdown |
| None of above | Plain text |
If Markdown detected, useAskUserQuestion to ask:
Detected existing markdown formatting. What would you like to do?
1. Optimize formatting (Recommended)
- Analyze content, improve headings, bold, lists for readability
- Run typography script (spacing, emphasis fixes)
- Output: {filename}-formatted.md
2. Keep original formatting
- Preserve existing markdown structure
- Run typography script only
- Output: {filename}-formatted.md
3. Typography fixes only
- Run typography script on original file in-place
- No copy created, modifies original file directly
Based on user choice:
Read the entire content carefully. Think from a reader's perspective: what would help them quickly understand and remember the key information?
Produce an analysis covering these dimensions:
2.1 Highlights & Key Insights
2.2 Structure Assessment
2.3 Reader-Important Information
2.4 Formatting Issues
Save analysis to file : {original-filename}-analysis.md
The analysis file serves as the blueprint for Step 3. Use this format:
# Content Analysis: {filename}
## Highlights & Key Insights
- [list findings]
## Structure Assessment
- Current flow: [describe]
- Suggested sections: [list heading candidates with brief rationale]
## Reader-Important Information
- [list actionable items, key concepts, buried lists, potential tables]
## Formatting Issues
- [list specific issues with location references]
## Typos Found
- [list any obvious typos with corrections, or "None found"]
Check for YAML frontmatter (--- block). Create if missing.
| Field | Processing |
|---|---|
title | See Title Generation below |
slug | Infer from file path or generate from title |
summary | One-sentence concise summary (see Summary Generation below) |
description | Longer descriptive summary (see Summary Generation below) |
coverImage | Check if imgs/cover.png exists in same directory; if so, use relative path |
Title Generation:
Whether or not a title already exists, always run the title optimization flow (unless auto_select_title is set).
Preparation — read the full text and extract:
Generate titles using formulas from references/title-formulas.md:
Use AskUserQuestion to present candidates:
Pick a title:
1. [Hook title A] — (recommended) [formula name]
2. [Hook title B] — [formula name]
3. [Hook title C] — [formula name]
4. [Straightforward title D] — straightforward
5. [Straightforward title E] — straightforward
Enter number, or type a custom title:
Put the strongest hook first and mark it (recommended). See references/title-formulas.md for title principles and prohibited patterns.
If first line is H1, extract to frontmatter and remove from body. If frontmatter already has title, include it as context but still generate fresh candidates.
Summary Generation:
Generate two versions directly (no user selection needed), both stored in frontmatter:
| Field | Length | Purpose |
|---|---|---|
summary | 1 sentence, ~50-80 chars | Concise hook — for feeds, social sharing, SEO meta |
description | 2-3 sentences, ~100-200 chars | Richer context — for article previews, newsletter blurbs |
Principles:
summary should be punchy and self-contained; description can expand with supporting detailssummary or description, keep existing and only generate the missing oneProhibited patterns:
EXTEND.md skip behavior: If auto_select: true or auto_select_title: true is set in EXTEND.md, skip title selection — generate the best candidate directly without asking.
Once title is in frontmatter, body should NOT have H1 (avoid duplication).
Apply formatting guided by the Step 2 analysis. The goal is making the content scannable and the key points impossible to miss.
Formatting toolkit:
| Element | When to use | Format |
|---|---|---|
| Headings | Natural topic boundaries, section breaks | ##, ### hierarchy |
| Bold | Key conclusions, important terms, core takeaways | **bold** |
| Unordered lists | Parallel items, feature lists, examples | - item |
| Ordered lists | Sequential steps, ranked items, procedures | 1. item |
| Tables | Comparisons, structured data, option matrices |
Formatting principles — what NOT to do:
Formatting principles — what TO do:
Save as {original-filename}-formatted.md
Backup existing file:
if [ -f "{filename}-formatted.md" ]; then
mv "{filename}-formatted.md" "{filename}-formatted.backup-$(date +%Y%m%d-%H%M%S).md"
fi
Run the formatting script on the output file:
${BUN_X} {baseDir}/scripts/main.ts {output-file-path} [options]
Script Options:
| Option | Short | Description | Default |
|---|---|---|---|
--quotes | -q | Replace ASCII quotes with fullwidth quotes "..." | false |
--no-quotes | Do not replace quotes | ||
--spacing | -s | Add CJK/English spacing via autocorrect |
Examples:
# Default: spacing + emphasis enabled, quotes disabled
${BUN_X} {baseDir}/scripts/main.ts article.md
# Enable all features including quote replacement
${BUN_X} {baseDir}/scripts/main.ts article.md --quotes
# Only fix emphasis issues, skip spacing
${BUN_X} {baseDir}/scripts/main.ts article.md --no-spacing
Script performs (based on options):
Display a report summarizing all changes made:
**Formatting Complete**
**Files:**
- Analysis: {filename}-analysis.md
- Formatted: {filename}-formatted.md
**Content Analysis Summary:**
- Highlights found: X key insights
- Golden quotes: X memorable sentences
- Formatting issues fixed: X items
**Changes Applied:**
- Frontmatter: [added/updated] (title, slug, summary)
- Headings added: X (##: N, ###: N)
- Bold markers added: X
- Lists created: X (from prose → list conversion)
- Tables created: X
- Code markers added: X
- Blockquotes added: X
- Typos fixed: X [list each: "original" → "corrected"]
**Typography Script:**
- CJK spacing: [applied/skipped]
- Emphasis fixes: [applied/skipped]
- Quote replacement: [applied/skipped]
Adjust the report to reflect actual changes — omit categories where no changes were made.
python, javascript)Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
Weekly Installs
10.2K
Repository
GitHub Stars
11.3K
First Seen
Jan 29, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode9.6K
codex9.3K
gemini-cli9.3K
github-copilot9.0K
cursor8.9K
kimi-cli8.9K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
| Skip title selection only |
auto_select_summary | true/false | false | Skip summary selection only |
| Other | — | — | Default formatting options, typography preferences |
| Markdown table |
| Code | Commands, file paths, technical terms, variable names | inline or fenced blocks |
| Blockquotes | Notable quotes, important warnings, cited text | > quote |
| Separators | Major topic transitions | --- |
| true |
--no-spacing | Do not add CJK/English spacing |
--emphasis | -e | Fix CJK emphasis punctuation issues | true |
--no-emphasis | Do not fix CJK emphasis issues |