From 67b89eaf0ff666573261b7856b262c4cf26f8bc9 Mon Sep 17 00:00:00 2001
From: Jannik Zschiesche
Date: Mon, 1 Jun 2015 18:45:17 +0200
Subject: [PATCH] Handlebars: support blocks with dashes
---
components/prism-handlebars.js | 4 ++--
components/prism-handlebars.min.js | 2 +-
examples/prism-handlebars.html | 10 +++++++---
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/components/prism-handlebars.js b/components/prism-handlebars.js
index 3154940500..00fe7714d6 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 d303e50220..acafd0c263 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 ec7d31d4f0..49c5096e34 100644
--- a/examples/prism-handlebars.html
+++ b/examples/prism-handlebars.html
@@ -26,8 +26,12 @@ Block helpers
{{/with}}
<div class="{{#if test}}foo{{else}}bar{{/if}}"></div>
{{#list array}}
- {{@index}}. {{title}}
-{{/list}}
+ {{@index}}. {{title}}
+{{/list}}
+{{#block-with-hyphens args=yep}}
+ This should probably work...
+{{/block-with-hyphens}}
+
Known failures
There are certain edge cases where Prism will fail.
@@ -37,4 +41,4 @@
Known failures
Handlebars tag in the middle of an HTML tag
-<div{{#if test}} class="test"{{/if}}></div>
\ No newline at end of file
+<div{{#if test}} class="test"{{/if}}></div>