Unified · Split
| @@ -20,6 +20,7 @@ var lang = /\blang(?:uage)?-(\w+)\b/i; · 19 unmodified lines | ||
| 20 | 20 | var uniqueId = 0; |
| 21 | 21 | |
| 22 | 22 | var _ = _self.Prism = { |
| 23 | + manual: _self.Prism && _self.Prism.manual, | |
| 23 | 24 | util: { |
| 24 | 25 | encode: function (tokens) { |
| 25 | 26 | if (tokens instanceof Token) { |
| @@ -204,6 +205,9 @@ var _ = _self.Prism = { · 178 unmodified lines | ||
| 204 | 205 | _.hooks.run('before-sanity-check', env); |
| 205 | 206 | |
| 206 | 207 | if (!env.code || !env.grammar) { |
| 208 | + if (env.code) { | |
| 209 | + env.element.textContent = env.code; | |
| 210 | + } | |
| 207 | 211 | _.hooks.run('complete', env); |
| 208 | 212 | return; |
| 209 | 213 | } |
| @@ -290,7 +294,7 @@ var _ = _self.Prism = { · 80 unmodified lines | ||
| 290 | 294 | pattern = pattern.pattern || pattern; |
| 291 | 295 | |
| 292 | 296 | // 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 | 299 | var str = strarr[i]; |
| 296 | 300 | |
| @@ -322,7 +326,7 @@ var _ = _self.Prism = { · 25 unmodified lines | ||
| 322 | 326 | p = pos; |
| 323 | 327 | |
| 324 | 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 | 330 | // Move the index i to the element in strarr that is closest to from |
| 327 | 331 | if (from >= p) { |
| 328 | 332 | ++i; |
| @@ -410,7 +414,7 @@ var Token = _.Token = function(type, content, alias, matchedStr, greedy) { · 81 unmodified lines | ||
| 410 | 414 | this.content = content; |
| 411 | 415 | this.alias = alias; |
| 412 | 416 | // Copy of the full string this token was created from |
| 413 | − this.matchedStr = matchedStr || null; | |
| 417 | + this.length = (matchedStr || "").length|0; | |
| 414 | 418 | this.greedy = !!greedy; |
| 415 | 419 | }; |
| 416 | 420 | |
| @@ -446,11 +450,9 @@ Token.stringify = function(o, language, parent) { · 29 unmodified lines | ||
| 446 | 450 | |
| 447 | 451 | _.hooks.run('wrap', env); |
| 448 | 452 | |
| 449 | − var attributes = ''; | |
| 450 | − | |
| 451 | − for (var name in env.attributes) { | |
| 452 | − attributes += (attributes ? ' ' : '') + name + '="' + (env.attributes[name] || '') + '"'; | |
| 453 | − } | |
| 453 | + var attributes = Object.keys(env.attributes).map(function(name) { | |
| 454 | + return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; | |
| 455 | + }).join(' '); | |
| 454 | 456 | |
| 455 | 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 | 485 | // if (script) { |
| 484 | 486 | // _.filename = script.src; |
| 485 | 487 | |
| 486 | −// if (document.addEventListener && !script.hasAttribute('data-manual')) { | |
| 488 | +// if (document.addEventListener && !_.manual && !script.hasAttribute('data-manual')) { | |
| 487 | 489 | // if(document.readyState !== "loading") { |
| 488 | 490 | // if (window.requestAnimationFrame) { |
| 489 | 491 | // window.requestAnimationFrame(_.highlightAll); |
| @@ -513,7 +515,7 @@ if (typeof global !== 'undefined') { · 23 unmodified lines | ||
| 513 | 515 | Prism.languages.markup = { |
| 514 | 516 | 'comment': /<!--[\w\W]*?-->/, |
| 515 | 517 | 'prolog': /<\?[\w\W]+?\?>/, |
| 516 | − 'doctype': /<!DOCTYPE[\w\W]+?>/, | |
| 518 | + 'doctype': /<!DOCTYPE[\w\W]+?>/i, | |
| 517 | 519 | 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i, |
| 518 | 520 | 'tag': { |
| 519 | 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 | 571 | 'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i, |
| 570 | 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 | 577 | 'property': /(\b|\B)[\w-]+(?=\s*:)/i, |
| 573 | 578 | 'important': /\B!important\b/i, |
| 574 | 579 | 'function': /[-a-z0-9]+(?=\()/i, |
| @@ -745,7 +750,7 @@ Prism.languages.coffeescript = Prism.languages.extend('javascript', { · 170 unmodified lines | ||
| 745 | 750 | // Strings are multiline |
| 746 | 751 | { |
| 747 | 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 | 852 | 'regex': [ |
| 848 | 853 | { |
| 849 | 854 | pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/, |
| 855 | + greedy: true, | |
| 850 | 856 | inside: { |
| 851 | 857 | 'interpolation': interpolation |
| 852 | 858 | } |
| 853 | 859 | }, |
| 854 | 860 | { |
| 855 | 861 | pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/, |
| 862 | + greedy: true, | |
| 856 | 863 | inside: { |
| 857 | 864 | 'interpolation': interpolation |
| 858 | 865 | } |
| @@ -860,25 +867,29 @@ delete Prism.languages.coffeescript['template-string']; · 1 unmodified line | ||
| 860 | 867 | { |
| 861 | 868 | // Here we need to specifically allow interpolation |
| 862 | 869 | pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/, |
| 870 | + greedy: true, | |
| 863 | 871 | inside: { |
| 864 | 872 | 'interpolation': interpolation |
| 865 | 873 | } |
| 866 | 874 | }, |
| 867 | 875 | { |
| 868 | 876 | pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/, |
| 877 | + greedy: true, | |
| 869 | 878 | inside: { |
| 870 | 879 | 'interpolation': interpolation |
| 871 | 880 | } |
| 872 | 881 | }, |
| 873 | 882 | { |
| 874 | 883 | pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/, |
| 884 | + greedy: true, | |
| 875 | 885 | inside: { |
| 876 | 886 | 'interpolation': interpolation |
| 877 | 887 | } |
| 878 | 888 | }, |
| 879 | 889 | { |
| 880 | − pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/, | |
| 881 | − lookbehind: true | |
| 890 | + pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/, | |
| 891 | + lookbehind: true, | |
| 892 | + greedy: true | |
| 882 | 893 | } |
| 883 | 894 | ], |
| 884 | 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 | 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 | 901 | 'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/ |
| 891 | 902 | }); |
| 892 | 903 | |
| 893 | 904 | Prism.languages.ruby.string = [ |
| 894 | 905 | { |
| 895 | 906 | pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/, |
| 907 | + greedy: true, | |
| 896 | 908 | inside: { |
| 897 | 909 | 'interpolation': interpolation |
| 898 | 910 | } |
| 899 | 911 | }, |
| 900 | 912 | { |
| 901 | 913 | pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/, |
| 914 | + greedy: true, | |
| 902 | 915 | inside: { |
| 903 | 916 | 'interpolation': interpolation |
| 904 | 917 | } |
| @@ -906,24 +919,28 @@ delete Prism.languages.coffeescript['template-string']; · 1 unmodified line | ||
| 906 | 919 | { |
| 907 | 920 | // Here we need to specifically allow interpolation |
| 908 | 921 | pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/, |
| 922 | + greedy: true, | |
| 909 | 923 | inside: { |
| 910 | 924 | 'interpolation': interpolation |
| 911 | 925 | } |
| 912 | 926 | }, |
| 913 | 927 | { |
| 914 | 928 | pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/, |
| 929 | + greedy: true, | |
| 915 | 930 | inside: { |
| 916 | 931 | 'interpolation': interpolation |
| 917 | 932 | } |
| 918 | 933 | }, |
| 919 | 934 | { |
| 920 | 935 | pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/, |
| 936 | + greedy: true, | |
| 921 | 937 | inside: { |
| 922 | 938 | 'interpolation': interpolation |
| 923 | 939 | } |
| 924 | 940 | }, |
| 925 | 941 | { |
| 926 | 942 | pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/, |
| 943 | + greedy: true, | |
| 927 | 944 | inside: { |
| 928 | 945 | 'interpolation': interpolation |
| 929 | 946 | } |
| @@ -944,12 +961,14 @@ Prism.languages.elixir = { · 14 unmodified lines | ||
| 944 | 961 | { |
| 945 | 962 | // ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo> |
| 946 | 963 | pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/, |
| 964 | + greedy: true, | |
| 947 | 965 | inside: { |
| 948 | 966 | // See interpolation below |
| 949 | 967 | } |
| 950 | 968 | }, |
| 951 | 969 | { |
| 952 | 970 | pattern: /("""|''')[\s\S]*?\1/, |
| 971 | + greedy: true, | |
| 953 | 972 | inside: { |
| 954 | 973 | // See interpolation below |
| 955 | 974 | } |
| @@ -957,6 +976,7 @@ Prism.languages.elixir = { · 1 unmodified line | ||
| 957 | 976 | { |
| 958 | 977 | // Multi-line strings are allowed |
| 959 | 978 | pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/, |
| 979 | + greedy: true, | |
| 960 | 980 | inside: { |
| 961 | 981 | // See interpolation below |
| 962 | 982 | } |
| @@ -1027,18 +1047,21 @@ Prism.languages.go = Prism.languages.extend('clike', { · 64 unmodified lines | ||
| 1027 | 1047 | 'boolean': /\b(_|iota|nil|true|false)\b/, |
| 1028 | 1048 | 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./, |
| 1029 | 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 | }); |
| 1032 | 1055 | delete Prism.languages.go['class-name']; |
| 1033 | 1056 | |
| 1034 | 1057 | Prism.languages.json = { |
| 1035 | − 'property': /".*?"(?=\s*:)/ig, | |
| 1036 | − 'string': /"(?!:)(\\?[^"])*?"(?!:)/g, | |
| 1037 | − 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g, | |
| 1038 | − 'punctuation': /[{}[\]);,]/g, | |
| 1039 | − 'operator': /:/g, | |
| 1040 | − 'boolean': /\b(true|false)\b/gi, | |
| 1041 | − 'null': /\bnull\b/gi, | |
| 1058 | + 'property': /"(?:\\.|[^\\"])*"(?=\s*:)/ig, | |
| 1059 | + 'string': /"(?!:)(?:\\.|[^\\"])*"(?!:)/g, | |
| 1060 | + 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?)\b/g, | |
| 1061 | + 'punctuation': /[{}[\]);,]/g, | |
| 1062 | + 'operator': /:/g, | |
| 1063 | + 'boolean': /\b(true|false)\b/gi, | |
| 1064 | + 'null': /\bnull\b/gi | |
| 1042 | 1065 | }; |
| 1043 | 1066 | |
| 1044 | 1067 | Prism.languages.jsonp = Prism.languages.json; |
| @@ -1151,92 +1174,143 @@ Prism.languages.perl = { · 106 unmodified lines | ||
| 1151 | 1174 | // TODO Could be nice to handle Heredoc too. |
| 1152 | 1175 | 'string': [ |
| 1153 | 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 | 1182 | // 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 | 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 | 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 | 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 | 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 | 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 | 1225 | 'regex': [ |
| 1179 | 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 | 1232 | // 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 | 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 | 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 | 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 | 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 | 1262 | // The lookbehinds prevent -s from breaking |
| 1198 | 1263 | // FIXME We don't handle change of separator like s(...)[...] |
| 1199 | 1264 | // s/.../.../ |
| 1200 | 1265 | { |
| 1201 | 1266 | pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/, |
| 1202 | − lookbehind: true | |
| 1267 | + lookbehind: true, | |
| 1268 | + greedy: true | |
| 1203 | 1269 | }, |
| 1204 | 1270 | |
| 1205 | 1271 | // s a...a...a |
| 1206 | 1272 | { |
| 1207 | 1273 | pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/, |
| 1208 | − lookbehind: true | |
| 1274 | + lookbehind: true, | |
| 1275 | + greedy: true | |
| 1209 | 1276 | }, |
| 1210 | 1277 | |
| 1211 | 1278 | // s(...)(...) |
| 1212 | 1279 | { |
| 1213 | 1280 | pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/, |
| 1214 | − lookbehind: true | |
| 1281 | + lookbehind: true, | |
| 1282 | + greedy: true | |
| 1215 | 1283 | }, |
| 1216 | 1284 | |
| 1217 | 1285 | // s{...}{...} |
| 1218 | 1286 | { |
| 1219 | 1287 | pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/, |
| 1220 | − lookbehind: true | |
| 1288 | + lookbehind: true, | |
| 1289 | + greedy: true | |
| 1221 | 1290 | }, |
| 1222 | 1291 | |
| 1223 | 1292 | // s[...][...] |
| 1224 | 1293 | { |
| 1225 | 1294 | pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/, |
| 1226 | − lookbehind: true | |
| 1295 | + lookbehind: true, | |
| 1296 | + greedy: true | |
| 1227 | 1297 | }, |
| 1228 | 1298 | |
| 1229 | 1299 | // s<...><...> |
| 1230 | 1300 | { |
| 1231 | 1301 | pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/, |
| 1232 | − lookbehind: true | |
| 1302 | + lookbehind: true, | |
| 1303 | + greedy: true | |
| 1233 | 1304 | }, |
| 1234 | 1305 | |
| 1235 | 1306 | // /.../ |
| 1236 | 1307 | // The look-ahead tries to prevent two divisions on |
| 1237 | 1308 | // the same line from being highlighted as regex. |
| 1238 | 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 | 1316 | // FIXME Not sure about the handling of ::, ', and # |
| @@ -1342,6 +1416,7 @@ if (Prism.languages.markup) { · 99 unmodified lines | ||
| 1342 | 1416 | |
| 1343 | 1417 | env.tokenStack = []; |
| 1344 | 1418 | |
| 1419 | + env.backupCode = env.code; | |
| 1345 | 1420 | env.code = env.code.replace(/(?:<\?php|<\?)[\w\W]*?(?:\?>)/ig, function(match) { |
| 1346 | 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 | 1435 | // Re-insert the tokens after highlighting |
| 1353 | 1436 | Prism.hooks.add('after-highlight', function(env) { |
| 1354 | 1437 | if (env.language !== 'php') { |
| @@ -1411,7 +1494,7 @@ Prism.languages.python= { · 56 unmodified lines | ||
| 1411 | 1494 | (function(Prism) { |
| 1412 | 1495 | Prism.languages.crystal = Prism.languages.extend('ruby', { |
| 1413 | 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 | 1499 | pattern: /(\.\s*)(?:is_a|responds_to)\?/, |
| 1417 | 1500 | lookbehind: true |
| @@ -1481,13 +1564,20 @@ Prism.languages.rust = { · 63 unmodified lines | ||
| 1481 | 1564 | } |
| 1482 | 1565 | ], |
| 1483 | 1566 | 'string': [ |
| 1484 | − /b?r(#*)"(?:\\?.)*?"\1/, | |
| 1485 | − /b?("|')(?:\\?.)*?\1/ | |
| 1567 | + { | |
| 1568 | + pattern: /b?r(#*)"(?:\\?.)*?"\1/, | |
| 1569 | + greedy: true | |
| 1570 | + }, | |
| 1571 | + { | |
| 1572 | + pattern: /b?("|')(?:\\?.)*?\1/, | |
| 1573 | + greedy: true | |
| 1574 | + } | |
| 1486 | 1575 | ], |
| 1487 | 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 | 1578 | 'attribute': { |
| 1490 | 1579 | pattern: /#!?\[.+?\]/, |
| 1580 | + greedy: true, | |
| 1491 | 1581 | alias: 'attr-name' |
| 1492 | 1582 | }, |
| 1493 | 1583 | |
| @@ -1597,6 +1687,7 @@ Prism.languages.sql= { · 103 unmodified lines | ||
| 1597 | 1687 | }, |
| 1598 | 1688 | 'string' : { |
| 1599 | 1689 | pattern: /(^|[^@\\])("|')(?:\\?[\s\S])*?\2/, |
| 1690 | + greedy: true, | |
| 1600 | 1691 | lookbehind: true |
| 1601 | 1692 | }, |
| 1602 | 1693 | 'variable': /@[\w.$]+|@("|'|`)(?:\\?[\s\S])+?\1/, |
| @@ -1608,6 +1699,8 @@ Prism.languages.sql= { · 5 unmodified lines | ||
| 1608 | 1699 | 'punctuation': /[;[\]()`,.]/ |
| 1609 | 1700 | }; |
| 1610 | 1701 | Prism.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 | |
| 1706 | +Prism.languages.ts = Prism.languages.typescript; | |