Markdown Formatter
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.
Script Directory
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 |
|---|
| INLINECODE9 | Main entry point with CLI options (uses remark-cjk-friendly for CJK emphasis) |
| INLINECODE10 |
Replace ASCII quotes with fullwidth quotes |
|
scripts/autocorrect.ts | Add CJK/English spacing via autocorrect |
Preferences (EXTEND.md)
Check EXTEND.md existence (priority order):
CODEBLOCK0
CODEBLOCK1
┌──────────────────────────────────────────────────────────┬───────────────────┐
│ 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 |
|---|
| INLINECODE12 | INLINECODE13 / INLINECODE14 | INLINECODE15 | Skip both title and summary selection, auto-pick best |
| INLINECODE16 |
true/
false |
false | Skip title selection only |
|
auto_select_summary |
true/
false |
false | Skip summary selection only |
| Other | — | — | Default formatting options, typography preferences |
Usage
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).
Workflow
Step 1: Read & Detect Content Type
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, use AskUserQuestion to ask:
CODEBLOCK2
Based on user choice:
- - Optimize: Continue to Step 2 (full workflow)
- Keep original: Skip to Step 5, copy file then run Step 6
- Typography only: Skip to Step 6, run on original file directly
Step 2: Analyze Content (Reader's Perspective)
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
- - Core arguments or conclusions the author makes
- Surprising facts, data points, or counterintuitive claims
- Memorable quotes or well-phrased sentences (golden quotes)
2.2 Structure Assessment
- - Does the content have a clear logical flow? What is it?
- Are there natural section boundaries that lack headings?
- Are there long walls of text that could benefit from visual breaks?
2.3 Reader-Important Information
- - Actionable advice or takeaways
- Definitions, explanations of key concepts
- Lists or enumerations buried in prose
- Comparisons or contrasts that would be clearer as tables
2.4 Formatting Issues
- - Missing or inconsistent heading hierarchy
- Paragraphs that mix multiple topics
- Parallel items written as prose instead of lists
- Code, commands, or technical terms not marked as code
- Obvious typos or formatting errors
Save analysis to file: INLINECODE31
The analysis file serves as the blueprint for Step 3. Use this format:
CODEBLOCK3
Step 3: Check/Create Frontmatter, Title & Summary
Check for YAML frontmatter (--- block). Create if missing.
| Field | Processing |
|---|
| INLINECODE33 | See Title Generation below |
| INLINECODE34 |
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:
- - Core argument (one sentence: "what is this article about?")
- Most impactful opinion or conclusion
- Reader pain point or curiosity trigger
- Most memorable metaphor or golden quote
Generate titles using formulas from references/title-formulas.md:
- 1. Select the 2-3 best-matching hook formulas based on the article's content, tone, and structure (see "When to pick each formula" in the reference)
- Generate 1-2 straightforward titles (descriptive or declarative, no formula — clear and accurate)
- If the user specifies a direction (e.g., "make it suspenseful"), prioritize that direction
- Total: 4-5 candidates
Use AskUserQuestion to present candidates:
CODEBLOCK4
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 |
|---|
| INLINECODE44 | 1 sentence, ~50-80 chars | Concise hook — for feeds, social sharing, SEO meta |
| INLINECODE45 |
2-3 sentences, ~100-200 chars | Richer context — for article previews, newsletter blurbs |
Principles:
- - Convey core value to the reader, not just the topic
- Use concrete details (numbers, outcomes, specific methods) over vague descriptions
- INLINECODE46 should be punchy and self-contained;
description can expand with supporting details - If frontmatter already has
summary or description, keep existing and only generate the missing one
Prohibited patterns:
- - "This article introduces...", "This article explores..."
- Pure topic description without value proposition
- Repeating the title in different words
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).
Step 4: Format Content
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 | INLINECODE52 , ### 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 | 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 | ---
|
**Formatting principles — what NOT to do:**
- Do NOT add sentences, explanations, or commentary
- Do NOT delete or shorten any content
- Do NOT rephrase or rewrite the author's words
- Do NOT add headings that editorialize (e.g., "Amazing Discovery" — use neutral descriptive headings)
- Do NOT over-format: not every sentence needs bold, not every paragraph needs a heading
**Formatting principles — what TO do:**
- Preserve the author's voice, tone, and every word
- **Bold key conclusions and core takeaways** — the sentences a reader would highlight
- Extract parallel items from prose into lists only when the structure is clearly there
- Add headings where the topic genuinely shifts — prefer vivid, specific headings over generic ones (e.g., "3 天搞定 vs 传统方案" over "方案对比")
- Use tables for comparisons or structured data buried in prose
- Use blockquotes for golden quotes, memorable statements, or important warnings
- Fix obvious typos (based on Step 2 findings)
### Step 5: Save Formatted File
Save as {original-filename}-formatted.md
**Backup existing file:**
CODEBLOCK5
### Step 6: Execute Typography Script
Run the formatting script on the output file:
CODEBLOCK6
**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 | 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 | |
**Examples:**
CODEBLOCK7
**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)
### Step 7: Completion Report
Display a report summarizing all changes made:
CODEBLOCK8
Adjust the report to reflect actual changes — omit categories where no changes were made.
## Notes
- Preserve original writing style and tone
- Specify correct language for code blocks (e.g., python
, javascript`)
- - Maintain CJK/English spacing standards
- The analysis file is a working document — it helps maintain consistency between what was identified and what was formatted
Extension Support
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
Markdown 格式化工具
将纯文本或 Markdown 转换为结构清晰、便于阅读的 Markdown 格式。目标是帮助读者快速掌握要点、重点和结构——不改变任何原始内容。
核心原则:仅调整格式并修正明显的拼写错误。绝不添加、删除或重写内容。
脚本目录
脚本位于 scripts/ 子目录中。{baseDir} = 本 SKILL.md 文件所在目录路径。解析 ${BUNX} 运行时:如果已安装 bun → 使用 bun;如果可用 npx → 使用 npx -y bun;否则建议安装 bun。将 {baseDir} 和 ${BUNX} 替换为实际值。
| 脚本 | 用途 |
|---|
| scripts/main.ts | 主入口,包含 CLI 选项(使用 remark-cjk-friendly 处理中日韩强调) |
| scripts/quotes.ts |
将 ASCII 引号替换为全角引号 |
| scripts/autocorrect.ts | 通过 autocorrect 添加中日韩/英文间距 |
偏好设置(EXTEND.md)
检查 EXTEND.md 是否存在(优先级顺序):
bash
macOS、Linux、WSL、Git Bash
test -f .baoyu-skills/baoyu-format-markdown/EXTEND.md && echo 项目
test -f ${XDG
CONFIGHOME:-$HOME/.config}/baoyu-skills/baoyu-format-markdown/EXTEND.md && echo xdg
test -f $HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md && echo 用户
powershell
PowerShell(Windows)
if (Test-Path .baoyu-skills/baoyu-format-markdown/EXTEND.md) { 项目 }
$xdg = if ($env:XDG
CONFIGHOME) { $env:XDG
CONFIGHOME } 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) { 用户 }
┌──────────────────────────────────────────────────────────┬───────────────────┐
│ 路径 │ 位置 │
├──────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-format-markdown/EXTEND.md │ 项目目录 │
├──────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-format-markdown/EXTEND.md │ 用户主目录 │
└──────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ 结果 │ 操作 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 找到 │ 读取、解析、应用设置 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 未找到 │ 使用默认设置 │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md 支持:
| 设置 | 值 | 默认值 | 描述 |
|---|
| autoselect | true/false | false | 跳过标题和摘要选择,自动选择最佳 |
| autoselect_title |
true/false | false | 仅跳过标题选择 |
| auto
selectsummary | true/false | false | 仅跳过摘要选择 |
| 其他 | — | — | 默认格式化选项、排版偏好 |
使用方法
工作流程分为两个阶段:分析(理解内容)然后格式化(应用格式)。Claude 执行内容分析和格式化(步骤 1-5),然后运行脚本进行排版修正(步骤 6)。
工作流程
步骤 1:读取并检测内容类型
读取用户指定的文件,然后检测内容类型:
| 指示符 | 分类 |
|---|
| 包含 --- YAML 前置元数据 | Markdown |
| 包含 #、##、### 标题 |
Markdown |
| 包含
粗体、
斜体、列表、代码块、引用 | Markdown |
| 以上皆无 | 纯文本 |
如果检测到 Markdown,使用 AskUserQuestion 询问:
检测到现有 Markdown 格式。您希望如何处理?
- 1. 优化格式(推荐)
- 分析内容,改进标题、粗体、列表以提高可读性
- 运行排版脚本(间距、强调修正)
- 输出:{filename}-formatted.md
- 2. 保留原始格式
- 保留现有 Markdown 结构
- 仅运行排版脚本
- 输出:{filename}-formatted.md
- 3. 仅排版修正
- 在原文件上直接运行排版脚本
- 不创建副本,直接修改原文件
根据用户选择:
- - 优化:继续执行步骤 2(完整工作流程)
- 保留原始:跳至步骤 5,复制文件然后运行步骤 6
- 仅排版:跳至步骤 6,直接在原文件上运行
步骤 2:分析内容(读者视角)
仔细阅读全部内容。从读者角度思考:什么能帮助他们快速理解和记住关键信息?
生成涵盖以下维度的分析:
2.1 重点与关键见解
- - 作者的核心论点或结论
- 令人惊讶的事实、数据点或反直觉的主张
- 令人难忘的引用或措辞优美的句子(金句)
2.2 结构评估
- - 内容是否有清晰的逻辑流程?是什么?
- 是否存在缺乏标题的自然章节边界?
- 是否存在可以通过视觉分隔改善的长篇文本块?
2.3 读者重要信息
- - 可操作的建议或要点
- 定义、关键概念的解释
- 隐藏在散文中的列表或枚举
- 用表格呈现会更清晰的比较或对比
2.4 格式问题
- - 缺失或不一致的标题层级
- 混合多个主题的段落
- 应作为列表而非散文书写的并列项
- 未标记为代码的代码、命令或技术术语
- 明显的拼写错误或格式错误
将分析保存到文件:{original-filename}-analysis.md
分析文件作为步骤 3 的蓝图。使用此格式:
markdown
内容分析:{filename}
重点与关键见解
结构评估
- - 当前流程:[描述]
- 建议章节:[列出标题候选及简要理由]
读者重要信息
- - [列出可操作项、关键概念、隐藏列表、潜在表格]
格式问题
发现的拼写错误
步骤 3:检查/创建前置元数据、标题和摘要
检查 YAML 前置元数据(--- 块)。如缺失则创建。
从文件路径推断或从标题生成 |
| summary | 一句话简洁摘要(参见下方
摘要生成) |
| description | 较长的描述性摘要(参见下方
摘要生成) |
| coverImage | 检查同一目录中是否存在 imgs/cover.png;如果存在,使用相对路径 |
标题生成:
无论是否已有标题,始终运行标题优化流程(除非设置了 autoselecttitle)。
准备——阅读全文并提取:
- - 核心论点(一句话:这篇文章是关于什么的?)
- 最有影响力的观点或结论
- 读者痛点或好奇心触发点
- 最令人难忘的隐喻或金句
使用 references/title-formulas.md 中的公式生成标题:
- 1. 根据文章内容、语气和结构选择 2-3 个最匹配的钩子公式(参见参考中的何时选择每个公式)
- 生成 1-2 个直白标题(描述性或陈述性,无公式——清晰准确)
- 如果用户指定方向(例如让它充满悬念),优先考虑该方向
- 总计:4-5 个候选
使用 AskUserQuestion 呈现候选:
选择一个标题:
- 1. [钩子标题 A] —(推荐)[公式名称]
- [钩子标题 B] — [公式名称]
- [钩子标题 C] — [公式名称]
- [直白标题 D] — 直白
- [直白