History

Update Prism.js

Thibaut Courouble committed 9 years ago

Commit 01f9d511 parent 2db57fd1 file · +141 −48Browse files

Unified · Split

assets/javascripts/vendor/prism.js+141−48
@@ -20,6 +20,7 @@ var lang = /\blang(?:uage)?-(\w+)\b/i; · 19 unmodified lines
20var uniqueId = 0;20var uniqueId = 0;
21 21
22var _ = _self.Prism = {22var _ = _self.Prism = {
23 manual: _self.Prism && _self.Prism.manual,
23 util: {24 util: {
24 encode: function (tokens) {25 encode: function (tokens) {
25 if (tokens instanceof Token) {26 if (tokens instanceof Token) {
@@ -204,6 +205,9 @@ var _ = _self.Prism = { · 178 unmodified lines
204 _.hooks.run('before-sanity-check', env);205 _.hooks.run('before-sanity-check', env);
205 206
206 if (!env.code || !env.grammar) {207 if (!env.code || !env.grammar) {
208 if (env.code) {
209 env.element.textContent = env.code;
210 }
207 _.hooks.run('complete', env);211 _.hooks.run('complete', env);
208 return;212 return;
209 }213 }
@@ -290,7 +294,7 @@ var _ = _self.Prism = { · 80 unmodified lines
290 pattern = pattern.pattern || pattern;294 pattern = pattern.pattern || pattern;
291 295
292 // Don’t cache length as it changes during the loop296 // Don’t cache length as it changes during the loop
293 for (var i=0, pos = 0; i<strarr.length; pos += (strarr[i].matchedStr || strarr[i]).length, ++i) {297 for (var i=0, pos = 0; i<strarr.length; pos += strarr[i].length, ++i) {
294 298
295 var str = strarr[i];299 var str = strarr[i];
296 300
@@ -322,7 +326,7 @@ var _ = _self.Prism = { · 25 unmodified lines
322 p = pos;326 p = pos;
323 327
324 for (var len = strarr.length; k < len && p < to; ++k) {328 for (var len = strarr.length; k < len && p < to; ++k) {
325 p += (strarr[k].matchedStr || strarr[k]).length;329 p += strarr[k].length;
326 // Move the index i to the element in strarr that is closest to from330 // Move the index i to the element in strarr that is closest to from
327 if (from >= p) {331 if (from >= p) {
328 ++i;332 ++i;
@@ -410,7 +414,7 @@ var Token = _.Token = function(type, content, alias, matchedStr, greedy) { · 81 unmodified lines
410 this.content = content;414 this.content = content;
411 this.alias = alias;415 this.alias = alias;
412 // Copy of the full string this token was created from416 // Copy of the full string this token was created from
413 this.matchedStr = matchedStr || null;417 this.length = (matchedStr || "").length|0;
414 this.greedy = !!greedy;418 this.greedy = !!greedy;
415};419};
416 420
@@ -446,11 +450,9 @@ Token.stringify = function(o, language, parent) { · 29 unmodified lines
446 450
447 _.hooks.run('wrap', env);451 _.hooks.run('wrap', env);
448 452
449 var attributes = '';453 var attributes = Object.keys(env.attributes).map(function(name) {
450 454 return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
451 for (var name in env.attributes) {455 }).join(' ');
452 attributes += (attributes ? ' ' : '') + name + '="' + (env.attributes[name] || '') + '"';
453 }
454 456
455 return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';457 return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
456 458
@@ -483,7 +485,7 @@ Token.stringify = function(o, language, parent) { · 26 unmodified lines
483// if (script) {485// if (script) {
484// _.filename = script.src;486// _.filename = script.src;
485 487
486// if (document.addEventListener && !script.hasAttribute('data-manual')) {488// if (document.addEventListener && !_.manual && !script.hasAttribute('data-manual')) {
487// if(document.readyState !== "loading") {489// if(document.readyState !== "loading") {
488// if (window.requestAnimationFrame) {490// if (window.requestAnimationFrame) {
489// window.requestAnimationFrame(_.highlightAll);491// window.requestAnimationFrame(_.highlightAll);
@@ -513,7 +515,7 @@ if (typeof global !== 'undefined') { · 23 unmodified lines
513Prism.languages.markup = {515Prism.languages.markup = {
514 'comment': /<!--[\w\W]*?-->/,516 'comment': /<!--[\w\W]*?-->/,
515 'prolog': /<\?[\w\W]+?\?>/,517 'prolog': /<\?[\w\W]+?\?>/,
516 'doctype': /<!DOCTYPE[\w\W]+?>/,518 'doctype': /<!DOCTYPE[\w\W]+?>/i,
517 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,519 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
518 'tag': {520 'tag': {
519 pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,521 pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
@@ -568,7 +570,10 @@ Prism.languages.css = { · 48 unmodified lines
568 },570 },
569 'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,571 'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
570 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,572 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
571 'string': /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,573 'string': {
574 pattern: /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
575 greedy: true
576 },
572 'property': /(\b|\B)[\w-]+(?=\s*:)/i,577 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
573 'important': /\B!important\b/i,578 'important': /\B!important\b/i,
574 'function': /[-a-z0-9]+(?=\()/i,579 'function': /[-a-z0-9]+(?=\()/i,
@@ -745,7 +750,7 @@ Prism.languages.coffeescript = Prism.languages.extend('javascript', { · 170 unmodified lines
745 // Strings are multiline750 // Strings are multiline
746 {751 {
747 pattern: /'(?:\\?[^\\])*?'/,752 pattern: /'(?:\\?[^\\])*?'/,
748 greedy: true,753 greedy: true
749 },754 },
750 755
751 {756 {
@@ -847,12 +852,14 @@ delete Prism.languages.coffeescript['template-string']; · 95 unmodified lines
847 'regex': [852 'regex': [
848 {853 {
849 pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,854 pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,
855 greedy: true,
850 inside: {856 inside: {
851 'interpolation': interpolation857 'interpolation': interpolation
852 }858 }
853 },859 },
854 {860 {
855 pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,861 pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
862 greedy: true,
856 inside: {863 inside: {
857 'interpolation': interpolation864 'interpolation': interpolation
858 }865 }
@@ -860,25 +867,29 @@ delete Prism.languages.coffeescript['template-string']; · 1 unmodified line
860 {867 {
861 // Here we need to specifically allow interpolation868 // Here we need to specifically allow interpolation
862 pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,869 pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
870 greedy: true,
863 inside: {871 inside: {
864 'interpolation': interpolation872 'interpolation': interpolation
865 }873 }
866 },874 },
867 {875 {
868 pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,876 pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
877 greedy: true,
869 inside: {878 inside: {
870 'interpolation': interpolation879 'interpolation': interpolation
871 }880 }
872 },881 },
873 {882 {
874 pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,883 pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
884 greedy: true,
875 inside: {885 inside: {
876 'interpolation': interpolation886 'interpolation': interpolation
877 }887 }
878 },888 },
879 {889 {
880 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,890 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
881 lookbehind: true891 lookbehind: true,
892 greedy: true
882 }893 }
883 ],894 ],
884 'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,895 'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,
@@ -886,19 +897,21 @@ delete Prism.languages.coffeescript['template-string']; · 1 unmodified line
886 });897 });
887 898
888 Prism.languages.insertBefore('ruby', 'number', {899 Prism.languages.insertBefore('ruby', 'number', {
889 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,900 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
890 'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/901 'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/
891 });902 });
892 903
893 Prism.languages.ruby.string = [904 Prism.languages.ruby.string = [
894 {905 {
895 pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,906 pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
907 greedy: true,
896 inside: {908 inside: {
897 'interpolation': interpolation909 'interpolation': interpolation
898 }910 }
899 },911 },
900 {912 {
901 pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,913 pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
914 greedy: true,
902 inside: {915 inside: {
903 'interpolation': interpolation916 'interpolation': interpolation
904 }917 }
@@ -906,24 +919,28 @@ delete Prism.languages.coffeescript['template-string']; · 1 unmodified line
906 {919 {
907 // Here we need to specifically allow interpolation920 // Here we need to specifically allow interpolation
908 pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,921 pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
922 greedy: true,
909 inside: {923 inside: {
910 'interpolation': interpolation924 'interpolation': interpolation
911 }925 }
912 },926 },
913 {927 {
914 pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,928 pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
929 greedy: true,
915 inside: {930 inside: {
916 'interpolation': interpolation931 'interpolation': interpolation
917 }932 }
918 },933 },
919 {934 {
920 pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,935 pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
936 greedy: true,
921 inside: {937 inside: {
922 'interpolation': interpolation938 'interpolation': interpolation
923 }939 }
924 },940 },
925 {941 {
926 pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,942 pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
943 greedy: true,
927 inside: {944 inside: {
928 'interpolation': interpolation945 'interpolation': interpolation
929 }946 }
@@ -944,12 +961,14 @@ Prism.languages.elixir = { · 14 unmodified lines
944 {961 {
945 // ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>962 // ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>
946 pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/,963 pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/,
964 greedy: true,
947 inside: {965 inside: {
948 // See interpolation below966 // See interpolation below
949 }967 }
950 },968 },
951 {969 {
952 pattern: /("""|''')[\s\S]*?\1/,970 pattern: /("""|''')[\s\S]*?\1/,
971 greedy: true,
953 inside: {972 inside: {
954 // See interpolation below973 // See interpolation below
955 }974 }
@@ -957,6 +976,7 @@ Prism.languages.elixir = { · 1 unmodified line
957 {976 {
958 // Multi-line strings are allowed977 // Multi-line strings are allowed
959 pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,978 pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
979 greedy: true,
960 inside: {980 inside: {
961 // See interpolation below981 // See interpolation below
962 }982 }
@@ -1027,18 +1047,21 @@ Prism.languages.go = Prism.languages.extend('clike', { · 64 unmodified lines
1027 'boolean': /\b(_|iota|nil|true|false)\b/,1047 'boolean': /\b(_|iota|nil|true|false)\b/,
1028 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,1048 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
1029 'number': /\b(-?(0x[a-f\d]+|(\d+\.?\d*|\.\d+)(e[-+]?\d+)?)i?)\b/i,1049 'number': /\b(-?(0x[a-f\d]+|(\d+\.?\d*|\.\d+)(e[-+]?\d+)?)i?)\b/i,
1030 'string': /("|'|`)(\\?.|\r|\n)*?\1/1050 'string': {
1051 pattern: /("|'|`)(\\?.|\r|\n)*?\1/,
1052 greedy: true
1053 }
1031});1054});
1032delete Prism.languages.go['class-name'];1055delete Prism.languages.go['class-name'];
1033 1056
1034Prism.languages.json = {1057Prism.languages.json = {
1035 'property': /".*?"(?=\s*:)/ig,1058 'property': /"(?:\\.|[^\\"])*"(?=\s*:)/ig,
1036 'string': /"(?!:)(\\?[^"])*?"(?!:)/g,1059 'string': /"(?!:)(?:\\.|[^\\"])*"(?!:)/g,
1037 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,1060 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?)\b/g,
1038 'punctuation': /[{}[\]);,]/g,1061 'punctuation': /[{}[\]);,]/g,
1039 'operator': /:/g,1062 'operator': /:/g,
1040 'boolean': /\b(true|false)\b/gi,1063 'boolean': /\b(true|false)\b/gi,
1041 'null': /\bnull\b/gi,1064 'null': /\bnull\b/gi
1042};1065};
1043 1066
1044Prism.languages.jsonp = Prism.languages.json;1067Prism.languages.jsonp = Prism.languages.json;
@@ -1151,92 +1174,143 @@ Prism.languages.perl = { · 106 unmodified lines
1151 // TODO Could be nice to handle Heredoc too.1174 // TODO Could be nice to handle Heredoc too.
1152 'string': [1175 'string': [
1153 // q/.../1176 // q/.../
1154 /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,1177 {
1178 pattern: /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
1179 greedy: true
1180 },
1155 1181
1156 // q a...a1182 // q a...a
1157 /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\1/,1183 {
1184 pattern: /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\1/,
1185 greedy: true
1186 },
1158 1187
1159 // q(...)1188 // q(...)
1160 /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,1189 {
1190 pattern: /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,
1191 greedy: true
1192 },
1161 1193
1162 // q{...}1194 // q{...}
1163 /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,1195 {
1196 pattern: /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,
1197 greedy: true
1198 },
1164 1199
1165 // q[...]1200 // q[...]
1166 /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,1201 {
1202 pattern: /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,
1203 greedy: true
1204 },
1167 1205
1168 // q<...>1206 // q<...>
1169 /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,1207 {
1208 pattern: /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,
1209 greedy: true
1210 },
1170 1211
1171 // "...", `...`1212 // "...", `...`
1172 /("|`)(?:[^\\]|\\[\s\S])*?\1/,1213 {
1214 pattern: /("|`)(?:[^\\]|\\[\s\S])*?\1/,
1215 greedy: true
1216 },
1173 1217
1174 // '...'1218 // '...'
1175 // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '1219 // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
1176 /'(?:[^'\\\r\n]|\\.)*'/1220 {
1221 pattern: /'(?:[^'\\\r\n]|\\.)*'/,
1222 greedy: true
1223 }
1177 ],1224 ],
1178 'regex': [1225 'regex': [
1179 // m/.../1226 // m/.../
1180 /\b(?:m|qr)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[msixpodualngc]*/,1227 {
1228 pattern: /\b(?:m|qr)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[msixpodualngc]*/,
1229 greedy: true
1230 },
1181 1231
1182 // m a...a1232 // m a...a
1183 /\b(?:m|qr)\s+([a-zA-Z0-9])(?:[^\\]|\\.)*?\1[msixpodualngc]*/,1233 {
1234 pattern: /\b(?:m|qr)\s+([a-zA-Z0-9])(?:[^\\]|\\.)*?\1[msixpodualngc]*/,
1235 greedy: true
1236 },
1184 1237
1185 // m(...)1238 // m(...)
1186 /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,1239 {
1240 pattern: /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,
1241 greedy: true
1242 },
1187 1243
1188 // m{...}1244 // m{...}
1189 /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,1245 {
1246 pattern: /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,
1247 greedy: true
1248 },
1190 1249
1191 // m[...]1250 // m[...]
1192 /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,1251 {
1252 pattern: /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,
1253 greedy: true
1254 },
1193 1255
1194 // m<...>1256 // m<...>
1195 /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,1257 {
1258 pattern: /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,
1259 greedy: true
1260 },
1196 1261
1197 // The lookbehinds prevent -s from breaking1262 // The lookbehinds prevent -s from breaking
1198 // FIXME We don't handle change of separator like s(...)[...]1263 // FIXME We don't handle change of separator like s(...)[...]
1199 // s/.../.../1264 // s/.../.../
1200 {1265 {
1201 pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,1266 pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
1202 lookbehind: true1267 lookbehind: true,
1268 greedy: true
1203 },1269 },
1204 1270
1205 // s a...a...a1271 // s a...a...a
1206 {1272 {
1207 pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,1273 pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
1208 lookbehind: true1274 lookbehind: true,
1275 greedy: true
1209 },1276 },
1210 1277
1211 // s(...)(...)1278 // s(...)(...)
1212 {1279 {
1213 pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,1280 pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,
1214 lookbehind: true1281 lookbehind: true,
1282 greedy: true
1215 },1283 },
1216 1284
1217 // s{...}{...}1285 // s{...}{...}
1218 {1286 {
1219 pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,1287 pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,
1220 lookbehind: true1288 lookbehind: true,
1289 greedy: true
1221 },1290 },
1222 1291
1223 // s[...][...]1292 // s[...][...]
1224 {1293 {
1225 pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,1294 pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,
1226 lookbehind: true1295 lookbehind: true,
1296 greedy: true
1227 },1297 },
1228 1298
1229 // s<...><...>1299 // s<...><...>
1230 {1300 {
1231 pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,1301 pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,
1232 lookbehind: true1302 lookbehind: true,
1303 greedy: true
1233 },1304 },
1234 1305
1235 // /.../1306 // /.../
1236 // The look-ahead tries to prevent two divisions on1307 // The look-ahead tries to prevent two divisions on
1237 // the same line from being highlighted as regex.1308 // the same line from being highlighted as regex.
1238 // This does not support multi-line regex.1309 // This does not support multi-line regex.
1239 /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/1310 {
1311 pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/,
1312 greedy: true
1313 }
1240 ],1314 ],
1241 1315
1242 // FIXME Not sure about the handling of ::, ', and #1316 // FIXME Not sure about the handling of ::, ', and #
@@ -1342,6 +1416,7 @@ if (Prism.languages.markup) { · 99 unmodified lines
1342 1416
1343 env.tokenStack = [];1417 env.tokenStack = [];
1344 1418
1419 env.backupCode = env.code;
1345 env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function(match) {1420 env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function(match) {
1346 env.tokenStack.push(match);1421 env.tokenStack.push(match);
1347 1422
@@ -1349,6 +1424,14 @@ if (Prism.languages.markup) { · 1 unmodified line
1349 });1424 });
1350 });1425 });
1351 1426
1427 // Restore env.code for other plugins (e.g. line-numbers)
1428 Prism.hooks.add('before-insert', function(env) {
1429 if (env.language === 'php') {
1430 env.code = env.backupCode;
1431 delete env.backupCode;
1432 }
1433 });
1434
1352 // Re-insert the tokens after highlighting1435 // Re-insert the tokens after highlighting
1353 Prism.hooks.add('after-highlight', function(env) {1436 Prism.hooks.add('after-highlight', function(env) {
1354 if (env.language !== 'php') {1437 if (env.language !== 'php') {
@@ -1411,7 +1494,7 @@ Prism.languages.python= { · 56 unmodified lines
1411(function(Prism) {1494(function(Prism) {
1412 Prism.languages.crystal = Prism.languages.extend('ruby', {1495 Prism.languages.crystal = Prism.languages.extend('ruby', {
1413 keyword: [1496 keyword: [
1414 /\b(?:abstract|alias|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|ifdef|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|rescue|return|require|self|sizeof|struct|super|then|type|typeof|union|unless|until|when|while|with|yield|__DIR__|__FILE__|__LINE__)\b/,1497 /\b(?:abstract|alias|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|rescue|return|require|select|self|sizeof|struct|super|then|type|typeof|uninitialized|union|unless|until|when|while|with|yield|__DIR__|__END_LINE__|__FILE__|__LINE__)\b/,
1415 {1498 {
1416 pattern: /(\.\s*)(?:is_a|responds_to)\?/,1499 pattern: /(\.\s*)(?:is_a|responds_to)\?/,
1417 lookbehind: true1500 lookbehind: true
@@ -1481,13 +1564,20 @@ Prism.languages.rust = { · 63 unmodified lines
1481 }1564 }
1482 ],1565 ],
1483 'string': [1566 'string': [
1484 /b?r(#*)"(?:\\?.)*?"\1/,1567 {
1485 /b?("|')(?:\\?.)*?\1/1568 pattern: /b?r(#*)"(?:\\?.)*?"\1/,
1569 greedy: true
1570 },
1571 {
1572 pattern: /b?("|')(?:\\?.)*?\1/,
1573 greedy: true
1574 }
1486 ],1575 ],
1487 'keyword': /\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,1576 'keyword': /\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,
1488 1577
1489 'attribute': {1578 'attribute': {
1490 pattern: /#!?\[.+?\]/,1579 pattern: /#!?\[.+?\]/,
1580 greedy: true,
1491 alias: 'attr-name'1581 alias: 'attr-name'
1492 },1582 },
1493 1583
@@ -1597,6 +1687,7 @@ Prism.languages.sql= { · 103 unmodified lines
1597 },1687 },
1598 'string' : {1688 'string' : {
1599 pattern: /(^|[^@\\])("|')(?:\\?[\s\S])*?\2/,1689 pattern: /(^|[^@\\])("|')(?:\\?[\s\S])*?\2/,
1690 greedy: true,
1600 lookbehind: true1691 lookbehind: true
1601 },1692 },
1602 'variable': /@[\w.$]+|@("|'|`)(?:\\?[\s\S])+?\1/,1693 'variable': /@[\w.$]+|@("|'|`)(?:\\?[\s\S])+?\1/,
@@ -1608,6 +1699,8 @@ Prism.languages.sql= { · 5 unmodified lines
1608 'punctuation': /[;[\]()`,.]/1699 'punctuation': /[;[\]()`,.]/
1609};1700};
1610Prism.languages.typescript = Prism.languages.extend('javascript', {1701Prism.languages.typescript = Prism.languages.extend('javascript', {
1611 'keyword': /\b(break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|get|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield|module|declare|constructor|string|Function|any|number|boolean|Array|enum)\b/1702 // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
1703 'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield|false|true|module|declare|constructor|string|Function|any|number|boolean|Array|enum|symbol|namespace|abstract|require|type)\b/
1612});1704});
1613 1705
1706Prism.languages.ts = Prism.languages.typescript;