History

Update Prism.js

Thibaut committed 11 years ago

Commit 83e8f5e1 parent 175c9821 file · +264 −127Browse files

Unified · Split

assets/javascripts/vendor/prism.js+264−127
@@ -1,4 +1,12 @@
1−/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+php+coffeescript+c+cpp+python+ruby */
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')
3+ ? window // if in browser
4+ : (
5+ (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
6+ ? self // if in worker
7+ : {} // if in node js
8+ );
9+
210 /**
311 * Prism: Lightweight, robust, elegant syntax highlighting
412 * MIT license http://www.opensource.org/licenses/mit-license.php/
@@ -43,7 +51,7 @@ var _ = self.Prism = { · 38 unmodified lines
4351 return clone;
4452
4553 case 'Array':
46− return o.slice();
54+ return o.map(function(v) { return _.util.clone(v); });
4755 }
4856
4957 return o;
@@ -174,6 +182,8 @@ var _ = self.Prism = { · 124 unmodified lines
174182 return;
175183 }
176184
185+ code = code.replace(/^(?:\r?\n|\r)/,'');
186+
177187 var env = {
178188 element: element,
179189 language: language,
@@ -203,7 +213,7 @@ var _ = self.Prism = { · 23 unmodified lines
203213 // }));
204214 // }
205215 // else {
206− env.highlightedCode = _.highlight(env.code, env.grammar, env.language)
216+ env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
207217
208218 _.hooks.run('before-insert', env);
209219
@@ -340,7 +350,7 @@ Token.stringify = function(o, language, parent) { · 130 unmodified lines
340350 return o;
341351 }
342352
343− if (Object.prototype.toString.call(o) == '[object Array]') {
353+ if (_.util.type(o) === 'Array') {
344354 return o.map(function(element) {
345355 return Token.stringify(element, language, o);
346356 }).join('');
@@ -395,7 +405,7 @@ Token.stringify = function(o, language, parent) { · 48 unmodified lines
395405 // return self.Prism;
396406 // }
397407
398−// Get current script and highlight
408+// // Get current script and highlight
399409 // var script = document.getElementsByTagName('script');
400410
401411 // script = script[script.length - 1];
@@ -412,17 +422,17 @@ return self.Prism; · 10 unmodified lines
412422
413423 })();
414424
415−// if (typeof module !== 'undefined' && module.exports) {
416−// module.exports = Prism;
417−// }
418−// ;
425+if (typeof module !== 'undefined' && module.exports) {
426+ module.exports = Prism;
427+}
428+;
419429 Prism.languages.markup = {
420− 'comment': /<!--[\w\W]*?-->/g,
430+ 'comment': /<!--[\w\W]*?-->/,
421431 'prolog': /<\?.+?\?>/,
422432 'doctype': /<!DOCTYPE.+?>/,
423433 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
424434 'tag': {
425− pattern: /<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/gi,
435+ pattern: /<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i,
426436 inside: {
427437 'tag': {
428438 pattern: /^<\/?[\w:-]+/i,
@@ -432,14 +442,14 @@ Prism.languages.markup = { · 3 unmodified lines
432442 }
433443 },
434444 'attr-value': {
435− pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,
445+ pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
436446 inside: {
437− 'punctuation': /=|>|"/g
447+ 'punctuation': /=|>|"/
438448 }
439449 },
440− 'punctuation': /\/?>/g,
450+ 'punctuation': /\/?>/,
441451 'attr-name': {
442− pattern: /[\w:-]+/g,
452+ pattern: /[\w:-]+/,
443453 inside: {
444454 'namespace': /^[\w-]+?:/
445455 }
@@ -447,7 +457,7 @@ Prism.languages.markup = { · 1 unmodified line
447457
448458 }
449459 },
450− 'entity': /\&#?[\da-z]{1,8};/gi
460+ 'entity': /&#?[\da-z]{1,8};/i
451461 };
452462
453463 // Plugin to make entity title show the real entity, idea by Roman Komarov
@@ -459,29 +469,29 @@ Prism.hooks.add('wrap', function(env) { · 5 unmodified lines
459469 });
460470 ;
461471 Prism.languages.css = {
462− 'comment': /\/\*[\w\W]*?\*\//g,
472+ 'comment': /\/\*[\w\W]*?\*\//,
463473 'atrule': {
464− pattern: /@[\w-]+?.*?(;|(?=\s*{))/gi,
474+ pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
465475 inside: {
466− 'punctuation': /[;:]/g
476+ 'punctuation': /[;:]/
467477 }
468478 },
469− 'url': /url\((["']?).*?\1\)/gi,
470− 'selector': /[^\{\}\s][^\{\};]*(?=\s*\{)/g,
471− 'property': /(\b|\B)[\w-]+(?=\s*:)/ig,
472− 'string': /("|')(\\?.)*?\1/g,
473− 'important': /\B!important\b/gi,
474− 'punctuation': /[\{\};:]/g,
475− 'function': /[-a-z0-9]+(?=\()/ig
479+ 'url': /url\((?:(["'])(\\\n|\\?.)*?\1|.*?)\)/i,
480+ 'selector': /[^\{\}\s][^\{\};]*(?=\s*\{)/,
481+ 'string': /("|')(\\\n|\\?.)*?\1/,
482+ 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
483+ 'important': /\B!important\b/i,
484+ 'punctuation': /[\{\};:]/,
485+ 'function': /[-a-z0-9]+(?=\()/i
476486 };
477487
478488 if (Prism.languages.markup) {
479489 Prism.languages.insertBefore('markup', 'tag', {
480490 'style': {
481− pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/ig,
491+ pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,
482492 inside: {
483493 'tag': {
484− pattern: /<style[\w\W]*?>|<\/style>/ig,
494+ pattern: /<style[\w\W]*?>|<\/style>/i,
485495 inside: Prism.languages.markup.tag.inside
486496 },
487497 rest: Prism.languages.css
@@ -492,15 +502,15 @@ if (Prism.languages.markup) { · 4 unmodified lines
492502
493503 Prism.languages.insertBefore('inside', 'attr-value', {
494504 'style-attr': {
495− pattern: /\s*style=("|').+?\1/ig,
505+ pattern: /\s*style=("|').*?\1/i,
496506 inside: {
497507 'attr-name': {
498− pattern: /^\s*style/ig,
508+ pattern: /^\s*style/i,
499509 inside: Prism.languages.markup.tag.inside
500510 },
501511 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
502512 'attr-value': {
503− pattern: /.+/gi,
513+ pattern: /.+/i,
504514 inside: Prism.languages.css
505515 }
506516 },
@@ -511,44 +521,45 @@ if (Prism.languages.markup) { · 4 unmodified lines
511521 Prism.languages.clike = {
512522 'comment': [
513523 {
514− pattern: /(^|[^\\])\/\*[\w\W]*?\*\//g,
524+ pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
515525 lookbehind: true
516526 },
517527 {
518− pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/g,
528+ pattern: /(^|[^\\:])\/\/.*/,
519529 lookbehind: true
520530 }
521531 ],
522− 'string': /("|')(\\?.)*?\1/g,
532+ 'string': /("|')(\\\n|\\?.)*?\1/,
523533 'class-name': {
524− pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/ig,
534+ pattern: /((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
525535 lookbehind: true,
526536 inside: {
527537 punctuation: /(\.|\\)/
528538 }
529539 },
530− 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/g,
531− 'boolean': /\b(true|false)\b/g,
540+ 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
541+ 'boolean': /\b(true|false)\b/,
532542 'function': {
533− pattern: /[a-z0-9_]+\(/ig,
543+ pattern: /[a-z0-9_]+\(/i,
534544 inside: {
535545 punctuation: /\(/
536546 }
537547 },
538− 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,
539− 'operator': /[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,
540− 'ignore': /&(lt|gt|amp);/gi,
541− 'punctuation': /[{}[\];(),.:]/g
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,
551+ 'punctuation': /[{}[\];(),.:]/
542552 };
543553 ;
544554 Prism.languages.javascript = Prism.languages.extend('clike', {
545− '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/g,
546− 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g
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
547558 });
548559
549560 Prism.languages.insertBefore('javascript', 'keyword', {
550561 'regex': {
551− pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,
562+ pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
552563 lookbehind: true
553564 }
554565 });
@@ -556,10 +567,10 @@ Prism.languages.insertBefore('javascript', 'keyword', { · 1 unmodified line
556567 if (Prism.languages.markup) {
557568 Prism.languages.insertBefore('markup', 'tag', {
558569 'script': {
559− pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/ig,
570+ pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,
560571 inside: {
561572 'tag': {
562− pattern: /<script[\w\W]*?>|<\/script>/ig,
573+ pattern: /<script[\w\W]*?>|<\/script>/i,
563574 inside: Prism.languages.markup.tag.inside
564575 },
565576 rest: Prism.languages.javascript
@@ -569,6 +580,127 @@ if (Prism.languages.markup) { · 3 unmodified lines
569580 });
570581 }
571582 ;
583+Prism.languages.c = Prism.languages.extend('clike', {
584+ // allow for c multiline strings
585+ 'string': /("|')([^\n\\\1]|\\.|\\\r*\n)*?\1/,
586+ '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}|\|?\||\?|\*|\//
588+});
589+
590+Prism.languages.insertBefore('c', 'string', {
591+ // property class reused for macro statements
592+ 'property': {
593+ // allow for multiline macro definitions
594+ // spaces after the # character compile fine with gcc
595+ pattern: /((^|\n)\s*)#\s*[a-z]+([^\n\\]|\\.|\\\r*\n)*/i,
596+ lookbehind: true,
597+ inside: {
598+ // highlight the path of the include statement as a string
599+ 'string': {
600+ pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
601+ lookbehind: true
602+ }
603+ }
604+ }
605+});
606+
607+delete Prism.languages.c['class-name'];
608+delete Prism.languages.c['boolean'];;
609+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/,
611+ 'boolean': /\b(true|false)\b/,
612+ '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/
613+});
614+
615+Prism.languages.insertBefore('cpp', 'keyword', {
616+ 'class-name': {
617+ pattern: /(class\s+)[a-z0-9_]+/i,
618+ lookbehind: true
619+ }
620+});;
621+(function(Prism) {
622+
623+// Ignore comments starting with { to privilege string interpolation highlighting
624+var comment = /#(?!\{).+/,
625+ interpolation = {
626+ pattern: /#\{[^}]+\}/,
627+ alias: 'variable'
628+ };
629+
630+Prism.languages.coffeescript = Prism.languages.extend('javascript', {
631+ 'comment': comment,
632+ 'string': [
633+
634+ // Strings are multiline
635+ /'(?:\\?[\s\S])*?'/,
636+
637+ {
638+ // Strings are multiline
639+ pattern: /"(?:\\?[\s\S])*?"/,
640+ inside: {
641+ 'interpolation': interpolation
642+ }
643+ }
644+ ],
645+ 'keyword': /\b(and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,
646+ 'class-member': {
647+ pattern: /@(?!\d)\w+/,
648+ alias: 'variable'
649+ }
650+});
651+
652+Prism.languages.insertBefore('coffeescript', 'comment', {
653+ 'multiline-comment': {
654+ pattern: /###[\s\S]+?###/,
655+ alias: 'comment'
656+ },
657+
658+ // Block regexp can contain comments and interpolation
659+ 'block-regex': {
660+ pattern: /\/{3}[\s\S]*?\/{3}/,
661+ alias: 'regex',
662+ inside: {
663+ 'comment': comment,
664+ 'interpolation': interpolation
665+ }
666+ }
667+});
668+
669+Prism.languages.insertBefore('coffeescript', 'string', {
670+ 'inline-javascript': {
671+ pattern: /`(?:\\?[\s\S])*?`/,
672+ inside: {
673+ 'delimiter': {
674+ pattern: /^`|`$/,
675+ alias: 'punctuation'
676+ },
677+ rest: Prism.languages.javascript
678+ }
679+ },
680+
681+ // Block strings
682+ 'multiline-string': [
683+ {
684+ pattern: /'''[\s\S]*?'''/,
685+ alias: 'string'
686+ },
687+ {
688+ pattern: /"""[\s\S]*?"""/,
689+ alias: 'string',
690+ inside: {
691+ interpolation: interpolation
692+ }
693+ }
694+ ]
695+
696+});
697+
698+Prism.languages.insertBefore('coffeescript', 'keyword', {
699+ // Object property
700+ 'property': /(?!\d)\w+(?=\s*:(?!:))/
701+});
702+
703+}(Prism));;
572704 /**
573705 * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
574706 * Modified by Miles Johnson: http://milesj.me
@@ -583,19 +715,29 @@ if (Prism.languages.markup) { · 8 unmodified lines
583715 */
584716
585717 Prism.languages.php = Prism.languages.extend('clike', {
586− '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/ig,
587− 'constant': /\b[A-Z0-9_]{2,}\b/g,
718+ '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,
719+ 'constant': /\b[A-Z0-9_]{2,}\b/,
588720 'comment': {
589− pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/|#).*?(\r?\n|$))/g,
721+ pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/).*?(\r?\n|$))/,
590722 lookbehind: true
591723 }
592724 });
593725
726+// Shell-like comments are matched after strings, because they are less
727+// common than strings containing hashes...
728+Prism.languages.insertBefore('php', 'class-name', {
729+ 'shell-comment': {
730+ pattern: /(^|[^\\])#.*?(\r?\n|$)/,
731+ lookbehind: true,
732+ alias: 'comment'
733+ }
734+});
735+
594736 Prism.languages.insertBefore('php', 'keyword', {
595− 'delimiter': /(\?>|<\?php|<\?)/ig,
596− 'variable': /(\$\w+)\b/ig,
737+ 'delimiter': /(\?>|<\?php|<\?)/i,
738+ 'variable': /(\$\w+)\b/i,
597739 'package': {
598− pattern: /(\\|namespace\s+|use\s+)[\w\\]+/g,
740+ pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
599741 lookbehind: true,
600742 inside: {
601743 punctuation: /\\/
@@ -606,7 +748,7 @@ Prism.languages.insertBefore('php', 'keyword', { · 4 unmodified lines
606748 // Must be defined after the function pattern
607749 Prism.languages.insertBefore('php', 'operator', {
608750 'property': {
609− pattern: /(->)[\w]+/g,
751+ pattern: /(->)[\w]+/,
610752 lookbehind: true
611753 }
612754 });
@@ -662,82 +804,24 @@ if (Prism.languages.markup) { · 49 unmodified lines
662804 // Add the rules before all others
663805 Prism.languages.insertBefore('php', 'comment', {
664806 'markup': {
665− pattern: /<[^?]\/?(.*?)>/g,
807+ pattern: /<[^?]\/?(.*?)>/,
666808 inside: Prism.languages.markup
667809 },
668− 'php': /\{\{\{PHP[0-9]+\}\}\}/g
810+ 'php': /\{\{\{PHP[0-9]+\}\}\}/
669811 });
670812 }
671813 ;
672−Prism.languages.coffeescript = Prism.languages.extend('javascript', {
673− 'comment': [
674− /([#]{3}\s*\r?\n(.*\s*\r*\n*)\s*?\r?\n[#]{3})/g,
675− /(\s|^)([#]{1}[^#^\r^\n]{2,}?(\r?\n|$))/g
676− ],
677− 'keyword': /\b(this|window|delete|class|extends|namespace|extend|ar|let|if|else|while|do|for|each|of|return|in|instanceof|new|with|typeof|try|catch|finally|null|undefined|break|continue)\b/g
678−});
679−
680−Prism.languages.insertBefore('coffeescript', 'keyword', {
681− 'function': {
682− pattern: /[a-z|A-z]+\s*[:|=]\s*(\([.|a-z\s|,|:|{|}|\"|\'|=]*\))?\s*-&gt;/gi,
683− inside: {
684− 'function-name': /[_?a-z-|A-Z-]+(\s*[:|=])| @[_?$?a-z-|A-Z-]+(\s*)| /g,
685− 'operator': /[-+]{1,2}|!|=?&lt;|=?&gt;|={1,2}|(&amp;){1,2}|\|?\||\?|\*|\//g
686− }
687− },
688− 'attr-name': /[_?a-z-|A-Z-]+(\s*:)| @[_?$?a-z-|A-Z-]+(\s*)| /g
689−});
690−;
691−Prism.languages.c = Prism.languages.extend('clike', {
692− // allow for c multiline strings
693− 'string': /("|')([^\n\\\1]|\\.|\\\r*\n)*?\1/g,
694− '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/g,
695− 'operator': /[-+]{1,2}|!=?|<{1,2}=?|>{1,2}=?|\->|={1,2}|\^|~|%|&{1,2}|\|?\||\?|\*|\//g
696−});
697−
698−Prism.languages.insertBefore('c', 'string', {
699− // property class reused for macro statements
700− 'property': {
701− // allow for multiline macro definitions
702− // spaces after the # character compile fine with gcc
703− pattern: /((^|\n)\s*)#\s*[a-z]+([^\n\\]|\\.|\\\r*\n)*/gi,
704− lookbehind: true,
705− inside: {
706− // highlight the path of the include statement as a string
707− 'string': {
708− pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/g,
709− lookbehind: true,
710− }
711− }
712− }
713−});
714−
715−delete Prism.languages.c['class-name'];
716−delete Prism.languages.c['boolean'];;
717−Prism.languages.cpp = Prism.languages.extend('c', {
718− '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/g,
719− 'boolean': /\b(true|false)\b/g,
720− '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/g
721−});
722−
723−Prism.languages.insertBefore('cpp', 'keyword', {
724− 'class-name': {
725− pattern: /(class\s+)[a-z0-9_]+/ig,
726− lookbehind: true,
727− },
728−});;
729814 Prism.languages.python= {
730815 'comment': {
731− pattern: /(^|[^\\])#.*?(\r?\n|$)/g,
816+ pattern: /(^|[^\\])#.*?(\r?\n|$)/,
732817 lookbehind: true
733818 },
734− 'string': /"""[\s\S]+?"""|("|')(\\?.)*?\1/g,
735− '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/g,
736− 'boolean' : /\b(True|False)\b/g,
737− 'number' : /\b-?(0x)?\d*\.?[\da-f]+\b/g,
738− 'operator' : /[-+]{1,2}|=?&lt;|=?&gt;|!|={1,2}|(&){1,2}|(&amp;){1,2}|\|?\||\?|\*|\/|~|\^|%|\b(or|and|not)\b/g,
739− 'ignore' : /&(lt|gt|amp);/gi,
740− 'punctuation' : /[{}[\];(),.:]/g
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/,
824+ 'punctuation' : /[{}[\];(),.:]/
741825 };
742826
743827 ;
@@ -748,18 +832,71 @@ Prism.languages.python= { · 4 unmodified lines
748832 * constant, builtin, variable, symbol, regex
749833 */
750834 Prism.languages.ruby = Prism.languages.extend('clike', {
751− 'comment': /#[^\r\n]*(\r?\n|$)/g,
752− '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/g,
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/,
753837 '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/,
754− 'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/g
838+ 'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/
755839 });
756840
757841 Prism.languages.insertBefore('ruby', 'keyword', {
758842 'regex': {
759− pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,
843+ pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
760844 lookbehind: true
761845 },
762− 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/g,
763− 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/g
846+ 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/,
847+ 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/
764848 });
765849 ;
850+/* TODO
851+ Add support for Markdown notation inside doc comments
852+ Add support for nested block comments...
853+ Match closure params even when not followed by dash or brace
854+ Add better support for macro definition
855+*/
856+
857+Prism.languages.rust = {
858+ 'comment': [
859+ {
860+ pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
861+ lookbehind: true
862+ },
863+ {
864+ pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/,
865+ lookbehind: true
866+ }
867+ ],
868+ 'string': [
869+ /b?r(#*)"(?:\\?.)*?"\1/,
870+ /b?("|')(?:\\?.)*?\1/
871+ ],
872+ '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/,
873+
874+ 'attribute': {
875+ pattern: /#!?\[.+?\]/,
876+ alias: 'attr-name'
877+ },
878+
879+ 'function': [
880+ /[a-z0-9_]+(?=\s*\()/i,
881+ // Macros can use parens or brackets
882+ /[a-z0-9_]+!(?=\s*\(|\[)/i
883+ ],
884+ 'macro-rules': {
885+ pattern: /[a-z0-9_]+!/i,
886+ alias: 'function'
887+ },
888+
889+ // 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/,
891+
892+ // Closure params should not be confused with bitwise OR |
893+ 'closure-params': {
894+ pattern: /\|[^|]*\|(?=\s*[{-])/,
895+ inside: {
896+ 'punctuation': /[\|:,]/,
897+ 'operator': /[&*]/
898+ }
899+ },
900+ 'punctuation': /[{}[\];(),.:]|->/,
901+ 'operator': /[-+]{1,2}|!=?|<=?|>=?|={1,3}|&&?|\|\|?|\*|\/|\^|%|<<|>>@/
902+};;