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

mermaid-diagram

它能做什么

这个技能用 Mermaid 编写图表代码,并检查其是否有效。Mermaid 是一种用于绘制图表的文本格式。适合需要根据文字描述快速制作图表的任何人。

适用场景

  • ✓当你需要根据文字描述绘制流程图、时序图或时间线的时候。
  • ✓当你希望得到可以粘贴到文档或维基页面中的图表代码的时候。
  • ✓当图表包含数学符号,需要整洁排版的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请帮我绘制一张订单流程的 Mermaid 流程图,并保存为文件,方便我粘贴到文档中。”

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

工作原理

智能体选择合适的图表类型,编写 Mermaid 代码,并保存到 figures 文件夹中。它会检查语法,并在几轮中修正错误。

技术内容(原始 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 all generated files
  • MAX_ITERATIONS = 3 — Maximum refinement rounds for syntax errors

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 user description to determine the most suitable diagram type
  2. Read the corresponding syntax reference documentation (see Step 2 below)
  3. If the diagram involves mathematical notation (formulas, equations, Greek letters, subscripts, superscripts, fractions, matrices, etc.), apply the math syntax rules from the Math Formulas in Diagrams section below
  4. Identify all components, connections, and data flow
  5. Plan the diagram structure

Step 2: Read Documentation

Select the appropriate diagram type based on the use case. Use your built-in knowledge of Mermaid syntax, or fetch up-to-date docs via the context7 MCP server if needed.

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 (C4 model)
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)

Configuration & Themes

  • Theming - Custom colors and styles
  • Directives - Diagram-level configuration
  • Layouts - Layout direction and spacing
  • Configuration - Global settings
  • Math - LaTeX math support (see Math Formulas in Diagrams section below)

Step 3: Generate Mermaid Code & Save Files

Generate the Mermaid code following the reference specification, then save TWO files:

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

The .mmd file contains ONLY the raw Mermaid code (no markdown fences). Example:

flowchart TD
    A[Start] --> B{Condition}
    B -->|Yes| C[Execute]
    B -->|No| D[End]
    C --> D

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

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

# Diagram Title

Brief description of what this diagram shows.

​```mermaid
flowchart TD
    A[Start] --> B{Condition}
    B -->|Yes| C[Execute]
    B -->|No| D[End]
    C --> D
​```

Naming convention: Use a descriptive kebab-case name derived from the user's request (e.g., auth-flow, system-architecture, database-er).

Step 4: Verify Mermaid Syntax (MANDATORY)

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

# Check if mermaid-cli is available
if command -v mmdc &> /dev/null; then
    # Render to PNG to verify syntax is correct
    mmdc -i figures/<diagram-name>.mmd -o figures/<diagram-name>.png -b transparent \
        && echo "✅ Syntax valid — PNG rendered to figures/<diagram-name>.png"
else
    # Try npx as fallback
    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 the verification fails:

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

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

After successful rendering, Claude MUST read the generat

常见问题

它支持多少种图表类型?

它涵盖二十多种类型,包括流程图、时序图、类图、ER 图和甘特图。

文件保存在哪里?

默认保存在项目中的 figures 文件夹里。

它能修正语法错误吗?

可以。出现语法错误时,它会在最多三轮中改进代码。

详情

作者的原始描述

Generate Mermaid diagrams from user requirements. Supports flowcharts, sequence diagrams, class diagrams, ER diagrams, Gantt charts, and 18 more diagram types.

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

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能