Skip to content

Commit

Permalink
Merge pull request #5 from hackmdio/add-plantuml
Browse files Browse the repository at this point in the history
Add plantuml language mode
  • Loading branch information
jackycute authored Feb 29, 2020
2 parents faf54b1 + e1e53ba commit e9fdf33
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 0 deletions.
1 change: 1 addition & 0 deletions mode/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ <h2>Language modes</h2>
<li><a href="pug/index.html">Pug</a></li>
<li><a href="puppet/index.html">Puppet</a></li>
<li><a href="python/index.html">Python</a></li>
<li><a href="plantuml/index.html">PlantUML</a></li>
<li><a href="q/index.html">Q</a></li>
<li><a href="r/index.html">R</a></li>
<li><a href="rpm/index.html">RPM</a></li>
Expand Down
1 change: 1 addition & 0 deletions mode/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
{name: "ProtoBuf", mime: "text/x-protobuf", mode: "protobuf", ext: ["proto"]},
{name: "Python", mime: "text/x-python", mode: "python", ext: ["BUILD", "bzl", "py", "pyw"], file: /^(BUCK|BUILD)$/},
{name: "Puppet", mime: "text/x-puppet", mode: "puppet", ext: ["pp"]},
{name: "PlantUML", mime: "text/x-plantuml", mode: "plantuml"},
{name: "Q", mime: "text/x-q", mode: "q", ext: ["q"]},
{name: "R", mime: "text/x-rsrc", mode: "r", ext: ["r", "R"], alias: ["rscript"]},
{name: "reStructuredText", mime: "text/x-rst", mode: "rst", ext: ["rst"], alias: ["rst"]},
Expand Down
58 changes: 58 additions & 0 deletions mode/plantuml/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!doctype html>
<title>CodeMirror: Pig Latin mode</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../../doc/docs.css">

<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="../../addon/mode/simple.js"></script>
<script src="plantuml.js"></script>
<style>.CodeMirror {border: 2px inset #dee;}</style>
<div id=nav>
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>

<ul>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul>
<ul>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">PlantUML</a>
</ul>
</div>

<article>
<h2>PlantUML mode</h2>
<form><textarea id="code" name="code">
start
if (condition A) then (yes)
:Text 1;
elseif (condition B) then (yes)
:Text 2;
stop
elseif (condition C) then (yes)
:Text 3;
elseif (condition D) then (yes)
:Text 4;
else (nothing)
:Text else;
endif
stop
</textarea></form>

<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
indentUnit: 4,
mode: "plantuml"
});
</script>

<p>
Simple mode that handles PlantUML language.
</p>

<p><strong>MIME type defined:</strong> <code>text/plantuml</code>
(PlantUML)
</article>
136 changes: 136 additions & 0 deletions mode/plantuml/plantuml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* PlantUML Mode for CodeMirror
* @author keisuke kimura https://github.com/kkeisuke
* @link https://github.com/kkeisuke/plantuml-editor/blob/master/src/lib/codemirror/mode/plantuml/plantuml.js
*/
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
CodeMirror.defineSimpleMode('plantuml', {
start: [
// シングルライン コメント
// TODO ^ が効かない
{
regex: /^'.*/,
token: 'comment'
},
// ダブルコーテーション付の文字列
{
regex: /"(?:[^\\]|\\.)*?(?:"|$)/,
token: 'string'
},
// {
// regex: /@enduml|@startuml/,
// token: 'keyword'
// },
{
regex: /\b(abstract|actor|agent|class|component|database|enum|interface|node|note|object|participant|partition|rectangle|state|static|storage|usecase)\b/,
token: 'keyword'
},
{
regex: /\b(true|false)\b/,
token: 'keyword'
},
{
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/,
token: 'atom'
},
{
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/,
token: 'atom'
},
{
regex: /!define/,
token: 'atom'
},
{
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)/,
token: 'variable-3'
},
// 単語
{
regex: /[a-zA-Z$][\w$]*/,
token: 'variable'
},
// -->
// TODO 旧アクティビティ図対応のため、\s を先頭に付けていない。
{
regex: /-+(up|right|down|left)*-*[|]?[>*o]*\s/,
token: 'variable-2'
},
// ..>
{
regex: /\s\.+(up|right|down|left)*\.*[|]?[>*o]*\s/,
token: 'variable-2'
},
// <--
{
regex: /\s[<*o]*[|]?-+(up|right|down|left)*-*\s/,
token: 'variable-2'
},
// <..
{
regex: /\s[<*o]*[|]?\.+(up|right|down|left)*\.*\s/,
token: 'variable-2'
},
// 記号
{
regex: /(<<|>>|:|;|\\n)/,
token: 'variable-2'
},
// Public メソッド
{
regex: /\+[^(]+\(\)/,
token: 'variable-2'
},
// Private メソッド
{
regex: /-[^(]+\(\)/,
token: 'variable-2'
},
// Protected メソッド
{
regex: /#[^(]+\(\)/,
token: 'variable-2'
},
// Activity β タイトル
// TODO ER図と重複してしまう
// {
// regex: /\|[^|#]+\|/,
// token: 'variable-2'
// },
// {} 内のインデントを揃える
{
regex: /[{[(]/,
indent: true
},
{
regex: /[}\])]/,
dedent: true
},
// 複数行のコメント
{
regex: /\/'/,
token: 'comment',
next: 'comment'
}
],
// 複数行のコメント
comment: [
{
regex: /.*?'\//,
token: 'comment',
next: 'start'
},
{
regex: /.*/,
token: 'comment'
}
]
})
})
1 change: 1 addition & 0 deletions release.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mode\clojure\clojure.js ^
mode\ruby\ruby.js ^
mode\rust\rust.js ^
mode\python\python.js ^
mode\plantuml\plantuml.js ^
mode\shell\shell.js ^
mode\php\php.js ^
mode\sas\sas.js ^
Expand Down
1 change: 1 addition & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ mode/diff/diff.js \
mode/ruby/ruby.js \
mode/rust/rust.js \
mode/python/python.js \
mode/plantuml/plantuml.js \
mode/shell/shell.js \
mode/php/php.js \
mode/sas/sas.js \
Expand Down

0 comments on commit e9fdf33

Please sign in to comment.