Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for PlantUML #3372

Merged
merged 2 commits into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Expand Up @@ -1027,6 +1027,11 @@
"modify": "php",
"owner": "milesj"
},
"plant-uml": {
"title": "PlantUML",
"alias": "plantuml",
"owner": "RunDevelopment"
},
"plsql": {
"title": "PL/SQL",
"require": "sql",
Expand Down
103 changes: 103 additions & 0 deletions components/prism-plant-uml.js
@@ -0,0 +1,103 @@
(function (Prism) {
var variable = /\$\w+|%[a-z]+%/;

var arrowAttr = /\[[^[\]]*\]/.source;
var arrowDirection = /(?:[drlu]|do|down|le|left|ri|right|up)/.source;
var arrowBody = '(?:-+' + arrowDirection + '-+|\\.+' + arrowDirection + '\\.+|-+(?:' + arrowAttr + '-*)?|' + arrowAttr + '-+|\\.+(?:' + arrowAttr + '\\.*)?|' + arrowAttr + '\\.+)';
var arrowLeft = /(?:<{1,2}|\/{1,2}|\\{1,2}|<\||[#*^+}xo])/.source;
var arrowRight = /(?:>{1,2}|\/{1,2}|\\{1,2}|\|>|[#*^+{xo])/.source;
var arrowPrefix = /[[?]?[ox]?/.source;
var arrowSuffix = /[ox]?[\]?]?/.source;
var arrow =
arrowPrefix +
'(?:' +
arrowBody + arrowRight +
'|' +
arrowLeft + arrowBody + '(?:' + arrowRight + ')?' +
')' +
arrowSuffix;

Prism.languages['plant-uml'] = {
'comment': {
pattern: /(^[ \t]*)(?:'.*|\/'[\s\S]*?'\/)/m,
lookbehind: true,
greedy: true
},
'preprocessor': {
pattern: /(^[ \t]*)!.*/m,
lookbehind: true,
greedy: true,
alias: 'property',
inside: {
'variable': variable
}
},
'delimiter': {
pattern: /(^[ \t]*)@(?:end|start)uml\b/m,
lookbehind: true,
greedy: true,
alias: 'punctuation'
},

'arrow': {
pattern: RegExp(/(^|[^-.<>?|\\[\]ox])/.source + arrow + /(?![-.<>?|\\\]ox])/.source),
lookbehind: true,
greedy: true,
alias: 'operator',
inside: {
'expression': {
pattern: /(\[)[^[\]]+(?=\])/,
lookbehind: true,
inside: null // see below
},
'punctuation': /\[(?=$|\])|^\]/
}
},

'string': {
pattern: /"[^"]*"/,
greedy: true
},
'text': {
pattern: /(\[[ \t]*[\r\n]+(?![\r\n]))[^\]]*(?=\])/,
lookbehind: true,
greedy: true,
alias: 'string'
},

'keyword': [
{
pattern: /^([ \t]*)(?:abstract\s+class|end\s+(?:box|fork|group|merge|note|ref|split|title)|(?:fork|split)(?:\s+again)?|activate|actor|agent|alt|annotation|artifact|autoactivate|autonumber|backward|binary|boundary|box|break|caption|card|case|circle|class|clock|cloud|collections|component|concise|control|create|critical|database|deactivate|destroy|detach|diamond|else|elseif|end|end[hr]note|endif|endswitch|endwhile|entity|enum|file|folder|footer|frame|group|[hr]?note|header|hexagon|hide|if|interface|label|legend|loop|map|namespace|network|newpage|node|nwdiag|object|opt|package|page|par|participant|person|queue|rectangle|ref|remove|repeat|restore|return|robust|scale|set|show|skinparam|stack|start|state|stop|storage|switch|title|together|usecase|usecase\/|while)(?=\s|$)/m,
lookbehind: true,
greedy: true
},
/\b(?:elseif|equals|not|while)(?=\s*\()/,
/\b(?:as|is|then)\b/
],

'divider': {
pattern: /^==.+==$/m,
greedy: true,
alias: 'important'
},

'time': {
pattern: /@(?:\d+(?:[:/]\d+){2}|[+-]?\d+|:[a-z]\w*(?:[+-]\d+)?)\b/i,
greedy: true,
alias: 'number'
},

'color': {
pattern: /#(?:[a-z_]+|[a-fA-F0-9]+)\b/,
alias: 'symbol'
},
'variable': variable,

'punctuation': /[:,;()[\]{}]|\.{3}/
};

Prism.languages['plant-uml'].arrow.inside.expression.inside = Prism.languages['plant-uml'];

Prism.languages['plantuml'] = Prism.languages['plant-uml'];

}(Prism));
1 change: 1 addition & 0 deletions components/prism-plant-uml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions examples/prism-plant-uml.html
@@ -0,0 +1,20 @@
<h2>Full example</h2>
<pre><code>' Source: https://plantuml.com/sequence-diagram
@startuml
participant Participant as Foo
actor Actor as Foo1
boundary Boundary as Foo2
control Control as Foo3
entity Entity as Foo4
database Database as Foo5
collections Collections as Foo6
queue Queue as Foo7
Foo -> Foo1 : To actor
Foo -> Foo2 : To boundary
Foo -> Foo3 : To control
Foo -> Foo4 : To entity
Foo -> Foo5 : To database
Foo -> Foo6 : To collections
Foo -> Foo7 : To queue
@enduml
</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Expand Up @@ -227,6 +227,7 @@
"objectpascal": "pascal",
"px": "pcaxis",
"pcode": "peoplecode",
"plantuml": "plant-uml",
"pq": "powerquery",
"mscript": "powerquery",
"pbfasm": "purebasic",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -187,6 +187,8 @@
"php": "PHP",
"phpdoc": "PHPDoc",
"php-extras": "PHP Extras",
"plant-uml": "PlantUML",
"plantuml": "PlantUML",
"plsql": "PL/SQL",
"powerquery": "PowerQuery",
"pq": "PowerQuery",
Expand Down