baoyu-format-markdown
Formats plain text or markdown files with frontmatter, titles, summaries, headings, bold, lists, and code blocks. Use when user asks to "format markdown", "beautify article", "add formatting", or improve article layout. Outputs to {filename}-formatted.md.
1How It Works & Mechanism
Division of responsibilities: Content-level analysis/refactoring is handled by the model following SKILL.md steps (Steps 1-5), while deterministic typesetting fixes are offloaded to built-in scripts (Step 6).
Claude performs content analysis and formatting (Steps 1-5), then runs the script for typography fixes (Step 6).
The core discipline is 'format only, do not touch content': no rewriting, no additions or deletions, and no commentary added.
**Core principle**: Only adjust formatting and fix obvious typos. Never add, delete, or rewrite content.
The core script runs on a unified/remark pipeline: parse → optional CJK-friendly emphasis fix → GFM/frontmatter → stringify, then write back to the file in place.
.use(options.emphasis ? remarkCjkFriendly : [])
CJK/English spacing is not implemented internally; instead, it executes `npx autocorrect-node --fix` at runtime to modify the file in place.
const result = spawnSync(npxCmd, ["autocorrect-node", "--fix", filePath], {
Optional quote normalization: replaces paired ASCII double quotes and 「」 with full-width curved quotes.
.replace(/"([^"]+)"/g, "\u201c$1\u201d")
Headline generation relies on a reusable formula library: references/title-formulas.md provides 8 hook formulas plus a straightforward type, outputting 4-5 candidates for the user to choose from.
8 hook formulas + straightforward style for balanced title generation.
Frontmatter fields follow fixed processing rules: title/slug/summary/description/coverImage, with dual summary/description versions meeting specific length criteria.
| `summary` | 1 sentence, ~50-80 chars | Concise hook — for feeds, social sharing, SEO meta |
Disk write discipline: outputs {filename}-formatted.md, backing up with a timestamp before overwriting; the analysis document {original-filename}-analysis.md is retained as the editorial basis.
mv "{filename}-formatted.md" "{filename}-formatted.backup-$(date +%Y%m%d-%H%M%S).md"
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | npx autocorrect-node --fix(CJK/英文间距修复) |
| package | remark-cjk-friendly |
| package | remark-parse / remark-stringify / remark-gfm / remark-frontmatter / unified / unist-util-visit / yaml |
| cli | bun(首选运行时;无 bun 时 npx -y bun) |
4Recommended Governance & Evidence
- scripts/: Local script or command execution: bun {baseDir}/scripts/main.ts <file.md> [--quotes/--no-spacing/--no-emphasi
- 网络端点: External network access declaration: registry.npmjs.org: npx fetches autocorrect-node (version unpinned in repository); cached by npm after initial run
- 本地工作目录: File I/O and artifact output: Writes back in-place to processed .md files (writeFileSync in main.ts during quotes/emphasis phases; the 'typography fixes only' path directly modifies user source files)
5Second-Pass Verification
- [ok] 『模型做内容、脚本做排版』的两段式划分 — SKILL.md Workflow 段逐字:'Claude performs content analysis and formatting (Steps 1-5), then runs the script for typography fixes (Step 6).' 与脚本能力一致(脚本无内容改写逻辑)。
- [ok] 脚本的确定性修复项与默认值 — main.ts DEFAULT_OPTIONS={quotes:false, spacing:true, emphasis:true};--quotes/--no-spacing/--no-emphasis 均有对应分支;与 SKILL.md 选项表一致。
- [ok] npx autocorrect-node 为唯一外部命令调用 — 全目录 grep spawn/exec/npx 仅 autocorrect.ts 命中一处;main.ts 只有 readFileSync/writeFileSync。
- [ok] 外部依赖清单完整性 — package.json 声明 8 个包(remark 生态 + unified + yaml),另加运行时 npx 的 autocorrect-node;全目录无任何 http 端点/API 调用。
- [ok] 无凭证读取 — 目录内 token 扫描 API_KEY/TOKEN/SECRET/.env/keychain 零命中;仅读取 EXTEND.md 偏好(路径在 SKILL.md 明列)。
- [ok] 标题公式库内容与『8 个公式』一致 — references/title-formulas.md 首行 '8 hook formulas + straightforward style for balanced title generation.',表格确为 8 行 hook(Subversive…Empathy)。
- [ok] 『仅排版修复』会原地改用户文件 — SKILL.md 第三条路径写明 'Run typography script on original file in-place / No copy created, modifies original file directly',与 main.ts writeFileSync(filePath…) 行为一致,已列为使用注意。
- [ok] 元数据(license/stars/commit) — git HEAD=1567581c26ec29f4216c6e6835415bf30343b0e3;仓库根 LICENSE=MIT(Copyright (c) 2026 Jim Liu);GitHub API stars=25926、pushed_at=2026-09-10T15:13:43Z。
6Verdict & Scenarios
6367312d8f2334bb…