plugins/languages/markdown/skills/mermaid/SKILL.md
Mermaid 图表规范,覆盖 Mermaid 11.x 的流程图(flowchart)、序列图(sequenceDiagram)、 类图(classDiagram)、ER 图(erDiagram)、状态图(stateDiagram-v2)、甘特图(gantt)、 时间轴(timeline)、思维导图(mindmap)、用户旅程(journey)、C4、git 图、饼图、 象限图(quadrantChart)、需求图(requirementDiagram)、桑基图(sankey-beta)、 XY 图(xychart-beta),以及 init 指令、主题、a11y 与渲染陷阱。在 Markdown 中绘制、 审查或修改 mermaid 代码块时加载。也响应 "mermaid", "流程图", "序列图", "类图", "ER 图", "状态图", "甘特图", "思维导图", "C4", "时序图", "时间线"。
npx skillsauth add lazygophers/ccplugin markdown-mermaidInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Mermaid 11.x 在 GitHub / GitLab / Docusaurus / VitePress / Obsidian 等平台原生渲染。
所有图表写在 Markdown 的 ```mermaid 代码块内。Markdown 通用规范参见
markdown-core。
flowchart TD / sequenceDiagram / 等),不可省略。[label] / (label) 中。(、:、-、空格、中文标点)时用 "..." 包裹。themeVariables,禁硬编码 style A fill:#f00 满图刷色。accTitle / accDescr,供屏幕阅读器与导出 alt。TD(top-down)、横向 LR(left-right),团队内统一。<br> 除外,平台支持不一致);多行用 "line1\nline2"。%%{init: {
"theme": "default",
"themeVariables": {
"primaryColor": "#1e88e5",
"fontFamily": "ui-monospace, SFMono-Regular, monospace"
},
"flowchart": { "curve": "basis", "htmlLabels": false }
}}%%
flowchart LR
A[开始] --> B[结束]
theme:default / dark / forest / neutral / base(base 才允许自定义变量)。%%{init: ... }%%。flowchart TD
A([开始]) --> B{条件}
B -- 是 --> C[处理]
B -- 否 --> D[兜底]
C --> E[(数据库)]
D --> E
E --> F([结束])
节点形状速查:
| 语法 | 形状 | 用途 |
|------|------|------|
| A[text] | 矩形 | 普通步骤 |
| A(text) | 圆角矩形 | 起止 |
| A([text]) | 体育场 | 流程边界 |
| A[[text]] | 子流程 | 复合步骤 |
| A[(text)] | 圆柱 | 数据库 / 存储 |
| A((text)) | 圆 | 连接点 |
| A{text} | 菱形 | 判断 |
| A{{text}} | 六边形 | 准备 / 配置 |
| A>text] | 旗帜 | 输入 / 输出 |
连线:-->(实线箭头)、---(实线)、-.->(虚线箭头)、==>(粗线箭头)、
-- label -->(带标签)。
sequenceDiagram
autonumber
participant C as 客户端
participant API as 服务
participant DB as 数据库
C->>+API: GET /users/1
API->>+DB: SELECT ...
DB-->>-API: row
API-->>-C: 200 OK
Note over C,API: 30 天 TTL 缓存
autonumber 自动编号步骤。->> 实线箭头,-->> 虚线返回;+ / - 控制激活条。alt / else / end、opt / end、loop / end、par / and / end、
critical / option / end、break / end。classDiagram
direction LR
class User {
+String id
+String email
+login() bool
}
class Admin {
+grant(role) void
}
User <|-- Admin
User "1" o-- "*" Order
关系:<|-- 继承、*-- 组合、o-- 聚合、--> 关联、..> 依赖、..|> 实现。
erDiagram
USER ||--o{ ORDER : places
USER {
int id PK
string email UK
string name
}
ORDER {
int id PK
int user_id FK
string status
}
基数:||--|| 一对一、||--o{ 一对多、}o--o{ 多对多;可选用 o。
stateDiagram-v2
[*] --> Pending
Pending --> Running: start
Running --> Done: success
Running --> Failed: error
Failed --> Pending: retry
Done --> [*]
支持并发 -- 分区、复合状态 state X { ... }、选择 <<choice>>、分叉 <<fork>>。
gantt
title 项目排期
dateFormat YYYY-MM-DD
axisFormat %m-%d
section 设计
需求评审 :done, d1, 2026-05-01, 3d
架构设计 :active, d2, after d1, 5d
section 开发
后端实现 : d3, after d2, 10d
前端实现 :crit, d4, after d2, 12d
任务状态:done / active / crit / milestone;时间用 after id 或绝对日期。
timeline
title 产品演进
2024 : v1 发布 : 用户突破 1k
2025 : v2 重构 : 引入插件市场
2026 : v3 智能化 : LLM 工作流
mindmap
root((Markdown))
规范
CommonMark
GFM
工具
remark
markdownlint
扩展
Mermaid
MDX
journey
title 新用户上手
section 注册
访问首页: 5: 用户
提交表单: 3: 用户, 系统
section 使用
浏览内容: 4: 用户
下单付款: 2: 用户, 系统
评分 1–5,越大体验越好。
| 类型 | 关键字 | 用途 |
|------|--------|------|
| C4 上下文 / 容器 | C4Context / C4Container | 系统架构(C4 模型) |
| Git 图 | gitGraph | 分支演示 |
| 饼图 | pie | 比例分布 |
| 象限图 | quadrantChart | 2×2 矩阵分析 |
| 需求图 | requirementDiagram | 需求追溯 |
| 桑基图 | sankey-beta | 流量分配(实验性) |
| XY 图 | xychart-beta | 折线 / 柱状(实验性) |
beta 图表在 GitHub / GitLab 渲染器版本滞后时可能失败,关键文档慎用。
flowchart LR
accTitle: 用户登录流程
accDescr: 用户输入账号密码,服务端校验后返回 token
A[输入凭据] --> B{校验}
B -- 通过 --> C[返回 token]
B -- 失败 --> D[报错]
accTitle / accDescr 是 Mermaid 内置 a11y 字段,导出 SVG 时写入 <title> /
<desc>。
| 陷阱 | 现象 | 修复 |
|------|------|------|
| 节点 ID 含中文 / 空格 | 解析失败 | ID 用 ASCII,文本写 [label] |
| 标签内有 ( : - | 截断 / 错位 | 用 "..." 包裹 |
| 主题变量未生效 | 仍是默认色 | theme: base + themeVariables |
| init 不在首行 | 指令被忽略 | 必须图声明之前 |
| GitHub 与本地渲染不一致 | 版本差 | 锁定 Mermaid 版本,跑预览 |
| 图过大 | 移动端不可读 | 拆图 / 横向布局 / 折叠节点 |
[label] 内"..." 包裹accTitle / accDescrdevelopment
Go 数据库规范——GORM Model 命名 ModelXxx、表名单数、枚举 uint8 + 常量、索引 idx_ 前缀 + deleted_at leading column、禁 time.Time 统一 int64 unix、禁指针/nullable 字段、TEXT/BLOB/JSON 禁 default、AutoMigrate 禁改主键。设计 DB model、写 GORM tag、建索引、做 migration 审查时触发。
development
Go HTTP API 规范——响应始终 200 + body code 字段、路由 /api/* 全 POST 单段 <Action><Model>、中间件逐路由注册禁 Group(prefix,mw...)、handler 仅返回 (rsp,error)、认证走 header。设计 HTTP API、写路由/handler/中间件时触发。
development
Go 项目结构规范——三层架构(API → Impl → State)、全局状态模式、internal/ 私有包、cmd/ 仅 main.go、go.work 多模块、禁止 Repository 接口和 DI 容器、struct 公共字段开头全 omitempty、handler var rsp 顶声明、禁 legacy migration。设计项目骨架、新建目录、组织包、做架构评审时触发。
development
Go 命名规范——Id/Uid 字段(非 ID)、IsActive/HasMFA 布尔前缀、CreatedAt 时间字段、接收者统一用 p、包名全小写无下划线、泛型类型参数描述性命名、集合字段 xxx_list 禁 xxxs 复数、Enum 0 值 XxxNil 禁 Unknown、禁 Status 统一 State、Set/Update 语义区分。定义结构体字段、函数、变量、包、接收者名、泛型、枚举时触发。