Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language support for Mermaid diagrams #6134

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@
[submodule "vendor/grammars/language-mcfunction"]
path = vendor/grammars/language-mcfunction
url = https://github.com/Arcensoth/language-mcfunction
[submodule "vendor/grammars/language-mermaid"]
path = vendor/grammars/language-mermaid
url = https://github.com/Alhadis/language-mermaid.git
[submodule "vendor/grammars/language-meson"]
path = vendor/grammars/language-meson
url = https://github.com/TingPing/language-meson
Expand Down
13 changes: 13 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,19 @@ vendor/grammars/language-maxscript:
vendor/grammars/language-mcfunction:
- markdown.mcfunction.codeblock
- source.mcfunction
vendor/grammars/language-mermaid:
- source.mermaid
- source.mermaid.c4c-diagram
- source.mermaid.class-diagram
- source.mermaid.er-diagram
- source.mermaid.flowchart
- source.mermaid.gantt
- source.mermaid.gitgraph
- source.mermaid.pie-chart
- source.mermaid.requirement-diagram
- source.mermaid.sequence-diagram
- source.mermaid.state-diagram
- source.mermaid.user-journey
vendor/grammars/language-meson:
- source.meson
vendor/grammars/language-msl:
Expand Down
17 changes: 14 additions & 3 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3959,6 +3959,17 @@ Mercury:
- ".moo"
tm_scope: source.mercury
language_id: 229
Mermaid:
type: markup
color: "#ff3670"
aliases:
- mermaid example
extensions:
- ".mmd"
- ".mermaid"
tm_scope: source.mermaid
ace_mode: text
language_id: 385992043
Meson:
type: programming
color: "#007800"
Expand Down Expand Up @@ -4575,15 +4586,15 @@ Open Policy Agent:
tm_scope: source.rego
OpenAPI Specification v2:
aliases:
- oasv2
- oasv2
type: data
color: "#85ea2d"
tm_scope: none
ace_mode: text
language_id: 848295328
OpenAPI Specification v3:
aliases:
- oasv3
- oasv3
type: data
color: "#85ea2d"
tm_scope: none
Expand Down Expand Up @@ -4919,7 +4930,7 @@ Perl:
- ".psgi"
- ".t"
filenames:
- .latexmkrc
- ".latexmkrc"
- Makefile.PL
- Rexfile
- ack
Expand Down
42 changes: 42 additions & 0 deletions samples/Mermaid/c4c-diagram.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
C4Context
title System Context diagram for Internet Banking System
Enterprise_Boundary(b0, "BankBoundary0") {
Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
Person(customerB, "Banking Customer B")
Person_Ext(customerC, "Banking Customer C", "desc")

Person(customerD, "Banking Customer D", "A customer of the bank, <br/> with personal bank accounts.")

System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")

Enterprise_Boundary(b1, "BankBoundary") {

SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")

System_Boundary(b2, "BankBoundary2") {
System(SystemA, "Banking System A")
System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts. next line.")
}

System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")
SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.")

Boundary(b3, "BankBoundary3", "boundary") {
SystemQueue(SystemF, "Banking System F Queue", "A system of the bank.")
SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")
}
}
}

BiRel(customerA, SystemAA, "Uses")
BiRel(SystemAA, SystemE, "Uses")
Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")
Rel(SystemC, customerA, "Sends e-mails to")

UpdateElementStyle(customerA, $fontColor="red", $bgColor="grey", $borderColor="red")
UpdateRelStyle(customerA, SystemAA, $textColor="blue", $lineColor="blue", $offsetX="5")
UpdateRelStyle(SystemAA, SystemE, $textColor="blue", $lineColor="blue", $offsetY="-10")
UpdateRelStyle(SystemAA, SystemC, $textColor="blue", $lineColor="blue", $offsetY="-40", $offsetX="-50")
UpdateRelStyle(SystemC, customerA, $textColor="red", $lineColor="red", $offsetX="-50", $offsetY="20")

UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")
24 changes: 24 additions & 0 deletions samples/Mermaid/class-diagram.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish {
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}

