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

Side by Side Diff: lib/src/prism/components/prism-smarty.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 /* TODO 1 /* TODO
2 Add support for variables inside double quoted strings 2 Add support for variables inside double quoted strings
3 Add support for {php} 3 Add support for {php}
4 */ 4 */
5 5
6 (function(Prism) { 6 (function(Prism) {
7 7
8 var smarty_pattern = /\{\*[\w\W]+?\*\}|\{[\w\W]+?\}/g; 8 var smarty_pattern = /\{\*[\w\W]+?\*\}|\{[\w\W]+?\}/g;
9 var smarty_litteral_start = '{literal}'; 9 var smarty_litteral_start = '{literal}';
10 var smarty_litteral_end = '{/literal}'; 10 var smarty_litteral_end = '{/literal}';
11 var smarty_litteral_mode = false; 11 var smarty_litteral_mode = false;
12 12
13 Prism.languages.smarty = Prism.languages.extend('markup', { 13 Prism.languages.smarty = Prism.languages.extend('markup', {
14 'smarty': { 14 'smarty': {
15 pattern: smarty_pattern, 15 pattern: smarty_pattern,
16 inside: { 16 inside: {
17 'delimiter': { 17 'delimiter': {
18 pattern: /^\{|\}$/i, 18 pattern: /^\{|\}$/i,
19 alias: 'punctuation' 19 alias: 'punctuation'
20 }, 20 },
21 » » » » 'string': /(["'])(\\?.)*?\1/, 21 » » » » 'string': /(["'])(?:\\?.)*?\1/,
22 » » » » 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d +)?)\b/, 22 » » » » 'number': /\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+(?:[Ee] [-+]?\d+)?)\b/,
23 'variable': [ 23 'variable': [
24 /\$(?!\d)\w+/, 24 /\$(?!\d)\w+/,
25 /#(?!\d)\w+#/, 25 /#(?!\d)\w+#/,
26 { 26 {
27 pattern: /(\.|->)(?!\d)\w+/, 27 pattern: /(\.|->)(?!\d)\w+/,
28 lookbehind: true 28 lookbehind: true
29 }, 29 },
30 { 30 {
31 pattern: /(\[)(?!\d)\w+(?=\])/, 31 pattern: /(\[)(?!\d)\w+(?=\])/,
32 lookbehind: true 32 lookbehind: true
33 } 33 }
34 ], 34 ],
35 'function': [ 35 'function': [
36 { 36 {
37 pattern: /(\|\s*)@?(?!\d)\w+/, 37 pattern: /(\|\s*)@?(?!\d)\w+/,
38 lookbehind: true 38 lookbehind: true
39 }, 39 },
40 /^\/?(?!\d)\w+/, 40 /^\/?(?!\d)\w+/,
41 /(?!\d)\w+(?=\()/ 41 /(?!\d)\w+(?=\()/
42 ], 42 ],
43 'attr-name': { 43 'attr-name': {
44 // Value is made optional because it may have already been tokenized 44 // Value is made optional because it may have already been tokenized
45 pattern: /\w+\s*=\s*(?:(?!\d)\w+)?/, 45 pattern: /\w+\s*=\s*(?:(?!\d)\w+)?/,
46 inside: { 46 inside: {
47 "variable": { 47 "variable": {
48 pattern: /(=\s*)(?!\d)\w +/, 48 pattern: /(=\s*)(?!\d)\w +/,
49 lookbehind: true 49 lookbehind: true
50 }, 50 },
51 » » » » » » "punctuation": /=/ 51 » » » » » » "operator": /=/
52 } 52 }
53 }, 53 },
54 » » » » 'punctuation': /[\[\]().,=\|:`]|\->/, 54 » » » » 'punctuation': [
55 » » » » » /[\[\]().,:`]|\->/
56 » » » » ],
55 'operator': [ 57 'operator': [
56 » » » » » /[+\-*\/%]|===?|[!<>]=?|&&|\|\|/, 58 » » » » » /[+\-*\/%]|==?=?|[!<>]=?|&&|\|\|?/,
57 /\bis\s+(?:not\s+)?(?:div|even|odd)(?:\s +by)?\b/, 59 /\bis\s+(?:not\s+)?(?:div|even|odd)(?:\s +by)?\b/,
58 /\b(?:eq|neq?|gt|lt|gt?e|lt?e|not|mod|or |and)\b/ 60 /\b(?:eq|neq?|gt|lt|gt?e|lt?e|not|mod|or |and)\b/
59 ], 61 ],
60 'keyword': /\b(?:false|off|on|no|true|yes)\b/ 62 'keyword': /\b(?:false|off|on|no|true|yes)\b/
61 } 63 }
62 } 64 }
63 }); 65 });
64 66
65 // Comments are inserted at top so that they can 67 // Comments are inserted at top so that they can
66 // surround markup 68 // surround markup
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 }); 110 });
109 111
110 // Re-insert the tokens after highlighting 112 // Re-insert the tokens after highlighting
111 // and highlight them with defined grammar 113 // and highlight them with defined grammar
112 Prism.hooks.add('after-highlight', function(env) { 114 Prism.hooks.add('after-highlight', function(env) {
113 if (env.language !== 'smarty') { 115 if (env.language !== 'smarty') {
114 return; 116 return;
115 } 117 }
116 118
117 for (var i = 0, t; t = env.tokenStack[i]; i++) { 119 for (var i = 0, t; t = env.tokenStack[i]; i++) {
118 » » » env.highlightedCode = env.highlightedCode.replace('___SM ARTY' + (i + 1) + '___', Prism.highlight(t, env.grammar, 'smarty')); 120 » » » // The replace prevents $$, $&, $`, $', $n, $nn from bei ng interpreted as special patterns
121 » » » env.highlightedCode = env.highlightedCode.replace('___SM ARTY' + (i + 1) + '___', Prism.highlight(t, env.grammar, 'smarty').replace(/\$/g , '$$$$'));
119 } 122 }
120 123
121 env.element.innerHTML = env.highlightedCode; 124 env.element.innerHTML = env.highlightedCode;
122 }); 125 });
123 126
124 }(Prism)); 127 }(Prism));
OLDNEW
« no previous file with comments | « lib/src/prism/components/prism-smalltalk.min.js ('k') | lib/src/prism/components/prism-smarty.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698