mermaid-render
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMermaid Diagram Renderer <!-- omit in toc -->
Mermaid图表渲染器 <!-- omit in toc -->
Render mermaid diagrams to PNG and display them inline. Supports iTerm2 (imgcat) and Ghostty (kitten icat). Built for fast visual iteration.
<!-- TODO: Once Claude Code supports inline image passthrough, update the workflow
to display directly instead of printing the view command.
Tracking: https://github.com/anthropics/claude-code/issues/29254 -->
将Mermaid图表渲染为PNG格式并内联展示,支持iTerm2(imgcat)和Ghostty(kitten icat),专为快速视觉迭代打造。
<!-- TODO:等Claude Code支持内联图片透传后,更新工作流以直接展示图片,而不是打印查看命令。追踪地址:https://github.com/anthropics/claude-code/issues/29254 -->
Workflow
工作流
Every time you generate or modify mermaid code, immediately render and display it. Never ask "want me to render?" — just do it.
Write the mermaid code:
bash
cat > /tmp/mermaid-diagram.mmd << 'MERMAID'
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action]
B -->|No| D[End]
MERMAIDRender:
bash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmdThe script outputs and . Always print the command for the user so they can copy-paste it to see the diagram inline. Claude Code's Bash tool captures stdout, so inline images won't display automatically.
Rendered: <path>View: <command>View:If the user provides a specific file path, use that instead of .
/tmp/mermaid-diagram.mmd每次你生成或修改Mermaid代码时,立即进行渲染展示,永远不要询问“需要我渲染吗?”,直接执行即可。
编写Mermaid代码:
bash
cat > /tmp/mermaid-diagram.mmd << 'MERMAID'
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action]
B -->|No| D[End]
MERMAID渲染:
bash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmd脚本会输出和。请务必为用户打印对应的命令,方便用户复制粘贴后内联查看图表。Claude Code的Bash工具会捕获标准输出,因此内联图片无法自动展示。
Rendered: <path>View: <command>View:如果用户提供了指定的文件路径,请用该路径代替。
/tmp/mermaid-diagram.mmdPrerequisites
前置依赖
On first use, check that is available:
mmdcbash
which mmdc || echo "MISSING: Run 'npm install -g @mermaid-js/mermaid-cli'"The display command ( or ) is detected automatically based on . No manual setup needed — the script falls back to if neither is available.
imgcatkitten icat$TERM_PROGRAMopen首次使用时,检查是否可用:
mmdcbash
which mmdc || echo "MISSING: Run 'npm install -g @mermaid-js/mermaid-cli'"展示命令(或)会根据自动检测,无需手动配置——如果两个命令都不可用,脚本会自动回退使用命令。
imgcatkitten icat$TERM_PROGRAMopenRendering
渲染
The script handles rendering with sensible defaults. It supports these flags:
render.sh- — mermaid theme:
--theme <name>,default,dark,forest(default:neutral)default - — output width in pixels (default:
--width <px>)1200 - — background color (default:
--bg <color>)transparent - — custom CSS file for styling
--css <path> - — custom output path (default: replaces
--output <path>with.mmd).png
Examples:
bash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmd --theme darkbash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmd --width 2400bash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmd --output ~/Desktop/diagram.pngrender.sh- — Mermaid主题:
--theme <name>、default、dark、forest(默认值:neutral)default - — 输出宽度,单位为像素(默认值:
--width <px>)1200 - — 背景颜色(默认值:
--bg <color>)transparent - — 用于自定义样式的CSS文件路径
--css <path> - — 自定义输出路径(默认值:将
--output <path>后缀替换为.mmd).png
示例:
bash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmd --theme darkbash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmd --width 2400bash
"${CLAUDE_SKILL_DIR}/scripts/render.sh" /tmp/mermaid-diagram.mmd --output ~/Desktop/diagram.pngIteration Rules
迭代规则
- After each user edit request, update the file and re-render immediately
.mmd - Show the command after every change — the user should never have to ask
View: - Keep the file path consistent within a session so edits accumulate
.mmd - If reports a syntax error, show the error message and fix the mermaid code before retrying
mmdc - Use the cheatsheet below for syntax reference when iterating
- 每次收到用户的编辑请求后,更新文件并立即重新渲染
.mmd - 每次修改后都要展示命令,永远不要等用户主动询问
View: - 同一会话内保持文件路径一致,方便编辑内容累积
.mmd - 如果报语法错误,先展示错误信息并修复Mermaid代码再重试
mmdc - 迭代时可参考下方的速查表获取语法说明
Mermaid Syntax Cheatsheet
Mermaid语法速查表
Graph Directions
图表方向
graph TDgraph LRgraph BTgraph RLgraph TDgraph LRgraph BTgraph RLNode Shapes
节点形状
text
A[Rectangle] B(Rounded) C{Diamond}
D((Circle)) E[[Subroutine]] F[(Database)]
G>Asymmetric] H{{Hexagon}} I[/Parallelogram/]text
A[Rectangle] B(Rounded) C{Diamond}
D((Circle)) E[[Subroutine]] F[(Database)]
G>Asymmetric] H{{Hexagon}} I[/Parallelogram/]Link Styles
连线样式
text
A --> B Solid arrow
A --- B Solid line (no arrow)
A -.-> B Dotted arrow
A ==> B Thick arrow
A -->|label| B Arrow with label
A -- text --> B Arrow with text (alternate)text
A --> B Solid arrow
A --- B Solid line (no arrow)
A -.-> B Dotted arrow
A ==> B Thick arrow
A -->|label| B Arrow with label
A -- text --> B Arrow with text (alternate)Subgraphs
子图
text
subgraph Title
A --> B
endtext
subgraph Title
A --> B
endStyling
样式设置
text
style A fill:#f9f,stroke:#333,stroke-width:2px
classDef highlight fill:#ff0,stroke:#333
class A,B highlighttext
style A fill:#f9f,stroke:#333,stroke-width:2px
classDef highlight fill:#ff0,stroke:#333
class A,B highlightThemes
主题
Set via flag: , , ,
--themedefaultdarkforestneutralOr in the diagram:
%%{init: {'theme': 'dark'}}%%通过参数设置:、、、
--themedefaultdarkforestneutral或直接在图表内声明:
%%{init: {'theme': 'dark'}}%%Sequence Diagram
时序图
text
sequenceDiagram
participant A as Alice
participant B as Bob
A->>B: Hello
B-->>A: Hi back
A->>+B: Request
B-->>-A: Response
Note over A,B: Handshake completetext
sequenceDiagram
participant A as Alice
participant B as Bob
A->>B: Hello
B-->>A: Hi back
A->>+B: Request
B-->>-A: Response
Note over A,B: Handshake completeState Diagram
状态图
text
stateDiagram-v2
[*] --> Idle
Idle --> Processing: start
Processing --> Done: finish
Done --> [*]text
stateDiagram-v2
[*] --> Idle
Idle --> Processing: start
Processing --> Done: finish
Done --> [*]Entity Relationship
实体关系图
text
erDiagram
USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : containstext
erDiagram
USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : containsClass Diagram
类图
text
classDiagram
class Animal {
+String name
+makeSound()
}
Animal <|-- Dog
Animal <|-- Cattext
classDiagram
class Animal {
+String name
+makeSound()
}
Animal <|-- Dog
Animal <|-- Cat