Handlebars: support blocks with dashes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/components/prism-handlebars.js b/components/prism-handlebars.js
index 3154940..00fe771 100644
--- a/components/prism-handlebars.js
+++ b/components/prism-handlebars.js
@@ -1,7 +1,7 @@
(function(Prism) {
var handlebars_pattern = /\{\{\{[\w\W]+?\}\}\}|\{\{[\w\W]+?\}\}/g;
-
+
Prism.languages.handlebars = Prism.languages.extend('markup', {
'handlebars': {
pattern: handlebars_pattern,
@@ -14,7 +14,7 @@
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
'boolean': /\b(true|false)\b/,
'block': {
- pattern: /^(\s*~?\s*)[#\/]\w+/i,
+ pattern: /^(\s*~?\s*)[#\/]\S+/i,
lookbehind: true,
alias: 'keyword'
},
diff --git a/components/prism-handlebars.min.js b/components/prism-handlebars.min.js
index d303e50..acafd0c 100644
--- a/components/prism-handlebars.min.js
+++ b/components/prism-handlebars.min.js
@@ -1 +1 @@
-!function(e){var a=/\{\{\{[\w\W]+?\}\}\}|\{\{[\w\W]+?\}\}/g;e.languages.handlebars=e.languages.extend("markup",{handlebars:{pattern:a,inside:{delimiter:{pattern:/^\{\{\{?|\}\}\}?$/i,alias:"punctuation"},string:/(["'])(\\?.)+?\1/,number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,"boolean":/\b(true|false)\b/,block:{pattern:/^(\s*~?\s*)[#\/]\w+/i,lookbehind:!0,alias:"keyword"},brackets:{pattern:/\[[^\]]+\]/,inside:{punctuation:/\[|\]/,variable:/[\w\W]+/}},punctuation:/[!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]/,variable:/[^!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+/}}}),e.languages.insertBefore("handlebars","tag",{"handlebars-comment":{pattern:/\{\{![\w\W]*?\}\}/,alias:["handlebars","comment"]}}),e.hooks.add("before-highlight",function(e){"handlebars"===e.language&&(e.tokenStack=[],e.backupCode=e.code,e.code=e.code.replace(a,function(a){return e.tokenStack.push(a),"___HANDLEBARS"+e.tokenStack.length+"___"}))}),e.hooks.add("before-insert",function(e){"handlebars"===e.language&&(e.code=e.backupCode,delete e.backupCode)}),e.hooks.add("after-highlight",function(a){if("handlebars"===a.language){for(var n,t=0;n=a.tokenStack[t];t++)a.highlightedCode=a.highlightedCode.replace("___HANDLEBARS"+(t+1)+"___",e.highlight(n,a.grammar,"handlebars"));a.element.innerHTML=a.highlightedCode}})}(Prism);
\ No newline at end of file
+!function(e){var a=/\{\{\{[\w\W]+?\}\}\}|\{\{[\w\W]+?\}\}/g;e.languages.handlebars=e.languages.extend("markup",{handlebars:{pattern:a,inside:{delimiter:{pattern:/^\{\{\{?|\}\}\}?$/i,alias:"punctuation"},string:/(["'])(\\?.)+?\1/,number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,"boolean":/\b(true|false)\b/,block:{pattern:/^(\s*~?\s*)[#\/]\S+/i,lookbehind:!0,alias:"keyword"},brackets:{pattern:/\[[^\]]+\]/,inside:{punctuation:/\[|\]/,variable:/[\w\W]+/}},punctuation:/[!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]/,variable:/[^!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+/}}}),e.languages.insertBefore("handlebars","tag",{"handlebars-comment":{pattern:/\{\{![\w\W]*?\}\}/,alias:["handlebars","comment"]}}),e.hooks.add("before-highlight",function(e){"handlebars"===e.language&&(e.tokenStack=[],e.backupCode=e.code,e.code=e.code.replace(a,function(a){return e.tokenStack.push(a),"___HANDLEBARS"+e.tokenStack.length+"___"}))}),e.hooks.add("before-insert",function(e){"handlebars"===e.language&&(e.code=e.backupCode,delete e.backupCode)}),e.hooks.add("after-highlight",function(a){if("handlebars"===a.language){for(var n,t=0;n=a.tokenStack[t];t++)a.highlightedCode=a.highlightedCode.replace("___HANDLEBARS"+(t+1)+"___",e.highlight(n,a.grammar,"handlebars"));a.element.innerHTML=a.highlightedCode}})}(Prism);
\ No newline at end of file
diff --git a/examples/prism-handlebars.html b/examples/prism-handlebars.html
index ec7d31d..49c5096 100644
--- a/examples/prism-handlebars.html
+++ b/examples/prism-handlebars.html
@@ -26,8 +26,12 @@
{{/with}}
<div class="{{#if test}}foo{{else}}bar{{/if}}"></div>
{{#list array}}
- {{@index}}. {{title}}
-{{/list}}</code></pre>
+ {{@index}}. {{title}}
+{{/list}}
+{{#block-with-hyphens args=yep}}
+ This should probably work...
+{{/block-with-hyphens}}
+</code></pre>
<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
@@ -37,4 +41,4 @@
</p>
<h3>Handlebars tag in the middle of an HTML tag</h3>
-<pre><code><div{{#if test}} class="test"{{/if}}></div></code></pre>
\ No newline at end of file
+<pre><code><div{{#if test}} class="test"{{/if}}></div></code></pre>