跳到正文
Skillpedia
图片与图标18k · #10605

mermaid-diagram

它能做什么

这个技能为流程图、时序图、类图等编写 Mermaid 图表代码,然后进行检查。适合任何需要根据文字描述绘制清晰图表的人。

适用场景

  • ✓当你需要根据描述生成流程图、时序图或类图时。
  • ✓当你希望把 Mermaid 文件保存在图表文件夹中用于文档时。
  • ✓当图表包含数学符号,并且必须正确渲染时。

技能链接

https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/skills-codex/mermaid-diagram/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/skills-codex/mermaid-diagram/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请为我的 API 调用画一张 Mermaid 时序图,保存到图表文件夹,并检查语法。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会选择图表类型,编写代码,并把 .mmd 和 .md 文件保存到图表文件夹。它会验证语法,并在需要时经过几轮调整布局。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Mermaid Diagram Generator

Generate high-quality Mermaid diagram code based on user requirements, with file output and verification.

Constants

  • OUTPUT_DIR = figures/ — Output directory for generated files
  • MAX_ITERATIONS = 3 — Maximum refinement rounds for syntax or layout issues

Workflow: MUST EXECUTE ALL STEPS

Step 0: Pre-flight Check

Create output directory

mkdir -p figures

Step 1: Understand Requirements & Select Diagram Type

Parse the input: $ARGUMENTS

  1. Analyze the request and choose the most suitable diagram type
  2. Read the corresponding Mermaid syntax reference below
  3. If the diagram involves mathematical notation, apply the math syntax rules from the Math Formulas in Diagrams section
  4. Identify all components, connections, and data flow
  5. Plan the diagram structure before writing code

Step 2: Read Documentation

Select the appropriate diagram type. Use built-in Mermaid knowledge first; if external documentation is needed and your environment provides it, fetch the up-to-date syntax reference.

Configuration & Themes

Choose theme, colors, and layout before writing code. For academic diagrams, prefer clean white backgrounds, restrained colors, and readable labels over decorative styling.

Type Use Cases
Flowchart Processes, decisions, steps
Sequence Diagram Interactions, messaging, API calls
Class Diagram Class structure, inheritance, associations
State Diagram State machines, state transitions
ER Diagram Database design, entity relationships
Gantt Chart Project planning, timelines
Pie Chart Proportions, distributions
Mindmap Hierarchical structures, knowledge graphs
Timeline Historical events, milestones
Git Graph Branches, merges, versions
Quadrant Chart Four-quadrant analysis
Requirement Diagram Requirements traceability
C4 Diagram System architecture
Sankey Diagram Flow, conversions
XY Chart Line charts, bar charts
Block Diagram System components, modules
Packet Diagram Network protocols, data structures
Kanban Task management, workflows
Architecture Diagram System architecture
Radar Chart Multi-dimensional comparison
Treemap Hierarchical data visualization
User Journey User experience flows
ZenUML Sequence diagrams (code style)

Step 3: Generate Mermaid Code & Save Files

Generate the Mermaid code and save two files:

File 1: figures/<diagram-name>.mmd — Raw Mermaid source

The .mmd file contains only raw Mermaid code, no markdown fences.

File 2: figures/<diagram-name>.md — Markdown with embedded Mermaid

The .md file wraps the same Mermaid code in a mermaid code block for preview rendering, plus a short title and description.

Diagram Title

Use a concise title in the .md wrapper that matches the generated diagram name.

Naming convention: use a descriptive kebab-case name derived from the request, such as auth-flow, system-architecture, or database-er.

Step 4: Verify Mermaid Syntax (MANDATORY)

Codex MUST verify the generated Mermaid code by running the Mermaid CLI (mmdc).

Check if mermaid-cli is available

if command -v mmdc >/dev/null 2>&1; then
    mmdc -i figures/<diagram-name>.mmd -o figures/<diagram-name>.png -b transparent \
        && echo "Syntax valid — PNG rendered to figures/<diagram-name>.png"
else
    npx -y @mermaid-js/mermaid-cli@latest -i figures/<diagram-name>.mmd -o figures/<diagram-name>.png -b transparent \
        && echo "Syntax valid — PNG rendered to figures/<diagram-name>.png"
fi

If verification fails:

  1. Read the error carefully
  2. Fix the syntax issue in both .mmd and .md
  3. Re-run verification
  4. Repeat up to MAX_ITERATIONS

Step 5: Codex STRICT Visual Review & Scoring (MANDATORY)

After successful rendering, Codex MUST read the generated PNG and perform a strict review:

## Codex's STRICT Review of <diagram-name>

### What I See
[Describe the rendered diagram in detail]

### Files Generated
- `figures/<diagram-name>.mmd`
- `figures/<diagram-name>.md`
- `figures/<diagram-name>.png`

### ═══════════════════════════════════════════════════════════════
### STRICT VERIFICATION CHECKLIST (ALL must pass for score ≥ 9)
### ═══════════════════════════════════════════════════════════════

#### A. File Correctness
- [ ] `.mmd` contains valid Mermaid syntax
- [ ] `.
常见问题

图表类型有多少种?

该技能涵盖很多类型,包括流程图、时序图、类图、ER 图和甘特图。

文件保存到哪里?

默认保存到项目中的图表文件夹。

它需要联网吗?

它先使用内置的 Mermaid 知识,只有在环境提供外部文档时才会去获取。

详情

作者的原始描述

Generate Mermaid diagrams from user requirements. Save .mmd and .md files to figures/ with syntax verification. Supports flowcharts, sequence diagrams, class diagrams, ER diagrams, Gantt charts, and many more diagram types.

repo: wanshuiyin/Auto-claude-code-research-in-sleep

热度

GitHub 星标
18k
排名
#10605
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能