Markdown to HTML Converter
Converts Markdown files to beautifully styled HTML with inline CSS, optimized for WeChat Official Account and other platforms.
Script Directory
Agent Execution: Determine this SKILL.md directory as {baseDir}. 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 |
|---|
| INLINECODE8 | Main entry point |
Preferences (EXTEND.md)
Check EXTEND.md existence (priority order):
CODEBLOCK0
CODEBLOCK1
┌──────────────────────────────────────────────────────────────┬───────────────────┐
│ 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 style
Workflow
Step 0: Pre-check (Chinese Content)
Condition: Only execute if input file contains Chinese text.
Detection:
- 1. 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 baoyu-format-markdown skill is available:
Use AskUserQuestion to ask whether to format first. Formatting can fix:
- - Bold markers with punctuation inside causing
** parse failures - CJK/English spacing issues
If user agrees: Invoke baoyu-format-markdown skill to format the file, then use formatted file as input.
If user declines: Continue with original file.
Step 1: Determine Theme
Theme resolution order (first match wins):
- 1. User explicitly specified theme (CLI
--theme or conversation) - EXTEND.md
default_theme (this skill's own EXTEND.md, checked in Step 0) - INLINECODE15 EXTEND.md
default_theme (cross-skill fallback) - If none found → use AskUserQuestion to confirm
Cross-skill EXTEND.md check (only if this skill's EXTEND.md has no default_theme):
CODEBLOCK2
CODEBLOCK3
If theme is resolved from EXTEND.md: Use it directly, do NOT ask the user.
If no default found: Use AskUserQuestion to confirm:
| Theme | Description |
|---|
| INLINECODE18 (Recommended) | Classic - traditional layout, centered title with bottom border, H2 with white text on colored background |
| INLINECODE19 |
Elegant - text shadow, rounded cards, refined blockquotes |
|
simple | Minimal - modern minimalist, asymmetric rounded corners, clean whitespace |
|
modern | Modern - large radius, pill-shaped titles, relaxed line height (pair with
--color red for traditional red-gold style) |
Step 1.5: Determine Citation Mode
Default: Off. Do not ask by default.
Enable only if the user explicitly asks for "微信外链转底部引用", "底部引用", "文末引用", or passes --cite.
Behavior when enabled:
- - Ordinary external links are rendered with numbered superscripts and collected under a final
引用链接 section. - INLINECODE25 links stay as direct links and are not moved to the bottom.
- Bare links where link text equals URL stay inline.
Step 2: Convert
CODEBLOCK4
Step 3: Report Result
Display the output path from JSON result. If backup was created, mention it.
Usage
CODEBLOCK5
Options:
| Option | Description | Default |
|---|
| INLINECODE26 | Theme name (default, grace, simple, modern) | default |
| INLINECODE27 |
Primary color: preset name or hex value | theme default |
|
--font-family <name> | Font: sans, serif, serif-cjk, mono, or CSS value | theme default |
|
--font-size <N> | Font size: 14px, 15px, 16px, 17px, 18px | 16px |
|
--title <title> | Override title from frontmatter | |
|
--cite | Convert external links to bottom citations, append
引用链接 section | false (off) |
|
--keep-title | Keep the first heading in content | false (removed) |
|
--help | Show help | |
Color Presets:
| Name | Hex | Label |
|---|
| blue | #0F4C81 | Classic Blue |
| green |
#009874 | Emerald Green |
| vermilion | #FA5151 | Vibrant Vermilion |
| yellow | #FECE00 | Lemon Yellow |
| purple | #92617E | Lavender Purple |
| sky | #55C9EA | Sky Blue |
| rose | #B76E79 | Rose Gold |
| olive | #556B2F | Olive Green |
| black | #333333 | Graphite Black |
| gray | #A9A9A9 | Smoke Gray |
| pink | #FFB7C5 | Sakura Pink |
| red | #A93226 | China Red |
| orange | #D97757 | Warm Orange (modern default) |
Examples:
CODEBLOCK6
Output
File location: Same directory as input markdown file.
- - Input: INLINECODE35
- Output: INLINECODE36
Conflict handling: If HTML file already exists, it will be backed up first:
JSON output to stdout:
CODEBLOCK7
Themes
| Theme | Description |
|---|
| INLINECODE38 | Classic - traditional layout, centered title with bottom border, H2 with white text on colored background |
| INLINECODE39 |
Elegant - text shadow, rounded cards, refined blockquotes (by @brzhang) |
|
simple | Minimal - modern minimalist, asymmetric rounded corners, clean whitespace (by @okooo5km) |
|
modern | Modern - large radius, pill-shaped titles, relaxed line height (pair with
--color red for traditional red-gold style) |
Supported Markdown Features
| Feature | Syntax |
|---|
| Headings | INLINECODE43 to INLINECODE44 |
| Bold/Italic |
**bold**,
*italic* |
| Code blocks |
`
lang with syntax highlighting |
| Inline code | `
code
|
| Tables | GitHub-flavored markdown tables |
| Images | 
|
| Links | text; add --cite
to move ordinary external links into bottom references |
| Blockquotes | > quote
|
| Lists | -
unordered, 1.
ordered |
| Alerts | > [!NOTE]
, > [!WARNING]
, etc. |
| Footnotes | [^1]
references |
| Ruby text | {base|annotation}
|
| Mermaid | ``
mermaid diagrams |
| PlantUML |
`
plantuml diagrams |
Frontmatter
Supports YAML frontmatter for metadata:
CODEBLOCK8
If no title is found, extracts from first H1/H2 heading or uses filename.
Extension Support
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
Markdown 转 HTML 转换器
将 Markdown 文件转换为带有内联 CSS 的精美 HTML,针对微信公众号及其他平台优化。
脚本目录
Agent 执行:将此 SKILL.md 所在目录确定为 {baseDir}。解析 ${BUNX} 运行时:若已安装 bun → bun;若 npx 可用 → npx -y bun;否则建议安装 bun。将 {baseDir} 和 ${BUNX} 替换为实际值。
偏好设置 (EXTEND.md)
检查 EXTEND.md 是否存在(优先级顺序):
bash
macOS, Linux, WSL, Git Bash
test -f .baoyu-skills/baoyu-markdown-to-html/EXTEND.md && echo project
test -f ${XDG
CONFIGHOME:-$HOME/.config}/baoyu-skills/baoyu-markdown-to-html/EXTEND.md && echo xdg
test -f $HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md && echo user
powershell
PowerShell (Windows)
if (Test-Path .baoyu-skills/baoyu-markdown-to-html/EXTEND.md) { project }
$xdg = if ($env:XDG
CONFIGHOME) { $env:XDG
CONFIGHOME } else { $HOME/.config }
if (Test-Path $xdg/baoyu-skills/baoyu-markdown-to-html/EXTEND.md) { xdg }
if (Test-Path $HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md) { user }
┌──────────────────────────────────────────────────────────────┬───────────────────┐
│ 路径 │ 位置 │
├──────────────────────────────────────────────────────────────┼───────────────────┤
│ .baoyu-skills/baoyu-markdown-to-html/EXTEND.md │ 项目目录 │
├──────────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md │ 用户主目录 │
└──────────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ 结果 │ 操作 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 找到 │ 读取、解析、应用设置 │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ 未找到 │ 使用默认值 │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md 支持:默认主题 | 自定义 CSS 变量 | 代码块样式
工作流程
步骤 0:预检查(中文内容)
条件:仅当输入文件包含中文文本时执行。
检测:
- 1. 读取输入 markdown 文件
- 检查内容是否包含中日韩(CJK)字符
- 若无 CJK 内容 → 跳至步骤 1
格式建议:
若检测到 CJK 内容且 baoyu-format-markdown 技能可用:
使用 AskUserQuestion 询问是否先进行格式化。格式化可修复:
- - 粗体标记内包含标点导致 解析失败
- 中日韩/英文间距问题
若用户同意:调用 baoyu-format-markdown 技能格式化文件,然后使用格式化后的文件作为输入。
若用户拒绝:继续使用原始文件。
步骤 1:确定主题
主题解析顺序(优先匹配第一个):
- 1. 用户明确指定的主题(CLI --theme 或对话中)
- EXTEND.md defaulttheme(本技能的 EXTEND.md,在步骤 0 中检查)
- baoyu-post-to-wechat EXTEND.md defaulttheme(跨技能回退)
- 若均未找到 → 使用 AskUserQuestion 确认
跨技能 EXTEND.md 检查(仅当本技能 EXTEND.md 无 default_theme 时):
bash
检查 baoyu-post-to-wechat EXTEND.md 中的 default_theme
test -f $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md && grep -o default_theme:.* $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md
powershell
PowerShell (Windows)
if (Test-Path $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md) { Select-String -Pattern default
theme:.* -Path $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md | ForEach-Object { $.Matches.Value } }
若从 EXTEND.md 解析到主题:直接使用,不要询问用户。
若未找到默认值:使用 AskUserQuestion 确认:
| 主题 | 描述 |
|---|
| default(推荐) | 经典 - 传统布局,居中标题带底部边框,H2 使用彩色背景白色文字 |
| grace |
优雅 - 文字阴影、圆角卡片、精致引用块 |
| simple | 简约 - 现代极简、不对称圆角、干净留白 |
| modern | 现代 - 大圆角、药丸形标题、宽松行高(搭配 --color red 实现传统红金风格) |
步骤 1.5:确定引用模式
默认:关闭。默认不询问。
仅当用户明确要求微信外链转底部引用、底部引用、文末引用或传递 --cite 时启用。
启用时行为:
- - 普通外部链接以编号上标形式呈现,并在最后的 引用链接 部分汇总。
- https://mp.weixin.qq.com/... 链接保持为直接链接,不移到底部。
- 链接文本等于 URL 的裸链接保持行内显示。
步骤 2:转换
bash
${BUNX} {baseDir}/scripts/main.ts file> --theme [--cite]
步骤 3:报告结果
显示 JSON 结果中的输出路径。若创建了备份,则提及。
用法
bash
${BUNX} {baseDir}/scripts/main.ts file> [options]
选项:
| 选项 | 描述 | 默认值 |
|---|
| --theme <name> | 主题名称(default, grace, simple, modern) | default |
| --color <name\ |
hex> | 主色:预设名称或十六进制值 | 主题默认 |
| --font-family
| 字体:sans, serif, serif-cjk, mono 或 CSS 值 | 主题默认 |
| --font-size | 字号:14px, 15px, 16px, 17px, 18px | 16px |
| --title | 覆盖 frontmatter 中的标题 | |
| --cite | 将外部链接转换为底部引用,追加 引用链接 部分 | false(关闭) |
| --keep-title | 保留内容中的第一个标题 | false(移除) |
| --help | 显示帮助 | |
颜色预设:
| 名称 | 十六进制 | 标签 |
|---|
| blue | #0F4C81 | 经典蓝 |
| green |
#009874 | 翡翠绿 |
| vermilion | #FA5151 | 活力朱红 |
| yellow | #FECE00 | 柠檬黄 |
| purple | #92617E | 薰衣草紫 |
| sky | #55C9EA | 天空蓝 |
| rose | #B76E79 | 玫瑰金 |
| olive | #556B2F | 橄榄绿 |
| black | #333333 | 石墨黑 |
| gray | #A9A9A9 | 烟灰 |
| pink | #FFB7C5 | 樱花粉 |
| red | #A93226 | 中国红 |
| orange | #D97757 | 暖橙(modern 默认) |
示例:
bash
基本转换(使用默认主题,移除第一个标题)
${BUN_X} {baseDir}/scripts/main.ts article.md
指定主题
${BUN_X} {baseDir}/scripts/main.ts article.md --theme grace
主题搭配自定义颜色
${BUN_X} {baseDir}/scripts/main.ts article.md