{"id":"baoyu-markdown-to-html","name":"baoyu-markdown-to-html","summary":"MarkdownをWeChat互換テーマでスタイリングされたHTMLに変換します。コードハイライト、数学、Mermaid(ヘッドレスChrome経由でPNGにレンダリング)、PlantUML、脚注、アラート、インフォグラフィック、外部リンク用のオプション下部引用をサポートしています。","body":"# Markdown to HTML Converter\n\nConverts Markdown files to beautifully styled HTML with inline CSS, optimized for WeChat Official Account and other platforms.\n\n## User Input Tools\n\nWhen this skill prompts the user, follow this tool-selection rule (priority order):\n\n1. **Prefer built-in user-input tools** exposed by the current agent runtime — e.g., `AskUserQuestion`, `request_user_input`, `clarify`, `ask_user`, or any equivalent.\n2. **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.\n3. **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.\n\nConcrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes.\n\n## Script Directory\n\n**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.\n\n| Script | Purpose |\n|--------|---------|\n| `scripts/main.ts` | Main entry point |\n\n## Preferences (EXTEND.md)\n\nCheck EXTEND.md in priority order — the first one found wins:\n\n| Priority | Path | Scope |\n|----------|------|-------|\n| 1 | `.baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | Project |\n| 2 | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | XDG |\n| 3 | `$HOME/.baoyu-skills/baoyu-markdown-to-html/EXTEND.md` | User home |\n\nIf none found, use defaults.\n\n**EXTEND.md supports**: default theme, custom CSS variables, code block style, mermaid defaults (`mermaid_theme`, `mermaid_scale`, `mermaid_background`).\n\n## Workflow\n\n### Step 0: Pre-check (Chinese Content)\n\n**Condition**: Only execute if input file contains Chinese text.\n\n**Detection**:\n1. Read input markdown file\n2. Check if content contains CJK characters (Chinese/Japanese/Korean)\n3. If no CJK content → skip to Step 1\n\n**Format Suggestion**:\n\nIf CJK content detected AND `baoyu-format-markdown` skill is available:\n\nUse `AskUserQuestion` to ask whether to format first. Formatting can fix:\n- Bold markers with punctuation inside causing `**` parse failures\n- CJK/English spacing issues\n\n**If user agrees**: Invoke `baoyu-format-markdown` skill to format the file, then use formatted file as input.\n\n**If user declines**: Continue with original file.\n\n### Step 1: Determine Theme\n\n**Theme resolution order** (first match wins):\n1. User explicitly specified theme (CLI `--theme` or conversation)\n2. EXTEND.md `default_theme` (this skill's own EXTEND.md, checked in Step 0)\n3. `baoyu-post-to-wechat` EXTEND.md `default_theme` (cross-skill fallback)\n4. If none found → use AskUserQuestion to confirm\n\n**Cross-skill EXTEND.md check** (only if this skill's EXTEND.md has no `default_theme`):\n\nRead `$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.\n\n**If theme is resolved from EXTEND.md**: Use it directly, do NOT ask the user.\n\n**If no default found**: use `AskUserQuestion` to confirm a theme from the [Themes](#themes) table below.\n\n### Step 1.5: Determine Citation Mode\n\n**Default**: Off. Do not ask by default.\n\n**Enable only if the user explicitly asks** for \"微信外链转底部引用\", \"底部引用\", \"文末引用\", or passes `--cite`.\n\n**Behavior when enabled**:\n- Ordinary external links are rendered with numbered superscripts and collected under a final `引用链接` section.\n- `https://mp.weixin.qq.com/...` links stay as direct links and are not moved to the bottom.\n- Bare links where link text equals URL stay inline.\n\n### Step 2: Convert\n\n```bash\n${BUN_X} {baseDir}/scripts/main.ts <markdown_file> --theme <theme> [--cite]\n```\n\n### Step 3: Report Result\n\nDisplay the output path from JSON result. If backup was created, mention it.\n\n## Usage\n\n```bash\n${BUN_X} {baseDir}/scripts/main.ts <markdown_file> [options]\n```\n\n**Options:**\n\n| Option | Description | Default |\n|--------|-------------|---------|\n| `--theme <name>` | Theme name (default, grace, simple, modern) | default |\n| `--color <name\\|hex>` | Primary color: preset name or hex value | theme default |\n| `--font-family <name>` | Font: sans, serif, serif-cjk, mono, or CSS value | theme default |\n| `--font-size <N>` | Font size: 14px, 15px, 16px, 17px, 18px | 16px |\n| `--title <title>` | Override title from frontmatter | |\n| `--cite` | Convert external links to bottom citations, append `引用链接` section | false (off) |\n| `--keep-title` | Keep the first heading in content | false (removed) |\n| `--mermaid-theme <name>` | Mermaid theme: `default`, `forest`, `dark`, `neutral`, `base` | default |\n| `--mermaid-scale <N>` | Mermaid render scale (positive number ≤ 4) | 2 |\n| `--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 |\n| `--mermaid-bg <value>` | Mermaid background: `white`, `transparent`, or `#hex` | white |\n| `--no-mermaid` | Skip Mermaid PNG rendering; emit `<pre class=\"mermaid\">` fallback | false |\n| `--help` | Show help | |\n\n**Color Presets:**\n\n| Name | Hex | Label |\n|------|-----|-------|\n| blue | #0F4C81 | Classic Blue |\n| green | #009874 | Emerald Green |\n| vermilion | #FA5151 | Vibrant Vermilion |\n| yellow | #FECE00 | Lemon Yellow |\n| purple | #92617E | Lavender Purple |\n| sky | #55C9EA | Sky Blue |\n| rose | #B76E79 | Rose Gold |\n| olive | #556B2F | Olive Green |\n| black | #333333 | Graphite Black |\n| gray | #A9A9A9 | Smoke Gray |\n| pink | #FFB7C5 | Sakura Pink |\n| red | #A93226 | China Red |\n| orange | #D97757 | Warm Orange (modern default) |\n\n**Examples:**\n\n```bash\n# Basic conversion (uses default theme, removes first heading)\n${BUN_X} {baseDir}/scripts/main.ts article.md\n\n# With specific theme\n${BUN_X} {baseDir}/scripts/main.ts article.md --theme grace\n\n# Theme with custom color\n${BUN_X} {baseDir}/scripts/main.ts article.md --theme modern --color red\n\n# Enable bottom citations for ordinary external links\n${BUN_X} {baseDir}/scripts/main.ts article.md --cite\n\n# Keep the first heading in content\n${BUN_X} {baseDir}/scripts/main.ts article.md --keep-title\n\n# Override title\n${BUN_X} {baseDir}/scripts/main.ts article.md --title \"My Article\"\n```\n\n## Output\n\n**File location**: Same directory as input markdown file.\n- Input: `/path/to/article.md`\n- Output: `/path/to/article.html`\n\n**Conflict handling**: If HTML file already exists, it will be backed up first:\n- Backup: `/path/to/article.html.bak-YYYYMMDDHHMMSS`\n\n**JSON output to stdout:**\n\n```json\n{\n  \"title\": \"Article Title\",\n  \"author\": \"Author Name\",\n  \"summary\": \"Article summary...\",\n  \"htmlPath\": \"/path/to/article.html\",\n  \"backupPath\": \"/path/to/article.html.bak-20260128180000\",\n  \"contentImages\": [\n    {\n      \"placeholder\": \"MDTOHTMLIMGPH_1\",\n      \"localPath\": \"/path/to/img.png\",\n      \"originalPath\": \"imgs/image.png\"\n    }\n  ],\n  \"mermaidImages\": [\n    {\n      \"hash\": \"a1b2c3d4e5f6\",\n      \"localPath\": \"/path/to/imgs/.mermaid-cache/mermaid-a1b2c3d4e5f6.png\",\n      \"cached\": false\n    }\n  ]\n}\n```\n\n**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.\n\n## Themes\n\n| Theme | Description |\n|-------|-------------|\n| `default` | Classic - traditional layout, centered title with bottom border, H2 with white text on colored background |\n| `grace` | Elegant - text shadow, rounded cards, refined blockquotes (by @brzhang) |\n| `simple` | Minimal - modern minimalist, asymmetric rounded corners, clean whitespace (by @okooo5km) |\n| `modern` | Modern - large radius, pill-shaped titles, relaxed line height (pair with `--color red` for traditional red-gold style) |\n\n## Supported Markdown Features\n\n| Feature | Syntax |\n|---------|--------|\n| Headings | `# H1` to `###### H6` |\n| Bold/Italic | `**bold**`, `*italic*` |\n| Code blocks | ` ```lang ` with syntax highlighting |\n| Inline code | `` `code` `` |\n| Tables | GitHub-flavored markdown tables |\n| Images | `![alt](src)` |\n| Links | `[text](url)`; add `--cite` to move ordinary external links into bottom references |\n| Blockquotes | `> quote` |\n| Lists | `-` unordered, `1.` ordered |\n| Alerts | `> [!NOTE]`, `> [!WARNING]`, etc. |\n| Footnotes | `[^1]` references |\n| Ruby text | `{base|annotation}` |\n| 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 |\n| PlantUML | ` ```plantuml ` diagrams |\n\n## Frontmatter\n\nSupports YAML frontmatter for metadata:\n\n```yaml\n---\ntitle: Article Title\nauthor: Author Name\ndescription: Article summary\n---\n```\n\nIf no title is found, extracts from first H1/H2 heading or uses filename.\n\n## Extension Support\n\nCustom configurations via EXTEND.md. See **Preferences** section for paths and supported options.","author":"@JimLiu","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/JimLiu/baoyu-skills/tree/main/skills/baoyu-markdown-to-html","license":"MIT","category":null,"lang":"en","tokens":2517,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"scripts/bun.lock","size":23718,"sha256":"663e82b6d0728cb3f5b4f585c3c3fa0d651df95a75661b71efe0803651d2a14b"},{"path":"scripts/main.test.ts","size":3587,"sha256":"8122be8e38a227478c9aa62c9db4596951279c149828935a282667a936848185"},{"path":"scripts/main.ts","size":12398,"sha256":"fc21350d369415012db91fe66f2a2b28578cc3450eadcebf7123ce8a0a6e0bac"},{"path":"scripts/package.json","size":170,"sha256":"2265564c1e99c81c3487f8f346fcf7dbef7e663c218cc0377843d1f3841a01bf"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[{"code":"net.endpoints","kind":"exfiltration","excerpt":"mp.weixin.qq.com","message":"bundled scripts reach 1 external host(s)","severity":"warn"}],"scannedAt":"2026-08-22","hasScripts":true,"networkEndpoints":["mp.weixin.qq.com"]}}