beautiful-mermaid
1
总安装量
1
周安装量
#42175
全站排名
安装命令
npx skills add https://github.com/994ak/beautiful-mermaid-skill --skill beautiful-mermaid
Agent 安装分布
codex
1
Skill 文档
Beautiful Mermaid
Overview
Enable fast, themeable Mermaid rendering in Node, browser, or CLI outputs using the beautiful-mermaid package. Use this skill to generate SVG diagrams, ASCII/Unicode diagrams, and consistent theming.
When To Use
- Render Mermaid diagrams to SVG or ASCII/Unicode.
- Add or customize themes (two-color base, enrichment colors, or Shiki themes).
- Integrate
beautiful-mermaidin Node, browser, or CLI tooling. - Troubleshoot diagram rendering, spacing, or theme output.
Scenario Map (Use-Case Examples)
- Terminal/CLI è¾åºå¾ï¼Use
renderMermaidAscii()withuseAscii: truefor pure ASCII. - ç»ç«¯æ´ç¾è§ï¼Use
renderMermaidAscii()default Unicode for box-drawing. - Web 页é¢/React ç»ä»¶ï¼Use
renderMermaid()to get SVG and inject into DOM. - éè¦ä¸»é¢ä¸è´ï¼Use
THEMES['...']to apply a built-in theme. - éè¦å
¬å¸åçè²ï¼Provide
bg+fg(mono) or addaccent/muted/surface. - éè¦è· VS Code 主é¢ä¸è´ï¼Use Shiki +
fromShikiTheme(). - CDN/æ æå
ç¯å¢ï¼Use the browser global bundle via
<script>tag. - éè¦å®æ¶æ¢è¤ï¼Update SVG CSS variables (
--bg,--fg) without re-render.
åºæ¯ä¸¾ä¾ï¼æäººç¾¤ï¼
ç¨åºå/å·¥ç¨å¸
- CLI/ç»ç«¯è¾åºå¾ï¼Use
renderMermaidAscii()+ ASCII å ¼å®¹
import { renderMermaidAscii } from 'beautiful-mermaid'
const ascii = renderMermaidAscii('graph LR; A-->B', { useAscii: true })
- Web/React å
åµ SVGï¼Use
renderMermaid()çæ SVG å符串
import { renderMermaid } from 'beautiful-mermaid'
const svg = await renderMermaid('graph TD; A-->B')
- CI/ææ¡£çæï¼æ¹é渲æ SVG æä»¶
import { renderMermaid } from 'beautiful-mermaid'
const svg = await renderMermaid('sequenceDiagram\nA->>B: ping')
- 主é¢ç»ä¸ï¼Use å ç½®ä¸»é¢æèªå®ä¹é¢è²
import { renderMermaid, THEMES } from 'beautiful-mermaid'
const svg = await renderMermaid('graph TD; A-->B', THEMES['tokyo-night'])
éææ¯ç¨æ·
- è¿è¥/äº§åææ¡£ï¼å¯¼åº SVG åµå ¥ææ¡£
import { renderMermaid } from 'beautiful-mermaid'
const svg = await renderMermaid('graph TD; A-->B')
- ä¼è®®/æ±æ¥ç»ä¸é£æ ¼ï¼ç¨ä¸»é¢è²ä¿æä¸è´
import { renderMermaid } from 'beautiful-mermaid'
const svg = await renderMermaid('graph TD; A-->B', { bg: '#0f0f0f', fg: '#e0e0e0' })
- 课ç¨/æ¼ç¤ºï¼ç»ç«¯å å±ç¤º ASCII/Unicode
import { renderMermaidAscii } from 'beautiful-mermaid'
const unicode = renderMermaidAscii('graph LR; A-->B')
- 设计ä¸è´æ§ï¼ç¨ Shiki 䏻颿 å°ç¼è¾å¨é£æ ¼
import { getSingletonHighlighter } from 'shiki'
import { renderMermaid, fromShikiTheme } from 'beautiful-mermaid'
const highlighter = await getSingletonHighlighter({ themes: ['vitesse-dark'] })
const colors = fromShikiTheme(highlighter.getTheme('vitesse-dark'))
const svg = await renderMermaid('graph TD; A-->B', colors)
Quick Start
- Install
beautiful-mermaidin the target project. - Use
renderMermaid()for SVG orrenderMermaidAscii()for terminal output. - Apply a built-in theme or custom colors.
import { renderMermaid, renderMermaidAscii, THEMES } from 'beautiful-mermaid'
const svg = await renderMermaid('graph TD; A-->B', THEMES['tokyo-night'])
const ascii = renderMermaidAscii('graph LR; A-->B', { useAscii: true })
Tasks
Render SVG
- Import
renderMermaidfrom the package. - Pass Mermaid source text (auto-detects diagram type).
- Provide optional
RenderOptionsfor colors, font, and transparency.
import { renderMermaid } from 'beautiful-mermaid'
const svg = await renderMermaid(`
sequenceDiagram
Alice->>Bob: Hello
`, {
bg: '#1a1b26',
fg: '#a9b1d6',
accent: '#7aa2f7',
transparent: false,
font: 'Inter'
})
Render ASCII/Unicode
- Import
renderMermaidAscii. - Use
useAscii: truefor pure ASCII compatibility. - Adjust
paddingX,paddingY, andboxBorderPaddingto tune spacing.
import { renderMermaidAscii } from 'beautiful-mermaid'
const unicode = renderMermaidAscii('graph LR; A-->B')
const ascii = renderMermaidAscii('graph LR; A-->B', { useAscii: true })
Theme With Two Colors
- Provide only
bgandfgto use mono mode. - Let the library derive all other colors with
color-mix().
const svg = await renderMermaid('graph TD; A-->B', {
bg: '#0f0f0f',
fg: '#e0e0e0'
})
Theme With Enrichment Colors
- Add any of:
line,accent,muted,surface,borderto override derivations. - Supply only the enrichments that matter.
const svg = await renderMermaid('graph TD; A-->B', {
bg: '#1a1b26',
fg: '#a9b1d6',
accent: '#7aa2f7',
line: '#3d59a1',
muted: '#565f89',
surface: '#292e42',
border: '#3d59a1'
})
Use Built-in Themes
- Import
THEMESand pass one of the 15 preset themes.
import { renderMermaid, THEMES } from 'beautiful-mermaid'
const svg = await renderMermaid('graph TD; A-->B', THEMES['tokyo-night'])
Use Shiki Themes
- Load a Shiki theme with
getSingletonHighlighter. - Convert it with
fromShikiTheme. - Pass converted colors to
renderMermaid.
import { getSingletonHighlighter } from 'shiki'
import { renderMermaid, fromShikiTheme } from 'beautiful-mermaid'
const highlighter = await getSingletonHighlighter({
themes: ['vitesse-dark']
})
const colors = fromShikiTheme(highlighter.getTheme('vitesse-dark'))
const svg = await renderMermaid('graph TD; A-->B', colors)
Browser Script Tag Usage
- Use the CDN global bundle.
- Access exports on
beautifulMermaid.
<script src="https://unpkg.com/beautiful-mermaid/dist/beautiful-mermaid.browser.global.js"></script>
<script>
const { renderMermaid, THEMES } = beautifulMermaid
renderMermaid('graph TD; A-->B', THEMES['tokyo-night']).then(svg => {
// use svg
})
</script>
Live Theme Switching
- Update SVG CSS custom properties (no re-render required).
svg.style.setProperty('--bg', '#282a36')
svg.style.setProperty('--fg', '#f8f8f2')
Troubleshooting
- If render fails, validate Mermaid syntax and diagram type.
- For terminal alignment, prefer Unicode or set
preserveDisplayWidth: true. - For browser usage, ensure the global bundle is loaded before use.
Resources
- Reference API details and theme lists in
references/beautiful-mermaid-reference.md. references/api-render.md: renderMermaid åæ°è¡¨ã误åºä¸ç¤ºä¾references/api-ascii.md: renderMermaidAscii åæ°è¡¨ã误åºä¸ç¤ºä¾references/themes-and-shiki.md: 䏻颿¨¡åãå 置主é¢ä¸ Shiki éæ