source: node_modules/refractor/lang/mermaid.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 3.6 KB
Line 
1'use strict'
2
3module.exports = mermaid
4mermaid.displayName = 'mermaid'
5mermaid.aliases = []
6function mermaid(Prism) {
7 Prism.languages.mermaid = {
8 comment: {
9 pattern: /%%.*/,
10 greedy: true
11 },
12 style: {
13 pattern:
14 /^([ \t]*(?:classDef|linkStyle|style)[ \t]+[\w$-]+[ \t]+)\w.*[^\s;]/m,
15 lookbehind: true,
16 inside: {
17 property: /\b\w[\w-]*(?=[ \t]*:)/,
18 operator: /:/,
19 punctuation: /,/
20 }
21 },
22 'inter-arrow-label': {
23 pattern:
24 /([^<>ox.=-])(?:-[-.]|==)(?![<>ox.=-])[ \t]*(?:"[^"\r\n]*"|[^\s".=-](?:[^\r\n.=-]*[^\s.=-])?)[ \t]*(?:\.+->?|--+[->]|==+[=>])(?![<>ox.=-])/,
25 lookbehind: true,
26 greedy: true,
27 inside: {
28 arrow: {
29 pattern: /(?:\.+->?|--+[->]|==+[=>])$/,
30 alias: 'operator'
31 },
32 label: {
33 pattern: /^([\s\S]{2}[ \t]*)\S(?:[\s\S]*\S)?/,
34 lookbehind: true,
35 alias: 'property'
36 },
37 'arrow-head': {
38 pattern: /^\S+/,
39 alias: ['arrow', 'operator']
40 }
41 }
42 },
43 arrow: [
44 // This might look complex but it really isn't.
45 // There are many possible arrows (see tests) and it's impossible to fit all of them into one pattern. The
46 // problem is that we only have one lookbehind per pattern. However, we cannot disallow too many arrow
47 // characters in the one lookbehind because that would create too many false negatives. So we have to split the
48 // arrows into different patterns.
49 {
50 // ER diagram
51 pattern: /(^|[^{}|o.-])[|}][|o](?:--|\.\.)[|o][|{](?![{}|o.-])/,
52 lookbehind: true,
53 alias: 'operator'
54 },
55 {
56 // flow chart
57 // (?:==+|--+|-\.*-)
58 pattern:
59 /(^|[^<>ox.=-])(?:[<ox](?:==+|--+|-\.*-)[>ox]?|(?:==+|--+|-\.*-)[>ox]|===+|---+|-\.+-)(?![<>ox.=-])/,
60 lookbehind: true,
61 alias: 'operator'
62 },
63 {
64 // sequence diagram
65 pattern:
66 /(^|[^<>()x-])(?:--?(?:>>|[x>)])(?![<>()x])|(?:<<|[x<(])--?(?!-))/,
67 lookbehind: true,
68 alias: 'operator'
69 },
70 {
71 // class diagram
72 pattern:
73 /(^|[^<>|*o.-])(?:[*o]--|--[*o]|<\|?(?:--|\.\.)|(?:--|\.\.)\|?>|--|\.\.)(?![<>|*o.-])/,
74 lookbehind: true,
75 alias: 'operator'
76 }
77 ],
78 label: {
79 pattern: /(^|[^|<])\|(?:[^\r\n"|]|"[^"\r\n]*")+\|/,
80 lookbehind: true,
81 greedy: true,
82 alias: 'property'
83 },
84 text: {
85 pattern: /(?:[(\[{]+|\b>)(?:[^\r\n"()\[\]{}]|"[^"\r\n]*")+(?:[)\]}]+|>)/,
86 alias: 'string'
87 },
88 string: {
89 pattern: /"[^"\r\n]*"/,
90 greedy: true
91 },
92 annotation: {
93 pattern:
94 /<<(?:abstract|choice|enumeration|fork|interface|join|service)>>|\[\[(?:choice|fork|join)\]\]/i,
95 alias: 'important'
96 },
97 keyword: [
98 // This language has both case-sensitive and case-insensitive keywords
99 {
100 pattern:
101 /(^[ \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,
102 lookbehind: true,
103 greedy: true
104 },
105 {
106 pattern:
107 /(^[ \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,
108 lookbehind: true,
109 greedy: true
110 }
111 ],
112 entity: /#[a-z0-9]+;/,
113 operator: {
114 pattern: /(\w[ \t]*)&(?=[ \t]*\w)|:::|:/,
115 lookbehind: true
116 },
117 punctuation: /[(){};]/
118 }
119}
Note: See TracBrowser for help on using the repository browser.