mermaid-studio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMermaid Studio
Mermaid Studio
Expert-level Mermaid diagram creation, validation, and multi-format rendering. Creates diagrams from descriptions or code analysis, validates syntax, and renders to SVG, PNG, or ASCII with professional theming.
专业级Mermaid图表创建、验证与多格式渲染工具。可根据描述或代码分析生成图表,验证语法,并通过专业主题渲染为SVG、PNG或ASCII格式。
Golden Rules — Elegant Diagrams by Default
黄金准则——默认生成优雅图表
Every diagram MUST follow these principles. They are not optional — they define the difference between a mediocre diagram and a gold-standard one.
所有图表必须遵循以下原则,这些原则是区分普通图表与高标准图表的核心,不可省略。
Rule 1: Always Use an Init Directive for Professional Styling
规则1:始终使用Init指令实现专业样式
NEVER create a diagram without an directive or frontmatter config. The default Mermaid theme produces harsh black lines and generic colors. Always apply a curated palette.
%%{init}For general diagrams (flowchart, sequence, state, class, ERD):
%%{init: {'theme': 'base', 'themeVariables': {
'primaryColor': '#4f46e5', 'primaryTextColor': '#ffffff',
'primaryBorderColor': '#3730a3', 'lineColor': '#94a3b8',
'secondaryColor': '#10b981', 'tertiaryColor': '#f59e0b',
'background': '#ffffff', 'mainBkg': '#f8fafc',
'nodeBorder': '#cbd5e1', 'clusterBkg': '#f1f5f9',
'clusterBorder': '#e2e8f0', 'titleColor': '#1e293b',
'edgeLabelBackground': '#ffffff', 'textColor': '#334155'
}}}%%⚠️ Font Warning: Do NOT set in theme variables. The Mermaid default font () works everywhere. Setting , , or will render as Times New Roman in headless Chromium (used by ).
fontFamilytrebuchet ms, verdana, arial, sans-serifsystem-uiSegoe UI-apple-systemmmdcFor C4 diagrams — see the dedicated C4 styling section below.
For architecture-beta diagrams — see the dedicated AWS/Architecture section below.
绝对不要在没有指令或前置配置的情况下创建图表。Mermaid默认主题线条生硬、颜色通用,务必使用精心调配的调色板。
%%{init}通用图表(流程图、时序图、状态图、类图、ERD):
%%{init: {'theme': 'base', 'themeVariables': {
'primaryColor': '#4f46e5', 'primaryTextColor': '#ffffff',
'primaryBorderColor': '#3730a3', 'lineColor': '#94a3b8',
'secondaryColor': '#10b981', 'tertiaryColor': '#f59e0b',
'background': '#ffffff', 'mainBkg': '#f8fafc',
'nodeBorder': '#cbd5e1', 'clusterBkg': '#f1f5f9',
'clusterBorder': '#e2e8f0', 'titleColor': '#1e293b',
'edgeLabelBackground': '#ffffff', 'textColor': '#334155'
}}}%%⚠️ 字体警告: 不要在主题变量中设置。Mermaid默认字体()可在所有环境正常显示。若设置、或,在使用的无头Chromium环境中会渲染为Times New Roman字体。
fontFamilytrebuchet ms, verdana, arial, sans-serifsystem-uiSegoe UI-apple-systemmmdcC4图表——请参考下方专门的C4样式章节。
architecture-beta图表——请参考下方专门的AWS/架构章节。
Rule 2: Soft Lines, Never Harsh Black
规则2:使用柔和线条,避免生硬黑色
The single biggest visual improvement is using (slate-400) instead of the default black. This creates a modern, breathable diagram. For dark themes, use (slate-500).
lineColor: '#94a3b8'lineColor: '#64748b'提升视觉效果最关键的一点是使用(石板灰-400)替代默认黑色,打造现代感、透气感的图表。深色主题下使用(石板灰-500)。
lineColor: '#94a3b8'lineColor: '#64748b'Rule 3: Limit Density — Breathe
规则3:控制密度,留足留白
- Maximum 15 nodes per diagram (not 20 — fewer is more elegant)
- Use or boundaries to create whitespace and visual grouping
subgraph - Prefer LR (left-right) for process flows — it reads more naturally
- Use invisible links () to add spacing when the layout is cramped
A ~~~ B
- 每张图最多15个节点(而非20个——越少越优雅)
- 使用或边界创建留白与视觉分组
subgraph - 流程类图表优先使用LR(从左到右)方向,更符合阅读习惯
- 布局拥挤时,使用隐形链接()增加间距
A ~~~ B
Rule 4: Meaningful Labels and Consistent Style
规则4:标签表意清晰,风格保持一致
- Node IDs: camelCase (, not
orderServiceors1)os - Labels: short, clear natural language ()
[Order Service] - Arrows: action verbs with protocol info ()
"Sends order via gRPC" - Descriptions: one-line, role-focused ()
"Handles order lifecycle"
- 节点ID:采用驼峰命名法(,而非
orderService或s1)os - 标签:简短、清晰的自然语言()
[订单服务] - 箭头:带协议信息的动作动词()
"通过gRPC发送订单" - 描述:单行、聚焦角色()
"处理订单生命周期"
Rule 5: Color Harmony Over Color Variety
规则5:色彩和谐优先于色彩多样
Use max 3-4 colors per diagram. Map colors to meaning:
- Blue tones (#4f46e5, #3b82f6) → primary systems, internal services
- Green tones (#10b981, #059669) → success states, data stores
- Amber tones (#f59e0b, #d97706) → external systems, warnings
- Slate tones (#64748b, #94a3b8) → lines, borders, secondary elements
- Red tones (#ef4444) → errors ONLY, never as decoration
每张图最多使用3-4种颜色,为颜色赋予明确含义:
- 蓝色调(#4f46e5、#3b82f6)→ 核心系统、内部服务
- 绿色调(#10b981、#059669)→ 成功状态、数据存储
- 琥珀色调(#f59e0b、#d97706)→ 外部系统、警告
- 石板色调(#64748b、#94a3b8)→ 线条、边框、次要元素
- 红色调(#ef4444)→ 仅用于错误提示,绝不作为装饰
Modes of Operation
运行模式
This skill operates in three modes based on user intent:
| Mode | Trigger | What happens |
|---|---|---|
| Create | "draw a diagram of...", "visualize my..." | Generates .mmd code only |
| Render | "render this mermaid", "convert to SVG/PNG/ASCII" | Renders existing .mmd |
| Full | "create and render...", ambiguous requests | Create → Validate → Render |
Default to Full mode when intent is unclear.
本工具根据用户意图分为三种运行模式:
| 模式 | 触发关键词 | 执行操作 |
|---|---|---|
| 创建 | "绘制...的图表"、"可视化我的..." | 仅生成.mmd代码 |
| 渲染 | "渲染这个Mermaid图表"、"转换为SVG/PNG/ASCII" | 渲染已有的.mmd文件 |
| 完整 | "创建并渲染..."、意图不明确的请求 | 创建 → 验证 → 渲染 |
当用户意图不明确时,默认使用完整模式。
Step 1: Understand the Request
步骤1:理解需求
Before writing any Mermaid code, determine:
- What to diagram — system, flow, schema, architecture, code structure?
- Which diagram type — use the Decision Matrix below
- Output format — code only, SVG, PNG, or ASCII?
- Theme preference — ask only if rendering; default to theme with curated palette
base
在编写任何Mermaid代码前,需明确:
- 图表内容 —— 系统、流程、 schema、架构、代码结构?
- 图表类型 —— 使用下方的决策矩阵选择
- 输出格式 —— 仅代码、SVG、PNG还是ASCII?
- 主题偏好 —— 仅在渲染时询问;默认使用主题及精心调配的调色板
base
Diagram Type Decision Matrix
图表类型决策矩阵
| User describes... | Diagram Type | Syntax keyword |
|---|---|---|
| Process, algorithm, decision tree, workflow | Flowchart | |
| API calls, message passing, request/response | Sequence | |
| Database schema, table relationships | ERD | |
| OOP classes, domain model, interfaces | Class | |
| State machine, lifecycle, transitions | State | |
| High-level system overview (C4 Level 1) | C4 Context | |
| Applications, databases, services (C4 Level 2) | C4 Container | |
| Internal components (C4 Level 3) | C4 Component | |
| Request flows with numbered steps | C4 Dynamic | |
| Infrastructure, cloud deployment | C4 Deployment | |
| Cloud services with icons (AWS/GCP/Azure) | Architecture | |
| Project timeline, scheduling | Gantt | |
| Proportional data, percentages | Pie | |
| Brainstorming, hierarchical ideas | Mindmap | |
| Historical events, chronology | Timeline | |
| Branching strategy, git history | Git Graph | |
| Flow quantities, resource distribution | Sankey | |
| X/Y data visualization | XY Chart | |
| Priority matrix, strategic positioning | Quadrant | |
| Layout control, grid positioning | Block | |
| Network packets, protocol headers | Packet | |
| Task boards, kanban workflow | Kanban | |
| User experience, satisfaction scoring | User Journey | |
| System requirements traceability | Requirement | |
If the user's description doesn't clearly map to one type, suggest 2-3 options with a brief rationale for each, then let them choose.
| 用户描述内容 | 图表类型 | 语法关键字 |
|---|---|---|
| 流程、算法、决策树、工作流 | 流程图 | |
| API调用、消息传递、请求/响应 | 时序图 | |
| 数据库schema、表关系 | ERD图 | |
| 面向对象类、领域模型、接口 | 类图 | |
| 状态机、生命周期、状态转换 | 状态图 | |
| 高层系统概览(C4 Level 1) | C4上下文图 | |
| 应用、数据库、服务(C4 Level 2) | C4容器图 | |
| 内部组件(C4 Level 3) | C4组件图 | |
| 带编号步骤的请求流 | C4动态图 | |
| 基础设施、云部署 | C4部署图 | |
| 带图标的云服务(AWS/GCP/Azure) | 架构图 | |
| 项目时间线、排程 | 甘特图 | |
| 比例数据、百分比 | 饼图 | |
| 头脑风暴、层级化想法 | 思维导图 | |
| 历史事件、年表 | 时间线图 | |
| 分支策略、Git历史 | Git图 | |
| 流量数量、资源分配 | 桑基图 | |
| X/Y数据可视化 | XY图表 | |
| 优先级矩阵、战略定位 | 象限图 | |
| 布局控制、网格定位 | 块图 | |
| 网络数据包、协议头 | 数据包图 | |
| 任务看板、看板工作流 | 看板图 | |
| 用户体验、满意度评分 | 用户旅程图 | |
| 系统需求可追溯性 | 需求图 | |
若用户描述无法明确对应某一类型,建议2-3个选项并简要说明理由,再让用户选择。
When to Load References
何时加载参考文件
Load reference files ONLY when needed for the specific diagram type:
- C4 diagrams → Read BEFORE writing code
references/c4-architecture.md - AWS/Cloud architecture → Read BEFORE writing code
references/aws-architecture.md - Code-to-diagram → Read BEFORE analyzing
references/code-to-diagram.md - Theming/styling → Read when user requests custom themes
references/themes.md - Syntax errors → Read when validation fails
references/troubleshooting.md - Any diagram type details → Read for comprehensive syntax
references/diagram-types.md
仅在特定图表类型需要时加载参考文件:
- C4图表 → 编写代码前阅读
references/c4-architecture.md - AWS/云架构图 → 编写代码前阅读
references/aws-architecture.md - 代码转图表 → 分析前阅读
references/code-to-diagram.md - 主题/样式 → 用户要求自定义主题时阅读
references/themes.md - 语法错误 → 验证失败时阅读
references/troubleshooting.md - 任何图表类型细节 → 阅读获取完整语法
references/diagram-types.md
Step 2: Create the Diagram
步骤2:创建图表
2.1 — Write Mermaid Code
2.1 — 编写Mermaid代码
Follow these principles in order of priority:
- Elegance first — every diagram must look professional with init directives and curated colors
- Correctness — valid syntax that renders without errors
- Clarity — meaningful labels, logical flow direction, clear relationships
- Simplicity — under 15 nodes per diagram; split complex systems into multiple
- Consistency — uniform naming (camelCase for IDs, descriptive labels in brackets)
按以下优先级遵循原则:
- 优雅优先 —— 所有图表必须通过init指令和精心调配的颜色实现专业外观
- 正确性 —— 语法有效,可正常渲染
- 清晰性 —— 标签表意明确、流向逻辑清晰、关系明确
- 简洁性 —— 每张图节点数少于15;复杂系统拆分为多张图
- 一致性 —— 命名统一(ID用驼峰命名法,标签用描述性括号格式)
2.2 — Structure Rules
2.2 — 结构规则
%% Diagram: [Purpose] | Author: [auto] | Date: [auto]
%%{init: {'theme': 'base', 'themeVariables': { ... }}}%%
[diagramType]
[content]CRITICAL: The directive MUST go on the very first non-comment line, BEFORE the diagram type declaration. Alternatively, use YAML frontmatter at the absolute start of the file.
%%{init}Naming conventions:
- Node IDs: camelCase, descriptive (, not
orderService)s1 - Labels: natural language in brackets ()
[Order Service] - Relationships: action verbs (,
"Sends order to")"Reads from"
Layout best practices:
- (top-down) for hierarchical flows and processes
TD - (left-right) for timelines, pipelines, and sequential processes
LR - for right-to-left reading contexts
RL - Use to group related nodes; name subgraphs meaningfully
subgraph - Add inside subgraphs when needed for different flow
direction
%% Diagram: [用途] | Author: [自动生成] | Date: [自动生成]
%%{init: {'theme': 'base', 'themeVariables': { ... }}}%%
[diagramType]
[内容]关键注意事项: 指令必须放在第一行非注释位置,在图表类型声明之前。或者,在文件最开头使用YAML前置配置。
%%{init}命名规范:
- 节点ID:驼峰命名法,具描述性(,而非
orderService)s1 - 标签:括号内的自然语言()
[订单服务] - 关系:动作动词(、
"发送订单至")"读取自"
布局最佳实践:
- (自上而下)用于层级化流程和处理过程
TD - (从左到右)用于时间线、流水线和顺序流程
LR - 用于从右到左的阅读场景
RL - 使用分组相关节点;子图命名需具意义
subgraph - 当需要不同流向时,在子图内添加指令
direction
2.3 — Quick Reference Examples
2.3 — 快速参考示例
Flowchart (with professional styling):
mermaid
%%{init: {'theme': 'base', 'themeVariables': {
'primaryColor': '#4f46e5', 'primaryTextColor': '#fff',
'primaryBorderColor': '#3730a3', 'lineColor': '#94a3b8',
'secondaryColor': '#10b981', 'tertiaryColor': '#f59e0b',
'background': '#ffffff', 'mainBkg': '#f8fafc',
'nodeBorder': '#cbd5e1', 'clusterBkg': '#f1f5f9',
'clusterBorder': '#e2e8f0', 'titleColor': '#1e293b',
'edgeLabelBackground': '#ffffff'
}}}%%
flowchart TD
Start([Start]) --> Input[/User Input/]
Input --> Validate{Valid?}
Validate -->|Yes| Process[Process Data]
Validate -->|No| Error[Show Error]
Error --> Input
Process --> Save[(Save to DB)]
Save --> End([End])For sequence diagram and ERD styling examples, read .
references/themes.mdC4 Context (with MANDATORY elegant styling):
mermaid
C4Context
title System Context — E-Commerce Platform
Person(customer, "Customer", "Places orders online")
System(platform, "E-Commerce Platform", "Handles orders and payments")
System_Ext(payment, "Payment Gateway", "Processes transactions")
System_Ext(email, "Email Service", "Sends notifications")
Rel(customer, platform, "Uses", "HTTPS")
Rel(platform, payment, "Processes payments", "API")
Rel(platform, email, "Sends emails", "SMTP")
UpdateRelStyle(customer, platform, $textColor="#475569", $lineColor="#94a3b8")
UpdateRelStyle(platform, payment, $textColor="#475569", $lineColor="#94a3b8")
UpdateRelStyle(platform, email, $textColor="#475569", $lineColor="#94a3b8")
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")Architecture (AWS with Iconify icons):
mermaid
architecture-beta
group vpc(logos:aws-vpc)[VPC]
service api(logos:aws-api-gateway)[API Gateway] in vpc
service lambda(logos:aws-lambda)[Lambda] in vpc
service db(logos:aws-dynamodb)[DynamoDB] in vpc
service s3(logos:aws-s3)[S3 Bucket]
api:R --> L:lambda
lambda:R --> L:db
lambda:B --> T:s3IMPORTANT: Architecture-beta diagrams with icons require icon pack registration. When rendering with the render script, use the flag. If rendering in a markdown viewer that doesn't support icon packs, use the built-in icons (, , , , ) as fallback. Read for the complete icon catalog and rendering instructions.
logos:*--icons logosclouddatabasediskserverinternetreferences/aws-architecture.mdFor comprehensive syntax of ALL diagram types, read .
references/diagram-types.md流程图(带专业样式):
mermaid
%%{init: {'theme': 'base', 'themeVariables': {
'primaryColor': '#4f46e5', 'primaryTextColor': '#fff',
'primaryBorderColor': '#3730a3', 'lineColor': '#94a3b8',
'secondaryColor': '#10b981', 'tertiaryColor': '#f59e0b',
'background': '#ffffff', 'mainBkg': '#f8fafc',
'nodeBorder': '#cbd5e1', 'clusterBkg': '#f1f5f9',
'clusterBorder': '#e2e8f0', 'titleColor': '#1e293b',
'edgeLabelBackground': '#ffffff'
}}}%%
flowchart TD
Start([开始]) --> Input[/用户输入/]
Input --> Validate{验证通过?}
Validate -->|是| Process[处理数据]
Validate -->|否| Error[显示错误]
Error --> Input
Process --> Save[(保存至数据库)]
Save --> End([结束])时序图和ERD样式示例,请阅读。
references/themes.mdC4上下文图(必须使用优雅样式):
mermaid
C4Context
title System Context — 电商平台
Person(customer, "客户", "在线下单")
System(platform, "电商平台", "处理订单与支付")
System_Ext(payment, "支付网关", "处理交易")
System_Ext(email, "邮件服务", "发送通知")
Rel(customer, platform, "使用", "HTTPS")
Rel(platform, payment, "处理支付", "API")
Rel(platform, email, "发送邮件", "SMTP")
UpdateRelStyle(customer, platform, $textColor="#475569", $lineColor="#94a3b8")
UpdateRelStyle(platform, payment, $textColor="#475569", $lineColor="#94a3b8")
UpdateRelStyle(platform, email, $textColor="#475569", $lineColor="#94a3b8")
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")架构图(AWS带Iconify图标):
mermaid
architecture-beta
group vpc(logos:aws-vpc)[VPC]
service api(logos:aws-api-gateway)[API网关] in vpc
service lambda(logos:aws-lambda)[Lambda] in vpc
service db(logos:aws-dynamodb)[DynamoDB] in vpc
service s3(logos:aws-s3)[S3存储桶]
api:R --> L:lambda
lambda:R --> L:db
lambda:B --> T:s3重要提示: 带图标的architecture-beta图表需要注册图标包。使用渲染脚本时,需添加参数。若在不支持图标包的Markdown查看器中渲染,使用内置图标(、、、、)作为替代。完整图标目录和渲染说明请阅读。
logos:*--icons logosclouddatabasediskserverinternetreferences/aws-architecture.md所有图表类型的完整语法,请阅读。
references/diagram-types.mdC4 Diagrams — Mandatory Styling Guide
C4图表——强制样式指南
C4 diagrams have fixed element styling (blue boxes for systems, gray for persons, etc.), but their relationship lines default to harsh black which creates visual noise. You MUST apply these styling rules:
C4图表的元素样式是固定的(系统为蓝色框,人物为灰色框等),但默认的关系线条是生硬的黑色,会造成视觉干扰。必须应用以下样式规则:
The C4 Styling Pattern
C4样式模板
Every C4 diagram MUST include these directives at the end:
%% === MANDATORY STYLING ===
%% Apply soft line colors to ALL relationships
UpdateRelStyle(fromAlias, toAlias, $textColor="#475569", $lineColor="#94a3b8")
%% Repeat for each Rel() in the diagram
%% Optimize layout spacing
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")所有C4图表必须在末尾添加以下指令:
%% === 强制样式 ===
%% 为所有关系应用柔和线条颜色
UpdateRelStyle(fromAlias, toAlias, $textColor="#475569", $lineColor="#94a3b8")
%% 为图表中每个Rel()重复此指令
%% 优化布局间距
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")C4 Color Values Reference
C4颜色参考值
| Purpose | Color | Hex | Notes |
|---|---|---|---|
| Soft line color | Slate-400 | | Replaces harsh default black |
| Line text color | Slate-600 | | Readable but not dominant |
| Accent line | Blue-400 | | For highlighted or primary relationships |
| Warning line | Amber-500 | | For external/risky connections |
| Custom element bg | Emerald | | For data stores or success highlights |
| Custom element bg | Indigo | | For primary system emphasis |
| 用途 | 颜色名称 | 十六进制值 | 说明 |
|---|---|---|---|
| 柔和线条颜色 | 石板灰-400 | | 替代生硬的默认黑色 |
| 线条文本颜色 | 石板灰-600 | | 清晰可读但不突兀 |
| 强调线条颜色 | 蓝色-400 | | 用于高亮或核心关系 |
| 警告线条颜色 | 琥珀色-500 | | 用于外部/高风险连接 |
| 自定义元素背景 | 翡翠绿 | | 用于数据存储或成功状态高亮 |
| 自定义元素背景 | 靛蓝色 | | 用于核心系统强调 |
C4 Layout Tips
C4布局技巧
CRITICAL — Maximum 6 per diagram. More than 6 relationships causes Dagre to route arrows through nodes, creating unreadable spaghetti. If your system needs more connections, split it into multiple focused diagrams.
Rel()- Use for most diagrams (prevents horizontal crowding)
$c4ShapeInRow="3" - Use for diagrams with long labels
$c4ShapeInRow="2" - Use always (stacks boundaries vertically for clarity)
$c4BoundaryInRow="1" - Apply to
$offsetY="-10"when labels overlap with elementsUpdateRelStyle - Prefer tree-shaped topologies (1 in, 1-2 out per node) over mesh topologies
- Declare elements in flow order — the order of declarations affects layout
Container() - Use directional ,
Rel_D, etc. only as a last resort when auto-layout creates overlappingRel_R
For comprehensive C4 syntax, examples, and patterns, read .
references/c4-architecture.md关键注意事项——每张图最多6个。超过6个关系会导致Dagre引擎将箭头穿过节点,造成图表难以阅读。若系统需要更多连接,将其拆分为多张聚焦的图表。
Rel()- 大多数图表使用(避免水平拥挤)
$c4ShapeInRow="3" - 标签较长的图表使用
$c4ShapeInRow="2" - 始终使用(垂直堆叠边界,提升清晰度)
$c4BoundaryInRow="1" - 标签与元素重叠时,在中添加
UpdateRelStyle$offsetY="-10" - 优先选择树形拓扑(每个节点1个输入,1-2个输出)而非网状拓扑
- 按流向顺序声明元素——的声明顺序会影响布局
Container() - 仅当自动布局造成重叠时,才作为最后手段使用定向、
Rel_D等指令Rel_R
完整C4语法、示例和模板,请阅读。
references/c4-architecture.mdStep 3: Validate
步骤3:验证
Before rendering, ALWAYS validate the Mermaid syntax:
bash
node $SKILL_DIR/scripts/validate.mjs <file.mmd>If validation fails:
- Read the error message carefully
- Consult for common fixes
references/troubleshooting.md - Fix the syntax and re-validate
- Maximum 3 fix attempts before asking the user for clarification
渲染前,必须验证Mermaid语法:
bash
node $SKILL_DIR/scripts/validate.mjs <file.mmd>若验证失败:
- 仔细阅读错误信息
- 参考获取常见修复方案
references/troubleshooting.md - 修复语法后重新验证
- 最多尝试3次修复,若仍失败则向用户请求澄清
Step 4: Render
步骤4:渲染
4.1 — Setup (First Run Only)
4.1 — 初始化(仅首次运行)
bash
bash $SKILL_DIR/scripts/setup.shThis auto-installs both rendering engines and icon pack dependencies. Run once per environment.
bash
bash $SKILL_DIR/scripts/setup.sh此脚本会自动安装两个渲染引擎和图标包依赖。每个环境仅需运行一次。
4.2 — Single Diagram Rendering
4.2 — 单图表渲染
bash
undefinedbash
undefinedSVG (default — best quality)
SVG(默认——最佳画质)
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg
PNG (for documents/presentations)
PNG(用于文档/演示文稿)
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.png --width 1200
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.png --width 1200
ASCII (for terminals/READMEs)
ASCII(用于终端/ README)
node $SKILL_DIR/scripts/render-ascii.mjs -i diagram.mmd
node $SKILL_DIR/scripts/render-ascii.mjs -i diagram.mmd
With icon packs (architecture-beta with AWS/tech icons)
带图标包(architecture-beta带AWS/技术图标)
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg --icons logos,fa
The `--icons` flag registers Iconify packs before rendering. Packs: `logos` (AWS/tech), `fa` (Font Awesome). Use `logos` for AWS.node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg --icons logos,fa
`--icons`参数用于在渲染前注册Iconify图标包。可用包:`logos`(AWS/技术图标)、`fa`(Font Awesome)。AWS图表使用`logos`包。4.3 — Batch Rendering
4.3 — 批量渲染
For multiple diagrams at once:
bash
node $SKILL_DIR/scripts/batch.mjs \
--input-dir ./diagrams \
--output-dir ./rendered \
--format svg \
--theme default \
--workers 4同时渲染多个图表:
bash
node $SKILL_DIR/scripts/batch.mjs \\
--input-dir ./diagrams \\
--output-dir ./rendered \\
--format svg \\
--theme default \\
--workers 44.4 — Available Themes
4.4 — 可用主题
beautiful-mermaid (15): | | | | | | | | | | | | | |
tokyo-nighttokyo-night-stormtokyo-night-lightdraculanordnord-lightcatppuccin-mochacatppuccin-lattegithub-darkgithub-lightsolarized-darksolarized-lightone-darkzinc-darkzinc-lightmermaid-cli native (5): | | | |
defaultforestdarkneutralbaseCustom theme:
--theme base --config '{"theme":"base","themeVariables":{"primaryColor":"#4f46e5","lineColor":"#94a3b8"}}'For the full theme catalog, read . The render script auto-selects the best engine (mmdc primary, beautiful-mermaid fallback, Puppeteer for icon packs).
references/themes.mdbeautiful-mermaid(15种): | | | | | | | | | | | | | |
tokyo-nighttokyo-night-stormtokyo-night-lightdraculanordnord-lightcatppuccin-mochacatppuccin-lattegithub-darkgithub-lightsolarized-darksolarized-lightone-darkzinc-darkzinc-lightmermaid-cli原生(5种): | | | |
defaultforestdarkneutralbase自定义主题:
--theme base --config '{"theme":"base","themeVariables":{"primaryColor":"#4f46e5","lineColor":"#94a3b8"}}'完整主题目录请阅读。渲染脚本会自动选择最佳引擎(优先mmdc,其次beautiful-mermaid,图标包使用Puppeteer)。
references/themes.mdStep 5: Code-to-Diagram (When Requested)
步骤5:代码转图表(按需使用)
When the user asks to visualize existing code or architecture:
- Read for the analysis methodology
references/code-to-diagram.md - Analyze the codebase to identify the right diagram type:
- Module dependencies → Flowchart or Class diagram
- API routes and handlers → Sequence diagram
- Database models/schemas → ERD
- Service architecture → C4 Container or Architecture diagram
- State machines in code → State diagram
- Generate the .mmd file with proper init directives (Golden Rule 1)
- Validate and render as usual
当用户要求可视化现有代码或架构时:
- 阅读获取分析方法
references/code-to-diagram.md - 分析代码库以确定合适的图表类型:
- 模块依赖 → 流程图或类图
- API路由与处理器 → 时序图
- 数据库模型/schema → ERD图
- 服务架构 → C4容器图或架构图
- 代码中的状态机 → 状态图
- 生成带正确init指令的.mmd文件(遵循黄金规则1)
- 按常规流程验证并渲染
Troubleshooting Quick Reference
故障排除快速参考
| Symptom | Likely Cause | Fix |
|---|---|---|
| Diagram won't render | Syntax error | Run validate.mjs, check brackets/quotes |
| Labels cut off | Text too long | Shorten labels or use line breaks |
| Layout looks wrong | Wrong direction | Try different TD/LR/BT/RL |
| Nodes overlap | Too many nodes | Split into subgraphs or multiple diagrams |
| Lines too dark/thick | No init directive | Add |
| C4 lines overlapping | No styling applied | Add |
| AWS icons not showing | No icon pack | Use |
| Not installed | Run |
| Theme not applied | Wrong engine | beautiful-mermaid themes only work with that engine |
For comprehensive troubleshooting, read .
references/troubleshooting.md| 症状 | 可能原因 | 修复方案 |
|---|---|---|
| 图表无法渲染 | 语法错误 | 运行validate.mjs,检查括号/引号 |
| 标签被截断 | 文本过长 | 缩短标签或使用换行符 |
| 布局异常 | 方向错误 | 尝试不同的TD/LR/BT/RL方向 |
| 节点重叠 | 节点过多 | 拆分为子图或多张图表 |
| 线条过暗/过粗 | 未使用init指令 | 添加带 |
| C4线条重叠 | 未应用样式 | 为每个Rel添加带偏移量的 |
| AWS图标不显示 | 未加载图标包 | 使用 |
| 未安装 | 运行 |
| 主题未生效 | 引擎错误 | beautiful-mermaid主题仅适用于对应引擎 |
完整故障排除指南,请阅读。
references/troubleshooting.mdOutput Conventions
输出规范
- Save .mmd source files alongside rendered outputs
- Naming: (e.g.,
{purpose}-{type}.mmd)auth-flow-sequence.mmd - For batch: maintain input filename, change extension
- Always provide both the .mmd source and rendered file to the user
- .mmd源文件与渲染输出文件保存在同一目录
- 命名规则:(例如:
{用途}-{类型}.mmd)auth-flow-sequence.mmd - 批量渲染:保留输入文件名,修改扩展名
- 始终向用户提供.mmd源文件和渲染后的文件 ",