Skip to content

Commit 1f91868

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

17 files changed

+412
-3
lines changed

Diff for: components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: components.json

+6
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"

Diff for: components/prism-dot.js

+77
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+

Diff for: components/prism-dot.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/prism-dot.html

+31
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>

Diff for: plugins/autoloader/prism-autoloader.js

+1
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",

Diff for: plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: plugins/show-language/prism-show-language.js

+2
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",

0 commit comments

Comments
 (0)