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 */
2self = (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
2/**10/**
3 * Prism: Lightweight, robust, elegant syntax highlighting11 * Prism: Lightweight, robust, elegant syntax highlighting
4 * MIT license http://www.opensource.org/licenses/mit-license.php/12 * MIT license http://www.opensource.org/licenses/mit-license.php/
@@ -43,7 +51,7 @@ var _ = self.Prism = { · 38 unmodified lines
43 return clone;51 return clone;
44 52
45 case 'Array':53 case 'Array':
46 return o.slice();54 return o.map(function(v) { return _.util.clone(v); });
47 }55 }
48 56
49 return o;57 return o;
@@ -174,6 +182,8 @@ var _ = self.Prism = { · 124 unmodified lines
174 return;182 return;
175 }183 }
176 184
185 code = code.replace(/^(?:\r?\n|\r)/,'');
186
177 var env = {187 var env = {
178 element: element,188 element: element,
179 language: language,189 language: language,
@@ -203,7 +213,7 @@ var _ = self.Prism = { · 23 unmodified lines
203 // }));213 // }));
204 // }214 // }
205 // else {215 // else {
206 env.highlightedCode = _.highlight(env.code, env.grammar, env.language)216 env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
207 217
208 _.hooks.run('before-insert', env);218 _.hooks.run('before-insert', env);
209 219
@@ -340,7 +350,7 @@ Token.stringify = function(o, language, parent) { · 130 unmodified lines
340 return o;350 return o;
341 }351 }
342 352
343 if (Object.prototype.toString.call(o) == '[object Array]') {353 if (_.util.type(o) === 'Array') {
344 return o.map(function(element) {354 return o.map(function(element) {
345 return Token.stringify(element, language, o);355 return Token.stringify(element, language, o);
346 }).join('');356 }).join('');
@@ -395,7 +405,7 @@ Token.stringify = function(o, language, parent) { · 48 unmodified lines
395// return self.Prism;405// return self.Prism;
396// }406// }
397 407
398// Get current script and highlight408// // Get current script and highlight
399// var script = document.getElementsByTagName('script');409// var script = document.getElementsByTagName('script');
400 410
401// script = script[script.length - 1];411// script = script[script.length - 1];
@@ -412,17 +422,17 @@ return self.Prism; · 10 unmodified lines
412 422
413})();423})();
414 424
415// if (typeof module !== 'undefined' && module.exports) {425if (typeof module !== 'undefined' && module.exports) {
416// module.exports = Prism;426 module.exports = Prism;
417// }427}
418// ;428;
419Prism.languages.markup = {429Prism.languages.markup = {
420 'comment': /<!--[\w\W]*?-->/g,430 'comment': /<!--[\w\W]*?-->/,
421 'prolog': /<\?.+?\?>/,431 'prolog': /<\?.+?\?>/,
422 'doctype': /<!DOCTYPE.+?>/,432 'doctype': /<!DOCTYPE.+?>/,
423 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,433 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
424 'tag': {434 '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,
426 inside: {436 inside: {
427 'tag': {437 'tag': {
428 pattern: /^<\/?[\w:-]+/i,438 pattern: /^<\/?[\w:-]+/i,
@@ -432,14 +442,14 @@ Prism.languages.markup = { · 3 unmodified lines
432 }442 }
433 },443 },
434 'attr-value': {444 'attr-value': {
435 pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,445 pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
436 inside: {446 inside: {
437 'punctuation': /=|>|"/g447 'punctuation': /=|>|"/
438 }448 }
439 },449 },
440 'punctuation': /\/?>/g,450 'punctuation': /\/?>/,
441 'attr-name': {451 'attr-name': {
442 pattern: /[\w:-]+/g,452 pattern: /[\w:-]+/,
443 inside: {453 inside: {
444 'namespace': /^[\w-]+?:/454 'namespace': /^[\w-]+?:/
445 }455 }
@@ -447,7 +457,7 @@ Prism.languages.markup = { · 1 unmodified line
447 457
448 }458 }
449 },459 },
450 'entity': /\&#?[\da-z]{1,8};/gi460 'entity': /&#?[\da-z]{1,8};/i
451};461};
452 462
453// Plugin to make entity title show the real entity, idea by Roman Komarov463// 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
459});469});
460;470;
461Prism.languages.css = {471Prism.languages.css = {
462 'comment': /\/\*[\w\W]*?\*\//g,472 'comment': /\/\*[\w\W]*?\*\//,
463 'atrule': {473 'atrule': {
464 pattern: /@[\w-]+?.*?(;|(?=\s*{))/gi,474 pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
465 inside: {475 inside: {
466 'punctuation': /[;:]/g476 'punctuation': /[;:]/
467 }477 }
468 },478 },
469 'url': /url\((["']?).*?\1\)/gi,479 'url': /url\((?:(["'])(\\\n|\\?.)*?\1|.*?)\)/i,
470 'selector': /[^\{\}\s][^\{\};]*(?=\s*\{)/g,480 'selector': /[^\{\}\s][^\{\};]*(?=\s*\{)/,
471 'property': /(\b|\B)[\w-]+(?=\s*:)/ig,481 'string': /("|')(\\\n|\\?.)*?\1/,
472 'string': /("|')(\\?.)*?\1/g,482 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
473 'important': /\B!important\b/gi,483 'important': /\B!important\b/i,
474 'punctuation': /[\{\};:]/g,484 'punctuation': /[\{\};:]/,
475 'function': /[-a-z0-9]+(?=\()/ig485 'function': /[-a-z0-9]+(?=\()/i
476};486};
477 487
478if (Prism.languages.markup) {488if (Prism.languages.markup) {
479 Prism.languages.insertBefore('markup', 'tag', {489 Prism.languages.insertBefore('markup', 'tag', {
480 'style': {490 'style': {
481 pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/ig,491 pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,
482 inside: {492 inside: {
483 'tag': {493 'tag': {
484 pattern: /<style[\w\W]*?>|<\/style>/ig,494 pattern: /<style[\w\W]*?>|<\/style>/i,
485 inside: Prism.languages.markup.tag.inside495 inside: Prism.languages.markup.tag.inside
486 },496 },
487 rest: Prism.languages.css497 rest: Prism.languages.css
@@ -492,15 +502,15 @@ if (Prism.languages.markup) { · 4 unmodified lines
492 502
493 Prism.languages.insertBefore('inside', 'attr-value', {503 Prism.languages.insertBefore('inside', 'attr-value', {
494 'style-attr': {504 'style-attr': {
495 pattern: /\s*style=("|').+?\1/ig,505 pattern: /\s*style=("|').*?\1/i,
496 inside: {506 inside: {
497 'attr-name': {507 'attr-name': {
498 pattern: /^\s*style/ig,508 pattern: /^\s*style/i,
499 inside: Prism.languages.markup.tag.inside509 inside: Prism.languages.markup.tag.inside
500 },510 },
501 'punctuation': /^\s*=\s*['"]|['"]\s*$/,511 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
502 'attr-value': {512 'attr-value': {
503 pattern: /.+/gi,513 pattern: /.+/i,
504 inside: Prism.languages.css514 inside: Prism.languages.css
505 }515 }
506 },516 },
@@ -511,44 +521,45 @@ if (Prism.languages.markup) { · 4 unmodified lines
511Prism.languages.clike = {521Prism.languages.clike = {
512 'comment': [522 'comment': [
513 {523 {
514 pattern: /(^|[^\\])\/\*[\w\W]*?\*\//g,524 pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
515 lookbehind: true525 lookbehind: true
516 },526 },
517 {527 {
518 pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/g,528 pattern: /(^|[^\\:])\/\/.*/,
519 lookbehind: true529 lookbehind: true
520 }530 }
521 ],531 ],
522 'string': /("|')(\\?.)*?\1/g,532 'string': /("|')(\\\n|\\?.)*?\1/,
523 'class-name': {533 '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,
525 lookbehind: true,535 lookbehind: true,
526 inside: {536 inside: {
527 punctuation: /(\.|\\)/537 punctuation: /(\.|\\)/
528 }538 }
529 },539 },
530 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/g,540 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
531 'boolean': /\b(true|false)\b/g,541 'boolean': /\b(true|false)\b/,
532 'function': {542 'function': {
533 pattern: /[a-z0-9_]+\(/ig,543 pattern: /[a-z0-9_]+\(/i,
534 inside: {544 inside: {
535 punctuation: /\(/545 punctuation: /\(/
536 }546 }
537 },547 },
538 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,548 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
539 'operator': /[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,549 'operator': /[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|~|\^|%/,
540 'ignore': /&(lt|gt|amp);/gi,550 'ignore': /&(lt|gt|amp);/i,
541 'punctuation': /[{}[\];(),.:]/g551 'punctuation': /[{}[\];(),.:]/
542};552};
543;553;
544Prism.languages.javascript = Prism.languages.extend('clike', {554Prism.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,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/,
546 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g556 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|-?Infinity)\b/,
557 'function': /(?!\d)[a-z0-9_$]+(?=\()/i
547});558});
548 559
549Prism.languages.insertBefore('javascript', 'keyword', {560Prism.languages.insertBefore('javascript', 'keyword', {
550 'regex': {561 'regex': {
551 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,562 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
552 lookbehind: true563 lookbehind: true
553 }564 }
554});565});
@@ -556,10 +567,10 @@ Prism.languages.insertBefore('javascript', 'keyword', { · 1 unmodified line
556if (Prism.languages.markup) {567if (Prism.languages.markup) {
557 Prism.languages.insertBefore('markup', 'tag', {568 Prism.languages.insertBefore('markup', 'tag', {
558 'script': {569 'script': {
559 pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/ig,570 pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,
560 inside: {571 inside: {
561 'tag': {572 'tag': {
562 pattern: /<script[\w\W]*?>|<\/script>/ig,573 pattern: /<script[\w\W]*?>|<\/script>/i,
563 inside: Prism.languages.markup.tag.inside574 inside: Prism.languages.markup.tag.inside
564 },575 },
565 rest: Prism.languages.javascript576 rest: Prism.languages.javascript
@@ -569,6 +580,127 @@ if (Prism.languages.markup) { · 3 unmodified lines
569 });580 });
570}581}
571;582;
583Prism.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
590Prism.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
607delete Prism.languages.c['class-name'];
608delete Prism.languages.c['boolean'];;
609Prism.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
615Prism.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
624var comment = /#(?!\{).+/,
625 interpolation = {
626 pattern: /#\{[^}]+\}/,
627 alias: 'variable'
628 };
629
630Prism.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
652Prism.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
669Prism.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
698Prism.languages.insertBefore('coffeescript', 'keyword', {
699 // Object property
700 'property': /(?!\d)\w+(?=\s*:(?!:))/
701});
702
703}(Prism));;
572/**704/**
573 * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/705 * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
574 * Modified by Miles Johnson: http://milesj.me706 * Modified by Miles Johnson: http://milesj.me
@@ -583,19 +715,29 @@ if (Prism.languages.markup) { · 8 unmodified lines
583 */715 */
584 716
585Prism.languages.php = Prism.languages.extend('clike', {717Prism.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,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,
587 'constant': /\b[A-Z0-9_]{2,}\b/g,719 'constant': /\b[A-Z0-9_]{2,}\b/,
588 'comment': {720 'comment': {
589 pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/|#).*?(\r?\n|$))/g,721 pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/).*?(\r?\n|$))/,
590 lookbehind: true722 lookbehind: true
591 }723 }
592});724});
593 725
726// Shell-like comments are matched after strings, because they are less
727// common than strings containing hashes...
728Prism.languages.insertBefore('php', 'class-name', {
729 'shell-comment': {
730 pattern: /(^|[^\\])#.*?(\r?\n|$)/,
731 lookbehind: true,
732 alias: 'comment'
733 }
734});
735
594Prism.languages.insertBefore('php', 'keyword', {736Prism.languages.insertBefore('php', 'keyword', {
595 'delimiter': /(\?>|<\?php|<\?)/ig,737 'delimiter': /(\?>|<\?php|<\?)/i,
596 'variable': /(\$\w+)\b/ig,738 'variable': /(\$\w+)\b/i,
597 'package': {739 'package': {
598 pattern: /(\\|namespace\s+|use\s+)[\w\\]+/g,740 pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
599 lookbehind: true,741 lookbehind: true,
600 inside: {742 inside: {
601 punctuation: /\\/743 punctuation: /\\/
@@ -606,7 +748,7 @@ Prism.languages.insertBefore('php', 'keyword', { · 4 unmodified lines
606// Must be defined after the function pattern748// Must be defined after the function pattern
607Prism.languages.insertBefore('php', 'operator', {749Prism.languages.insertBefore('php', 'operator', {
608 'property': {750 'property': {
609 pattern: /(->)[\w]+/g,751 pattern: /(->)[\w]+/,
610 lookbehind: true752 lookbehind: true
611 }753 }
612});754});
@@ -662,82 +804,24 @@ if (Prism.languages.markup) { · 49 unmodified lines
662 // Add the rules before all others804 // Add the rules before all others
663 Prism.languages.insertBefore('php', 'comment', {805 Prism.languages.insertBefore('php', 'comment', {
664 'markup': {806 'markup': {
665 pattern: /<[^?]\/?(.*?)>/g,807 pattern: /<[^?]\/?(.*?)>/,
666 inside: Prism.languages.markup808 inside: Prism.languages.markup
667 },809 },
668 'php': /\{\{\{PHP[0-9]+\}\}\}/g810 'php': /\{\{\{PHP[0-9]+\}\}\}/
669 });811 });
670}812}
671;813;
672Prism.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
680Prism.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;
691Prism.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
698Prism.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
715delete Prism.languages.c['class-name'];
716delete Prism.languages.c['boolean'];;
717Prism.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
723Prism.languages.insertBefore('cpp', 'keyword', {
724 'class-name': {
725 pattern: /(class\s+)[a-z0-9_]+/ig,
726 lookbehind: true,
727 },
728});;
729Prism.languages.python= {814Prism.languages.python= {
730 'comment': {815 'comment': {
731 pattern: /(^|[^\\])#.*?(\r?\n|$)/g,816 pattern: /(^|[^\\])#.*?(\r?\n|$)/,
732 lookbehind: true817 lookbehind: true
733 },818 },
734 'string': /"""[\s\S]+?"""|("|')(\\?.)*?\1/g,819 'string': /"""[\s\S]+?"""|'''[\s\S]+?'''|("|')(\\?.)*?\1/,
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,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/,
736 'boolean' : /\b(True|False)\b/g,821 'boolean' : /\b(True|False)\b/,
737 'number' : /\b-?(0x)?\d*\.?[\da-f]+\b/g,822 'number' : /\b-?(0[box])?(?:[\da-f]+\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
738 'operator' : /[-+]{1,2}|=?&lt;|=?&gt;|!|={1,2}|(&){1,2}|(&amp;){1,2}|\|?\||\?|\*|\/|~|\^|%|\b(or|and|not)\b/g,823 'operator' : /[-+]|<=?|>=?|!|={1,2}|&{1,2}|\|?\||\?|\*|\/|~|\^|%|\b(or|and|not)\b/,
739 'ignore' : /&(lt|gt|amp);/gi,824 'punctuation' : /[{}[\];(),.:]/
740 'punctuation' : /[{}[\];(),.:]/g
741};825};
742 826
743;827;
@@ -748,18 +832,71 @@ Prism.languages.python= { · 4 unmodified lines
748 * constant, builtin, variable, symbol, regex832 * constant, builtin, variable, symbol, regex
749 */833 */
750Prism.languages.ruby = Prism.languages.extend('clike', {834Prism.languages.ruby = Prism.languages.extend('clike', {
751 'comment': /#[^\r\n]*(\r?\n|$)/g,835 'comment': /#[^\r\n]*(\r?\n|$)/,
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,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/,
753 '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/,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/,
754 'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/g838 'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/
755});839});
756 840
757Prism.languages.insertBefore('ruby', 'keyword', {841Prism.languages.insertBefore('ruby', 'keyword', {
758 'regex': {842 'regex': {
759 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,843 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
760 lookbehind: true844 lookbehind: true
761 },845 },
762 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/g,846 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/,
763 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/g847 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/
764});848});
765;849;
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
857Prism.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};;