canghe-markdown-to-html
Converts Markdown to styled HTML with WeChat-compatible themes. Supports code highlighting, math, PlantUML, footnotes, alerts, and infographics. Use when user asks for "markdown to html", "convert md to html", "md转html", or needs styled HTML output from markdown.
1How It Works & Mechanism
Prompt orchestration + single-script execution: SKILL.md instructs the agent to treat its own directory as SKILL_DIR, delegating the actual conversion to a Bun/TypeScript script scripts/main.ts.
**Agent Execution**: Determine this SKILL.md directory as `SKILL_DIR`, then use `${SKILL_DIR}/scripts/<name>.ts`.
The conversion command executes the local script on the fly via npx -y bun and supports options such as --theme / --title / --keep-title.
npx -y bun ${SKILL_DIR}/scripts/main.ts <markdown_file> --theme <theme>
The implementation stack is exposed via its dependency manifest: marked for parsing, highlight.js for syntax highlighting, juice for inlining CSS, and front-matter for metadata extraction.
"juice": "^11.0.1", "marked": "^15.0.6", "reading-time": "^1.5.0",
Themes are implemented via CSS variables + theme files; the default theme defines typography for headings, blockquotes, code blocks, tables, etc. (e.g., centered white text on colored background for H2 headings).
h2 { display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: var(--md-primary-color);
A three-tier external preference mechanism: project-level .canghe-skills/... takes precedence, followed by $HOME/.canghe-skills/..., supporting default themes, custom CSS variables, and code block styles.
**EXTEND.md Supports**: Default theme | Custom CSS variables | Code block style
Output and conflict handling: HTML is saved in the same directory as the input; if it already exists, it is backed up as .bak-YYYYMMDDHHMMSS first, and a JSON containing image placeholders is printed to stdout for downstream replacement.
**Conflict handling**: If HTML file already exists, it will be backed up first:
Chinese pre-processing: Only when the input contains CJK characters, if canghe-format-markdown is detected, it asks the user whether to format first (e.g., fixing ** corrupted by punctuation).
**Condition**: Only execute if input file contains Chinese text.
Optional PlantUML rendering transmits diagram source code to a public server (default: www.plantuml.com), which is the sole outbound egress path at runtime.
* @default 'https://www.plantuml.com/plantuml'
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | bun(经 npx -y 即时拉取) |
| api | PlantUML 公共渲染服务(图表源码外发) |
| package | marked(Markdown 解析) |
| package | juice(CSS 内联化) |
4Recommended Governance & Evidence
- scripts/: Execute local script or command: npx -y bun ${SKILL_DIR}/scripts/main.ts <markdown_file> --theme <theme> (age
- 网络端点: Declare external network access: PlantUML rendering: sends GET to https://www.plantuml.com/plantuml to fetch SVG (diagram source code transmitted externally), only when document contains p
- 本地工作目录: File read/write & artifact output: Writes <name>.html in the same directory as input (backed up as .bak-YYYYMMDDHHMMSS before overwriting)
5Second-Pass Verification
- [ok] 实现原理(SKILL.md 编排 + main.ts 执行) — SKILL.md 的 Script Directory/Workflow 段落自证 agent 只做路由,转换由 scripts/main.ts 承担;执行命令逐字可核。
- [ok] PlantUML 执行期外发 — plantuml.ts 的 @default 端点与风险扫描 plantuml.ts:193 的 fetch(svgUrl) 相互印证,判橙据成立。
- [ok] 三套主题存在性 — §1 清单与 §2 内文均含 themes/default.css、grace.css、simple.css,主题描述与 SKILL.md 一致。
- [ok] 依赖栈 — package.json 列出 marked/highlight.js/juice/front-matter/remark-cjk-friendly 等,与实现原理相符。
- [ok] 是否存在凭证读取 — 「凭证/环境变量」65 条命中均为 ${SKILL_DIR}/$HOME 路径或示例占位,未发现密钥/cookie 读取,判定为无。
- [unlocatable] main.ts / render.ts 写盘细节 — bundle 只列清单未展开这两份正文,写盘/备份行为以 SKILL.md 描述与扫描行(main.ts:244、render.ts:868)为据,未代码级复核。
- [ok] URL 命中性质 — 193 条 URL 命中绝大多数为注释/文档链接与 highlight.js 语言名;真实执行期网络仅 plantuml fetch,未发现被夸大的外发。
- [ok] 跨 skill 调用 canghe-format-markdown — SKILL.md Step 0 明写条件式调用,属他人 skill 行为,按范式不参与本 skill 判级。
6Verdict & Scenarios
1c1036babb2494ed…