Skip to content

Commit e9fdf33

Browse files
authored
Merge pull request #5 from hackmdio/add-plantuml
Add plantuml language mode
2 parents faf54b1 + e1e53ba commit e9fdf33

File tree

6 files changed

+198
-0
lines changed

6 files changed

+198
-0
lines changed

mode/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ <h2>Language modes</h2>
110110
<li><a href="pug/index.html">Pug</a></li>
111111
<li><a href="puppet/index.html">Puppet</a></li>
112112
<li><a href="python/index.html">Python</a></li>
113+
<li><a href="plantuml/index.html">PlantUML</a></li>
113114
<li><a href="q/index.html">Q</a></li>
114115
<li><a href="r/index.html">R</a></li>
115116
<li><a href="rpm/index.html">RPM</a></li>

mode/meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
{name: "ProtoBuf", mime: "text/x-protobuf", mode: "protobuf", ext: ["proto"]},
113113
{name: "Python", mime: "text/x-python", mode: "python", ext: ["BUILD", "bzl", "py", "pyw"], file: /^(BUCK|BUILD)$/},
114114
{name: "Puppet", mime: "text/x-puppet", mode: "puppet", ext: ["pp"]},
115+
{name: "PlantUML", mime: "text/x-plantuml", mode: "plantuml"},
115116
{name: "Q", mime: "text/x-q", mode: "q", ext: ["q"]},
116117
{name: "R", mime: "text/x-rsrc", mode: "r", ext: ["r", "R"], alias: ["rscript"]},
117118
{name: "reStructuredText", mime: "text/x-rst", mode: "rst", ext: ["rst"], alias: ["rst"]},

mode/plantuml/index.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!doctype html>
2+
<title>CodeMirror: Pig Latin mode</title>
3+
<meta charset="utf-8"/>
4+
<link rel=stylesheet href="../../doc/docs.css">
5+
6+
<link rel="stylesheet" href="../../lib/codemirror.css">
7+
<script src="../../lib/codemirror.js"></script>
8+
<script src="../../addon/mode/simple.js"></script>
9+
<script src="plantuml.js"></script>
10+
<style>.CodeMirror {border: 2px inset #dee;}</style>
11+
<div id=nav>
12+
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
13+
14+
<ul>
15+
<li><a href="../../index.html">Home</a>
16+
<li><a href="../../doc/manual.html">Manual</a>
17+
<li><a href="https://github.com/codemirror/codemirror">Code</a>
18+
</ul>
19+
<ul>
20+
<li><a href="../index.html">Language modes</a>
21+
<li><a class=active href="#">PlantUML</a>
22+
</ul>
23+
</div>
24+
25+
<article>
26+
<h2>PlantUML mode</h2>
27+
<form><textarea id="code" name="code">
28+
start
29+
if (condition A) then (yes)
30+
:Text 1;
31+
elseif (condition B) then (yes)
32+
:Text 2;
33+
stop
34+
elseif (condition C) then (yes)
35+
:Text 3;
36+
elseif (condition D) then (yes)
37+
:Text 4;
38+
else (nothing)
39+
:Text else;
40+
endif
41+
stop
42+
</textarea></form>
43+
44+
<script>
45+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
46+
lineNumbers: true,
47+
indentUnit: 4,
48+
mode: "plantuml"
49+
});
50+
</script>
51+
52+
<p>
53+
Simple mode that handles PlantUML language.
54+
</p>
55+
56+
<p><strong>MIME type defined:</strong> <code>text/plantuml</code>
57+
(PlantUML)
58+
</article>

