baoyu-format-markdown

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Markdown Formatter

Markdown 格式化工具

Transforms plain text or markdown files into well-structured markdown with proper frontmatter, formatting, and typography.
将纯文本或Markdown文件转换为结构清晰的Markdown格式,包含规范的frontmatter、格式和排版。

Script Directory

脚本目录

Scripts in
scripts/
subdirectory. Replace
${SKILL_DIR}
with this SKILL.md's directory path.
ScriptPurpose
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
脚本位于
scripts/
子目录中。将
${SKILL_DIR}
替换为当前SKILL.md所在的目录路径。
脚本用途
scripts/main.ts
主入口点,包含CLI选项(使用remark-cjk-friendly处理CJK强调格式)
scripts/quotes.ts
将ASCII引号替换为全角引号
scripts/autocorrect.ts
通过autocorrect添加CJK与英文的间距

Preferences (EXTEND.md)

偏好设置(EXTEND.md)

Use Bash to check EXTEND.md existence (priority order):
bash
undefined
使用Bash检查EXTEND.md是否存在(优先级顺序):
bash
undefined

Check project-level first

先检查项目级配置

test -f .baoyu-skills/baoyu-format-markdown/EXTEND.md && echo "project"
test -f .baoyu-skills/baoyu-format-markdown/EXTEND.md && echo "project"

Then user-level (cross-platform: $HOME works on macOS/Linux/WSL)

再检查用户级配置(跨平台:$HOME适用于macOS/Linux/WSL)

test -f "$HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md" && echo "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**: Default formatting options | Summary length preferences
test -f "$HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md" && echo "user"

┌──────────────────────────────────────────────────────────┬───────────────────┐
│ 路径 │ 位置 │
├──────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-format-markdown/EXTEND.md │ 项目目录 │
├──────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md │ 用户主目录 │
└──────────────────────────────────────────────────────────┴───────────────────┘

┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ 结果 │ 操作 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 找到 │ 读取、解析并应用设置 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 未找到 │ 使用默认设置 │
└───────────┴───────────────────────────────────────────────────────────────────────────┘

**EXTEND.md 支持**:默认格式化选项 | 摘要长度偏好设置

Usage

使用方法

Claude performs content analysis and formatting (Steps 1-6), then runs the script for typography fixes (Step 7).
Claude会先进行内容分析和格式化(步骤1-6),然后运行脚本进行排版修复(步骤7)。

Workflow

工作流程

Step 1: Read Source File

步骤1:读取源文件

Read the user-specified markdown or plain text file.
读取用户指定的Markdown或纯文本文件。

Step 1.5: Detect Content Type & Confirm

步骤1.5:检测内容类型并确认

Content Type Detection:
IndicatorClassification
Has
---
YAML frontmatter
Markdown
Has
#
,
##
,
###
headings
Markdown
Has
**bold**
,
*italic*
Markdown
Has
- 
or
1. 
lists
Markdown
Has ``` code blocksMarkdown
Has
> 
blockquotes
Markdown
None of abovePlain text
Decision Flow:
┌─────────────────┬────────────────────────────────────────────────┐ │ Content Type │ Action │ ├─────────────────┼────────────────────────────────────────────────┤ │ Plain text │ Proceed to Step 2 (format to markdown) │ ├─────────────────┼────────────────────────────────────────────────┤ │ Markdown │ Use AskUserQuestion to confirm optimization │ └─────────────────┴────────────────────────────────────────────────┘
If Markdown detected, ask user:
Detected existing markdown formatting. What would you like to do?

1. Optimize formatting (Recommended)
   - Add/improve frontmatter, headings, bold, lists
   - Run typography script (spacing, emphasis fixes)
   - Output: {filename}-formatted.md

2. Keep original formatting
   - Preserve existing markdown structure
   - Run typography script (spacing, emphasis fixes)
   - 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:
  • Optimize: Continue to Step 2-8 (full workflow)
  • Keep original: Skip Steps 2-5, copy file → Step 6-8 (run script on copy)
  • Typography only: Skip Steps 2-6, run Step 7 on original file directly
内容类型检测:
识别特征分类
包含
---
YAML frontmatter
Markdown
包含
#
##
###
标题
Markdown
包含
**粗体**
*斜体*
Markdown
包含
- 
1. 
列表
Markdown
包含```代码块Markdown
包含
> 
块引用
Markdown
无以上特征纯文本
决策流程:
┌─────────────────┬────────────────────────────────────────────────┐ │ 内容类型 │ 操作 │ ├─────────────────┼────────────────────────────────────────────────┤ │ 纯文本 │ 继续执行步骤2(格式化为Markdown) │ ├─────────────────┼────────────────────────────────────────────────┤ │ Markdown │ 使用AskUserQuestion工具确认是否优化 │ └─────────────────┴────────────────────────────────────────────────┘
如果检测到Markdown格式,询问用户:
检测到已存在Markdown格式。您希望执行以下哪项操作?

