Mermaid

Ever wanted to simplify documentation and avoid heavy tools like Visio when explaining your code? This is why mermaid was born, a simple markdown-like script language for generating charts from text via javascript.

语法

Flowcharts: https://mermaidjs.github.io/

Sequence diagrams: https://mermaidjs.github.io/sequenceDiagram.html

Gant diagrams: https://mermaidjs.github.io/gantt.html

插入 Mermaid 图形卡片

image.png

示例

Basic sequence diagram

Mermaid - 图2

  1. sequenceDiagram
  2. Alice ->> Bob: Hello Bob, how are you?
  3. Bob-->>John: How about you John?
  4. Bob--x Alice: I am good thanks!
  5. Bob-x John: I am good thanks!
  6. Note right of John: Bob thinks a long<br/>long time, so long<br/>that the text does<br/>not fit on a row.
  7.  
  8. Bob-->Alice: Checking with John...
  9. Alice->John: Yes... John, how are you?

Basic flowchart

Mermaid - 图3

  1. graph LR
  2. A[Square Rect] -- Link text --> B((Circle))
  3. A --> C(Round Rect)
  4. B --> D{Rhombus}
  5. C --> D
  6. D --> E

Larger flowchart with some styling

Mermaid - 图4

  1. graph TB
  2. sq[Square shape] --> ci((Circle shape))
  3.  
  4. subgraph A subgraph
  5. od>Odd shape]-- Two line edge comment --> ro
  6. di{Diamond with line break} -.-> ro(Rounded square shape)
  7. di==>ro2(Rounded square shape)
  8. end
  9.  
  10. %% Notice that no text in shape are added here instead that is appended further down
  11. e --> od3>Really long text with linebreak in an Odd shape]
  12.  
  13. %% Comments after double percent signs
  14. e((Inner / circle and some odd special characters)) --> f(,.?!+-*ز)
  15.  
  16. cyr[Cyrillic]-->cyr2((Circle shape Начало));
  17.  
  18. classDef green fill:#9f6,stroke:#333,stroke-width:2px;
  19. classDef orange fill:#f96,stroke:#333,stroke-width:4px;
  20. class sq,e green
  21. class di orange

Loops, alt and opt

Mermaid - 图5

  1. sequenceDiagram
  2. loop Daily query
  3. Alice->>Bob: Hello Bob, how are you?
  4. alt is sick
  5. Bob->>Alice: Not so good :(
  6. else is well
  7. Bob->>Alice: Feeling fresh like a daisy
  8. end
  9.  
  10. opt Extra response
  11. Bob->>Alice: Thanks for asking
  12. end
  13. end

Message to self in loop

Mermaid - 图6

  1. sequenceDiagram
  2. participant Alice
  3. participant Bob
  4. Alice->>John: Hello John, how are you?
  5. loop Healthcheck
  6. John->>John: Fight against hypochondria
  7. end
  8. Note right of John: Rational thoughts<br/>prevail...
  9. John-->>Alice: Great!
  10. John->>Bob: How about you?
  11. Bob-->>John: Jolly good!

Basic Gantt

Mermaid - 图7

  1. gantt
  2. title A Gantt Diagram
  3. dateFormat YYYY-MM-DD
  4. section Section
  5. A task :a1, 2014-01-01, 30d
  6. Another task :after a1 , 20d
  7. section Another
  8. Task in sec :2014-01-12 , 12d
  9. another task : 24d

Gantt with color

Mermaid - 图8

  1. gantt
  2. dateFormat YYYY-MM-DD
  3. title Adding GANTT diagram functionality to mermaid
  4.  
  5. section A section
  6. Completed task :done, des1, 2014-01-06,2014-01-08
  7. Active task :active, des2, 2014-01-09, 3d
  8. Future task : des3, after des2, 5d
  9. Future task2 : des4, after des3, 5d
  10.  
  11. section Critical tasks
  12. Completed task in the critical line :crit, done, 2014-01-06,24h
  13. Implement parser and jison :crit, done, after des1, 2d
  14. Create tests for parser :crit, active, 3d
  15. Future task in critical line :crit, 5d
  16. Create tests for renderer :2d
  17. Add to mermaid :1d
  18.  
  19. section Documentation
  20. Describe gantt syntax :active, a1, after des1, 3d
  21. Add gantt diagram to demo page :after a1 , 20h
  22. Add another diagram to demo page :doc1, after a1 , 48h
  23.  
  24. section Last section
  25. Describe gantt syntax :after doc1, 3d
  26. Add gantt diagram to demo page :20h
  27. Add another diagram to demo page :48h

若有收获,就赏束稻谷吧

14 颗稻谷