mode/plantuml/plantuml.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* PlantUML Mode for CodeMirror
3+
* @author keisuke kimura https://github.com/kkeisuke
4+
* @link https://github.com/kkeisuke/plantuml-editor/blob/master/src/lib/codemirror/mode/plantuml/plantuml.js
5+
*/
6+
(function(mod) {
7+
if (typeof exports == "object" && typeof module == "object") // CommonJS
8+
mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
9+
else if (typeof define == "function" && define.amd) // AMD
10+
define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
11+
else // Plain browser env
12+
mod(CodeMirror);
13+
})(function(CodeMirror) {
14+
CodeMirror.defineSimpleMode('plantuml', {
15+
start: [
16+
// シングルライン コメント
17+
// TODO ^ が効かない
18+
{
19+
regex: /^'.*/,
20+
token: 'comment'
21+
},
22+
// ダブルコーテーション付の文字列
23+
{
24+
regex: /"(?:[^\\]|\\.)*?(?:"|$)/,
25+
token: 'string'
26+
},
27+
// {
28+
// regex: /@enduml|@startuml/,
29+
// token: 'keyword'
30+
// },
31+
{
32+
regex: /\b(abstract|actor|agent|class|component|database|enum|interface|node|note|object|participant|partition|rectangle|state|static|storage|usecase)\b/,
33+
token: 'keyword'
34+
},
35+
{
36+
regex: /\b(true|false)\b/,
37+
token: 'keyword'
38+
},
39+
{
40+
regex: /\b(activate|again|allow_mixing|also|alt|as|autonumber|bottom|box|break|caption|center|create|critical|deactivate|destroy|direction|down|else|end|endfooter|endheader|endif|endlegend|endwhile|entity|footbox|footer|fork|group)\b/,
41+
token: 'atom'
42+
},
43+
{
44+
regex: /\b(header|hide|if|is|left|legend|link|loop|namespace|newpage|of|on|opt|over|package|page|par|ref|repeat|return|right|rotate|scale|show|skin|skinparam|start|stop|title|then|top|up|while)\b/,
45+
token: 'atom'
46+
},
47+
{
48+
regex: /!define/,
49+
token: 'atom'
50+
},
51+
{
52+
regex: /(AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGreen|DarkGrey|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkSlateGrey|DarkTurquoise|DarkViolet|Darkorange|DeepPink|DeepSkyBlue|DimGray|DimGrey|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gray|Green|GreenYellow|Grey|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGreen|LightGrey|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSlateGrey|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|SlateGrey|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)/,
53+
token: 'variable-3'
54+
},
55+
// 単語
56+
{
57+
regex: /[a-zA-Z$][\w$]*/,
58+
token: 'variable'
59+
},
60+
// -->
61+
// TODO 旧アクティビティ図対応のため、\s を先頭に付けていない。
62+
{
63+
regex: /-+(up|right|down|left)*-*[|]?[>*o]*\s/,
64+
token: 'variable-2'
65+
},
66+
// ..>
67+
{
68+
regex: /\s\.+(up|right|down|left)*\.*[|]?[>*o]*\s/,
69+
token: 'variable-2'
70+
},
71+
// <--
72+
{
73+
regex: /\s[<*o]*[|]?-+(up|right|down|left)*-*\s/,
74+
token: 'variable-2'
75+
},
76+
// <..
77+
{
78+
regex: /\s[<*o]*[|]?\.+(up|right|down|left)*\.*\s/,
79+
token: 'variable-2'
80+
},
81+
// 記号
82+
{
83+
regex: /(<<|>>|:|;|\\n)/,
84+
token: 'variable-2'
85+
},
86+
// Public メソッド
87+
{
88+
regex: /\+[^(]+\(\)/,
89+
token: 'variable-2'
90+
},
91+
// Private メソッド
92+
{
93+
regex: /-[^(]+\(\)/,
94+
token: 'variable-2'
95+
},
96+
// Protected メソッド
97+
{
98+
regex: /#[^(]+\(\)/,
99+
token: 'variable-2'
100+
},
101+
// Activity β タイトル
102+
// TODO ER図と重複してしまう
103+
// {
104+
// regex: /\|[^|#]+\|/,
105+
// token: 'variable-2'
106+
// },
107+
// {} 内のインデントを揃える
108+
{
109+
regex: /[{[(]/,
110+
indent: true
111+
},
112+
{
113+
regex: /[}\])]/,
114+
dedent: true
115+
},
116+
// 複数行のコメント
117+
{
118+
regex: /\/'/,
119+
token: 'comment',
120+
next: 'comment'
121+
}
122+
],
123+
// 複数行のコメント
124+
comment: [
125+
{
126+
regex: /.*?'\//,
127+
token: 'comment',
128+
next: 'start'
129+
},
130+
{
131+
regex: /.*/,
132+
token: 'comment'
133+
}
134+
]
135+
})
136+
})

release.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mode\clojure\clojure.js ^
4444
mode\ruby\ruby.js ^
4545
mode\rust\rust.js ^
4646
mode\python\python.js ^
47+
mode\plantuml\plantuml.js ^
4748
mode\shell\shell.js ^
4849
mode\php\php.js ^
4950
mode\sas\sas.js ^

release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ mode/diff/diff.js \
5353
mode/ruby/ruby.js \
5454
mode/rust/rust.js \
5555
mode/python/python.js \
56+
mode/plantuml/plantuml.js \
5657
mode/shell/shell.js \
5758
mode/php/php.js \
5859
mode/sas/sas.js \

0 commit comments

Comments
 (0)