1. 优化格式(推荐)
   - 添加/完善frontmatter、标题层级、粗体、列表
   - 运行排版脚本(间距、强调格式修复)
   - 输出文件:{filename}-formatted.md

2. 保留原格式
   - 保留现有Markdown结构
   - 运行排版脚本(间距、强调格式修复)
   - 输出文件:{filename}-formatted.md

3. 仅修复排版
   - 直接在原文件上运行排版脚本
   - 不创建副本,直接修改原文件
根据用户选择:
  • 优化:继续执行步骤2-8(完整工作流程)
  • 保留原格式:跳过步骤2-5,复制文件 → 执行步骤6-8(在副本上运行脚本)
  • 仅修复排版:跳过步骤2-6,直接在原文件上执行步骤7

Step 2: Analyze Content Structure

步骤2:分析内容结构

Identify:
  • Existing title (H1
    #
    )
  • Paragraph separations
  • Keywords suitable for bold
  • Parallel content convertible to lists
  • Code snippets
  • Quotations
识别以下内容:
  • 现有标题(H1
    #
  • 段落分隔
  • 适合设置为粗体的关键词
  • 可转换为列表的平行内容
  • 代码片段
  • 引用内容

Step 3: Check/Create Frontmatter

步骤3:检查/创建Frontmatter

Check for YAML frontmatter (
---
block). Create if missing.
Meta field handling:
FieldProcessing
title
See Step 4
slug
Infer from file path (e.g.,
posts/2026/01/10/vibe-coding/
vibe-coding
) or generate from title
summary
Generate engaging summary (100-150 characters)
featureImage
Check if
imgs/cover.png
exists in same directory; if so, use relative path
检查是否存在YAML frontmatter(
---
块),如果缺失则创建。
元字段处理:
字段处理方式
title
参见步骤4
slug
从文件路径推断(例如
posts/2026/01/10/vibe-coding/
vibe-coding
),或从标题生成
summary
生成吸引人的摘要(100-150字符)
featureImage
检查同一目录下是否存在
imgs/cover.png
,如果存在则使用相对路径

Step 4: Title Handling

步骤4:标题处理

Logic:
  1. If frontmatter already has
    title
    → use it, no H1 in body
  2. If first line is H1 → extract to frontmatter
    title
    , remove H1 from body
  3. If neither exists → generate candidate titles
Title generation flow:
  1. Generate 3 candidate titles based on content
  2. Use
    AskUserQuestion
    tool:
Select a title:

1. [Title A] (Recommended)
2. [Title B]
3. [Title C]
  1. If no selection within a few seconds, use recommended (option 1)
Title principles:
  • Concise, max 20 characters
  • Captures core message
  • Engaging, sparks reading interest
  • Accurate, avoids clickbait
Important: Once title is in frontmatter, body should NOT have H1 (avoid duplication)
逻辑:
  1. 如果frontmatter中已有
    title
    → 使用该标题,正文中不保留H1
  2. 如果第一行是H1 → 将其提取到frontmatter的
    title
    字段,从正文中移除H1
  3. 如果两者都不存在 → 生成候选标题
标题生成流程:
  1. 根据内容生成3个候选标题
  2. 使用
    AskUserQuestion
    工具:
选择一个标题:

1. [标题A](推荐)
2. [标题B]
3. [标题C]
  1. 如果用户在几秒内未选择,则使用推荐选项(选项1)
标题原则:
  • 简洁,最多20个字符
  • 抓住核心信息
  • 吸引人,激发阅读兴趣
  • 准确,避免标题党
**注意:**一旦标题存入frontmatter,正文中不应再包含H1(避免重复)

Step 5: Format Processing

步骤5:格式处理

Formatting rules:
ElementFormat
TitlesUse
#
,
##
,
###
hierarchy
Key pointsUse
**bold**
Parallel itemsConvert to
-
unordered or
1.
ordered lists
Code/commandsUse
`inline`
or
```block```
Quotes/sayingsUse
>
blockquote
SeparatorsUse
---
where appropriate
Formatting principles:
  • Preserve original content and viewpoints
  • Add formatting only, do not modify text
  • Formatting serves readability
  • Avoid over-formatting
格式化规则:
元素格式要求
标题使用
#
##
###
层级结构
关键点使用
**粗体**
平行项转换为
-
无序列表或
1.
有序列表
代码/命令使用
`行内代码`
```代码块```
引用/名言使用
>
块引用
分隔符在合适的位置使用
---
格式化原则:
  • 保留原文内容和观点
  • 仅添加格式,不修改文本内容
  • 格式服务于可读性
  • 避免过度格式化

Step 6: Save Formatted File

步骤6:保存格式化后的文件

Save as
{original-filename}-formatted.md
Examples:
  • final.md
    final-formatted.md
  • draft-v1.md
    draft-v1-formatted.md
If user chose "Keep original formatting" (from Step 1.5):
  • Copy original file to
    {filename}-formatted.md
    without modifications
  • Proceed to Step 7 for typography fixes only
Backup existing file:
If
{filename}-formatted.md
already exists, backup before overwriting:
bash
undefined
保存为
{original-filename}-formatted.md
示例:
  • final.md
    final-formatted.md
  • draft-v1.md
    draft-v1-formatted.md
备份现有文件:
如果
{filename}-formatted.md
已存在,在覆盖前备份:
bash
undefined

Check if formatted file exists

检查格式化文件是否存在

if [ -f "{filename}-formatted.md" ]; then

Backup with timestamp

mv "{filename}-formatted.md" "{filename}-formatted.backup-$(date +%Y%m%d-%H%M%S).md" fi

Example:
- `final-formatted.md` exists → backup to `final-formatted.backup-20260128-143052.md`
if [ -f "{filename}-formatted.md" ]; then

带时间戳备份

mv "{filename}-formatted.md" "{filename}-formatted.backup-$(date +%Y%m%d-%H%M%S).md" fi

示例:
- `final-formatted.md`已存在 → 备份为`final-formatted.backup-20260128-143052.md`

Step 7: Execute Text Formatting Script

步骤7:执行文本格式化脚本

After saving, must run the formatting script:
bash
npx -y bun ${SKILL_DIR}/scripts/main.ts {output-file-path} [options]
Script Options:
OptionShortDescriptionDefault
--quotes
-q
Replace ASCII quotes with fullwidth quotes
"..."
false
--no-quotes
Do not replace quotes
--spacing
-s
Add CJK/English spacing via autocorrecttrue
--no-spacing
Do not add CJK/English spacing
--emphasis
-e
Fix CJK emphasis punctuation issuestrue
--no-emphasis
Do not fix CJK emphasis issues
--help
-h
Show help message
Examples:
bash
undefined
保存后,必须运行格式化脚本:
bash
npx -y bun ${SKILL_DIR}/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强调问题
--help
-h
显示帮助信息
示例:
bash
undefined

Default: spacing + emphasis enabled, quotes disabled

默认配置:启用间距与强调修复,禁用引号替换

npx -y bun ${SKILL_DIR}/scripts/main.ts article.md
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md

Enable all features including quote replacement

启用所有功能,包括引号替换

npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --quotes
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --quotes

Only fix emphasis issues, skip spacing

仅修复强调问题,跳过间距处理

npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing

Disable all processing except frontmatter formatting

除frontmatter格式化外,禁用所有其他处理

npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing --no-emphasis

**Script performs (based on options):**
1. Fix CJK emphasis/bold punctuation issues (default: enabled)
2. Add CJK/English mixed text spacing via autocorrect (default: enabled)
3. Replace ASCII quotes `"..."` with fullwidth quotes `"..."` (default: disabled)
4. Format frontmatter YAML (always enabled)
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing --no-emphasis

**脚本执行操作(根据选项):**
1. 修复CJK强调/粗体标点问题(默认:启用)
2. 通过autocorrect添加CJK与英文混合文本的间距(默认:启用)
3. 将ASCII引号`"..."`替换为全角引号`"..."`(默认:禁用)
4. 格式化frontmatter YAML(始终启用)

Step 8: Display Results

步骤8:显示结果

**Formatting complete**

File: posts/2026/01/09/example/final-formatted.md

Changes:
- Added title: [title content]
- Added X bold markers
- Added X lists
- Added X code blocks
**格式化完成**

文件:posts/2026/01/09/example/final-formatted.md

修改内容:
- 添加标题:[标题内容]
- 添加了X个粗体标记
- 添加了X个列表
- 添加了X个代码块

Formatting Example

格式化示例

Before:
This is plain text. First point is efficiency improvement. Second point is cost reduction. Third point is experience optimization. Use npm install to install dependencies.
After:
markdown
---
title: Three Core Advantages
slug: three-core-advantages
summary: Discover the three key benefits that drive success in modern projects.
---

This is plain text.

**Main advantages:**
- Efficiency improvement
- Cost reduction
- Experience optimization

Use `npm install` to install dependencies.
格式化前:
This is plain text. First point is efficiency improvement. Second point is cost reduction. Third point is experience optimization. Use npm install to install dependencies.
格式化后:
markdown
---
title: Three Core Advantages
slug: three-core-advantages
summary: Discover the three key benefits that drive success in modern projects.
---

This is plain text.

**Main advantages:**
- Efficiency improvement
- Cost reduction
- Experience optimization

Use `npm install` to install dependencies.

Notes

注意事项

  • Preserve original writing style and tone
  • Specify correct language for code blocks (e.g.,
    python
    ,
    javascript
    )
  • Maintain CJK/English spacing standards
  • Do not add content not present in original
  • 保留原文写作风格和语气
  • 为代码块指定正确的语言(例如
    python
    javascript
  • 遵循CJK与英文的间距标准
  • 不添加原文中没有的内容

Extension Support

扩展支持

Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
通过EXTEND.md进行自定义配置。有关路径和支持的选项,请参阅偏好设置部分。