History

Update Prism.js

Thibaut committed 11 years ago

Commit f879ad01 parent 4ce964c1 file · +347 −127Browse files

Unified · Split

assets/javascripts/vendor/prism.js+347−127
@@ -1,5 +1,5 @@
1−/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+php+python+ruby+rust */
2−self = (typeof window !== 'undefined')
1+/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+elixir+php+python+rust */
2+var _self = (typeof window !== 'undefined')
33 ? window // if in browser
44 : (
55 (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
@@ -18,7 +18,7 @@ var Prism = (function(){ · 12 unmodified lines
1818 // Private helper vars
1919 var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
2020
21−var _ = self.Prism = {
21+var _ = _self.Prism = {
2222 util: {
2323 encode: function (tokens) {
2424 if (tokens instanceof Token) {
@@ -51,7 +51,8 @@ var _ = self.Prism = { · 26 unmodified lines
5151 return clone;
5252
5353 case 'Array':
54− return o.map(function(v) { return _.util.clone(v); });
54+ // Check for existence for IE8
55+ return o.map && o.map(function(v) { return _.util.clone(v); });
5556 }
5657
5758 return o;
@@ -140,6 +141,7 @@ var _ = self.Prism = { · 82 unmodified lines
140141 }
141142 }
142143 },
144+ plugins: {},
143145
144146 highlightAll: function(async, callback) {
145147 var elements = document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');
@@ -162,10 +164,6 @@ var _ = self.Prism = { · 16 unmodified lines
162164 grammar = _.languages[language];
163165 }
164166
165− if (!grammar) {
166− return;
167− }
168−
169167 // Set language on the element, if not present
170168 element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
171169
@@ -178,12 +176,6 @@ var _ = self.Prism = { · 6 unmodified lines
178176
179177 var code = element.textContent;
180178
181− if(!code) {
182− return;
183− }
184−
185− code = code.replace(/^(?:\r?\n|\r)/,'');
186−
187179 var env = {
188180 element: element,
189181 language: language,
@@ -191,13 +183,18 @@ var _ = self.Prism = { · 1 unmodified line
191183 code: code
192184 };
193185
186+ if (!code || !grammar) {
187+ _.hooks.run('complete', env);
188+ return;
189+ }
190+
194191 _.hooks.run('before-highlight', env);
195192
196− // if (async && self.Worker) {
193+ // if (async && _self.Worker) {
197194 // var worker = new Worker(_.filename);
198195
199196 // worker.onmessage = function(evt) {
200− // env.highlightedCode = Token.stringify(JSON.parse(evt.data), language);
197+ // env.highlightedCode = evt.data;
201198
202199 // _.hooks.run('before-insert', env);
203200
@@ -205,11 +202,13 @@ var _ = self.Prism = { · 1 unmodified line
205202
206203 // callback && callback.call(env.element);
207204 // _.hooks.run('after-highlight', env);
205+ // _.hooks.run('complete', env);
208206 // };
209207
210208 // worker.postMessage(JSON.stringify({
211209 // language: env.language,
212− // code: env.code
210+ // code: env.code,
211+ // immediateClose: true
213212 // }));
214213 // }
215214 // else {
@@ -222,6 +221,7 @@ var _ = self.Prism = { · 6 unmodified lines
222221 callback && callback.call(element);
223222
224223 _.hooks.run('after-highlight', env);
224+ _.hooks.run('complete', env);
225225 // }
226226 },
227227
@@ -380,29 +380,32 @@ Token.stringify = function(o, language, parent) { · 152 unmodified lines
380380 var attributes = '';
381381
382382 for (var name in env.attributes) {
383− attributes += name + '="' + (env.attributes[name] || '') + '"';
383+ attributes += (attributes ? ' ' : '') + name + '="' + (env.attributes[name] || '') + '"';
384384 }
385385
386386 return '<' + env.tag + ' class="' + env.classes.join(' ') + '" ' + attributes + '>' + env.content + '</' + env.tag + '>';
387387
388388 };
389389
390−// if (!self.document) {
391−// if (!self.addEventListener) {
390+// if (!_self.document) {
391+// if (!_self.addEventListener) {
392392 // // in Node.js
393−// return self.Prism;
393+// return _self.Prism;
394394 // }
395395 // // In worker
396−// self.addEventListener('message', function(evt) {
396+// _self.addEventListener('message', function(evt) {
397397 // var message = JSON.parse(evt.data),
398398 // lang = message.language,
399−// code = message.code;
399+// code = message.code,
400+// immediateClose = message.immediateClose;
400401
401−// self.postMessage(JSON.stringify(_.util.encode(_.tokenize(code, _.languages[lang]))));
402−// self.close();
402+// _self.postMessage(_.highlight(code, _.languages[lang], lang));
403+// if (immediateClose) {
404+// _self.close();
405+// }
403406 // }, false);
404407
405−// return self.Prism;
408+// return _self.Prism;
406409 // }
407410
408411 // // Get current script and highlight
@@ -418,40 +421,45 @@ Token.stringify = function(o, language, parent) { · 9 unmodified lines
418421 // }
419422 // }
420423
421−return self.Prism;
424+return _self.Prism;
422425
423426 })();
424427
425428 if (typeof module !== 'undefined' && module.exports) {
426429 module.exports = Prism;
427430 }
431+
432+// hack for components to work correctly in node.js
433+if (typeof global !== 'undefined') {
434+ global.Prism = Prism;
435+}
428436 ;
429437 Prism.languages.markup = {
430438 'comment': /<!--[\w\W]*?-->/,
431− 'prolog': /<\?.+?\?>/,
432− 'doctype': /<!DOCTYPE.+?>/,
439+ 'prolog': /<\?[\w\W]+?\?>/,
440+ 'doctype': /<!DOCTYPE[\w\W]+?>/,
433441 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
434442 'tag': {
435− pattern: /<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i,
443+ pattern: /<\/?(?!\d)[^\s>\/=.$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
436444 inside: {
437445 'tag': {
438− pattern: /^<\/?[\w:-]+/i,
446+ pattern: /^<\/?[^\s>\/]+/i,
439447 inside: {
440448 'punctuation': /^<\/?/,
441− 'namespace': /^[\w-]+?:/
449+ 'namespace': /^[^\s>\/:]+:/
442450 }
443451 },
444452 'attr-value': {
445453 pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
446454 inside: {
447− 'punctuation': /=|>|"/
455+ 'punctuation': /[=>"']/
448456 }
449457 },
450458 'punctuation': /\/?>/,
451459 'attr-name': {
452− pattern: /[\w:-]+/,
460+ pattern: /[^\s>\/]+/,
453461 inside: {
454− 'namespace': /^[\w-]+?:/
462+ 'namespace': /^[^\s>\/:]+:/
455463 }
456464 }
457465
@@ -467,35 +475,38 @@ Prism.hooks.add('wrap', function(env) { · 9 unmodified lines
467475 env.attributes['title'] = env.content.replace(/&amp;/, '&');
468476 }
469477 });
470−;
478+
479+Prism.languages.xml = Prism.languages.markup;
480+Prism.languages.html = Prism.languages.markup;
481+Prism.languages.mathml = Prism.languages.markup;
482+Prism.languages.svg = Prism.languages.markup;
483+
471484 Prism.languages.css = {
472485 'comment': /\/\*[\w\W]*?\*\//,
473486 'atrule': {
474487 pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
475488 inside: {
476− 'punctuation': /[;:]/
489+ 'rule': /@[\w-]+/
490+ // See rest below
477491 }
478492 },
479− 'url': /url\((?:(["'])(\\\n|\\?.)*?\1|.*?)\)/i,
480− 'selector': /[^\{\}\s][^\{\};]*(?=\s*\{)/,
481− 'string': /("|')(\\\n|\\?.)*?\1/,
493+ 'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
494+ 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
495+ 'string': /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
482496 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
483497 'important': /\B!important\b/i,
484− 'punctuation': /[\{\};:]/,
485− 'function': /[-a-z0-9]+(?=\()/i
498+ 'function': /[-a-z0-9]+(?=\()/i,
499+ 'punctuation': /[(){};:]/
486500 };
487501
502+Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
503+
488504 if (Prism.languages.markup) {
489505 Prism.languages.insertBefore('markup', 'tag', {
490506 'style': {
491− pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,
492− inside: {
493− 'tag': {
494− pattern: /<style[\w\W]*?>|<\/style>/i,
495− inside: Prism.languages.markup.tag.inside
496− },
497− rest: Prism.languages.css
498− },
507+ pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
508+ lookbehind: true,
509+ inside: Prism.languages.css,
499510 alias: 'language-css'
500511 }
501512 });
@@ -529,9 +540,9 @@ Prism.languages.clike = { · 27 unmodified lines
529540 lookbehind: true
530541 }
531542 ],
532− 'string': /("|')(\\\n|\\?.)*?\1/,
543+ 'string': /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
533544 'class-name': {
534− pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
545+ pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
535546 lookbehind: true,
536547 inside: {
537548 punctuation: /(\.|\\)/
@@ -539,75 +550,93 @@ Prism.languages.clike = { · 1 unmodified line
539550 },
540551 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
541552 'boolean': /\b(true|false)\b/,
542− 'function': {
543− pattern: /[a-z0-9_]+\(/i,
544− inside: {
545− punctuation: /\(/
546− }
547− },
548− 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
549− 'operator': /[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|~|\^|%/,
550− 'ignore': /&(lt|gt|amp);/i,
553+ 'function': /[a-z0-9_]+(?=\()/i,
554+ 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
555+ 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
551556 'punctuation': /[{}[\];(),.:]/
552557 };
553−;
558+
554559 Prism.languages.javascript = Prism.languages.extend('clike', {
555− '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)\b/,
556− 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|-?Infinity)\b/,
557− 'function': /(?!\d)[a-z0-9_$]+(?=\()/i
560+ '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)\b/,
561+ 'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
562+ // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
563+ 'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i
558564 });
559565
560566 Prism.languages.insertBefore('javascript', 'keyword', {
561567 'regex': {
562− pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
568+ pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
563569 lookbehind: true
564570 }
565571 });
566572
573+Prism.languages.insertBefore('javascript', 'class-name', {
574+ 'template-string': {
575+ pattern: /`(?:\\`|\\?[^`])*`/,
576+ inside: {
577+ 'interpolation': {
578+ pattern: /\$\{[^}]+\}/,
579+ inside: {
580+ 'interpolation-punctuation': {
581+ pattern: /^\$\{|\}$/,
582+ alias: 'punctuation'
583+ },
584+ rest: Prism.languages.javascript
585+ }
586+ },
587+ 'string': /[\s\S]+/
588+ }
589+ }
590+});
591+
567592 if (Prism.languages.markup) {
568593 Prism.languages.insertBefore('markup', 'tag', {
569594 'script': {
570− pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,
571− inside: {
572− 'tag': {
573− pattern: /<script[\w\W]*?>|<\/script>/i,
574− inside: Prism.languages.markup.tag.inside
575− },
576− rest: Prism.languages.javascript
577− },
595+ pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
596+ lookbehind: true,
597+ inside: Prism.languages.javascript,
578598 alias: 'language-javascript'
579599 }
580600 });
581601 }
582−;
602+
603+Prism.languages.js = Prism.languages.javascript;
583604 Prism.languages.c = Prism.languages.extend('clike', {
584− // allow for c multiline strings
585− 'string': /("|')([^\n\\\1]|\\.|\\\r*\n)*?\1/,
586605 'keyword': /\b(asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
587− 'operator': /[-+]{1,2}|!=?|<{1,2}=?|>{1,2}=?|\->|={1,2}|\^|~|%|&{1,2}|\|?\||\?|\*|\//
606+ 'operator': /\-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*\/]/,
607+ 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*\b/i
588608 });
589609
590610 Prism.languages.insertBefore('c', 'string', {
591− // property class reused for macro statements
592− 'property': {
611+ 'macro': {
593612 // allow for multiline macro definitions
594613 // spaces after the # character compile fine with gcc
595− pattern: /((^|\n)\s*)#\s*[a-z]+([^\n\\]|\\.|\\\r*\n)*/i,
614+ pattern: /(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,
596615 lookbehind: true,
616+ alias: 'property',
597617 inside: {
598618 // highlight the path of the include statement as a string
599619 'string': {
600620 pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
601621 lookbehind: true
622+ },
623+ // highlight macro directives as keywords
624+ 'directive': {
625+ pattern: /(#\s*)\b(define|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
626+ lookbehind: true,
627+ alias: 'keyword'
602628 }
603629 }
604− }
630+ },
631+ // highlight predefined macros as constants
632+ 'constant': /\b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|stdin|stdout|stderr)\b/
605633 });
606634
607635 delete Prism.languages.c['class-name'];
608−delete Prism.languages.c['boolean'];;
636+delete Prism.languages.c['boolean'];
637+
609638 Prism.languages.cpp = Prism.languages.extend('c', {
610− 'keyword': /\b(alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype|default|delete|delete\[\]|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|long|mutable|namespace|new|new\[\]|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,
639+ 'keyword': /\b(alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,
611640 'boolean': /\b(true|false)\b/,
612641 'operator': /[-+]{1,2}|!=?|<{1,2}=?|>{1,2}=?|\->|:{1,2}|={1,2}|\^|~|%|&{1,2}|\|?\||\?|\*|\/|\b(and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/
613642 });
@@ -617,7 +646,7 @@ Prism.languages.insertBefore('cpp', 'keyword', { · 3 unmodified lines
617646 pattern: /(class\s+)[a-z0-9_]+/i,
618647 lookbehind: true
619648 }
620−});;
649+});
621650 (function(Prism) {
622651
623652 // Ignore comments starting with { to privilege string interpolation highlighting
@@ -632,11 +661,11 @@ Prism.languages.coffeescript = Prism.languages.extend('javascript', { · 8 unmodified lines
632661 'string': [
633662
634663 // Strings are multiline
635− /'(?:\\?[\s\S])*?'/,
664+ /'(?:\\?[^\\])*?'/,
636665
637666 {
638667 // Strings are multiline
639− pattern: /"(?:\\?[\s\S])*?"/,
668+ pattern: /"(?:\\?[^\\])*?"/,
640669 inside: {
641670 'interpolation': interpolation
642671 }
@@ -700,7 +729,208 @@ Prism.languages.insertBefore('coffeescript', 'keyword', { · 57 unmodified lines
700729 'property': /(?!\d)\w+(?=\s*:(?!:))/
701730 });
702731
703−}(Prism));;
732+}(Prism));
733+/**
734+ * Original by Samuel Flores
735+ *
736+ * Adds the following new token classes:
737+ * constant, builtin, variable, symbol, regex
738+ */
739+(function(Prism) {
740+ Prism.languages.ruby = Prism.languages.extend('clike', {
741+ 'comment': /#(?!\{[^\r\n]*?\}).*/,
742+ 'keyword': /\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/
743+ });
744+
745+ var interpolation = {
746+ pattern: /#\{[^}]+\}/,
747+ inside: {
748+ 'delimiter': {
749+ pattern: /^#\{|\}$/,
750+ alias: 'tag'
751+ },
752+ rest: Prism.util.clone(Prism.languages.ruby)
753+ }
754+ };
755+
756+ Prism.languages.insertBefore('ruby', 'keyword', {
757+ 'regex': [
758+ {
759+ pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,
760+ inside: {
761+ 'interpolation': interpolation
762+ }
763+ },
764+ {
765+ pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
766+ inside: {
767+ 'interpolation': interpolation
768+ }
769+ },
770+ {
771+ // Here we need to specifically allow interpolation
772+ pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
773+ inside: {
774+ 'interpolation': interpolation
775+ }
776+ },
777+ {
778+ pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
779+ inside: {
780+ 'interpolation': interpolation
781+ }
782+ },
783+ {
784+ pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
785+ inside: {
786+ 'interpolation': interpolation
787+ }
788+ },
789+ {
790+ pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
791+ lookbehind: true
792+ }
793+ ],
794+ 'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,
795+ 'symbol': /:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/
796+ });
797+
798+ Prism.languages.insertBefore('ruby', 'number', {
799+ '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/,
800+ 'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/
801+ });
802+
803+ Prism.languages.ruby.string = [
804+ {
805+ pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
806+ inside: {
807+ 'interpolation': interpolation
808+ }
809+ },
810+ {
811+ pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
812+ inside: {
813+ 'interpolation': interpolation
814+ }
815+ },
816+ {
817+ // Here we need to specifically allow interpolation
818+ pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
819+ inside: {
820+ 'interpolation': interpolation
821+ }
822+ },
823+ {
824+ pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
825+ inside: {
826+ 'interpolation': interpolation
827+ }
828+ },
829+ {
830+ pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
831+ inside: {
832+ 'interpolation': interpolation
833+ }
834+ },
835+ {
836+ pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
837+ inside: {
838+ 'interpolation': interpolation
839+ }
840+ }
841+ ];
842+}(Prism));
843+Prism.languages.elixir = {
844+ // Negative look-ahead is needed for string interpolation
845+ // Negative look-behind is needed to avoid highlighting markdown headers in
846+ // multi-line doc strings
847+ 'comment': {
848+ pattern: /(^|[^#])#(?![{#]).*/m,
849+ lookbehind: true
850+ },
851+ // ~r"""foo""", ~r'''foo''', ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
852+ 'regex': /~[rR](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|[^}])+\}|<(?:\\>|[^>])+>)[uismxfr]*/,
853+ 'string': [
854+ {
855+ // ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>
856+ pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/,
857+ inside: {
858+ // See interpolation below
859+ }
860+ },
861+ {
862+ pattern: /("""|''')[\s\S]*?\1/,
863+ inside: {
864+ // See interpolation below
865+ }
866+ },
867+ {
868+ // Multi-line strings are allowed
869+ pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
870+ inside: {
871+ // See interpolation below
872+ }
873+ }
874+ ],
875+ 'atom': {
876+ // Look-behind prevents bad highlighting of the :: operator
877+ pattern: /(^|[^:]):\w+/,
878+ lookbehind: true,
879+ alias: 'symbol'
880+ },
881+ // Look-ahead prevents bad highlighting of the :: operator
882+ 'attr-name': /\w+:(?!:)/,
883+ 'capture': {
884+ // Look-behind prevents bad highlighting of the && operator
885+ pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
886+ lookbehind: true,
887+ alias: 'function'
888+ },
889+ 'argument': {
890+ // Look-behind prevents bad highlighting of the && operator
891+ pattern: /(^|[^&])&\d+/,
892+ lookbehind: true,
893+ alias: 'variable'
894+ },
895+ 'attribute': {
896+ pattern: /@[\S]+/,
897+ alias: 'variable'
898+ },
899+ 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
900+ 'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct)?|do|else|end|fn|for|if|import|not|or|require|rescue|try|unless|use|when)\b/,
901+ 'boolean': /\b(?:true|false|nil)\b/,
902+ 'operator': [
903+ /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
904+ {
905+ // We don't want to match <<
906+ pattern: /([^<])<(?!<)/,
907+ lookbehind: true
908+ },
909+ {
910+ // We don't want to match >>
911+ pattern: /([^>])>(?!>)/,
912+ lookbehind: true
913+ }
914+ ],
915+ 'punctuation': /<<|>>|[.,%\[\]{}()]/
916+};
917+
918+Prism.languages.elixir.string.forEach(function(o) {
919+ o.inside = {
920+ 'interpolation': {
921+ pattern: /#\{[^}]+\}/,
922+ inside: {
923+ 'delimiter': {
924+ pattern: /^#\{|\}$/,
925+ alias: 'punctuation'
926+ },
927+ rest: Prism.util.clone(Prism.languages.elixir)
928+ }
929+ }
930+ };
931+});
932+
933+
704934 /**
705935 * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
706936 * Modified by Miles Johnson: http://milesj.me
@@ -718,7 +948,7 @@ Prism.languages.php = Prism.languages.extend('clike', { · 11 unmodified lines
718948 'keyword': /\b(and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|private|protected|parent|throw|null|echo|print|trait|namespace|final|yield|goto|instanceof|finally|try|catch)\b/i,
719949 'constant': /\b[A-Z0-9_]{2,}\b/,
720950 'comment': {
721− pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/).*?(\r?\n|$))/,
951+ pattern: /(^|[^\\])(?:\/\*[\w\W]*?\*\/|\/\/.*)/,
722952 lookbehind: true
723953 }
724954 });
@@ -727,15 +957,15 @@ Prism.languages.php = Prism.languages.extend('clike', { · 2 unmodified lines
727957 // common than strings containing hashes...
728958 Prism.languages.insertBefore('php', 'class-name', {
729959 'shell-comment': {
730− pattern: /(^|[^\\])#.*?(\r?\n|$)/,
960+ pattern: /(^|[^\\])#.*/,
731961 lookbehind: true,
732962 alias: 'comment'
733963 }
734964 });
735965
736966 Prism.languages.insertBefore('php', 'keyword', {
737− 'delimiter': /(\?>|<\?php|<\?)/i,
738− 'variable': /(\$\w+)\b/i,
967+ 'delimiter': /\?>|<\?(?:php)?/i,
968+ 'variable': /\$\w+\b/i,
739969 'package': {
740970 pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
741971 lookbehind: true,
@@ -788,7 +1018,8 @@ if (Prism.languages.markup) { · 46 unmodified lines
7881018 }
7891019
7901020 for (var i = 0, t; t = env.tokenStack[i]; i++) {
791− env.highlightedCode = env.highlightedCode.replace('{{{PHP' + (i + 1) + '}}}', Prism.highlight(t, env.grammar, 'php'));
1021+ // The replace prevents $$, $&, $`, $', $n, $nn from being interpreted as special patterns
1022+ env.highlightedCode = env.highlightedCode.replace('{{{PHP' + (i + 1) + '}}}', Prism.highlight(t, env.grammar, 'php').replace(/\$/g, '$$$$'));
7921023 }
7931024
7941025 env.element.innerHTML = env.highlightedCode;
@@ -812,41 +1043,30 @@ if (Prism.languages.markup) { · 17 unmodified lines
8121043 }
8131044 ;
8141045 Prism.languages.python= {
1046+ 'triple-quoted-string': {
1047+ pattern: /"""[\s\S]+?"""|'''[\s\S]+?'''/,
1048+ alias: 'string'
1049+ },
8151050 'comment': {
816− pattern: /(^|[^\\])#.*?(\r?\n|$)/,
1051+ pattern: /(^|[^\\])#.*/,
1052+ lookbehind: true
1053+ },
1054+ 'string': /("|')(?:\\?.)*?\1/,
1055+ 'function' : {
1056+ pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\()/g,
1057+ lookbehind: true
1058+ },
1059+ 'class-name': {
1060+ pattern: /(\bclass\s+)[a-z0-9_]+/i,
8171061 lookbehind: true
8181062 },
819− 'string': /"""[\s\S]+?"""|'''[\s\S]+?'''|("|')(\\?.)*?\1/,
820− 'keyword' : /\b(as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/,
821− 'boolean' : /\b(True|False)\b/,
822− 'number' : /\b-?(0[box])?(?:[\da-f]+\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
823− 'operator' : /[-+]|<=?|>=?|!|={1,2}|&{1,2}|\|?\||\?|\*|\/|~|\^|%|\b(or|and|not)\b/,
1063+ 'keyword' : /\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/,
1064+ 'boolean' : /\b(?:True|False)\b/,
1065+ 'number' : /\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
1066+ 'operator' : /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
8241067 'punctuation' : /[{}[\];(),.:]/
8251068 };
8261069
827−;
828−/**
829− * Original by Samuel Flores
830− *
831− * Adds the following new token classes:
832− * constant, builtin, variable, symbol, regex
833− */
834−Prism.languages.ruby = Prism.languages.extend('clike', {
835− 'comment': /#[^\r\n]*(\r?\n|$)/,
836− 'keyword': /\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/,
837− '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/,
838− 'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/
839−});
840−
841−Prism.languages.insertBefore('ruby', 'keyword', {
842− 'regex': {
843− pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
844− lookbehind: true
845− },
846− 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/,
847− 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/
848−});
849−;
8501070 /* TODO
8511071 Add support for Markdown notation inside doc comments
8521072 Add support for nested block comments...
@@ -861,7 +1081,7 @@ Prism.languages.rust = { · 8 unmodified lines
8611081 lookbehind: true
8621082 },
8631083 {
864− pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/,
1084+ pattern: /(^|[^\\:])\/\/.*/,
8651085 lookbehind: true
8661086 }
8671087 ],
@@ -887,7 +1107,7 @@ Prism.languages.rust = { · 19 unmodified lines
8871107 },
8881108
8891109 // Hex, oct, bin, dec numbers with visual separators and type suffix
890− 'number': /\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32)?|f32|f64))?\b/,
1110+ 'number': /\b-?(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64)?|f32|f64))?\b/,
8911111
8921112 // Closure params should not be confused with bitwise OR |
8931113 'closure-params': {
@@ -897,6 +1117,6 @@ Prism.languages.rust = { · 3 unmodified lines
8971117 'operator': /[&*]/
8981118 }
8991119 },
900− 'punctuation': /[{}[\];(),.:]|->/,
901− 'operator': /[-+]{1,2}|!=?|<=?|>=?|={1,3}|&&?|\|\|?|\*|\/|\^|%|<<|>>@/
902−};;
1120+ 'punctuation': /[{}[\];(),:]|\.+|->/,
1121+ 'operator': /[-+*\/%!^=]=?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
1122+};