UNPKG

17 kBMarkdownView Raw
1<p align="center">
2<img src="https://raw.githubusercontent.com/mermaid-js/mermaid/develop/docs/public/favicon.svg" height="150">
3</p>
4<h1 align="center">
5Mermaid
6</h1>
7<p align="center">
8通过解析类 Markdown 的文本语法来实现图表的创建和动态修改。
9<p>
10<p align="center">
11 <a href="https://www.npmjs.com/package/mermaid"><img src="https://img.shields.io/npm/v/mermaid?color=ff3670&label="></a>
12<p>
13
14<p align="center">
15<a href="https://mermaid.live/"><b>Live Editor!</b></a>
16</p>
17<p align="center">
18 <a href="https://mermaid.js.org">📖 文档</a> | <a href="https://mermaid.js.org/intro/">🚀 入门</a> | <a href="https://www.jsdelivr.com/package/npm/mermaid">🌐 CDN</a> | <a href="https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE" title="Slack invite">🙌 加入我们</a>
19</p>
20<p align="center">
21<a href="./README.md">English</a>
22</p>
23
24<br>
25<br>
26
27[![NPM](https://img.shields.io/npm/v/mermaid)](https://www.npmjs.com/package/mermaid)
28[![Build CI Status](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml/badge.svg)](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml)
29[![npm minified gzipped bundle size](https://img.shields.io/bundlephobia/minzip/mermaid)](https://bundlephobia.com/package/mermaid)
30[![Coverage Status](https://coveralls.io/repos/github/mermaid-js/mermaid/badge.svg?branch=master)](https://coveralls.io/github/mermaid-js/mermaid?branch=master)
31[![CDN Status](https://img.shields.io/jsdelivr/npm/hm/mermaid)](https://www.jsdelivr.com/package/npm/mermaid)
32[![NPM Downloads](https://img.shields.io/npm/dm/mermaid)](https://www.npmjs.com/package/mermaid)
33[![Join our Slack!](https://img.shields.io/static/v1?message=join%20chat&color=9cf&logo=slack&label=slack)](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE)
34[![Twitter Follow](https://img.shields.io/badge/Social-mermaidjs__-blue?style=social&logo=twitter)](https://twitter.com/mermaidjs_)
35
36<img src="./img/header.png" alt="" />
37
38:trophy: **Mermaid 被提名并获得了 [JS Open Source Awards (2019)](https://osawards.com/javascript/2019) 的 "The most exciting use of technology" 奖项!!!**
39
40**感谢所有参与进来提交 PR,解答疑问的人们! 🙏**
41
42<a href="https://mermaid-js.github.io/mermaid/landing/"><img src="https://github.com/mermaid-js/mermaid/blob/master/docs/intro/img/book-banner-post-release.jpg" alt="Explore Mermaid.js in depth, with real-world examples, tips & tricks from the creator... The first official book on Mermaid is available for purchase. Check it out!"></a>
43
44## 关于 Mermaid
45
46<!-- <Main description> -->
47
48Mermaid 是一个基于 Javascript 的图表绘制工具,通过解析类 Markdown 的文本语法来实现图表的创建和动态修改。Mermaid 诞生的主要目的是让文档的更新能够及时跟上开发进度。
49
50> Doc-Rot 是 Mermaid 致力于解决的一个难题。
51
52绘图和编写文档花费了开发者宝贵的开发时间,而且随着业务的变更,它很快就会过期。 但是如果缺少了图表或文档,对于生产力和团队新人的业务学习都会产生巨大的阻碍。 <br/>
53Mermaid 通过允许用户创建便于修改的图表来解决这一难题,它也可以作为生产脚本(或其他代码)的一部分。<br/>
54<br/>
55Mermaid 甚至能让非程序员也能通过 [Mermaid Live Editor](https://mermaid.live/) 轻松创建详细的图表。<br/>
56你可以访问 [教程](./docs/config/Tutorials.md) 来查看 Live Editor 的视频教程,也可以查看 [Mermaid 的集成和使用](./docs/ecosystem/integrations.md) 这个清单来检查你的文档工具是否已经集成了 Mermaid 支持。
57
58如果想要查看关于 Mermaid 更详细的介绍及基础使用方式,可以查看 [入门指引](./docs/community/n00b-overview.md), [用法](./docs/config/usage.md) 和 [教程](./docs/config/Tutorials.md).
59
60<!-- </Main description> -->
61
62## 示例
63
64**下面是一些可以使用 Mermaid 创建的图表示例。点击 [语法](https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference) 查看详情。**
65
66<table>
67<!-- <Flowchart> -->
68
69### 流程图 [<a href="https://mermaid-js.github.io/mermaid/#/flowchart">文档</a> - <a href="https://mermaid.live/edit#base64:eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0hhcmRdIC0tPnxUZXh0fCBCKFJvdW5kKVxuICAgIEIgLS0-IEN7RGVjaXNpb259XG4gICAgQyAtLT58T25lfCBEW1Jlc3VsdCAxXVxuICAgIEMgLS0-fFR3b3wgRVtSZXN1bHQgMl0iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9fQ">live editor</a>]
70
71```
72flowchart LR
73A[Hard] -->|Text| B(Round)
74B --> C{Decision}
75C -->|One| D[Result 1]
76C -->|Two| E[Result 2]
77```
78
79```mermaid
80flowchart LR
81A[Hard] -->|Text| B(Round)
82B --> C{Decision}
83C -->|One| D[Result 1]
84C -->|Two| E[Result 2]
85```
86
87### 时序图 [<a href="https://mermaid-js.github.io/mermaid/#/sequenceDiagram">文档</a> - <a href="https://mermaid.live/edit#base64:eyJjb2RlIjoic2VxdWVuY2VEaWFncmFtXG5BbGljZS0-PkpvaG46IEhlbGxvIEpvaG4sIGhvdyBhcmUgeW91P1xubG9vcCBIZWFsdGhjaGVja1xuICAgIEpvaG4tPj5Kb2huOiBGaWdodCBhZ2FpbnN0IGh5cG9jaG9uZHJpYVxuZW5kXG5Ob3RlIHJpZ2h0IG9mIEpvaG46IFJhdGlvbmFsIHRob3VnaHRzIVxuSm9obi0tPj5BbGljZTogR3JlYXQhXG5Kb2huLT4-Qm9iOiBIb3cgYWJvdXQgeW91P1xuQm9iLS0-PkpvaG46IEpvbGx5IGdvb2QhIiwibWVybWFpZCI6eyJ0aGVtZSI6ImRlZmF1bHQifX0">live editor</a>]
88
89```
90sequenceDiagram
91Alice->>John: Hello John, how are you?
92loop Healthcheck
93 John->>John: Fight against hypochondria
94end
95Note right of John: Rational thoughts!
96John-->>Alice: Great!
97John->>Bob: How about you?
98Bob-->>John: Jolly good!
99```
100
101```mermaid
102sequenceDiagram
103Alice->>John: Hello John, how are you?
104loop Healthcheck
105 John->>John: Fight against hypochondria
106end
107Note right of John: Rational thoughts!
108John-->>Alice: Great!
109John->>Bob: How about you?
110Bob-->>John: Jolly good!
111```
112
113### 甘特图 [<a href="https://mermaid-js.github.io/mermaid/#/gantt">文档</a> - <a href="https://mermaid.live/edit#base64:eyJjb2RlIjoiZ2FudHRcbnNlY3Rpb24gU2VjdGlvblxuQ29tcGxldGVkIDpkb25lLCAgICBkZXMxLCAyMDE0LTAxLTA2LDIwMTQtMDEtMDhcbkFjdGl2ZSAgICAgICAgOmFjdGl2ZSwgIGRlczIsIDIwMTQtMDEtMDcsIDNkXG5QYXJhbGxlbCAxICAgOiAgICAgICAgIGRlczMsIGFmdGVyIGRlczEsIDFkXG5QYXJhbGxlbCAyICAgOiAgICAgICAgIGRlczQsIGFmdGVyIGRlczEsIDFkXG5QYXJhbGxlbCAzICAgOiAgICAgICAgIGRlczUsIGFmdGVyIGRlczMsIDFkXG5QYXJhbGxlbCA0ICAgOiAgICAgICAgIGRlczYsIGFmdGVyIGRlczQsIDFkIiwibWVybWFpZCI6eyJ0aGVtZSI6ImRlZmF1bHQifX0">live editor</a>]
114
115```
116gantt
117 section Section
118 Completed :done, des1, 2014-01-06,2014-01-08
119 Active :active, des2, 2014-01-07, 3d
120 Parallel 1 : des3, after des1, 1d
121 Parallel 2 : des4, after des1, 1d
122 Parallel 3 : des5, after des3, 1d
123 Parallel 4 : des6, after des4, 1d
124```
125
126```mermaid
127gantt
128 section Section
129 Completed :done, des1, 2014-01-06,2014-01-08
130 Active :active, des2, 2014-01-07, 3d
131 Parallel 1 : des3, after des1, 1d
132 Parallel 2 : des4, after des1, 1d
133 Parallel 3 : des5, after des3, 1d
134 Parallel 4 : des6, after des4, 1d
135```
136
137### 类图 [<a href="https://mermaid-js.github.io/mermaid/#/classDiagram">文档</a> - <a href="https://mermaid.live/edit#base64:eyJjb2RlIjoiY2xhc3NEaWFncmFtXG5DbGFzczAxIDx8LS0gQXZlcnlMb25nQ2xhc3MgOiBDb29sXG48PGludGVyZmFjZT4-IENsYXNzMDFcbkNsYXNzMDkgLS0-IEMyIDogV2hlcmUgYW0gaT9cbkNsYXNzMDkgLS0qIEMzXG5DbGFzczA5IC0tfD4gQ2xhc3MwN1xuQ2xhc3MwNyA6IGVxdWFscygpXG5DbGFzczA3IDogT2JqZWN0W10gZWxlbWVudERhdGFcbkNsYXNzMDEgOiBzaXplKClcbkNsYXNzMDEgOiBpbnQgY2hpbXBcbkNsYXNzMDEgOiBpbnQgZ29yaWxsYVxuY2xhc3MgQ2xhc3MxMCB7XG4gID4-c2VydmljZT4-XG4gIGludCBpZFxuICBzaXplKClcbn0iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9fQ">live editor</a>]
138
139```
140classDiagram
141Class01 <|-- AveryLongClass : Cool
142<<Interface>> Class01
143Class09 --> C2 : Where am I?
144Class09 --* C3
145Class09 --|> Class07
146Class07 : equals()
147Class07 : Object[] elementData
148Class01 : size()
149Class01 : int chimp
150Class01 : int gorilla
151class Class10 {
152 <<service>>
153 int id
154 size()
155}
156```
157
158```mermaid
159classDiagram
160Class01 <|-- AveryLongClass : Cool
161<<Interface>> Class01
162Class09 --> C2 : Where am I?
163Class09 --* C3
164Class09 --|> Class07
165Class07 : equals()
166Class07 : Object[] elementData
167Class01 : size()
168Class01 : int chimp
169Class01 : int gorilla
170class Class10 {
171 <<service>>
172 int id
173 size()
174}
175```
176
177### 状态图 [[<a href="https://mermaid-js.github.io/mermaid/#/stateDiagram">docs</a> - <a href="https://mermaid.live/edit#pako:eNpdkLsOwjAMRX-l8ojahTEDCzB26kgYrMYtkfJAqVMJVf13QiIKqqfr44d8vUDvFYGAiZHponEMaJv5KF2V4na4V01zqjrWxhSUZYapuEetn7UbCy16P_5HzwGnR6FZfpdCDZaCRa3SWcunQQI_yJIEkaSiAaNhCdKtqRUj--7lehAcItUQn-pnBMSAZtroVWn2YYOU07b4z29Y37gJVYk">live editor</a>]
178
179```
180stateDiagram-v2
181[*] --> Still
182Still --> [*]
183Still --> Moving
184Moving --> Still
185Moving --> Crash
186Crash --> [*]
187```
188
189```mermaid
190stateDiagram-v2
191[*] --> Still
192Still --> [*]
193Still --> Moving
194Moving --> Still
195Moving --> Crash
196Crash --> [*]
197```
198
199### 饼图 [<a href="https://mermaid-js.github.io/mermaid/#/pie">文档</a> - <a href="https://mermaid.live/edit#base64:eyJjb2RlIjoicGllXG5cIkRvZ3NcIiA6IDQyLjk2XG5cIkNhdHNcIiA6IDUwLjA1XG5cIlJhdHNcIiA6IDEwLjAxIiwibWVybWFpZCI6eyJ0aGVtZSI6ImRlZmF1bHQifX0">live editor</a>]
200
201```
202pie
203"Dogs" : 386
204"Cats" : 85
205"Rats" : 15
206```
207
208```mermaid
209pie
210"Dogs" : 386
211"Cats" : 85
212"Rats" : 15
213```
214
215### Git 图 [实验特性 - <a href="https://mermaid.live/edit#base64:eyJjb2RlIjoiZ2l0R3JhcGg6XG5vcHRpb25zXG57XG4gICAgXCJub2RlU3BhY2luZ1wiOiAxNTAsXG4gICAgXCJub2RlUmFkaXVzXCI6IDEwXG59XG5lbmRcbmNvbW1pdFxuYnJhbmNoIG5ld2JyYW5jaFxuY2hlY2tvdXQgbmV3YnJhbmNoXG5jb21taXRcbmNvbW1pdFxuY2hlY2tvdXQgbWFzdGVyXG5jb21taXRcbmNvbW1pdFxubWVyZ2UgbmV3YnJhbmNoXG4iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9fQ">live editor</a>]
216
217### 用户体验旅程图 [<a href="https://mermaid-js.github.io/mermaid/#/user-journey">文档</a> - <a href="https://mermaid.live/edit#pako:eNpljzEPgkAMhf9K05nFGJdbJXFiYmVpuKIncDVHL4QQ_ruHaILaqXnf63vpjLVYRoMAd4nB81R5SKNOO4ZiglFC6_wVLL3JwLU68XARUHnhTQcoqGVQJgMnAwV_5GSMj0HJhcHAcU_y7d7AYVUzOJP-ddyk3ydZGf0n66uldPqCPxWYYc-hJ2fTj_OqVqg3Tplo0mq5odhphZVfkpWiSjn5Go2GyBnGhyXl3NE1UI-moW7g5QkSoF5m">live editor</a>]
218
219```
220 journey
221 title My working day
222 section Go to work
223 Make tea: 5: Me
224 Go upstairs: 3: Me
225 Do work: 1: Me, Cat
226 section Go home
227 Go downstairs: 5: Me
228 Sit down: 3: Me
229```
230
231```mermaid
232 journey
233 title My working day
234 section Go to work
235 Make tea: 5: Me
236 Go upstairs: 3: Me
237 Do work: 1: Me, Cat
238 section Go home
239 Go downstairs: 5: Me
240 Sit down: 3: Me
241```
242
243### C4 图 [<a href="https://mermaid-js.github.io/mermaid/#/c4c">文档</a>]
244
245```
246C4Context
247title System Context diagram for Internet Banking System
248
249Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
250Person(customerB, "Banking Customer B")
251Person_Ext(customerC, "Banking Customer C")
252System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")
253
254Person(customerD, "Banking Customer D", "A customer of the bank, <br/> with personal bank accounts.")
255
256Enterprise_Boundary(b1, "BankBoundary") {
257
258 SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")
259
260 System_Boundary(b2, "BankBoundary2") {
261 System(SystemA, "Banking System A")
262 System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.")
263 }
264
265 System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")
266 SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.")
267
268 Boundary(b3, "BankBoundary3", "boundary") {
269 SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.")
270 SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")
271 }
272}
273
274BiRel(customerA, SystemAA, "Uses")
275BiRel(SystemAA, SystemE, "Uses")
276Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")
277Rel(SystemC, customerA, "Sends e-mails to")
278```
279
280```mermaid
281C4Context
282title System Context diagram for Internet Banking System
283
284Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
285Person(customerB, "Banking Customer B")
286Person_Ext(customerC, "Banking Customer C")
287System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")
288
289Person(customerD, "Banking Customer D", "A customer of the bank, <br/> with personal bank accounts.")
290
291Enterprise_Boundary(b1, "BankBoundary") {
292
293 SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")
294
295 System_Boundary(b2, "BankBoundary2") {
296 System(SystemA, "Banking System A")
297 System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.")
298 }
299
300 System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")
301 SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.")
302
303 Boundary(b3, "BankBoundary3", "boundary") {
304 SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.")
305 SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")
306 }
307}
308
309BiRel(customerA, SystemAA, "Uses")
310BiRel(SystemAA, SystemE, "Uses")
311Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")
312Rel(SystemC, customerA, "Sends e-mails to")
313```
314
315## 发布
316
317对于有权限的同学来说,你可以通过以下步骤来完成发布操作:
318
319更新 `package.json` 中的版本号,然后执行如下命令:
320
321```sh
322npm publish
323```
324
325以上的命令会将文件打包到 `dist` 目录并发布至 npmjs.org.
326
327## 相关项目
328
329- [Command Line Interface](https://github.com/mermaid-js/mermaid-cli)
330- [Live Editor](https://github.com/mermaid-js/mermaid-live-editor)
331- [HTTP Server](https://github.com/TomWright/mermaid-server)
332
333## 贡献者 [![Good first issue](https://img.shields.io/github/labels/mermaid-js/mermaid/Good%20first%20issue%21)](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [![Contributors](https://img.shields.io/github/contributors/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors) [![Commits](https://img.shields.io/github/commit-activity/m/mermaid-js/mermaid)](https://github.com/mermaid-js/mermaid/graphs/contributors)
334
335Mermaid 是一个不断发展中的社区,并且还在接收新的贡献者。有很多不同的方式可以参与进来,而且我们还在寻找额外的帮助。如果你想知道如何开始贡献,请查看 [这个 issue](https://github.com/mermaid-js/mermaid/issues/866)。
336
337关于如何贡献的详细信息可以在 [贡献指南](CONTRIBUTING.md) 中找到。
338
339## 安全
340
341对于公开网站来说,从互联网上的用户处检索文本、存储供后续在浏览器中展示的内容可能是不安全的,理由是用户的内容可能嵌入一些数据加载完成之后就会运行的恶意脚本,这些对于 Mermaid 来说毫无疑问是一个风险,尤其是 mermaid 图表还包含了许多在 html 中使用的字符,这意味着我们难以使用常规的手段来过滤不安全代码,因为这些常规手段会造成图表损坏。我们仍然在努力对获取到的代码进行安全过滤并不断完善我们的程序,但很难保证没有漏洞。
342
343作为拥有外部用户的网站的额外安全级别,我们很高兴推出一个新的安全级别,其中的图表在沙盒 iframe 中渲染,防止代码中的 javascript 被执行,这是在安全性方面迈出的一大步。
344
345_很不幸的是,鱼与熊掌不可兼得,在这个场景下它意味着在可能的恶意代码被阻止时,也会损失部分交互能力_
346
347## 报告漏洞
348
349如果想要报告漏洞,请发送邮件到 security@mermaid.live, 并附上问题的描述、复现问题的步骤、受影响的版本,以及解决问题的方案(如果有的话)。
350
351## 鸣谢
352
353来自 Knut Sveidqvist:
354
355> _特别感谢 [d3](https://d3js.org/) 和 [dagre-d3](https://github.com/cpettitt/dagre-d3) 这两个优秀的项目,它们提供了图形布局和绘图工具库!_ > _同样感谢 [js-sequence-diagram](https://bramp.github.io/js-sequence-diagrams) 提供了时序图语法的使用。 感谢 Jessica Peter 提供了甘特图渲染的灵感。_ > _感谢 [Tyler Long](https://github.com/tylerlong) 从 2017 年四月开始成为了项目的合作者。_
356>
357> _感谢越来越多的 [贡献者们](https://github.com/knsv/mermaid/graphs/contributors),没有你们,就没有这个项目的今天!_
358
359---
360
361_Mermaid 是由 Knut Sveidqvist 创建,它为了更简单的文档编写而生。_