Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: lib/src/prism/components/prism-handlebars.js

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 (function(Prism) { 1 (function(Prism) {
2 2
3 var handlebars_pattern = /\{\{\{[\w\W]+?\}\}\}|\{\{[\w\W]+?\}\}/g; 3 var handlebars_pattern = /\{\{\{[\w\W]+?\}\}\}|\{\{[\w\W]+?\}\}/g;
4 4
5 Prism.languages.handlebars = Prism.languages.extend('markup', { 5 Prism.languages.handlebars = Prism.languages.extend('markup', {
6 'handlebars': { 6 'handlebars': {
7 pattern: handlebars_pattern, 7 pattern: handlebars_pattern,
8 inside: { 8 inside: {
9 'delimiter': { 9 'delimiter': {
10 pattern: /^\{\{\{?|\}\}\}?$/i, 10 pattern: /^\{\{\{?|\}\}\}?$/i,
11 alias: 'punctuation' 11 alias: 'punctuation'
12 }, 12 },
13 » » » » 'string': /(["'])(\\?.)+?\1/, 13 » » » » 'string': /(["'])(\\?.)*?\1/,
14 » » » » 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d +)?)\b/, 14 » » » » 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-] ?\d+)?)\b/,
15 'boolean': /\b(true|false)\b/, 15 'boolean': /\b(true|false)\b/,
16 'block': { 16 'block': {
17 » » » » » pattern: /^(\s*~?\s*)[#\/]\S+/i, 17 » » » » » pattern: /^(\s*~?\s*)[#\/]\S+?(?=\s*~?\s *$|\s)/i,
18 lookbehind: true, 18 lookbehind: true,
19 alias: 'keyword' 19 alias: 'keyword'
20 }, 20 },
21 'brackets': { 21 'brackets': {
22 pattern: /\[[^\]]+\]/, 22 pattern: /\[[^\]]+\]/,
23 inside: { 23 inside: {
24 punctuation: /\[|\]/, 24 punctuation: /\[|\]/,
25 variable: /[\w\W]+/ 25 variable: /[\w\W]+/
26 } 26 }
27 }, 27 },
28 'punctuation': /[!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~ ]/, 28 'punctuation': /[!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~ ]/,
29 » » » » 'variable': /[^!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+ / 29 » » » » 'variable': /[^!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~\s ]+/
30 } 30 }
31 } 31 }
32 }); 32 });
33 33
34 // Comments are inserted at top so that they can 34 // Comments are inserted at top so that they can
35 // surround markup 35 // surround markup
36 Prism.languages.insertBefore('handlebars', 'tag', { 36 Prism.languages.insertBefore('handlebars', 'tag', {
37 'handlebars-comment': { 37 'handlebars-comment': {
38 pattern: /\{\{![\w\W]*?\}\}/, 38 pattern: /\{\{![\w\W]*?\}\}/,
39 alias: ['handlebars','comment'] 39 alias: ['handlebars','comment']
(...skipping 26 matching lines...) Expand all
66 }); 66 });
67 67
68 // Re-insert the tokens after highlighting 68 // Re-insert the tokens after highlighting
69 // and highlight them with defined grammar 69 // and highlight them with defined grammar
70 Prism.hooks.add('after-highlight', function(env) { 70 Prism.hooks.add('after-highlight', function(env) {
71 if (env.language !== 'handlebars') { 71 if (env.language !== 'handlebars') {
72 return; 72 return;
73 } 73 }
74 74
75 for (var i = 0, t; t = env.tokenStack[i]; i++) { 75 for (var i = 0, t; t = env.tokenStack[i]; i++) {
76 » » » env.highlightedCode = env.highlightedCode.replace('___HA NDLEBARS' + (i + 1) + '___', Prism.highlight(t, env.grammar, 'handlebars')); 76 » » » // The replace prevents $$, $&, $`, $', $n, $nn from bei ng interpreted as special patterns
77 » » » env.highlightedCode = env.highlightedCode.replace('___HA NDLEBARS' + (i + 1) + '___', Prism.highlight(t, env.grammar, 'handlebars').repla ce(/\$/g, '$$$$'));
77 } 78 }
78 79
79 env.element.innerHTML = env.highlightedCode; 80 env.element.innerHTML = env.highlightedCode;
80 }); 81 });
81 82
82 }(Prism)); 83 }(Prism));
OLDNEW
« no previous file with comments | « lib/src/prism/components/prism-haml.min.js ('k') | lib/src/prism/components/prism-handlebars.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698