baoyu-markdown-to-html
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMarkdown to HTML Converter
Markdown转HTML转换器
Converts Markdown files to beautifully styled HTML with inline CSS, optimized for WeChat Official Account and other platforms.
将Markdown文件转换为带有内联CSS的精美样式HTML,适配微信公众号及其他平台。
Script Directory
脚本目录
Agent Execution: Determine this SKILL.md directory as , then use .
SKILL_DIR${SKILL_DIR}/scripts/<name>.ts| Script | Purpose |
|---|---|
| Main entry point |
Agent执行:将当前SKILL.md所在目录设为,然后使用。
SKILL_DIR${SKILL_DIR}/scripts/<name>.ts| 脚本 | 用途 |
|---|---|
| 主入口文件 |
Preferences (EXTEND.md)
偏好设置(EXTEND.md)
Use Bash to check EXTEND.md existence (priority order):
bash
undefined使用Bash检查EXTEND.md是否存在(优先级顺序):
bash
undefinedCheck project-level first
Check project-level first
test -f .baoyu-skills/baoyu-markdown-to-html/EXTEND.md && echo "project"
test -f .baoyu-skills/baoyu-markdown-to-html/EXTEND.md && echo "project"
Then user-level (cross-platform: $HOME works on macOS/Linux/WSL)
Then user-level (cross-platform: $HOME works on macOS/Linux/WSL)
test -f "$HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md" && echo "user"
┌──────────────────────────────────────────────────────────────┬───────────────────┐
│ Path │ Location │
├──────────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-markdown-to-html/EXTEND.md │ Project directory │
├──────────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md │ User home │
└──────────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ Result │ Action │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Found │ Read, parse, apply settings │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Not found │ Use defaults │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
**EXTEND.md Supports**: Default theme | Custom CSS variables | Code block styletest -f "$HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md" && echo "user"
┌──────────────────────────────────────────────────────────────┬───────────────────┐
│ 路径 │ 位置 │
├──────────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-markdown-to-html/EXTEND.md │ 项目目录 │
├──────────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md │ 用户主目录 │
└──────────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ 结果 │ 操作 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 已找到 │ 读取、解析并应用设置 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 未找到 │ 使用默认设置 │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
**EXTEND.md支持**:默认主题 | 自定义CSS变量 | 代码块样式Workflow
工作流程
Step 0: Pre-check (Chinese Content)
步骤0:预检查(中文内容)
Condition: Only execute if input file contains Chinese text.
Detection:
- Read input markdown file
- Check if content contains CJK characters (Chinese/Japanese/Korean)
- If no CJK content → skip to Step 1
Format Suggestion:
If CJK content detected AND skill is available:
baoyu-format-markdownUse to ask whether to format first. Formatting can fix:
AskUserQuestion- Bold markers with punctuation inside causing parse failures
** - CJK/English spacing issues
If user agrees: Invoke skill to format the file, then use formatted file as input.
baoyu-format-markdownIf user declines: Continue with original file.
条件:仅当输入文件包含中文文本时执行。
检测方式:
- 读取输入的Markdown文件
- 检查内容是否包含CJK字符(中文/日文/韩文)
- 若无CJK内容 → 跳至步骤1
格式建议:
若检测到CJK内容且技能可用:
baoyu-format-markdown使用询问是否先进行格式化。格式化可修复以下问题:
AskUserQuestion- 标点符号位于粗体标记内导致的解析失败
** - CJK与英文之间的空格问题
若用户同意:调用技能格式化文件,然后将格式化后的文件作为输入。
baoyu-format-markdown若用户拒绝:继续使用原文件。
Step 1: Confirm Theme
步骤1:确认主题
Before converting, use AskUserQuestion to confirm the theme (unless user already specified):
| Theme | Description |
|---|---|
| 经典主题 - 传统排版,标题居中带底边,二级标题白字彩底 |
| 优雅主题 - 文字阴影,圆角卡片,精致引用块 |
| 简洁主题 - 现代极简风,不对称圆角,清爽留白 |
转换前,使用AskUserQuestion确认主题(除非用户已指定):
| 主题 | 描述 |
|---|---|
| 经典主题 - 传统排版,标题居中带底边,二级标题白字彩底 |
| 优雅主题 - 文字阴影,圆角卡片,精致引用块 |
| 简洁主题 - 现代极简风,不对称圆角,清爽留白 |
Step 2: Convert
步骤2:转换
bash
npx -y bun ${SKILL_DIR}/scripts/main.ts <markdown_file> --theme <theme>bash
npx -y bun ${SKILL_DIR}/scripts/main.ts <markdown_file> --theme <theme>Step 3: Report Result
步骤3:报告结果
Display the output path from JSON result. If backup was created, mention it.
显示JSON结果中的输出路径。若已创建备份,需提及备份信息。
Usage
使用方法
bash
npx -y bun ${SKILL_DIR}/scripts/main.ts <markdown_file> [options]Options:
| Option | Description | Default |
|---|---|---|
| Theme name (default, grace, simple) | default |
| Override title from frontmatter | |
| Keep the first heading in content | false (removed) |
| Show help |
Examples:
bash
undefinedbash
npx -y bun ${SKILL_DIR}/scripts/main.ts <markdown_file> [options]选项:
| 选项 | 描述 | 默认值 |
|---|---|---|
| 主题名称(default、grace、simple) | default |
| 覆盖前置元数据中的标题 | 无 |
| 保留内容中的第一个标题 | false(默认移除) |
| 显示帮助信息 | 无 |
示例:
bash
undefinedBasic conversion (uses default theme, removes first heading)
Basic conversion (uses default theme, removes first heading)
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md
With specific theme
With specific theme
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --theme grace
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --theme grace
Keep the first heading in content
Keep the first heading in content
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --keep-title
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --keep-title
Override title
Override title
npx -y bun ${SKILL_DIR}/scripts/main.ts article.md --title "My Article"
undefinednpx -y bun ${SKILL_DIR}/scripts/main.ts article.md --title "My Article"
undefinedOutput
输出
File location: Same directory as input markdown file.
- Input:
/path/to/article.md - Output:
/path/to/article.html
Conflict handling: If HTML file already exists, it will be backed up first:
- Backup:
/path/to/article.html.bak-YYYYMMDDHHMMSS
JSON output to stdout:
json
{
"title": "Article Title",
"author": "Author Name",
"summary": "Article summary...",
"htmlPath": "/path/to/article.html",
"backupPath": "/path/to/article.html.bak-20260128180000",
"contentImages": [
{
"placeholder": "MDTOHTMLIMGPH_1",
"localPath": "/path/to/img.png",
"originalPath": "imgs/image.png"
}
]
}文件位置:与输入Markdown文件同一目录。
- 输入:
/path/to/article.md - 输出:
/path/to/article.html
冲突处理:若HTML文件已存在,将先创建备份:
- 备份:
/path/to/article.html.bak-YYYYMMDDHHMMSS
标准输出的JSON结果:
json
{
"title": "Article Title",
"author": "Author Name",
"summary": "Article summary...",
"htmlPath": "/path/to/article.html",
"backupPath": "/path/to/article.html.bak-20260128180000",
"contentImages": [
{
"placeholder": "MDTOHTMLIMGPH_1",
"localPath": "/path/to/img.png",
"originalPath": "imgs/image.png"
}
]
}Themes
主题
| Theme | Description |
|---|---|
| 经典主题 - 传统排版,标题居中带底边,二级标题白字彩底 |
| 优雅主题 - 文字阴影,圆角卡片,精致引用块 (by @brzhang) |
| 简洁主题 - 现代极简风,不对称圆角,清爽留白 (by @okooo5km) |
| 主题 | 描述 |
|---|---|
| 经典主题 - 传统排版,标题居中带底边,二级标题白字彩底 |
| 优雅主题 - 文字阴影,圆角卡片,精致引用块(作者:@brzhang) |
| 简洁主题 - 现代极简风,不对称圆角,清爽留白(作者:@okooo5km) |
Supported Markdown Features
支持的Markdown特性
| Feature | Syntax |
|---|---|
| Headings | |
| Bold/Italic | |
| Code blocks | |
| Inline code | |
| Tables | GitHub-flavored markdown tables |
| Images | |
| Links | |
| Blockquotes | |
| Lists | |
| Alerts | |
| Footnotes | |
| Ruby text | `{base |
| Mermaid | |
| PlantUML | |
| 特性 | 语法 |
|---|---|
| 标题 | |
| 粗体/斜体 | |
| 代码块 | |
| 行内代码 | |
| 表格 | GitHub风格Markdown表格 |
| 图片 | |
| 链接 | |
| 块引用 | |
| 列表 | |
| 提示框 | |
| 脚注 | |
| 注音文本 | `{base |
| Mermaid图 | |
| PlantUML图 | |
Frontmatter
前置元数据
Supports YAML frontmatter for metadata:
yaml
---
title: Article Title
author: Author Name
description: Article summary
---If no title is found, extracts from first H1/H2 heading or uses filename.
支持使用YAML前置元数据存储元信息:
yaml
---
title: Article Title
author: Author Name
description: Article summary
---若未找到标题,将从第一个H1/H2标题提取或使用文件名作为标题。
Extension Support
扩展支持
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
通过EXTEND.md进行自定义配置。路径及支持的选项请查看偏好设置章节。