-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
mermaid.js
119 lines (118 loc) · 3.64 KB
/
mermaid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// @ts-nocheck
mermaid.displayName = 'mermaid'
mermaid.aliases = []
/** @type {import('../core.js').Syntax} */
export default function mermaid(Prism) {
Prism.languages.mermaid = {
comment: {
pattern: /%%.*/,
greedy: true
},
style: {
pattern:
/^([ \t]*(?:classDef|linkStyle|style)[ \t]+[\w$-]+[ \t]+)\w.*[^\s;]/m,
lookbehind: true,
inside: {
property: /\b\w[\w-]*(?=[ \t]*:)/,
operator: /:/,
punctuation: /,/
}
},
'inter-arrow-label': {
pattern:
/([^<>ox.=-])(?:-[-.]|==)(?![<>ox.=-])[ \t]*(?:"[^"\r\n]*"|[^\s".=-](?:[^\r\n.=-]*[^\s.=-])?)[ \t]*(?:\.+->?|--+[->]|==+[=>])(?![<>ox.=-])/,
lookbehind: true,
greedy: true,
inside: {
arrow: {
pattern: /(?:\.+->?|--+[->]|==+[=>])$/,
alias: 'operator'
},
label: {
pattern: /^([\s\S]{2}[ \t]*)\S(?:[\s\S]*\S)?/,
lookbehind: true,
alias: 'property'
},
'arrow-head': {
pattern: /^\S+/,
alias: ['arrow', 'operator']
}
}
},
arrow: [
// This might look complex but it really isn't.
// There are many possible arrows (see tests) and it's impossible to fit all of them into one pattern. The
// problem is that we only have one lookbehind per pattern. However, we cannot disallow too many arrow
// characters in the one lookbehind because that would create too many false negatives. So we have to split the
// arrows into different patterns.
{
// ER diagram
pattern: /(^|[^{}|o.-])[|}][|o](?:--|\.\.)[|o][|{](?![{}|o.-])/,
lookbehind: true,
alias: 'operator'
},
{
// flow chart
// (?:==+|--+|-\.*-)
pattern:
/(^|[^<>ox.=-])(?:[<ox](?:==+|--+|-\.*-)[>ox]?|(?:==+|--+|-\.*-)[>ox]|===+|---+|-\.+-)(?![<>ox.=-])/,
lookbehind: true,
alias: 'operator'
},
{
// sequence diagram
pattern:
/(^|[^<>()x-])(?:--?(?:>>|[x>)])(?![<>()x])|(?:<<|[x<(])--?(?!-))/,
lookbehind: true,
alias: 'operator'
},
{
// class diagram
pattern:
/(^|[^<>|*o.-])(?:[*o]--|--[*o]|<\|?(?:--|\.\.)|(?:--|\.\.)\|?>|--|\.\.)(?![<>|*o.-])/,
lookbehind: true,
alias: 'operator'
}
],
label: {
pattern: /(^|[^|<])\|(?:[^\r\n"|]|"[^"\r\n]*")+\|/,
lookbehind: true,
greedy: true,
alias: 'property'
},
text: {
pattern: /(?:[(\[{]+|\b>)(?:[^\r\n"()\[\]{}]|"[^"\r\n]*")+(?:[)\]}]+|>)/,
alias: 'string'
},
string: {
pattern: /"[^"\r\n]*"/,
greedy: true
},
annotation: {
pattern:
/<<(?:abstract|choice|enumeration|fork|interface|join|service)>>|\[\[(?:choice|fork|join)\]\]/i,
alias: 'important'
},
keyword: [
// This language has both case-sensitive and case-insensitive keywords
{
pattern:
/(^[ \t]*)(?:action|callback|class|classDef|classDiagram|click|direction|erDiagram|flowchart|gantt|gitGraph|graph|journey|link|linkStyle|pie|requirementDiagram|sequenceDiagram|stateDiagram|stateDiagram-v2|style|subgraph)(?![\w$-])/m,
lookbehind: true,
greedy: true
},
{
pattern:
/(^[ \t]*)(?:activate|alt|and|as|autonumber|deactivate|else|end(?:[ \t]+note)?|loop|opt|par|participant|rect|state|note[ \t]+(?:over|(?:left|right)[ \t]+of))(?![\w$-])/im,
lookbehind: true,
greedy: true
}
],
entity: /#[a-z0-9]+;/,
operator: {
pattern: /(\w[ \t]*)&(?=[ \t]*\w)|:::|:/,
lookbehind: true
},
punctuation: /[(){};]/
}
}