Beautiful Mermaid

calesthio/OpenMontage/.claude/skills/beautiful-mermaid

作者 calesthio9327439db69021ab4b0e2776729bf3b58fdb5a87無授權條款65K 個星標收錄於 2026年10月9日更新於 2026年10月9日儲存庫5 天前更新

Render Mermaid diagrams as SVG and PNG using the Beautiful Mermaid library. Use when the user asks to render a Mermaid diagram.

包含腳本Design & Creative
AI 產生的概覽

使用 Beautiful Mermaid 函式庫將 Mermaid 圖表算繪為主題化 SVG 與高解析度 PNG 圖片。

功能
此技能接收 Mermaid 圖表程式碼或描述,產出兩種結果:向量 SVG 檔案,以及在 4K 視埠下擷取的高解析度 PNG。它支援流程圖、時序圖、狀態圖、類別圖與實體關聯圖,並提供 Dracula、Nord、GitHub Dark 等多種具名主題。它也會產生用於螢幕擷取的暫存 HTML 包裝檔,之後清理中介檔案,只保留最終的 SVG 與 PNG。
適用情境
當使用者要求算繪 Mermaid 圖表,或需要將圖表程式碼轉為可分享的 SVG 或 PNG 圖片檔案時使用。它適合流程、API 呼叫時序、狀態機、UML 類別圖與資料庫結構描述。
執行需求
需要 JavaScript/TypeScript 執行環境(Bun、npx tsx 或 Deno)來執行隨附的 scripts/render.ts 與 scripts/create-html.ts,並需要 agent-browser 技能與 CLI 進行 PNG 擷取。Deno 權限與語法驗證可能需要網路存取;未提及認證資訊。

Beautiful Mermaid Diagram Rendering

Render Mermaid diagrams as SVG and PNG images using the Beautiful Mermaid library.

Dependencies

This skill requires the agent-browser skill for PNG rendering. Load it before proceeding with PNG capture.

Supported Diagram Types

  • Flowchart - Process flows, decision trees, CI/CD pipelines
  • Sequence - API calls, OAuth flows, database transactions
  • State - State machines, connection lifecycles
  • Class - UML class diagrams, design patterns
  • Entity-Relationship - Database schemas, data models

Available Themes

Default, Dracula, Solarized, Zinc Dark, Tokyo Night, Tokyo Night Storm, Tokyo Night Light, Catppuccin Latte, Nord, Nord Light, GitHub Dark, GitHub Light, One Dark.

If no theme is specified, use default.

Common Syntax Patterns

Flowchart Edge Labels

Use pipe syntax for edge labels:

mermaid
A -->|label| BA ---|label| B

Avoid space-dash syntax which can cause incomplete renders:

mermaid
A -- label --> B   # May cause issues

Node Labels with Special Characters

Wrap labels containing special characters in quotes:

mermaid
A["Label with (parens)"]B["Label with / slash"]

Workflow

Step 1: Generate or Validate Mermaid Code

If the user provides a description rather than code, generate valid Mermaid syntax. Consult references/mermaid-syntax.md for full syntax details.

Step 2: Render SVG

Run the rendering script to produce an SVG file:

bash
bun run scripts/render.ts --code "graph TD; A-->B" --output diagram --theme default

Or from a file:

bash
bun run scripts/render.ts --input diagram.mmd --output diagram --theme tokyo-night

Alternative runtimes:

bash
npx tsx scripts/render.ts --code "..." --output diagramdeno run --allow-read --allow-write --allow-net scripts/render.ts --code "..." --output diagram

This produces <output>.svg in the current working directory.

Step 3: Create HTML Wrapper

Run the HTML wrapper script to prepare for screenshot:

bash
bun run scripts/create-html.ts --svg diagram.svg --output diagram.html

This creates a minimal HTML file that displays the SVG with proper padding and background.

Step 4: Capture High-Resolution PNG with agent-browser

Use the agent-browser CLI to capture a high-quality screenshot. Refer to the agent-browser skill for full CLI documentation.

bash
# Set 4K viewport for high-resolution captureagent-browser set viewport 3840 2160
# Open the HTML wrapperagent-browser open "file://$(pwd)/diagram.html"
# Wait for render to completeagent-browser wait 1000
# Capture full-page screenshotagent-browser screenshot --full diagram.png
# Close browseragent-browser close

For even higher resolution on complex diagrams, increase the viewport further or use the --padding option when creating the HTML wrapper to give the diagram more space.

Step 5: Clean Up Intermediary Files

After rendering, remove all intermediary files. Only the final .svg and .png should remain.

Files to clean up:

  • The HTML wrapper file (e.g., diagram.html)
  • Any temporary .mmd files created to hold diagram code
  • Any other files created during the rendering process
bash
rm diagram.html

If a temporary .mmd file was created, remove it as well.

Output

Both outputs are always produced:

  • SVG: Vector format, infinitely scalable, small file size
  • PNG: High-resolution raster, captured at 4K (3840×2160) viewport with minimum 1200px diagram width

Files are saved to the current working directory unless the user explicitly specifies a different path.

Theme Selection Guide

ThemeBackgroundBest For
defaultLight greyGeneral use
draculaDark purpleDark mode preference
tokyo-nightDark blueModern dark aesthetic
tokyo-night-stormDarker blueHigher contrast
nordDark arcticMuted, calm visuals
nord-lightLight arcticLight mode with soft tones
github-darkGitHub darkMatches GitHub UI
github-lightGitHub lightMatches GitHub UI
catppuccin-latteWarm lightSoft pastel aesthetic
solarizedTan/creamSolarized colour scheme
one-darkAtom darkAtom editor aesthetic
zinc-darkNeutral darkMinimal, no colour bias

Troubleshooting

Theme not applied

Check the render script output for the bg and fg values, or inspect the SVG's opening tag for --bg and --fg CSS custom properties.

Diagram appears cut off or incomplete

  • Check edge label syntax — use -->|label| pipe notation, not -- label -->
  • Verify all node IDs are unique
  • Check for unclosed brackets in node labels

Render produces empty or malformed SVG

  • Validate Mermaid syntax at https://mermaid.live before rendering
  • Check for special characters that need escaping (wrap in quotes)
  • Ensure flowchart direction is specified (graph TD, graph LR, etc.)

來源與署名

來源:calesthio/OpenMontage位於.claude/skills/beautiful-mermaid提交9327439

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架