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 */1/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+elixir+php+python+rust */
2self = (typeof window !== 'undefined')2var _self = (typeof window !== 'undefined')
3 ? window // if in browser3 ? window // if in browser
4 : (4 : (
5 (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)5 (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
@@ -18,7 +18,7 @@ var Prism = (function(){ · 12 unmodified lines
18// Private helper vars18// Private helper vars
19var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;19var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
20 20
21var _ = self.Prism = {21var _ = _self.Prism = {
22 util: {22 util: {
23 encode: function (tokens) {23 encode: function (tokens) {
24 if (tokens instanceof Token) {24 if (tokens instanceof Token) {
@@ -51,7 +51,8 @@ var _ = self.Prism = { · 26 unmodified lines
51 return clone;51 return clone;
52 52
53 case 'Array':53 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); });
55 }56 }
56 57
57 return o;58 return o;
@@ -140,6 +141,7 @@ var _ = self.Prism = { · 82 unmodified lines
140 }141 }
141 }142 }
142 },143 },
144 plugins: {},
143 145
144 highlightAll: function(async, callback) {146 highlightAll: function(async, callback) {
145 var elements = document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');147 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
162 grammar = _.languages[language];164 grammar = _.languages[language];
163 }165 }
164 166
165 if (!grammar) {
166 return;
167 }
168
169 // Set language on the element, if not present167 // Set language on the element, if not present
170 element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;168 element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
171 169
@@ -178,12 +176,6 @@ var _ = self.Prism = { · 6 unmodified lines
178 176
179 var code = element.textContent;177 var code = element.textContent;
180 178
181 if(!code) {
182 return;
183 }
184
185 code = code.replace(/^(?:\r?\n|\r)/,'');
186
187 var env = {179 var env = {
188 element: element,180 element: element,
189 language: language,181 language: language,
@@ -191,13 +183,18 @@ var _ = self.Prism = { · 1 unmodified line
191 code: code183 code: code
192 };184 };
193 185
186 if (!code || !grammar) {
187 _.hooks.run('complete', env);
188 return;
189 }
190
194 _.hooks.run('before-highlight', env);191 _.hooks.run('before-highlight', env);
195 192
196 // if (async && self.Worker) {193 // if (async && _self.Worker) {
197 // var worker = new Worker(_.filename);194 // var worker = new Worker(_.filename);
198 195
199 // worker.onmessage = function(evt) {196 // worker.onmessage = function(evt) {
200 // env.highlightedCode = Token.stringify(JSON.parse(evt.data), language);197 // env.highlightedCode = evt.data;
201 198
202 // _.hooks.run('before-insert', env);199 // _.hooks.run('before-insert', env);
203 200
@@ -205,11 +202,13 @@ var _ = self.Prism = { · 1 unmodified line
205 202
206 // callback && callback.call(env.element);203 // callback && callback.call(env.element);
207 // _.hooks.run('after-highlight', env);204 // _.hooks.run('after-highlight', env);
205 // _.hooks.run('complete', env);
208 // };206 // };
209 207
210 // worker.postMessage(JSON.stringify({208 // worker.postMessage(JSON.stringify({
211 // language: env.language,209 // language: env.language,
212 // code: env.code210 // code: env.code,
211 // immediateClose: true
213 // }));212 // }));
214 // }213 // }
215 // else {214 // else {
@@ -222,6 +221,7 @@ var _ = self.Prism = { · 6 unmodified lines
222 callback && callback.call(element);221 callback && callback.call(element);
223 222
224 _.hooks.run('after-highlight', env);223 _.hooks.run('after-highlight', env);
224 _.hooks.run('complete', env);
225 // }225 // }
226 },226 },
227 227
@@ -380,29 +380,32 @@ Token.stringify = function(o, language, parent) { · 152 unmodified lines
380 var attributes = '';380 var attributes = '';
381 381
382 for (var name in env.attributes) {382 for (var name in env.attributes) {
383 attributes += name + '="' + (env.attributes[name] || '') + '"';383 attributes += (attributes ? ' ' : '') + name + '="' + (env.attributes[name] || '') + '"';
384 }384 }
385 385
386 return '<' + env.tag + ' class="' + env.classes.join(' ') + '" ' + attributes + '>' + env.content + '</' + env.tag + '>';386 return '<' + env.tag + ' class="' + env.classes.join(' ') + '" ' + attributes + '>' + env.content + '</' + env.tag + '>';
387 387
388};388};
389 389
390// if (!self.document) {390// if (!_self.document) {
391// if (!self.addEventListener) {391// if (!_self.addEventListener) {
392// // in Node.js392// // in Node.js
393// return self.Prism;393// return _self.Prism;
394// }394// }
395// // In worker395// // In worker
396// self.addEventListener('message', function(evt) {396// _self.addEventListener('message', function(evt) {
397// var message = JSON.parse(evt.data),397// var message = JSON.parse(evt.data),
398// lang = message.language,398// lang = message.language,
399// code = message.code;399// code = message.code,
400// immediateClose = message.immediateClose;
400 401
401// self.postMessage(JSON.stringify(_.util.encode(_.tokenize(code, _.languages[lang]))));402// _self.postMessage(_.highlight(code, _.languages[lang], lang));
402// self.close();403// if (immediateClose) {
404// _self.close();
405// }
403// }, false);406// }, false);
404 407
405// return self.Prism;408// return _self.Prism;
406// }409// }
407 410
408// // Get current script and highlight411// // Get current script and highlight
@@ -418,40 +421,45 @@ Token.stringify = function(o, language, parent) { · 9 unmodified lines
418// }421// }
419// }422// }
420 423
421return self.Prism;424return _self.Prism;
422 425
423})();426})();
424 427
425if (typeof module !== 'undefined' && module.exports) {428if (typeof module !== 'undefined' && module.exports) {
426 module.exports = Prism;429 module.exports = Prism;
427}430}
431
432// hack for components to work correctly in node.js
433if (typeof global !== 'undefined') {
434 global.Prism = Prism;
435}
428;436;
429Prism.languages.markup = {437Prism.languages.markup = {
430 'comment': /<!--[\w\W]*?-->/,438 'comment': /<!--[\w\W]*?-->/,
431 'prolog': /<\?.+?\?>/,439 'prolog': /<\?[\w\W]+?\?>/,
432 'doctype': /<!DOCTYPE.+?>/,440 'doctype': /<!DOCTYPE[\w\W]+?>/,
433 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,441 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
434 'tag': {442 '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,
436 inside: {444 inside: {
437 'tag': {445 'tag': {
438 pattern: /^<\/?[\w:-]+/i,446 pattern: /^<\/?[^\s>\/]+/i,
439 inside: {447 inside: {
440 'punctuation': /^<\/?/,448 'punctuation': /^<\/?/,
441 'namespace': /^[\w-]+?:/449 'namespace': /^[^\s>\/:]+:/
442 }450 }
443 },451 },
444 'attr-value': {452 'attr-value': {
445 pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,453 pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
446 inside: {454 inside: {
447 'punctuation': /=|>|"/455 'punctuation': /[=>"']/
448 }456 }
449 },457 },
450 'punctuation': /\/?>/,458 'punctuation': /\/?>/,
451 'attr-name': {459 'attr-name': {
452 pattern: /[\w:-]+/,460 pattern: /[^\s>\/]+/,
453 inside: {461 inside: {
454 'namespace': /^[\w-]+?:/462 'namespace': /^[^\s>\/:]+:/
455 }463 }
456 }464 }
457 465
@@ -467,35 +475,38 @@ Prism.hooks.add('wrap', function(env) { · 9 unmodified lines
467 env.attributes['title'] = env.content.replace(/&amp;/, '&');475 env.attributes['title'] = env.content.replace(/&amp;/, '&');
468 }476 }
469});477});
470;478
479Prism.languages.xml = Prism.languages.markup;
480Prism.languages.html = Prism.languages.markup;
481Prism.languages.mathml = Prism.languages.markup;
482Prism.languages.svg = Prism.languages.markup;
483
471Prism.languages.css = {484Prism.languages.css = {
472 'comment': /\/\*[\w\W]*?\*\//,485 'comment': /\/\*[\w\W]*?\*\//,
473 'atrule': {486 'atrule': {
474 pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,487 pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
475 inside: {488 inside: {
476 'punctuation': /[;:]/489 'rule': /@[\w-]+/
490 // See rest below
477 }491 }
478 },492 },
479 'url': /url\((?:(["'])(\\\n|\\?.)*?\1|.*?)\)/i,493 'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
480 'selector': /[^\{\}\s][^\{\};]*(?=\s*\{)/,494 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
481 'string': /("|')(\\\n|\\?.)*?\1/,495 'string': /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
482 'property': /(\b|\B)[\w-]+(?=\s*:)/i,496 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
483 'important': /\B!important\b/i,497 'important': /\B!important\b/i,
484 'punctuation': /[\{\};:]/,498 'function': /[-a-z0-9]+(?=\()/i,
485 'function': /[-a-z0-9]+(?=\()/i499 'punctuation': /[(){};:]/
486};500};
487 501
502Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
503
488if (Prism.languages.markup) {504if (Prism.languages.markup) {
489 Prism.languages.insertBefore('markup', 'tag', {505 Prism.languages.insertBefore('markup', 'tag', {
490 'style': {506 'style': {
491 pattern: /<style[\w\W]*?>[\w\W]*?<\/style>/i,507 pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
492 inside: {508 lookbehind: true,
493 'tag': {509 inside: Prism.languages.css,
494 pattern: /<style[\w\W]*?>|<\/style>/i,
495 inside: Prism.languages.markup.tag.inside
496 },
497 rest: Prism.languages.css
498 },
499 alias: 'language-css'510 alias: 'language-css'
500 }511 }
501 });512 });
@@ -529,9 +540,9 @@ Prism.languages.clike = { · 27 unmodified lines
529 lookbehind: true540 lookbehind: true
530 }541 }
531 ],542 ],
532 'string': /("|')(\\\n|\\?.)*?\1/,543 'string': /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
533 'class-name': {544 '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,
535 lookbehind: true,546 lookbehind: true,
536 inside: {547 inside: {
537 punctuation: /(\.|\\)/548 punctuation: /(\.|\\)/
@@ -539,75 +550,93 @@ Prism.languages.clike = { · 1 unmodified line
539 },550 },
540 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,551 '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/,552 'boolean': /\b(true|false)\b/,
542 'function': {553 'function': /[a-z0-9_]+(?=\()/i,
543 pattern: /[a-z0-9_]+\(/i,554 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
544 inside: {555 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
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,
551 'punctuation': /[{}[\];(),.:]/556 'punctuation': /[{}[\];(),.:]/
552};557};
553;558
554Prism.languages.javascript = Prism.languages.extend('clike', {559Prism.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/,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/,
556 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|-?Infinity)\b/,561 'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
557 'function': /(?!\d)[a-z0-9_$]+(?=\()/i562 // 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
558});564});
559 565
560Prism.languages.insertBefore('javascript', 'keyword', {566Prism.languages.insertBefore('javascript', 'keyword', {
561 'regex': {567 'regex': {
562 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,568 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
563 lookbehind: true569 lookbehind: true
564 }570 }
565});571});
566 572
573Prism.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
567if (Prism.languages.markup) {592if (Prism.languages.markup) {
568 Prism.languages.insertBefore('markup', 'tag', {593 Prism.languages.insertBefore('markup', 'tag', {
569 'script': {594 'script': {
570 pattern: /<script[\w\W]*?>[\w\W]*?<\/script>/i,595 pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
571 inside: {596 lookbehind: true,
572 'tag': {597 inside: Prism.languages.javascript,
573 pattern: /<script[\w\W]*?>|<\/script>/i,
574 inside: Prism.languages.markup.tag.inside
575 },
576 rest: Prism.languages.javascript
577 },
578 alias: 'language-javascript'598 alias: 'language-javascript'
579 }599 }
580 });600 });
581}601}
582;602
603Prism.languages.js = Prism.languages.javascript;
583Prism.languages.c = Prism.languages.extend('clike', {604Prism.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/,605 '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
588});608});
589 609
590Prism.languages.insertBefore('c', 'string', {610Prism.languages.insertBefore('c', 'string', {
591 // property class reused for macro statements611 'macro': {
592 'property': {
593 // allow for multiline macro definitions612 // allow for multiline macro definitions
594 // spaces after the # character compile fine with gcc613 // 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,
596 lookbehind: true,615 lookbehind: true,
616 alias: 'property',
597 inside: {617 inside: {
598 // highlight the path of the include statement as a string618 // highlight the path of the include statement as a string
599 'string': {619 'string': {
600 pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,620 pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
601 lookbehind: true621 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'
602 }628 }
603 }629 }
604 }630 },
631 // highlight predefined macros as constants
632 'constant': /\b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|stdin|stdout|stderr)\b/
605});633});
606 634
607delete Prism.languages.c['class-name'];635delete Prism.languages.c['class-name'];
608delete Prism.languages.c['boolean'];;636delete Prism.languages.c['boolean'];
637
609Prism.languages.cpp = Prism.languages.extend('c', {638Prism.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/,
611 'boolean': /\b(true|false)\b/,640 '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/641 '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});642});
@@ -617,7 +646,7 @@ Prism.languages.insertBefore('cpp', 'keyword', { · 3 unmodified lines
617 pattern: /(class\s+)[a-z0-9_]+/i,646 pattern: /(class\s+)[a-z0-9_]+/i,
618 lookbehind: true647 lookbehind: true
619 }648 }
620});;649});
621(function(Prism) {650(function(Prism) {
622 651
623// Ignore comments starting with { to privilege string interpolation highlighting652// Ignore comments starting with { to privilege string interpolation highlighting
@@ -632,11 +661,11 @@ Prism.languages.coffeescript = Prism.languages.extend('javascript', { · 8 unmodified lines
632 'string': [661 'string': [
633 662
634 // Strings are multiline663 // Strings are multiline
635 /'(?:\\?[\s\S])*?'/,664 /'(?:\\?[^\\])*?'/,
636 665
637 {666 {
638 // Strings are multiline667 // Strings are multiline
639 pattern: /"(?:\\?[\s\S])*?"/,668 pattern: /"(?:\\?[^\\])*?"/,
640 inside: {669 inside: {
641 'interpolation': interpolation670 'interpolation': interpolation
642 }671 }
@@ -700,7 +729,208 @@ Prism.languages.insertBefore('coffeescript', 'keyword', { · 57 unmodified lines
700 'property': /(?!\d)\w+(?=\s*:(?!:))/729 'property': /(?!\d)\w+(?=\s*:(?!:))/
701});730});
702 731
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));
843Prism.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
918Prism.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
704/**934/**
705 * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/935 * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
706 * Modified by Miles Johnson: http://milesj.me936 * Modified by Miles Johnson: http://milesj.me
@@ -718,7 +948,7 @@ Prism.languages.php = Prism.languages.extend('clike', { · 11 unmodified lines
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,948 '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/,949 'constant': /\b[A-Z0-9_]{2,}\b/,
720 'comment': {950 'comment': {
721 pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])(\/\/).*?(\r?\n|$))/,951 pattern: /(^|[^\\])(?:\/\*[\w\W]*?\*\/|\/\/.*)/,
722 lookbehind: true952 lookbehind: true
723 }953 }
724});954});
@@ -727,15 +957,15 @@ Prism.languages.php = Prism.languages.extend('clike', { · 2 unmodified lines
727// common than strings containing hashes...957// common than strings containing hashes...
728Prism.languages.insertBefore('php', 'class-name', {958Prism.languages.insertBefore('php', 'class-name', {
729 'shell-comment': {959 'shell-comment': {
730 pattern: /(^|[^\\])#.*?(\r?\n|$)/,960 pattern: /(^|[^\\])#.*/,
731 lookbehind: true,961 lookbehind: true,
732 alias: 'comment'962 alias: 'comment'
733 }963 }
734});964});
735 965
736Prism.languages.insertBefore('php', 'keyword', {966Prism.languages.insertBefore('php', 'keyword', {
737 'delimiter': /(\?>|<\?php|<\?)/i,967 'delimiter': /\?>|<\?(?:php)?/i,
738 'variable': /(\$\w+)\b/i,968 'variable': /\$\w+\b/i,
739 'package': {969 'package': {
740 pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,970 pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
741 lookbehind: true,971 lookbehind: true,
@@ -788,7 +1018,8 @@ if (Prism.languages.markup) { · 46 unmodified lines
788 }1018 }
789 1019
790 for (var i = 0, t; t = env.tokenStack[i]; i++) {1020 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, '$$$$'));
792 }1023 }
793 1024
794 env.element.innerHTML = env.highlightedCode;1025 env.element.innerHTML = env.highlightedCode;
@@ -812,41 +1043,30 @@ if (Prism.languages.markup) { · 17 unmodified lines
812}1043}
813;1044;
814Prism.languages.python= {1045Prism.languages.python= {
1046 'triple-quoted-string': {
1047 pattern: /"""[\s\S]+?"""|'''[\s\S]+?'''/,
1048 alias: 'string'
1049 },
815 'comment': {1050 '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,
817 lookbehind: true1061 lookbehind: true
818 },1062 },
819 'string': /"""[\s\S]+?"""|'''[\s\S]+?'''|("|')(\\?.)*?\1/,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/,
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/,1064 'boolean' : /\b(?:True|False)\b/,
821 'boolean' : /\b(True|False)\b/,1065 'number' : /\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
822 'number' : /\b-?(0[box])?(?:[\da-f]+\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,1066 'operator' : /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
823 'operator' : /[-+]|<=?|>=?|!|={1,2}|&{1,2}|\|?\||\?|\*|\/|~|\^|%|\b(or|and|not)\b/,
824 'punctuation' : /[{}[\];(),.:]/1067 'punctuation' : /[{}[\];(),.:]/
825};1068};
826 1069
827;
828/**
829 * Original by Samuel Flores
830 *
831 * Adds the following new token classes:
832 * constant, builtin, variable, symbol, regex
833 */
834Prism.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
841Prism.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;
850/* TODO1070/* TODO
851 Add support for Markdown notation inside doc comments1071 Add support for Markdown notation inside doc comments
852 Add support for nested block comments...1072 Add support for nested block comments...
@@ -861,7 +1081,7 @@ Prism.languages.rust = { · 8 unmodified lines
861 lookbehind: true1081 lookbehind: true
862 },1082 },
863 {1083 {
864 pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/,1084 pattern: /(^|[^\\:])\/\/.*/,
865 lookbehind: true1085 lookbehind: true
866 }1086 }
867 ],1087 ],
@@ -887,7 +1107,7 @@ Prism.languages.rust = { · 19 unmodified lines
887 },1107 },
888 1108
889 // Hex, oct, bin, dec numbers with visual separators and type suffix1109 // 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/,
891 1111
892 // Closure params should not be confused with bitwise OR |1112 // Closure params should not be confused with bitwise OR |
893 'closure-params': {1113 'closure-params': {
@@ -897,6 +1117,6 @@ Prism.languages.rust = { · 3 unmodified lines
897 'operator': /[&*]/1117 'operator': /[&*]/
898 }1118 }
899 },1119 },
900 'punctuation': /[{}[\];(),.:]|->/,1120 'punctuation': /[{}[\];(),:]|\.+|->/,
901 'operator': /[-+]{1,2}|!=?|<=?|>=?|={1,3}|&&?|\|\|?|\*|\/|\^|%|<<|>>@/1121 'operator': /[-+*\/%!^=]=?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
902};;1122};