Skip to content

Commit

Permalink
Add support for Velocity. Fix #1372 (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote authored Apr 11, 2018
1 parent 1bfc084 commit 5a524f7
Show file tree
Hide file tree
Showing 11 changed files with 739 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,11 @@
"require": "basic",
"owner": "Bigsby"
},
"velocity": {
"title": "Velocity",
"require": "markup",
"owner": "Golmote"
},
"verilog": {
"title": "Verilog",
"owner": "a-rey"
Expand Down
72 changes: 72 additions & 0 deletions components/prism-velocity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
(function (Prism) {
Prism.languages.velocity = Prism.languages.extend('markup', {});

var velocity = {
'variable': {
pattern: /(^|[^\\](?:\\\\)*)\$!?(?:[a-z][\w-]*(?:\([^)]*\))?(?:\.[a-z][\w-]*(?:\([^)]*\))?|\[[^\]]+])*|{[^}]+})/i,
lookbehind: true,
inside: {} // See below
},
'string': {
pattern: /"[^"]*"|'[^']*'/,
greedy: true
},
'number': /\b\d+\b/,
'boolean': /\b(?:true|false)\b/,
'operator': /[=!<>]=?|[+*/%-]|&&|\|\||\.\.|\b(?:eq|g[et]|l[et]|n(?:e|ot))\b/,
'punctuation': /[(){}[\]:,.]/
};

velocity.variable.inside = {
'string': velocity['string'],
'function': {
pattern: /([^\w-])[a-z][\w-]*(?=\()/,
lookbehind: true
},
'number': velocity['number'],
'boolean': velocity['boolean'],
'punctuation': velocity['punctuation']
};

Prism.languages.insertBefore('velocity', 'comment', {
'unparsed': {
pattern: /(^|[^\\])#\[\[[\s\S]*?]]#/,
lookbehind: true,
greedy: true,
inside: {
'punctuation': /^#\[\[|]]#$/
}
},
'velocity-comment': [
{
pattern: /(^|[^\\])#\*[\s\S]*?\*#/,
lookbehind: true,
greedy: true,
alias: 'comment'
},
{
pattern: /(^|[^\\])##.*/,
lookbehind: true,
greedy: true,
alias: 'comment'
}
],
'directive': {
pattern: /(^|[^\\](?:\\\\)*)#@?(?:[a-z][\w-]*|{[a-z][\w-]*})(?:\s*\((?:[^()]|\([^()]*\))*\))?/i,
lookbehind: true,
inside: {
keyword: {
pattern: /^#@?(?:[a-z][\w-]*|{[a-z][\w-]*})|\bin\b/,
inside: {
'punctuation': /[{}]/
}
},
rest: velocity
}
},
'variable': velocity['variable']
});

Prism.languages.velocity['tag'].inside['attr-value'].inside.rest = Prism.languages.velocity;

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

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

47 changes: 47 additions & 0 deletions examples/prism-velocity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<h2>Comments</h2>
<pre><code>## Single line comment
#* Multi-line
comment *#</code></pre>

<h2>Unparsed sections</h2>
<pre><code>## Section below is not parsed
#[[
## This is not a comment
]]#</code></pre>

<h2>Variables</h2>
<pre><code>$mud
$customer.Name
$flogger.getPromo( $mud )
$!{mudSlinger_9}
$foo[0]
$foo[$i]
$foo["bar"]
$foo.bar[1].junk
$foo.callMethod()[1]</code></pre>

<h2>Directives</h2>
<pre><code>#set($foo.bar[1] = 3)
#if($a==1)true enough#{else}no way!#end
#macro( d )
&lt;tr>&lt;td>$!bodyContent&lt;/td>&lt;/tr>
#end
#@d()Hello!#end</code></pre>

<h2>Integration with HTML</h2>
<pre><code>&lt;html>
&lt;body>
Hello $customer.Name!
&lt;table>
#foreach( $mud in $mudsOnSpecial )
#if ( $customer.hasPurchased($mud) )
&lt;tr>
&lt;td>
$flogger.getPromo( $mud )
&lt;/td>
&lt;/tr>
#end
#end
&lt;/table>
&lt;/body>
&lt;/html></code></pre>
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","vbnet":"basic","wiki":"markup","xeora":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup"}/*]*/;

var lang_data = {};

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.

Loading

0 comments on commit 5a524f7

Please sign in to comment.