$npx -y skills add jimliu/baoyu-skills --skill baoyu-markdown-to-htmlConverts Markdown to styled HTML with WeChat-compatible themes. Supports code highlighting, math, Mermaid (rendered to PNG via headless Chrome), PlantUML, footnotes, alerts, infographics, and optional bottom citations for external links. Use when user asks for "markdown to html",
| 1 | # Markdown to HTML Converter |
| 2 | |
| 3 | Converts Markdown files to beautifully styled HTML with inline CSS, optimized for WeChat Official Account and other platforms. |
| 4 | |
| 5 | ## User Input Tools |
| 6 | |
| 7 | When this skill prompts the user, follow this tool-selection rule (priority order): |
| 8 | |
| 9 | 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. |
| 10 | 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. |
| 11 | 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. |
| 12 | |
| 13 | Concrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes. |
| 14 | |
| 15 | ## Script Directory |
| 16 | |
| 17 | **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. |
| 18 | |
| 19 | | Script | Purpose | |
| 20 | |--------|---------| |
| 21 | | `scripts/main.ts` | Main entry point | |
| 22 | |
| 23 | ## Preferences (EXTEND.md) |
| 24 | |
| 25 | Check EXTEND.md in priority order — the first one found wins: |
| 26 | |
| 27 | | Priority | Path | Scope | |
| 28 | |----------|------|-------| |
| 29 | | 1 | `.baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | Project | |
| 30 | | 2 | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | XDG | |
| 31 | | 3 | `$HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | User home | |
| 32 | |
| 33 | If none found, use defaults. |
| 34 | |
| 35 | **EXTEND.md supports**: default theme, custom CSS variables, code block style, mermaid defaults (`mermaid_theme`, `mermaid_scale`, `mermaid_background`). |
| 36 | |
| 37 | ## Workflow |
| 38 | |
| 39 | ### Step 0: Pre-check (Chinese Content) |
| 40 | |
| 41 | **Condition**: Only execute if input file contains Chinese text. |
| 42 | |
| 43 | **Detection**: |
| 44 | 1. Read input markdown file |
| 45 | 2. Check if content contains CJK characters (Chinese/Japanese/Korean) |
| 46 | 3. If no CJK content → skip to Step 1 |
| 47 | |
| 48 | **Format Suggestion**: |
| 49 | |
| 50 | If CJK content detected AND `baoyu-format-markdown` skill is available: |
| 51 | |
| 52 | Use `AskUserQuestion` to ask whether to format first. Formatting can fix: |
| 53 | - Bold markers with punctuation inside causing `**` parse failures |
| 54 | - CJK/English spacing issues |
| 55 | |
| 56 | **If user agrees**: Invoke `baoyu-format-markdown` skill to format the file, then use formatted file as input. |
| 57 | |
| 58 | **If user declines**: Continue with original file. |
| 59 | |
| 60 | ### Step 1: Determine Theme |
| 61 | |
| 62 | **Theme resolution order** (first match wins): |
| 63 | 1. User explicitly specified theme (CLI `--theme` or conversation) |
| 64 | 2. EXTEND.md `default_theme` (this skill's own EXTEND.md, checked in Step 0) |
| 65 | 3. `baoyu-post-to-wechat` EXTEND.md `default_theme` (cross-skill fallback) |
| 66 | 4. If none found → use AskUserQuestion to confirm |
| 67 | |
| 68 | **Cross-skill EXTEND.md check** (only if this skill's EXTEND.md has no `default_theme`): |
| 69 | |
| 70 | 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. |
| 71 | |
| 72 | **If theme is resolved from EXTEND.md**: Use it directly, do NOT ask the user. |
| 73 | |
| 74 | **If no default found**: use `AskUserQuestion` to confirm a theme from the [Themes](#themes) table below. |
| 75 | |
| 76 | ### Step 1.5: Determine Citation Mode |
| 77 | |
| 78 | **Default**: Off. Do not ask by default. |
| 79 | |
| 80 | **Enable only if the user explicitly asks** for "微信外链转底部引用", "底部引用", "文末引用", or passes `--cite`. |
| 81 | |
| 82 | **Behavior when enabled**: |
| 83 | - Ordinary external links are rendered with numbered superscripts and collected under a final `引用链接` section. |
| 84 | - `https://mp.weixin.qq.com/...` links stay as direct links and are not moved to the bottom. |
| 85 | - Bare links where link text equals URL stay inline. |
| 86 | |
| 87 | ### Step 2: Convert |
| 88 | |
| 89 | ```bash |
| 90 | ${BUN_X} {baseDir}/scripts/main.ts <markdown_file> --theme <theme> [--cite] |
| 91 | ``` |
| 92 | |
| 93 | ### Step 3: Report Result |
| 94 | |
| 95 | Display the output path from JSON result. If backup was created, mention it. |
| 96 | |
| 97 | ## Usage |
| 98 | |
| 99 | ```bash |
| 100 | ${BUN_X} {baseDir}/scripts/main.ts <markdown_file> [options] |
| 101 | ``` |
| 102 | |
| 103 | **Options:** |
| 104 | |
| 105 | | Option | Description | Default | |
| 106 | |--------|-------------|---------| |
| 107 | | `--theme <name>` | Theme name (default, grace, simple, modern) | default | |
| 108 | | `--color <name\|hex>` | Primary color: preset name or hex value | theme default | |
| 109 | | `--font-family <name>` | Font: sans, serif, serif-cjk, mono, or CSS value | theme default | |
| 110 | | `--font-si |