callback Duck callback "Tooltip"
link Zebra "https://www.github.com" "This is a link"
15 changes: 15 additions & 0 deletions samples/Mermaid/er-diagram.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
erDiagram
CAR ||--o{ NAMED-DRIVER : allows
CAR {
string allowedDriver FK "The license of the allowed driver"
string registrationNumber
string make
string model
}
PERSON ||--o{ NAMED-DRIVER : is
PERSON {
string driversLicense PK "The license #"
string firstName
string lastName
int age
}
5 changes: 5 additions & 0 deletions samples/Mermaid/flowchart.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flowchart LR
A[Hard edge] -->|Link text| B(Round edge)
B --> C{Decision}
C -->|One| D[Result one]
C -->|Two| E[Result two]
37 changes: 37 additions & 0 deletions samples/Mermaid/gantt.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
gantt
dateFormat YYYY-MM-DD %% Comment
title Adding Gantt diagram functionality to Mermaid

%% `excludes` accepts specific dates in YYYY-MM-DD format, days of
%% the week ("sunday") or "weekends", but not the word "weekdays".
excludes weekends

todayMarker stroke-width:5px,stroke:#0f0,opacity:0.5
todayMarker off
inclusiveEndDates
topAxis

section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
Future task : des3, after des2, 5d
Future task2 : des4, after des3, 5d

section Critical tasks
Completed task in the critical line :crit, done, 2014-01-06,24h
Implement parser and jison :crit, done, after des1, 2d
Create tests for parser :crit, active, 3d
Future task in critical line :crit, 5d
Create tests for renderer :2d
Add to mermaid :1d
Functionality added :milestone, 2014-01-25, 0d

section Documentation
Describe Gantt syntax :active, a1, after des1, 3d
Add gantt diagram to demo page :after a1 , 20h
Add another diagram to demo page :doc1, after a1 , 48h

section Last section
Describe Gantt syntax :after doc1, 3d
Add gantt diagram to demo page :20h
Add another diagram to demo page :48h
17 changes: 17 additions & 0 deletions samples/Mermaid/gitgraph.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': {
'tagLabelColor': '#ff0000',
'tagLabelBackground': '#00ff00',
'tagLabelBorder': '#0000ff'
}}}%%
gitGraph
commit
branch develop
commit tag:"v1.0.0"
commit
checkout main
commit type: HIGHLIGHT
commit
merge develop
commit
branch featureA
commit
13 changes: 13 additions & 0 deletions samples/Mermaid/pie-chart.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pie showData
title Alhadis's ancestry composition, according to 23andme.com

%% NB: Values are expressed as percentages
"British & Irish" : 44.8
"French & German" : 7.3
"Scandinavian" : 1.8
"Broadly Northwestern European" : 12.5
"Eastern European" : 16.2
"Greek & Balkan": 8.0
"Italian" : 2.0
"Broadly Southern European": 2.2
"Broadly European": 5.2
71 changes: 71 additions & 0 deletions samples/Mermaid/requirement-diagram.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
requirementDiagram
%% Obligatory comment

requirement test_req {
%% Comment
id: 1
text: the test text.
risk: high
verifymethod: test
}

functionalRequirement test_req2 {
id: 1.1
text: the second test text.
risk: low
verifymethod: inspection
}

performanceRequirement test_req3 {
id: 1.2
text: the third test text.
risk: medium
verifymethod: demonstration
}

interfaceRequirement test_req4 {
id: 1.2.1
text: the fourth test text.
risk: medium
verifymethod: analysis
}

physicalRequirement test_req5 {
id: 1.2.2
text: the fifth test text.
risk: medium
verifyMethod: analysis
}

designConstraint test_req6 {
id: 1.2.3
text: the sixth test text.
risk: medium
verifymethod: analysis
}

element test_entity {
%% Another comment
type: simulation
}

element test_entity2 {
type: word doc
docRef: reqs/test_entity
}

element test_entity3 {
type: "test suite"
docRef: github.com/all_the_tests
}


test_entity - satisfies -> test_req2
test_req - traces -> test_req2
test_req - contains -> test_req3
test_req3 - contains -> test_req4
test_req4 - derives -> test_req5
test_req5 - refines -> test_req6
test_entity3 - verifies -> test_req5
test_req <- copies - test_entity2
not - traumatises -> valid
8 changes: 8 additions & 0 deletions samples/Mermaid/sequence-diagram.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sequenceDiagram
participant Alice
participant John
links Alice: {"Dashboard": "https://dashboard.contoso.com/alice", "Wiki": "https://wiki.contoso.com/alice"}
links John: {"Dashboard": "https://dashboard.contoso.com/john", "Wiki": "https://wiki.contoso.com/john"}
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
Alice-)John: See you later!
17 changes: 17 additions & 0 deletions samples/Mermaid/state-diagram.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
stateDiagram-v2
direction LR
[*] --> Active

state Active {
[*] --> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] --> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] --> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvScrollLockPressed
ScrollLockOn --> ScrollLockOff : EvScrollLockPressed
}
9 changes: 9 additions & 0 deletions samples/Mermaid/user-journey.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Maven POM:** [textmate/maven.tmbundle](https://github.com/textmate/maven.tmbundle)
- **Max:** [Nixinova/NovaGrammars](https://github.com/Nixinova/NovaGrammars)
- **Mercury:** [sebgod/mercury-tmlanguage](https://github.com/sebgod/mercury-tmlanguage)
- **Mermaid:** [Alhadis/language-mermaid](https://github.com/Alhadis/language-mermaid)
- **Meson:** [TingPing/language-meson](https://github.com/TingPing/language-meson)
- **Metal:** [textmate/c.tmbundle](https://github.com/textmate/c.tmbundle)
- **Microsoft Visual Studio Solution:** [Nixinova/NovaGrammars](https://github.com/Nixinova/NovaGrammars)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/language-mermaid
Submodule language-mermaid added at 1cd199
23 changes: 23 additions & 0 deletions vendor/licenses/git_submodule/language-mermaid.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: language-mermaid
version: 1cd1997642b11a551bc415e8833f33c55850158f
type: git_submodule
homepage: https://github.com/Alhadis/language-mermaid.git
license: isc
licenses:
- sources: LICENSE.md
text: |
Copyright (c) 2022, John Gardner

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
notices: []