baoyu-markdown-to-html
- 作者仓库星标 0
- 作者更新于 2026年7月4日 09:22
- 作者仓库 baoyu-skills
Markdown 转 HTML 转换器
将 Markdown 文件转换为精美风格的 HTML,内联 CSS,针对微信公众号及其他平台优化。
用户输入工具
当此技能提示用户时,请遵循以下工具选择规则(优先级顺序):
- 优先使用当前 Agent 运行时暴露的内置用户输入工具——例如
AskUserQuestion、request_user_input、clarify、ask_user或任何等效工具。 - 备选方案:如果不存在此类工具,则发出带编号的纯文本消息,并要求用户回复所选编号/答案以回答每个问题。
- 批量处理:如果工具支持每次调用处理多个问题,则将所有适用问题合并到一次调用中;如果只支持单个问题,则按优先级顺序逐一提问。
下面具体的 AskUserQuestion 引用是示例——在其他运行时请替换为本地等效工具。
脚本目录
Agent 执行:将此 SKILL.md 目录确定为 {baseDir}。解析 ${BUN_X} 运行时:如果安装了 bun → bun;如果 npx 可用 → npx -y bun;否则建议安装 bun。将 {baseDir} 和 ${BUN_X} 替换为实际值。
| 脚本 | 用途 |
|---|---|
scripts/main.ts |
主入口点 |
首选项 (EXTEND.md)
按优先级顺序检查 EXTEND.md——找到的第一个生效:
| 优先级 | 路径 | 范围 |
|---|---|---|
| 1 | .baoyu-skills/baoyu-markdown-to-html/EXTEND.md |
项目 |
| 2 | ${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-markdown-to-html/EXTEND.md |
XDG |
| 3 | $HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md |
用户主目录 |
如果未找到,则使用默认值。
EXTEND.md 支持:默认主题、自定义 CSS 变量、代码块样式。
工作流程
步骤 0:预检查(中文内容)
条件:仅当输入文件包含中文文本时才执行。
检测:
- 读取输入 Markdown 文件
- 检查内容是否包含 CJK 字符(中文/日文/韩文)
- 如果没有 CJK 内容 → 跳到步骤 1
格式化建议:
如果检测到 CJK 内容且 baoyu-format-markdown 技能可用:
使用 AskUserQuestion 询问是否先进行格式化。格式化可以修复:
- 粗体标记内包含标点符号导致
**解析失败的问题 - CJK/英文间距问题
如果用户同意:调用 baoyu-format-markdown 技能格式化文件,然后使用格式化后的文件作为输入。
如果用户拒绝:继续使用原始文件。
步骤 1:确定主题
主题解析顺序(第一个匹配项胜出):
- 用户明确指定的主题(CLI
--theme或对话中) - EXTEND.md
default_theme(此技能自己的 EXTEND.md,在步骤 0 中检查) baoyu-post-to-wechatEXTEND.mddefault_theme(跨技能回退)- 如果未找到 → 使用 AskUserQuestion 确认
跨技能 EXTEND.md 检查(仅当此技能的 EXTEND.md 没有 default_theme 时):
如果 $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md 存在,则读取它并查找 default_theme: 行。如果存在该值则使用;否则继续。
如果主题从 EXTEND.md 解析:直接使用,不要询问用户。
如果未找到默认主题:使用 AskUserQuestion 从下面的主题表格中确认一个主题。
步骤 1.5:确定引用模式
默认:关闭。默认不询问。
仅当用户明确要求“微信外链转底部引用”、“底部引用”、“文末引用”或传递 --cite 时启用。
启用时的行为:
- 普通外部链接以带编号的上标形式呈现,并收集在最终的「引用链接」部分下。
https://mp.weixin.qq.com/...链接保持为直接链接,不移至底部。- 链接文本等于 URL 的裸链接保持内联。
步骤 2:转换
${BUN_X} {baseDir}/scripts/main.ts <markdown_file> --theme <theme> [--cite]
步骤 3:报告结果
显示 JSON 结果中的输出路径。如果创建了备份,请提及。
用法
${BUN_X} {baseDir}/scripts/main.ts <markdown_file> [options]
选项:
| 选项 | 描述 | 默认值 |
|---|---|---|
--theme <name> |
主题名称 (default, grace, simple, modern) | default |
--color <name|hex> |
主色调:预设名称或十六进制值 | 主题默认值 |
--font-family <name> |
字体:sans, serif, serif-cjk, mono, 或 CSS 值 | 主题默认值 |
--font-size <N> |
字体大小:14px, 15px, 16px, 17px, 18px | 16px |
--title <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 默认) |
示例:
# 基本转换(使用默认主题,移除第一个标题)
${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 --theme modern --color red
# 启用普通外部链接的底部引用
${BUN_X} {baseDir}/scripts/main.ts article.md --cite
# 保留内容中的第一个标题
${BUN_X} {baseDir}/scripts/main.ts article.md --keep-title
# 覆盖标题
${BUN_X} {baseDir}/scripts/main.ts article.md --title "My Article"
输出
文件位置:与输入 Markdown 文件在同一目录。
- 输入:
/path/to/article.md - 输出:
/path/to/article.html
冲突处理:如果 HTML 文件已存在,将首先进行备份:
- 备份:
/path/to/article.html.bak-YYYYMMDDHHMMSS
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"
}
]
}
主题
| 主题 | 描述 |
|---|---|
default |
经典 - 传统布局,居中标题带底边框,H2 带白色文字在彩色背景上 |
grace |
优雅 - 文本阴影,圆角卡片,精致的引用块(由 @brzhang 提供) |
simple |
极简 - 现代极简主义,不对称圆角,干净的留白(由 @okooo5km 提供) |
modern |
现代 - 大圆角,药丸形标题,宽松行高(搭配 --color red 可获得传统红金风格) |
支持的 Markdown 功能
| 功能 | 语法 |
|---|---|
| 标题 | # H1 到 ###### H6 |
| 粗体/斜体 | **bold**, *italic* |
| 代码块 | ```lang 带语法高亮 |
| 行内代码 | `code` |
| 表格 | GitHub 风格的 Markdown 表格 |
| 图片 |  |
| 链接 | [text](url);添加 --cite 将普通外部链接移至底部引用 |
| 引用块 | > quote |
| 列表 | - 无序,1. 有序 |
| 提示 | > [!NOTE], > [!WARNING], 等 |
| 脚注 | [^1] 引用 |
| Ruby 文本 | `{base |
| Mermaid | ```mermaid 图表 |
| PlantUML | ```plantuml 图表 |
Frontmatter
支持 YAML frontmatter 用于元数据:
---
title: Article Title
author: Author Name
description: Article summary
---
如果未找到标题,则从第一个 H1/H2 标题中提取或使用文件名。
扩展支持
通过 EXTEND.md 进行自定义配置。请参阅首选项部分了解路径和支持的选项。
Markdown to HTML Converter
Converts Markdown files to beautifully styled HTML with inline CSS, optimized for WeChat Official Account and other platforms.
User Input Tools
When this skill prompts the user, follow this tool-selection rule (priority order):
- Prefer built-in user-input tools exposed by the current agent runtime — e.g.,
AskUserQuestion,request_user_input,clarify,ask_user, or any equivalent. - Fallback: if no such tool exists, emit a numbered plain-text message and ask the user to reply with the chosen number/answer for each question.
- Batching: if the tool supports multiple questions per call, combine all applicable questions into a single call; if only single-question, ask them one at a time in priority order.
Concrete AskUserQuestion references below are examples — substitute the local equivalent in other runtimes.
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 |
|---|---|
scripts/main.ts |
Main entry point |
Preferences (EXTEND.md)
Check EXTEND.md in priority order — the first one found wins:
| Priority | Path | Scope |
|---|---|---|
| 1 | .baoyu-skills/baoyu-markdown-to-html/EXTEND.md |
Project |
| 2 | ${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-markdown-to-html/EXTEND.md |
XDG |
| 3 | $HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md |
User home |
If none found, use defaults.
EXTEND.md supports: default theme, custom CSS variables, code block style, mermaid defaults (mermaid_theme, mermaid_scale, mermaid_background).
Workflow
Step 0: Pre-check (Chinese Content)
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 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):
- User explicitly specified theme (CLI
--themeor conversation) - EXTEND.md
default_theme(this skill's own EXTEND.md, checked in Step 0) baoyu-post-to-wechatEXTEND.mddefault_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):
Read $HOME/.baoyu-skills/baoyu-post-to-wechat/EXTEND.md if it exists and look for a default_theme: line. Use the value if present; otherwise fall through.
If theme is resolved from EXTEND.md: Use it directly, do NOT ask the user.
If no default found: use AskUserQuestion to confirm a theme from the Themes table below.
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. https://mp.weixin.qq.com/...links stay as direct links and are not moved to the bottom.- Bare links where link text equals URL stay inline.
Step 2: Convert
${BUN_X} {baseDir}/scripts/main.ts <markdown_file> --theme <theme> [--cite]
Step 3: Report Result
Display the output path from JSON result. If backup was created, mention it.
Usage
${BUN_X} {baseDir}/scripts/main.ts <markdown_file> [options]
Options:
| Option | Description | Default |
|---|---|---|
--theme <name> |
Theme name (default, grace, simple, modern) | default |
--color <name|hex> |
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) |
--mermaid-theme <name> |
Mermaid theme: default, forest, dark, neutral, base |
default |
--mermaid-scale <N> |
Mermaid render scale (positive number ≤ 4) | 2 |
--mermaid-width <N> |
Mermaid target display width in CSS px; PNG is rendered at width × scale pixels when the diagram is narrower than this |
860 |
--mermaid-bg <value> |
Mermaid background: white, transparent, or #hex |
white |
--no-mermaid |
Skip Mermaid PNG rendering; emit <pre class="mermaid"> fallback |
false |
--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:
# Basic conversion (uses default theme, removes first heading)
${BUN_X} {baseDir}/scripts/main.ts article.md
# With specific theme
${BUN_X} {baseDir}/scripts/main.ts article.md --theme grace
# Theme with custom color
${BUN_X} {baseDir}/scripts/main.ts article.md --theme modern --color red
# Enable bottom citations for ordinary external links
${BUN_X} {baseDir}/scripts/main.ts article.md --cite
# Keep the first heading in content
${BUN_X} {baseDir}/scripts/main.ts article.md --keep-title
# Override title
${BUN_X} {baseDir}/scripts/main.ts article.md --title "My Article"
Output
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:
{
"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"
}
],
"mermaidImages": [
{
"hash": "a1b2c3d4e5f6",
"localPath": "/path/to/imgs/.mermaid-cache/mermaid-a1b2c3d4e5f6.png",
"cached": false
}
]
}
Mermaid rendering: Code blocks fenced as ```mermaid are rendered to PNGs via headless Chrome (CDP) and cached at imgs/.mermaid-cache/mermaid-<hash>.png. The cache key includes the code, theme, scale, target width, background, and mermaid version. Add imgs/.mermaid-cache/ to .gitignore if you do not want generated diagrams checked in. Requires Chrome/Chromium/Edge on the system; otherwise the block falls back to <pre class="mermaid">…</pre> and conversion still succeeds.
Themes
| Theme | Description |
|---|---|
default |
Classic - traditional layout, centered title with bottom border, H2 with white text on colored background |
grace |
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 | # H1 to ###### H6 |
| Bold/Italic | **bold**, *italic* |
| Code blocks | ```lang with syntax highlighting |
| Inline code | `code` |
| Tables | GitHub-flavored markdown tables |
| Images |  |
| Links | [text](url); 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 |
| Mermaid | ```mermaid blocks rendered to local PNG via headless Chrome (cached under imgs/.mermaid-cache/); falls back to <pre class="mermaid"> if Chrome is unavailable or rendering fails |
| PlantUML | ```plantuml diagrams |
Frontmatter
Supports YAML frontmatter for metadata:
---
title: Article Title
author: Author Name
description: Article summary
---
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.
- 流狐分类
- 文档
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 92 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @JimLiu · v1.117.3 · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 需简单配置
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- macOS · Linux · Windows
- 底层运行要求
- Bun
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
# Step 3: Report Result
Display the output path from JSON result. If backup was created, mention it. Workflow
Condition: Only execute if input file contains Chinese text. Detection: Read input markdown file
Theme resolution order (first match wins): User explicitly specified theme (CLI --theme or conversation) EXTEND.md defaulttheme (this skill's own EXTEND.md, checked in Step 0)
Default: Off. Do not ask by default. Enable only if the user explicitly asks for "微信外链转底部引用", "底部引用", "文末引用", or passes --cite. Behavior when enabled:
Step 2: Convert
Display the output path from JSON result. If backup was created, mention it.
# Markdown to HTML Converter
Converts Markdown files to beautifully styled HTML with inline CSS, optimized for WeChat Official Account and other platforms.
## User Input Tools
When this skill prompts the user, follow this tool-selection rule (priority order):
1. **Prefer built-in user-input tools** exposed by the current agent runtime — e.g., `AskUserQuestion`, `request_user_input`, `clarify`, `ask_user`, or any equivalent.
2. **Fallback**: if no such tool exists, emit a numbered plain-text message and ask the user to reply with the chosen number/answer for each question.
3. **Batching**: if the tool supports multiple questions per call, combine all applicable questions into a single call; if only single-question, ask them one at a time in priority order.
Concrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes.
## 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 |
|--------|---------|
| `scripts/main.ts` | Main entry point |
## Preferences (EXTEND.md)
Check EXTEND.md in priority order — the first one found wins:
| Priority | Path | Scope |
|----------|------|-------|
| 1 | `.baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | Project |
| 2 | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | XDG |
| 3 | `$HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | User home |
If none found, use defaults.
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> User Input Tools → Script Directory → Preferences (EXTEND.md) → Workflow → Step 0: Pre-check (Chinese Content) → Step 1: Determine Theme
要点 -> Prefer built-in user-input tools · Fallback · Batching · Agent Execution · EXTEND.md supports · Condition · Detection · Format Suggestion
文件/命令 -> AskUserQuestion · requestuserinput · clarify · askuser · {baseDir} · ${BUNX} · bun · npx
内容 SHA-256 -> d44bb802d2eb
baoyu-markdown-to-html 把 Markdown 转成「带内联样式的可发布 HTML」——重点不是简单转换,而是为公众号、博客这种不能加载外部 CSS 的平台优化。
核心痛点
微信公众号编辑器粘贴 HTML 时,会过滤掉
<link>、<style>标签,所有样式必须 inline 在style=""属性里。手写这种 HTML 很痛苦。这个技能把所有样式 inline 化,粘贴进公众号编辑器后立刻就有样式。工作流
按 Workflow 章节:① 读 Markdown 文件(含 frontmatter);② 选 Theme(多种预设,对应不同视觉风格);③ 处理 Supported Markdown Features:标题、列表、代码块、引用、表格、图片、链接,每一种都映射成带 inline 样式的 HTML 片段;④ 输出
.html文件。Frontmatter 处理
顶部 YAML frontmatter(title、author、cover、tags)会被解析并放进 HTML 顶部成可读的 banner。
Themes
内置多套主题,比如:
适合谁
与
baoyu-format-markdown配套baoyu-format-markdown把粗稿整理成结构良好的 Markdown,然后这个技能把它变成可发布 HTML。流程:粗稿 →baoyu-format-markdown→ 干净 MD →baoyu-markdown-to-html→ 公众号 HTML → 粘贴发布。Extension Support
EXTEND.md 章节给了扩展点——你可以加自定义模板、改主题、接广告位 / 二维码自动插入。
不适合
需要复杂交互(按钮、表单、视频)的页面——这是文章排版器,不是建站器;需要响应式布局、暗色切换的现代网站——用 Astro / Hugo 这类 SSG。