Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f91868

Browse files
authoredJan 17, 2021
Added support for DOT (#2690)
1 parent 4e7b2a8 commit 1f91868

17 files changed

+412
-3
lines changed
 

‎components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@
322322
"alias": "dockerfile",
323323
"owner": "JustinBeckwith"
324324
},
325+
"dot": {
326+
"title": "DOT (Graphviz)",
327+
"alias": "gv",
328+
"optional": "markup",
329+
"owner": "RunDevelopment"
330+
},
325331
"ebnf": {
326332
"title": "EBNF",
327333
"owner": "RunDevelopment"

‎components/prism-dot.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// https://www.graphviz.org/doc/info/lang.html
2+
3+
(function (Prism) {
4+
5+
var ID = '(?:' + [
6+
// an identifier
7+
/[a-zA-Z_\x80-\uFFFF][\w\x80-\uFFFF]*/.source,
8+
// a number
9+
/-?(?:\.\d+|\d+(?:\.\d*)?)/.source,
10+
// a double-quoted string
11+
/"[^"\\]*(?:\\[\s\S][^"\\]*)*"/.source,
12+
// HTML-like string
13+
/<(?:[^<>]|(?!<!--)<(?:[^<>"']|"[^"]*"|'[^']*')+>|<!--(?:[^-]|-(?!->))*-->)*>/.source
14+
].join('|') + ')';
15+
16+
var IDInside = {
17+
'markup': {
18+
pattern: /(^<)[\s\S]+(?=>$)/,
19+
lookbehind: true,
20+
alias: ['language-markup', 'language-html', 'language-xml'],
21+
inside: Prism.languages.markup
22+
}
23+
};
24+
25+
/**
26+
* @param {string} source
27+
* @param {string} flags
28+
* @returns {RegExp}
29+
*/
30+
function withID(source, flags) {
31+
return RegExp(source.replace(/<ID>/g, function () { return ID; }), flags);
32+
}
33+
34+
Prism.languages.dot = {
35+
'comment': {
36+
pattern: /\/\/.*|\/\*[\s\S]*?\*\/|^#.*/m,
37+
greedy: true
38+
},
39+
'graph-name': {
40+
pattern: withID(/(\b(?:digraph|graph|subgraph)[ \t\r\n]+)<ID>/.source, 'i'),
41+
lookbehind: true,
42+
greedy: true,
43+
alias: 'class-name',
44+
inside: IDInside
45+
},
46+
'attr-value': {
47+
pattern: withID(/(=[ \t\r\n]*)<ID>/.source),
48+
lookbehind: true,
49+
greedy: true,
50+
inside: IDInside
51+
},
52+
'attr-name': {
53+
pattern: withID(/([\[;, \t\r\n])<ID>(?=[ \t\r\n]*=)/.source),
54+
lookbehind: true,
55+
greedy: true,
56+
inside: IDInside
57+
},
58+
'keyword': /\b(?:digraph|edge|graph|node|strict|subgraph)\b/i,
59+
'compass-point': {
60+
pattern: /(:[ \t\r\n]*)(?:[ns][ew]?|[ewc_])(?![\w\x80-\uFFFF])/,
61+
lookbehind: true,
62+
alias: 'builtin'
63+
},
64+
'node': {
65+
pattern: withID(/(^|[^-.\w\x80-\uFFFF\\])<ID>/.source),
66+
lookbehind: true,
67+
greedy: true,
68+
inside: IDInside
69+
},
70+
'operator': /[=:]|-[->]/,
71+
'punctuation': /[\[\]{};,]/
72+
};
73+
74+
Prism.languages.gv = Prism.languages.dot;
75+
76+
}(Prism));
77+

‎components/prism-dot.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-dot.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h2>Full example</h2>
2+
<pre><code>// source: http://www.ryandesign.com/canviz/graphs/dot/directed/ctext.gv.txt
3+
# Generated Tue Aug 21 10:21:21 GMT 2007 by dot - Graphviz version 2.15.20070819.0440 (Tue Aug 21 09:56:32 GMT 2007)
4+
#
5+
#
6+
# real 0m0.105s
7+
# user 0m0.076s
8+
# sys 0m0.022s
9+
10+
digraph G {
11+
node [label="\N"];
12+
graph [bb="0,0,352,238",
13+
_draw_="c 5 -white C 5 -white P 4 0 0 0 238 352 238 352 0 ",
14+
xdotversion="1.2"];
15+
xyz [label="hello\nworld", color=slateblue, fontsize=24, fontname="Palatino-Italic", style=filled, fontcolor=hotpink, pos="67,191", width="1.64", height="1.29", _draw_="S 6 -filled c 9 -slateblue C 9 -slateblue E 67 191 59 47 ", _ldraw_="F 24.000000 15 -Palatino-Italic c 7 -hotpink T 67 196 0 65 5 -hello F 24.000000 15 -Palatino-Italic c 7 -hotpink T 67 167 0 75 5\
16+
-world "];
17+
red [color=red, style=filled, pos="171,191", width="0.75", height="0.50", _draw_="S 6 -filled c 3 -red C 3 -red E 171 191 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 5 -black T 171 186 0 24 3 -red "];
18+
green [color=green, style=filled, pos="128,90", width="0.92", height="0.50", _draw_="S 6 -filled c 5 -green C 5 -green E 128 90 33 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 5 -black T 128 85 0 41 5 -green "];
19+
blue [color=blue, style=filled, fontcolor=black, pos="214,90", width="0.78", height="0.50", _draw_="S 6 -filled c 4 -blue C 4 -blue E 214 90 28 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 5 -black T 214 85 0 31 4 -blue "];
20+
cyan [color=cyan, style=filled, pos="214,18", width="0.83", height="0.50", _draw_="S 6 -filled c 4 -cyan C 4 -cyan E 214 18 30 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 5 -black T 214 13 0 34 4 -cyan "];
21+
magenta [color=magenta, style=filled, pos="307,18", width="1.25", height="0.50", _draw_="S 6 -filled c 7 -magenta C 7 -magenta E 307 18 45 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 5 -black T 307 13 0 64 7 -magenta "];
22+
yellow [color=yellow, style=filled, pos="36,18", width="1.00", height="0.50", _draw_="S 6 -filled c 6 -yellow C 6 -yellow E 36 18 36 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 5 -black T 36 13 0 47 6 -yellow "];
23+
orange [color=orange, style=filled, pos="128,18", width="1.06", height="0.50", _draw_="S 6 -filled c 6 -orange C 6 -orange E 128 18 38 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 5 -black T 128 13 0 51 6 -orange "];
24+
red -> green [pos="e,136,108 164,173 157,158 147,135 140,118", _draw_="c 5 -black B 4 164 173 157 158 147 135 140 118 ", _hdraw_="S 5 -solid S 15 -setlinewidth(1) c 5 -black C 5 -black P 3 143 116 136 108 136 119 "];
25+
red -> blue [pos="e,206,108 178,173 185,158 195,135 202,118", _draw_="c 5 -black B 4 178 173 185 158 195 135 202 118 ", _hdraw_="S 5 -solid S 15 -setlinewidth(1) c 5 -black C 5 -black P 3 206 119 206 108 199 116 "];
26+
blue -> cyan [pos="e,214,36 214,72 214,64 214,55 214,46", _draw_="c 5 -black B 4 214 72 214 64 214 55 214 46 ", _hdraw_="S 5 -solid S 15 -setlinewidth(1) c 5 -black C 5 -black P 3 218 46 214 36 211 46 "];
27+
blue -> magenta [pos="e,286,34 232,76 246,66 263,52 278,40", _draw_="c 5 -black B 4 232 76 246 66 263 52 278 40 ", _hdraw_="S 5 -solid S 15 -setlinewidth(1) c 5 -black C 5 -black P 3 280 43 286 34 276 37 "];
28+
green -> yellow [pos="e,56,33 109,75 96,65 78,51 64,40", _draw_="c 5 -black B 4 109 75 96 65 78 51 64 40 ", _hdraw_="S 5 -solid S 15 -setlinewidth(1) c 5 -black C 5 -black P 3 66 37 56 33 61 42 "];
29+
green -> orange [pos="e,128,36 128,72 128,64 128,55 128,46", _draw_="c 5 -black B 4 128 72 128 64 128 55 128 46 ", _hdraw_="S 5 -solid S 15 -setlinewidth(1) c 5 -black C 5 -black P 3 132 46 128 36 125 46 "];
30+
}
31+
</code></pre>

‎plugins/autoloader/prism-autoloader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
"jinja2": "django",
174174
"dns-zone": "dns-zone-file",
175175
"dockerfile": "docker",
176+
"gv": "dot",
176177
"eta": "ejs",
177178
"xlsx": "excel-formula",
178179
"xls": "excel-formula",

‎plugins/autoloader/prism-autoloader.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎plugins/show-language/prism-show-language.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
"dns-zone-file": "DNS zone file",
6161
"dns-zone": "DNS zone file",
6262
"dockerfile": "Docker",
63+
"dot": "DOT (Graphviz)",
64+
"gv": "DOT (Graphviz)",
6365
"ebnf": "EBNF",
6466
"editorconfig": "EditorConfig",
6567
"ejs": "EJS",

‎plugins/show-language/prism-show-language.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
[label=<
2+
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
3+
<TR><TD>left</TD><TD PORT="f1">mid dle</TD><TD PORT="f2">right</TD></TR>
4+
</TABLE>>]
5+
6+
----------------------------------------------------
7+
8+
[
9+
["punctuation", "["],
10+
["attr-name", ["label"]],
11+
["operator", "="],
12+
["attr-value", [
13+
"<",
14+
["markup", [
15+
["tag", [
16+
["tag", [
17+
["punctuation", "<"],
18+
"TABLE"
19+
]],
20+
["attr-name", ["BORDER"]],
21+
["attr-value", [
22+
["punctuation", "="],
23+
["punctuation", "\""],
24+
"0",
25+
["punctuation", "\""]
26+
]],
27+
["attr-name", ["CELLBORDER"]],
28+
["attr-value", [
29+
["punctuation", "="],
30+
["punctuation", "\""],
31+
"1",
32+
["punctuation", "\""]
33+
]],
34+
["attr-name", ["CELLSPACING"]],
35+
["attr-value", [
36+
["punctuation", "="],
37+
["punctuation", "\""],
38+
"0",
39+
["punctuation", "\""]
40+
]],
41+
["punctuation", ">"]
42+
]],
43+
44+
["tag", [
45+
["tag", [
46+
["punctuation", "<"],
47+
"TR"
48+
]],
49+
["punctuation", ">"]
50+
]],
51+
["tag", [
52+
["tag", [
53+
["punctuation", "<"],
54+
"TD"
55+
]],
56+
["punctuation", ">"]
57+
]],
58+
"left",
59+
["tag", [
60+
["tag", [
61+
["punctuation", "</"],
62+
"TD"
63+
]],
64+
["punctuation", ">"]
65+
]],
66+
["tag", [
67+
["tag", [
68+
["punctuation", "<"],
69+
"TD"
70+
]],
71+
["attr-name", ["PORT"]],
72+
["attr-value", [
73+
["punctuation", "="],
74+
["punctuation", "\""],
75+
"f1",
76+
["punctuation", "\""]
77+
]],
78+
["punctuation", ">"]
79+
]],
80+
"mid dle",
81+
["tag", [
82+
["tag", [
83+
["punctuation", "</"],
84+
"TD"
85+
]],
86+
["punctuation", ">"]
87+
]],
88+
["tag", [
89+
["tag", [
90+
["punctuation", "<"],
91+
"TD"
92+
]],
93+
["attr-name", ["PORT"]],
94+
["attr-value", [
95+
["punctuation", "="],
96+
["punctuation", "\""],
97+
"f2",
98+
["punctuation", "\""]
99+
]],
100+
["punctuation", ">"]
101+
]],
102+
"right",
103+
["tag", [
104+
["tag", [
105+
["punctuation", "</"],
106+
"TD"
107+
]],
108+
["punctuation", ">"]
109+
]],
110+
["tag", [
111+
["tag", [
112+
["punctuation", "</"],
113+
"TR"
114+
]],
115+
["punctuation", ">"]
116+
]],
117+
118+
["tag", [
119+
["tag", [
120+
["punctuation", "</"],
121+
"TABLE"
122+
]],
123+
["punctuation", ">"]
124+
]]
125+
]],
126+
">"
127+
]],
128+
["punctuation", "]"]
129+
]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[foo=bar]
2+
3+
[
4+
foo = 123;
5+
"graph" = "
6+
some
7+
value", 123 = bar baz = 123
8+
]
9+
10+
[label=<
11+
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
12+
<TR><TD>left</TD><TD PORT="f1">mid dle</TD><TD PORT="f2">right</TD></TR>
13+
</TABLE>>]
14+
15+
----------------------------------------------------
16+
17+
[
18+
["punctuation", "["],
19+
["attr-name", ["foo"]],
20+
["operator", "="],
21+
["attr-value", ["bar"]],
22+
["punctuation", "]"],
23+
24+
["punctuation", "["],
25+
26+
["attr-name", ["foo"]],
27+
["operator", "="],
28+
["attr-value", ["123"]],
29+
["punctuation", ";"],
30+
31+
["attr-name", ["\"graph\""]],
32+
["operator", "="],
33+
["attr-value", ["\"\r\nsome\r\nvalue\""]],
34+
["punctuation", ","],
35+
["attr-name", ["123"]],
36+
["operator", "="],
37+
["attr-value", ["bar"]],
38+
["attr-name", ["baz"]],
39+
["operator", "="],
40+
["attr-value", ["123"]],
41+
42+
["punctuation", "]"],
43+
44+
["punctuation", "["],
45+
["attr-name", ["label"]],
46+
["operator", "="],
47+
["attr-value", [
48+
"<",
49+
["markup", "\r\n<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">\r\n <TR><TD>left</TD><TD PORT=\"f1\">mid dle</TD><TD PORT=\"f2\">right</TD></TR>\r\n</TABLE>"],
50+
">"
51+
]],
52+
["punctuation", "]"]
53+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// comment
2+
/*
3+
comment
4+
*/
5+
6+
# not really a comment but ignored
7+
8+
----------------------------------------------------
9+
10+
[
11+
["comment", "// comment"],
12+
["comment", "/*\r\ncomment\r\n*/"],
13+
14+
["comment", "# not really a comment but ignored"]
15+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
graph ethane {}
2+
digraph foo {}
3+
subgraph bar {}
4+
5+
----------------------------------------------------
6+
7+
[
8+
["keyword", "graph"],
9+
["graph-name", ["ethane"]],
10+
["punctuation", "{"],
11+
["punctuation", "}"],
12+
13+
["keyword", "digraph"],
14+
["graph-name", ["foo"]],
15+
["punctuation", "{"],
16+
["punctuation", "}"],
17+
18+
["keyword", "subgraph"],
19+
["graph-name", ["bar"]],
20+
["punctuation", "{"],
21+
["punctuation", "}"]
22+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
digraph;
2+
edge;
3+
graph;
4+
node;
5+
strict;
6+
subgraph;
7+
8+
----------------------------------------------------
9+
10+
[
11+
["keyword", "digraph"], ["punctuation", ";"],
12+
["keyword", "edge"], ["punctuation", ";"],
13+
["keyword", "graph"], ["punctuation", ";"],
14+
["keyword", "node"], ["punctuation", ";"],
15+
["keyword", "strict"], ["punctuation", ";"],
16+
["keyword", "subgraph"], ["punctuation", ";"]
17+
]

‎tests/languages/dot/node_feature.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
struct1:f1 -> struct2:f0;
2+
struct1:f2 -> struct3:here;
3+
4+
A:ne -> B:sw
5+
6+
----------------------------------------------------
7+
8+
[
9+
["node", ["struct1"]],
10+
["operator", ":"],
11+
["node", ["f1"]],
12+
["operator", "->"],
13+
["node", ["struct2"]],
14+
["operator", ":"],
15+
["node", ["f0"]],
16+
["punctuation", ";"],
17+
18+
["node", ["struct1"]],
19+
["operator", ":"],
20+
["node", ["f2"]],
21+
["operator", "->"],
22+
["node", ["struct3"]],
23+
["operator", ":"],
24+
["node", ["here"]],
25+
["punctuation", ";"],
26+
27+
["node", ["A"]],
28+
["operator", ":"],
29+
["compass-point", "ne"],
30+
["operator", "->"],
31+
["node", ["B"]],
32+
["operator", ":"],
33+
["compass-point", "sw"]
34+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- ->
2+
= :
3+
4+
----------------------------------------------------
5+
6+
[
7+
["operator", "--"], ["operator", "->"],
8+
["operator", "="], ["operator", ":"]
9+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[ ] { } ; ,
2+
3+
----------------------------------------------------
4+
5+
[
6+
["punctuation", "["],
7+
["punctuation", "]"],
8+
["punctuation", "{"],
9+
["punctuation", "}"],
10+
["punctuation", ";"],
11+
["punctuation", ","]
12+
]

0 commit comments

Comments
 (0)
Please sign in to comment.