canghe-format-markdown by freestylefly/canghe-skills
npx skills add https://github.com/freestylefly/canghe-skills --skill canghe-format-markdown将纯文本或 Markdown 文件转换为结构良好、具有适当 Frontmatter、格式和排版的 Markdown 文档。
脚本位于 scripts/ 子目录中。请将 ${SKILL_DIR} 替换为此 SKILL.md 文件的目录路径。
| 脚本 | 用途 |
|---|---|
scripts/main.ts | 主入口点,包含 CLI 选项(使用 remark-cjk-friendly 处理 CJK 强调) |
scripts/quotes.ts | 将 ASCII 引号替换为全角引号 |
scripts/autocorrect.ts | 通过 autocorrect 添加 CJK/英文间距 |
使用 Bash 检查 EXTEND.md 是否存在(优先级顺序):
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 首先检查项目级
test -f .canghe-skills/canghe-format-markdown/EXTEND.md && echo "project"
# 然后检查用户级(跨平台:$HOME 在 macOS/Linux/WSL 上均适用)
test -f "$HOME/.canghe-skills/canghe-format-markdown/EXTEND.md" && echo "user"
┌──────────────────────────────────────────────────────────┬───────────────────┐ │ 路径 │ 位置 │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ .canghe-skills/canghe-format-markdown/EXTEND.md │ 项目目录 │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ $HOME/.canghe-skills/canghe-format-markdown/EXTEND.md │ 用户主目录 │ └──────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐ │ 结果 │ 操作 │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ 找到 │ 读取、解析、应用设置 │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ 未找到 │ 使用默认值 │ └───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md 支持:默认格式化选项 | 摘要长度偏好
Claude 执行内容分析和格式化(步骤 1-6),然后运行脚本进行排版修正(步骤 7)。
读取用户指定的 Markdown 或纯文本文件。
内容类型检测:
| 指示器 | 分类 |
|---|---|
包含 --- YAML frontmatter | Markdown |
包含 #、##、### 标题 | Markdown |
包含 **粗体**、*斜体* | Markdown |
包含 - 或 1. 列表 | Markdown |
| 包含 ```` 代码块 | Markdown |
包含 > 块引用 | Markdown |
| 以上皆无 | 纯文本 |
决策流程:
┌─────────────────┬────────────────────────────────────────────────┐ │ 内容类型 │ 操作 │ ├─────────────────┼────────────────────────────────────────────────┤ │ 纯文本 │ 继续步骤 2(格式化为 Markdown) │ ├─────────────────┼────────────────────────────────────────────────┤ │ Markdown │ 使用 AskUserQuestion 确认优化 │ └─────────────────┴────────────────────────────────────────────────┘
如果检测到 Markdown,询问用户:
检测到现有的 Markdown 格式。您希望如何操作?
1. 优化格式(推荐)
- 添加/改进 frontmatter、标题、粗体、列表
- 运行排版脚本(间距、强调修正)
- 输出:{文件名}-formatted.md
2. 保持原始格式
- 保留现有的 Markdown 结构
- 运行排版脚本(间距、强调修正)
- 输出:{文件名}-formatted.md
3. 仅进行排版修正
- 在原文件上直接运行排版脚本
- 不创建副本,直接修改原文件
根据用户选择:
识别:
#)检查是否存在 YAML frontmatter(--- 块)。如果缺失则创建。
元字段处理:
| 字段 | 处理 |
|---|---|
title | 参见步骤 4 |
slug | 从文件路径推断(例如 posts/2026/01/10/vibe-coding/ → vibe-coding)或根据标题生成 |
summary | 生成吸引人的摘要(100-150 字符) |
coverImage | 检查同目录下是否存在 imgs/cover.png;如果存在,使用相对路径(也接受 featureImage) |
逻辑:
title → 使用它,正文中不添加 H1title,从正文中移除 H1标题生成流程:
AskUserQuestion 工具:请选择一个标题:
1. [标题 A](推荐)
2. [标题 B]
3. [标题 C]
3. 如果几秒内未选择,则使用推荐选项(选项 1)
标题原则:
重要: 一旦标题进入 frontmatter,正文中不应再有 H1(避免重复)
格式化规则:
| 元素 | 格式 |
|---|---|
| 标题 | 使用 #、##、### 层级结构 |
| 关键点 | 使用 **粗体** |
| 平行项目 | 转换为 - 无序列表或 1. 有序列表 |
| 代码/命令 | 使用 行内代码 或 代码块 |
| 引用/名言 | 使用 > 块引用 |
| 分隔符 | 在适当位置使用 --- |
格式化原则:
保存为 {原始文件名}-formatted.md
示例:
final.md → final-formatted.mddraft-v1.md → draft-v1-formatted.md如果用户选择了“保持原始格式”(来自步骤 1.5):
{文件名}-formatted.md,不做修改备份现有文件:
如果 {文件名}-formatted.md 已存在,则在覆盖前备份:
# 检查格式化文件是否存在
if [ -f "{文件名}-formatted.md" ]; then
# 使用时间戳备份
mv "{文件名}-formatted.md" "{文件名}-formatted.backup-$(date +%Y%m%d-%H%M%S).md"
fi
示例:
final-formatted.md 存在 → 备份为 final-formatted.backup-20260128-143052.md保存后,必须 运行格式化脚本:
npx -y bun ${SKILL_DIR}/scripts/main.ts {输出文件路径} [选项]
脚本选项:
| 选项 | 短选项 | 描述 | 默认值 |
|---|---|---|---|
--quotes | -q | 将 ASCII 引号替换为全角引号 "..." | false |
--no-quotes | 不替换引号 | ||
--spacing | -s | 通过 autocorrect 添加 CJK/英文间距 | true |
--no-spacing | 不添加 CJK/英文间距 | ||
--emphasis | -e | 修正 CJK 强调标点问题 | true |
--no-emphasis | 不修正 CJK 强调问题 | ||
--help | -h | 显示帮助信息 |
示例:
# 默认:间距 + 强调启用,引号禁用
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md
# 启用所有功能,包括引号替换
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --quotes
# 仅修正强调问题,跳过间距
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing
# 禁用所有处理,仅保留 frontmatter 格式化
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing --no-emphasis
脚本执行(基于选项):
"..." 替换为全角引号 "..."(默认:禁用)**格式化完成**
文件:posts/2026/01/09/example/final-formatted.md
更改:
- 添加了标题:[标题内容]
- 添加了 X 个粗体标记
- 添加了 X 个列表
- 添加了 X 个代码块
之前:
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.
之后:
---
title: 三大核心优势
slug: three-core-advantages
summary: 探索推动现代项目成功的三个关键优势。
---
This is plain text.
**主要优势:**
- 效率提升
- 成本降低
- 体验优化
使用 `npm install` 安装依赖。
python、javascript)通过 EXTEND.md 进行自定义配置。有关路径和支持的选项,请参见 偏好设置 部分。
每周安装次数
99
代码仓库
GitHub 星标数
182
首次出现
2026年2月24日
安全审计
安装于
github-copilot98
gemini-cli98
codex98
kimi-cli98
cursor98
opencode98
Transforms plain text or markdown files into well-structured markdown with proper frontmatter, formatting, and typography.
Scripts in scripts/ subdirectory. Replace ${SKILL_DIR} with this SKILL.md's directory path.
| 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 |
Use Bash to check EXTEND.md existence (priority order):
# Check project-level first
test -f .canghe-skills/canghe-format-markdown/EXTEND.md && echo "project"
# Then user-level (cross-platform: $HOME works on macOS/Linux/WSL)
test -f "$HOME/.canghe-skills/canghe-format-markdown/EXTEND.md" && echo "user"
┌──────────────────────────────────────────────────────────┬───────────────────┐ │ Path │ Location │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ .canghe-skills/canghe-format-markdown/EXTEND.md │ Project directory │ ├──────────────────────────────────────────────────────────┼───────────────────┤ │ $HOME/.canghe-skills/canghe-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
Claude performs content analysis and formatting (Steps 1-6), then runs the script for typography fixes (Step 7).
Read the user-specified markdown or plain text file.
Content Type Detection:
| Indicator | Classification |
|---|---|
Has --- YAML frontmatter | Markdown |
Has #, ##, ### headings | Markdown |
Has **bold**, *italic* | Markdown |
Has - or 1. lists |
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:
Identify:
#)Check for YAML frontmatter (--- block). Create if missing.
Meta field handling:
| Field | Processing |
|---|---|
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) |
coverImage | Check if imgs/cover.png exists in same directory; if so, use relative path (also accepted: ) |
Logic:
title → use it, no H1 in bodytitle, remove H1 from bodyTitle generation flow:
AskUserQuestion tool:Select a title:
1. [Title A] (Recommended)
2. [Title B]
3. [Title C]
3. If no selection within a few seconds, use recommended (option 1)
Title principles:
Important: Once title is in frontmatter, body should NOT have H1 (avoid duplication)
Formatting rules:
| Element | Format |
|---|---|
| Titles | Use #, ##, ### hierarchy |
| Key points | Use **bold** |
| Parallel items | Convert to - unordered or 1. ordered lists |
| Code/commands | Use inline or block |
Formatting principles:
Save as {original-filename}-formatted.md
Examples:
final.md → final-formatted.mddraft-v1.md → draft-v1-formatted.mdIf user chose "Keep original formatting" (from Step 1.5):
{filename}-formatted.md without modificationsBackup existing file:
If {filename}-formatted.md already exists, backup before overwriting:
# 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.mdAfter saving, must run the formatting script:
npx -y bun ${SKILL_DIR}/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
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
# Only fix emphasis issues, skip spacing
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing
# Disable all processing except frontmatter formatting
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --no-spacing --no-emphasis
Script performs (based on options):
"..." with fullwidth quotes "..." (default: disabled)**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
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:
---
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.
python, javascript)Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
Weekly Installs
99
Repository
GitHub Stars
182
First Seen
Feb 24, 2026
Security Audits
Gen Agent Trust HubWarnSocketWarnSnykWarn
Installed on
github-copilot98
gemini-cli98
codex98
kimi-cli98
cursor98
opencode98
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
157,400 周安装
GWAS研究深度探索与荟萃分析工具 - 比较研究、执行荟萃分析、评估可重复性
134 周安装
PowerPoint PPTX 翻译技能:使用 Claude API 和 Python-pptx 实现自动化翻译与调试
141 周安装
整洁代码标准权威指南:CC-*规则、跨团队代码评审与自动化实践
130 周安装
邮件IMAP自动抓取工具:实时监控未读邮件并转发至Webhook
145 周安装
WordPress渗透测试指南:WPScan工具使用、漏洞扫描与安全评估
171 周安装
API模糊测试漏洞赏金指南:REST、SOAP、GraphQL安全测试与IDOR绕过技术
176 周安装
| Markdown |
| Has ``` code blocks | Markdown |
Has > blockquotes | Markdown |
| None of above | Plain text |
featureImage| Quotes/sayings | Use > blockquote |
| Separators | Use --- where appropriate |
| 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 |
--help | -h | Show help message |