1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var _self = (typeof window !== 'undefined')
|
9 | ? window
|
10 | : (
|
11 | (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
12 | ? self
|
13 | : {}
|
14 | );
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var Prism = (function (_self) {
|
25 |
|
26 |
|
27 | var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
|
28 | var uniqueId = 0;
|
29 |
|
30 |
|
31 | var plainTextGrammar = {};
|
32 |
|
33 |
|
34 | var _ = {
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | manual: _self.Prism && _self.Prism.manual,
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
|
79 |
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | util: {
|
90 | encode: function encode(tokens) {
|
91 | if (tokens instanceof Token) {
|
92 | return new Token(tokens.type, encode(tokens.content), tokens.alias);
|
93 | } else if (Array.isArray(tokens)) {
|
94 | return tokens.map(encode);
|
95 | } else {
|
96 | return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
97 | }
|
98 | },
|
99 |
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | type: function (o) {
|
117 | return Object.prototype.toString.call(o).slice(8, -1);
|
118 | },
|
119 |
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | objId: function (obj) {
|
127 | if (!obj['__id']) {
|
128 | Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
129 | }
|
130 | return obj['__id'];
|
131 | },
|
132 |
|
133 | |
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | clone: function deepClone(o, visited) {
|
144 | visited = visited || {};
|
145 |
|
146 | var clone; var id;
|
147 | switch (_.util.type(o)) {
|
148 | case 'Object':
|
149 | id = _.util.objId(o);
|
150 | if (visited[id]) {
|
151 | return visited[id];
|
152 | }
|
153 | clone = ({});
|
154 | visited[id] = clone;
|
155 |
|
156 | for (var key in o) {
|
157 | if (o.hasOwnProperty(key)) {
|
158 | clone[key] = deepClone(o[key], visited);
|
159 | }
|
160 | }
|
161 |
|
162 | return (clone);
|
163 |
|
164 | case 'Array':
|
165 | id = _.util.objId(o);
|
166 | if (visited[id]) {
|
167 | return visited[id];
|
168 | }
|
169 | clone = [];
|
170 | visited[id] = clone;
|
171 |
|
172 | (((o))).forEach(function (v, i) {
|
173 | clone[i] = deepClone(v, visited);
|
174 | });
|
175 |
|
176 | return (clone);
|
177 |
|
178 | default:
|
179 | return o;
|
180 | }
|
181 | },
|
182 |
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | getLanguage: function (element) {
|
192 | while (element) {
|
193 | var m = lang.exec(element.className);
|
194 | if (m) {
|
195 | return m[1].toLowerCase();
|
196 | }
|
197 | element = element.parentElement;
|
198 | }
|
199 | return 'none';
|
200 | },
|
201 |
|
202 | |
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | setLanguage: function (element, language) {
|
210 |
|
211 |
|
212 | element.className = element.className.replace(RegExp(lang, 'gi'), '');
|
213 |
|
214 |
|
215 |
|
216 | element.classList.add('language-' + language);
|
217 | },
|
218 |
|
219 | |
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | currentScript: function () {
|
227 | if (typeof document === 'undefined') {
|
228 | return null;
|
229 | }
|
230 | if ('currentScript' in document && 1 < 2 ) {
|
231 | return (document.currentScript);
|
232 | }
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | try {
|
239 | throw new Error();
|
240 | } catch (err) {
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
|
249 | if (src) {
|
250 | var scripts = document.getElementsByTagName('script');
|
251 | for (var i in scripts) {
|
252 | if (scripts[i].src == src) {
|
253 | return scripts[i];
|
254 | }
|
255 | }
|
256 | }
|
257 | return null;
|
258 | }
|
259 | },
|
260 |
|
261 | |
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | isActive: function (element, className, defaultActivation) {
|
281 | var no = 'no-' + className;
|
282 |
|
283 | while (element) {
|
284 | var classList = element.classList;
|
285 | if (classList.contains(className)) {
|
286 | return true;
|
287 | }
|
288 | if (classList.contains(no)) {
|
289 | return false;
|
290 | }
|
291 | element = element.parentElement;
|
292 | }
|
293 | return !!defaultActivation;
|
294 | }
|
295 | },
|
296 |
|
297 | |
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | languages: {
|
305 | |
306 |
|
307 |
|
308 | plain: plainTextGrammar,
|
309 | plaintext: plainTextGrammar,
|
310 | text: plainTextGrammar,
|
311 | txt: plainTextGrammar,
|
312 |
|
313 | |
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 | extend: function (id, redef) {
|
342 | var lang = _.util.clone(_.languages[id]);
|
343 |
|
344 | for (var key in redef) {
|
345 | lang[key] = redef[key];
|
346 | }
|
347 |
|
348 | return lang;
|
349 | },
|
350 |
|
351 | |
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 | insertBefore: function (inside, before, insert, root) {
|
427 | root = root || (_.languages);
|
428 | var grammar = root[inside];
|
429 |
|
430 | var ret = {};
|
431 |
|
432 | for (var token in grammar) {
|
433 | if (grammar.hasOwnProperty(token)) {
|
434 |
|
435 | if (token == before) {
|
436 | for (var newToken in insert) {
|
437 | if (insert.hasOwnProperty(newToken)) {
|
438 | ret[newToken] = insert[newToken];
|
439 | }
|
440 | }
|
441 | }
|
442 |
|
443 |
|
444 | if (!insert.hasOwnProperty(token)) {
|
445 | ret[token] = grammar[token];
|
446 | }
|
447 | }
|
448 | }
|
449 |
|
450 | var old = root[inside];
|
451 | root[inside] = ret;
|
452 |
|
453 |
|
454 | _.languages.DFS(_.languages, function (key, value) {
|
455 | if (value === old && key != inside) {
|
456 | this[key] = ret;
|
457 | }
|
458 | });
|
459 |
|
460 | return ret;
|
461 | },
|
462 |
|
463 |
|
464 | DFS: function DFS(o, callback, type, visited) {
|
465 | visited = visited || {};
|
466 |
|
467 | var objId = _.util.objId;
|
468 |
|
469 | for (var i in o) {
|
470 | if (o.hasOwnProperty(i)) {
|
471 | callback.call(o, i, o[i], type || i);
|
472 |
|
473 | var property = o[i];
|
474 | var propertyType = _.util.type(property);
|
475 |
|
476 | if (propertyType === 'Object' && !visited[objId(property)]) {
|
477 | visited[objId(property)] = true;
|
478 | DFS(property, callback, null, visited);
|
479 | } else if (propertyType === 'Array' && !visited[objId(property)]) {
|
480 | visited[objId(property)] = true;
|
481 | DFS(property, callback, i, visited);
|
482 | }
|
483 | }
|
484 | }
|
485 | }
|
486 | },
|
487 |
|
488 | plugins: {},
|
489 |
|
490 | |
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 | highlightAll: function (async, callback) {
|
503 | _.highlightAllUnder(document, async, callback);
|
504 | },
|
505 |
|
506 | |
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 | highlightAllUnder: function (container, async, callback) {
|
522 | var env = {
|
523 | callback: callback,
|
524 | container: container,
|
525 | selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
526 | };
|
527 |
|
528 | _.hooks.run('before-highlightall', env);
|
529 |
|
530 | env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
|
531 |
|
532 | _.hooks.run('before-all-elements-highlight', env);
|
533 |
|
534 | for (var i = 0, element; (element = env.elements[i++]);) {
|
535 | _.highlightElement(element, async === true, env.callback);
|
536 | }
|
537 | },
|
538 |
|
539 | |
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 | highlightElement: function (element, async, callback) {
|
568 |
|
569 | var language = _.util.getLanguage(element);
|
570 | var grammar = _.languages[language];
|
571 |
|
572 |
|
573 | _.util.setLanguage(element, language);
|
574 |
|
575 |
|
576 | var parent = element.parentElement;
|
577 | if (parent && parent.nodeName.toLowerCase() === 'pre') {
|
578 | _.util.setLanguage(parent, language);
|
579 | }
|
580 |
|
581 | var code = element.textContent;
|
582 |
|
583 | var env = {
|
584 | element: element,
|
585 | language: language,
|
586 | grammar: grammar,
|
587 | code: code
|
588 | };
|
589 |
|
590 | function insertHighlightedCode(highlightedCode) {
|
591 | env.highlightedCode = highlightedCode;
|
592 |
|
593 | _.hooks.run('before-insert', env);
|
594 |
|
595 | env.element.innerHTML = env.highlightedCode;
|
596 |
|
597 | _.hooks.run('after-highlight', env);
|
598 | _.hooks.run('complete', env);
|
599 | callback && callback.call(env.element);
|
600 | }
|
601 |
|
602 | _.hooks.run('before-sanity-check', env);
|
603 |
|
604 |
|
605 | parent = env.element.parentElement;
|
606 | if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
|
607 | parent.setAttribute('tabindex', '0');
|
608 | }
|
609 |
|
610 | if (!env.code) {
|
611 | _.hooks.run('complete', env);
|
612 | callback && callback.call(env.element);
|
613 | return;
|
614 | }
|
615 |
|
616 | _.hooks.run('before-highlight', env);
|
617 |
|
618 | if (!env.grammar) {
|
619 | insertHighlightedCode(_.util.encode(env.code));
|
620 | return;
|
621 | }
|
622 |
|
623 | if (async && _self.Worker) {
|
624 | var worker = new Worker(_.filename);
|
625 |
|
626 | worker.onmessage = function (evt) {
|
627 | insertHighlightedCode(evt.data);
|
628 | };
|
629 |
|
630 | worker.postMessage(JSON.stringify({
|
631 | language: env.language,
|
632 | code: env.code,
|
633 | immediateClose: true
|
634 | }));
|
635 | } else {
|
636 | insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
|
637 | }
|
638 | },
|
639 |
|
640 | |
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 | highlight: function (text, grammar, language) {
|
661 | var env = {
|
662 | code: text,
|
663 | grammar: grammar,
|
664 | language: language
|
665 | };
|
666 | _.hooks.run('before-tokenize', env);
|
667 | if (!env.grammar) {
|
668 | throw new Error('The language "' + env.language + '" has no grammar.');
|
669 | }
|
670 | env.tokens = _.tokenize(env.code, env.grammar);
|
671 | _.hooks.run('after-tokenize', env);
|
672 | return Token.stringify(_.util.encode(env.tokens), env.language);
|
673 | },
|
674 |
|
675 | |
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 | tokenize: function (text, grammar) {
|
700 | var rest = grammar.rest;
|
701 | if (rest) {
|
702 | for (var token in rest) {
|
703 | grammar[token] = rest[token];
|
704 | }
|
705 |
|
706 | delete grammar.rest;
|
707 | }
|
708 |
|
709 | var tokenList = new LinkedList();
|
710 | addAfter(tokenList, tokenList.head, text);
|
711 |
|
712 | matchGrammar(text, tokenList, grammar, tokenList.head, 0);
|
713 |
|
714 | return toArray(tokenList);
|
715 | },
|
716 |
|
717 | |
718 |
|
719 |
|
720 |
|
721 |
|
722 | hooks: {
|
723 | all: {},
|
724 |
|
725 | |
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 | add: function (name, callback) {
|
738 | var hooks = _.hooks.all;
|
739 |
|
740 | hooks[name] = hooks[name] || [];
|
741 |
|
742 | hooks[name].push(callback);
|
743 | },
|
744 |
|
745 | |
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 | run: function (name, env) {
|
755 | var callbacks = _.hooks.all[name];
|
756 |
|
757 | if (!callbacks || !callbacks.length) {
|
758 | return;
|
759 | }
|
760 |
|
761 | for (var i = 0, callback; (callback = callbacks[i++]);) {
|
762 | callback(env);
|
763 | }
|
764 | }
|
765 | },
|
766 |
|
767 | Token: Token
|
768 | };
|
769 | _self.Prism = _;
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 | |
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 | function Token(type, content, alias, matchedStr) {
|
789 | |
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 | this.type = type;
|
799 | |
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 | this.content = content;
|
808 | |
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 | this.alias = alias;
|
816 |
|
817 | this.length = (matchedStr || '').length | 0;
|
818 | }
|
819 |
|
820 | |
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 |
|
836 | |
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 | Token.stringify = function stringify(o, language) {
|
849 | if (typeof o == 'string') {
|
850 | return o;
|
851 | }
|
852 | if (Array.isArray(o)) {
|
853 | var s = '';
|
854 | o.forEach(function (e) {
|
855 | s += stringify(e, language);
|
856 | });
|
857 | return s;
|
858 | }
|
859 |
|
860 | var env = {
|
861 | type: o.type,
|
862 | content: stringify(o.content, language),
|
863 | tag: 'span',
|
864 | classes: ['token', o.type],
|
865 | attributes: {},
|
866 | language: language
|
867 | };
|
868 |
|
869 | var aliases = o.alias;
|
870 | if (aliases) {
|
871 | if (Array.isArray(aliases)) {
|
872 | Array.prototype.push.apply(env.classes, aliases);
|
873 | } else {
|
874 | env.classes.push(aliases);
|
875 | }
|
876 | }
|
877 |
|
878 | _.hooks.run('wrap', env);
|
879 |
|
880 | var attributes = '';
|
881 | for (var name in env.attributes) {
|
882 | attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
|
883 | }
|
884 |
|
885 | return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
|
886 | };
|
887 |
|
888 | |
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 | function matchPattern(pattern, pos, text, lookbehind) {
|
896 | pattern.lastIndex = pos;
|
897 | var match = pattern.exec(text);
|
898 | if (match && lookbehind && match[1]) {
|
899 |
|
900 | var lookbehindLength = match[1].length;
|
901 | match.index += lookbehindLength;
|
902 | match[0] = match[0].slice(lookbehindLength);
|
903 | }
|
904 | return match;
|
905 | }
|
906 |
|
907 | |
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 | function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
922 | for (var token in grammar) {
|
923 | if (!grammar.hasOwnProperty(token) || !grammar[token]) {
|
924 | continue;
|
925 | }
|
926 |
|
927 | var patterns = grammar[token];
|
928 | patterns = Array.isArray(patterns) ? patterns : [patterns];
|
929 |
|
930 | for (var j = 0; j < patterns.length; ++j) {
|
931 | if (rematch && rematch.cause == token + ',' + j) {
|
932 | return;
|
933 | }
|
934 |
|
935 | var patternObj = patterns[j];
|
936 | var inside = patternObj.inside;
|
937 | var lookbehind = !!patternObj.lookbehind;
|
938 | var greedy = !!patternObj.greedy;
|
939 | var alias = patternObj.alias;
|
940 |
|
941 | if (greedy && !patternObj.pattern.global) {
|
942 |
|
943 | var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
|
944 | patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
|
945 | }
|
946 |
|
947 |
|
948 | var pattern = patternObj.pattern || patternObj;
|
949 |
|
950 | for (
|
951 | var currentNode = startNode.next, pos = startPos;
|
952 | currentNode !== tokenList.tail;
|
953 | pos += currentNode.value.length, currentNode = currentNode.next
|
954 | ) {
|
955 |
|
956 | if (rematch && pos >= rematch.reach) {
|
957 | break;
|
958 | }
|
959 |
|
960 | var str = currentNode.value;
|
961 |
|
962 | if (tokenList.length > text.length) {
|
963 |
|
964 | return;
|
965 | }
|
966 |
|
967 | if (str instanceof Token) {
|
968 | continue;
|
969 | }
|
970 |
|
971 | var removeCount = 1;
|
972 | var match;
|
973 |
|
974 | if (greedy) {
|
975 | match = matchPattern(pattern, pos, text, lookbehind);
|
976 | if (!match || match.index >= text.length) {
|
977 | break;
|
978 | }
|
979 |
|
980 | var from = match.index;
|
981 | var to = match.index + match[0].length;
|
982 | var p = pos;
|
983 |
|
984 |
|
985 | p += currentNode.value.length;
|
986 | while (from >= p) {
|
987 | currentNode = currentNode.next;
|
988 | p += currentNode.value.length;
|
989 | }
|
990 |
|
991 | p -= currentNode.value.length;
|
992 | pos = p;
|
993 |
|
994 |
|
995 | if (currentNode.value instanceof Token) {
|
996 | continue;
|
997 | }
|
998 |
|
999 |
|
1000 | for (
|
1001 | var k = currentNode;
|
1002 | k !== tokenList.tail && (p < to || typeof k.value === 'string');
|
1003 | k = k.next
|
1004 | ) {
|
1005 | removeCount++;
|
1006 | p += k.value.length;
|
1007 | }
|
1008 | removeCount--;
|
1009 |
|
1010 |
|
1011 | str = text.slice(pos, p);
|
1012 | match.index -= pos;
|
1013 | } else {
|
1014 | match = matchPattern(pattern, 0, str, lookbehind);
|
1015 | if (!match) {
|
1016 | continue;
|
1017 | }
|
1018 | }
|
1019 |
|
1020 |
|
1021 | var from = match.index;
|
1022 | var matchStr = match[0];
|
1023 | var before = str.slice(0, from);
|
1024 | var after = str.slice(from + matchStr.length);
|
1025 |
|
1026 | var reach = pos + str.length;
|
1027 | if (rematch && reach > rematch.reach) {
|
1028 | rematch.reach = reach;
|
1029 | }
|
1030 |
|
1031 | var removeFrom = currentNode.prev;
|
1032 |
|
1033 | if (before) {
|
1034 | removeFrom = addAfter(tokenList, removeFrom, before);
|
1035 | pos += before.length;
|
1036 | }
|
1037 |
|
1038 | removeRange(tokenList, removeFrom, removeCount);
|
1039 |
|
1040 | var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
|
1041 | currentNode = addAfter(tokenList, removeFrom, wrapped);
|
1042 |
|
1043 | if (after) {
|
1044 | addAfter(tokenList, currentNode, after);
|
1045 | }
|
1046 |
|
1047 | if (removeCount > 1) {
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 | var nestedRematch = {
|
1053 | cause: token + ',' + j,
|
1054 | reach: reach
|
1055 | };
|
1056 | matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
|
1057 |
|
1058 |
|
1059 | if (rematch && nestedRematch.reach > rematch.reach) {
|
1060 | rematch.reach = nestedRematch.reach;
|
1061 | }
|
1062 | }
|
1063 | }
|
1064 | }
|
1065 | }
|
1066 | }
|
1067 |
|
1068 | |
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 | |
1078 |
|
1079 |
|
1080 |
|
1081 | function LinkedList() {
|
1082 |
|
1083 | var head = { value: null, prev: null, next: null };
|
1084 |
|
1085 | var tail = { value: null, prev: head, next: null };
|
1086 | head.next = tail;
|
1087 |
|
1088 |
|
1089 | this.head = head;
|
1090 |
|
1091 | this.tail = tail;
|
1092 | this.length = 0;
|
1093 | }
|
1094 |
|
1095 | |
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 | function addAfter(list, node, value) {
|
1105 |
|
1106 | var next = node.next;
|
1107 |
|
1108 | var newNode = { value: value, prev: node, next: next };
|
1109 | node.next = newNode;
|
1110 | next.prev = newNode;
|
1111 | list.length++;
|
1112 |
|
1113 | return newNode;
|
1114 | }
|
1115 | |
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 | function removeRange(list, node, count) {
|
1124 | var next = node.next;
|
1125 | for (var i = 0; i < count && next !== list.tail; i++) {
|
1126 | next = next.next;
|
1127 | }
|
1128 | node.next = next;
|
1129 | next.prev = node;
|
1130 | list.length -= i;
|
1131 | }
|
1132 | |
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 | function toArray(list) {
|
1138 | var array = [];
|
1139 | var node = list.head.next;
|
1140 | while (node !== list.tail) {
|
1141 | array.push(node.value);
|
1142 | node = node.next;
|
1143 | }
|
1144 | return array;
|
1145 | }
|
1146 |
|
1147 |
|
1148 | if (!_self.document) {
|
1149 | if (!_self.addEventListener) {
|
1150 |
|
1151 | return _;
|
1152 | }
|
1153 |
|
1154 | if (!_.disableWorkerMessageHandler) {
|
1155 |
|
1156 | _self.addEventListener('message', function (evt) {
|
1157 | var message = JSON.parse(evt.data);
|
1158 | var lang = message.language;
|
1159 | var code = message.code;
|
1160 | var immediateClose = message.immediateClose;
|
1161 |
|
1162 | _self.postMessage(_.highlight(code, _.languages[lang], lang));
|
1163 | if (immediateClose) {
|
1164 | _self.close();
|
1165 | }
|
1166 | }, false);
|
1167 | }
|
1168 |
|
1169 | return _;
|
1170 | }
|
1171 |
|
1172 |
|
1173 | var script = _.util.currentScript();
|
1174 |
|
1175 | if (script) {
|
1176 | _.filename = script.src;
|
1177 |
|
1178 | if (script.hasAttribute('data-manual')) {
|
1179 | _.manual = true;
|
1180 | }
|
1181 | }
|
1182 |
|
1183 | function highlightAutomaticallyCallback() {
|
1184 | if (!_.manual) {
|
1185 | _.highlightAll();
|
1186 | }
|
1187 | }
|
1188 |
|
1189 | if (!_.manual) {
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 | var readyState = document.readyState;
|
1197 | if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
|
1198 | document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
|
1199 | } else {
|
1200 | if (window.requestAnimationFrame) {
|
1201 | window.requestAnimationFrame(highlightAutomaticallyCallback);
|
1202 | } else {
|
1203 | window.setTimeout(highlightAutomaticallyCallback, 16);
|
1204 | }
|
1205 | }
|
1206 | }
|
1207 |
|
1208 | return _;
|
1209 |
|
1210 | }(_self));
|
1211 |
|
1212 | if (typeof module !== 'undefined' && module.exports) {
|
1213 | module.exports = Prism;
|
1214 | }
|
1215 |
|
1216 |
|
1217 | if (typeof global !== 'undefined') {
|
1218 | global.Prism = Prism;
|
1219 | }
|
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 |
|
1275 | Prism.languages.markup = {
|
1276 | 'comment': {
|
1277 | pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
|
1278 | greedy: true
|
1279 | },
|
1280 | 'prolog': {
|
1281 | pattern: /<\?[\s\S]+?\?>/,
|
1282 | greedy: true
|
1283 | },
|
1284 | 'doctype': {
|
1285 |
|
1286 | pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
1287 | greedy: true,
|
1288 | inside: {
|
1289 | 'internal-subset': {
|
1290 | pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
|
1291 | lookbehind: true,
|
1292 | greedy: true,
|
1293 | inside: null
|
1294 | },
|
1295 | 'string': {
|
1296 | pattern: /"[^"]*"|'[^']*'/,
|
1297 | greedy: true
|
1298 | },
|
1299 | 'punctuation': /^<!|>$|[[\]]/,
|
1300 | 'doctype-tag': /^DOCTYPE/i,
|
1301 | 'name': /[^\s<>'"]+/
|
1302 | }
|
1303 | },
|
1304 | 'cdata': {
|
1305 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
1306 | greedy: true
|
1307 | },
|
1308 | 'tag': {
|
1309 | pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
1310 | greedy: true,
|
1311 | inside: {
|
1312 | 'tag': {
|
1313 | pattern: /^<\/?[^\s>\/]+/,
|
1314 | inside: {
|
1315 | 'punctuation': /^<\/?/,
|
1316 | 'namespace': /^[^\s>\/:]+:/
|
1317 | }
|
1318 | },
|
1319 | 'special-attr': [],
|
1320 | 'attr-value': {
|
1321 | pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
1322 | inside: {
|
1323 | 'punctuation': [
|
1324 | {
|
1325 | pattern: /^=/,
|
1326 | alias: 'attr-equals'
|
1327 | },
|
1328 | /"|'/
|
1329 | ]
|
1330 | }
|
1331 | },
|
1332 | 'punctuation': /\/?>/,
|
1333 | 'attr-name': {
|
1334 | pattern: /[^\s>\/]+/,
|
1335 | inside: {
|
1336 | 'namespace': /^[^\s>\/:]+:/
|
1337 | }
|
1338 | }
|
1339 |
|
1340 | }
|
1341 | },
|
1342 | 'entity': [
|
1343 | {
|
1344 | pattern: /&[\da-z]{1,8};/i,
|
1345 | alias: 'named-entity'
|
1346 | },
|
1347 | /&#x?[\da-f]{1,8};/i
|
1348 | ]
|
1349 | };
|
1350 |
|
1351 | Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
|
1352 | Prism.languages.markup['entity'];
|
1353 | Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
|
1354 |
|
1355 |
|
1356 | Prism.hooks.add('wrap', function (env) {
|
1357 |
|
1358 | if (env.type === 'entity') {
|
1359 | env.attributes['title'] = env.content.replace(/&/, '&');
|
1360 | }
|
1361 | });
|
1362 |
|
1363 | Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
|
1364 | |
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 | value: function addInlined(tagName, lang) {
|
1376 | var includedCdataInside = {};
|
1377 | includedCdataInside['language-' + lang] = {
|
1378 | pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
1379 | lookbehind: true,
|
1380 | inside: Prism.languages[lang]
|
1381 | };
|
1382 | includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
|
1383 |
|
1384 | var inside = {
|
1385 | 'included-cdata': {
|
1386 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
1387 | inside: includedCdataInside
|
1388 | }
|
1389 | };
|
1390 | inside['language-' + lang] = {
|
1391 | pattern: /[\s\S]+/,
|
1392 | inside: Prism.languages[lang]
|
1393 | };
|
1394 |
|
1395 | var def = {};
|
1396 | def[tagName] = {
|
1397 | pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
|
1398 | lookbehind: true,
|
1399 | greedy: true,
|
1400 | inside: inside
|
1401 | };
|
1402 |
|
1403 | Prism.languages.insertBefore('markup', 'cdata', def);
|
1404 | }
|
1405 | });
|
1406 | Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
|
1407 | |
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 | value: function (attrName, lang) {
|
1419 | Prism.languages.markup.tag.inside['special-attr'].push({
|
1420 | pattern: RegExp(
|
1421 | /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
|
1422 | 'i'
|
1423 | ),
|
1424 | lookbehind: true,
|
1425 | inside: {
|
1426 | 'attr-name': /^[^\s=]+/,
|
1427 | 'attr-value': {
|
1428 | pattern: /=[\s\S]+/,
|
1429 | inside: {
|
1430 | 'value': {
|
1431 | pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
|
1432 | lookbehind: true,
|
1433 | alias: [lang, 'language-' + lang],
|
1434 | inside: Prism.languages[lang]
|
1435 | },
|
1436 | 'punctuation': [
|
1437 | {
|
1438 | pattern: /^=/,
|
1439 | alias: 'attr-equals'
|
1440 | },
|
1441 | /"|'/
|
1442 | ]
|
1443 | }
|
1444 | }
|
1445 | }
|
1446 | });
|
1447 | }
|
1448 | });
|
1449 |
|
1450 | Prism.languages.html = Prism.languages.markup;
|
1451 | Prism.languages.mathml = Prism.languages.markup;
|
1452 | Prism.languages.svg = Prism.languages.markup;
|
1453 |
|
1454 | Prism.languages.xml = Prism.languages.extend('markup', {});
|
1455 | Prism.languages.ssml = Prism.languages.xml;
|
1456 | Prism.languages.atom = Prism.languages.xml;
|
1457 | Prism.languages.rss = Prism.languages.xml;
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 | (function (Prism) {
|
1465 |
|
1466 | var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
|
1467 |
|
1468 | Prism.languages.css = {
|
1469 | 'comment': /\/\*[\s\S]*?\*\//,
|
1470 | 'atrule': {
|
1471 | pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
|
1472 | inside: {
|
1473 | 'rule': /^@[\w-]+/,
|
1474 | 'selector-function-argument': {
|
1475 | pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
|
1476 | lookbehind: true,
|
1477 | alias: 'selector'
|
1478 | },
|
1479 | 'keyword': {
|
1480 | pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
|
1481 | lookbehind: true
|
1482 | }
|
1483 |
|
1484 | }
|
1485 | },
|
1486 | 'url': {
|
1487 |
|
1488 | pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
|
1489 | greedy: true,
|
1490 | inside: {
|
1491 | 'function': /^url/i,
|
1492 | 'punctuation': /^\(|\)$/,
|
1493 | 'string': {
|
1494 | pattern: RegExp('^' + string.source + '$'),
|
1495 | alias: 'url'
|
1496 | }
|
1497 | }
|
1498 | },
|
1499 | 'selector': {
|
1500 | pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
|
1501 | lookbehind: true
|
1502 | },
|
1503 | 'string': {
|
1504 | pattern: string,
|
1505 | greedy: true
|
1506 | },
|
1507 | 'property': {
|
1508 | pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
|
1509 | lookbehind: true
|
1510 | },
|
1511 | 'important': /!important\b/i,
|
1512 | 'function': {
|
1513 | pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
|
1514 | lookbehind: true
|
1515 | },
|
1516 | 'punctuation': /[(){};:,]/
|
1517 | };
|
1518 |
|
1519 | Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
|
1520 |
|
1521 | var markup = Prism.languages.markup;
|
1522 | if (markup) {
|
1523 | markup.tag.addInlined('style', 'css');
|
1524 | markup.tag.addAttribute('style', 'css');
|
1525 | }
|
1526 |
|
1527 | }(Prism));
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 | Prism.languages.clike = {
|
1535 | 'comment': [
|
1536 | {
|
1537 | pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
1538 | lookbehind: true,
|
1539 | greedy: true
|
1540 | },
|
1541 | {
|
1542 | pattern: /(^|[^\\:])\/\/.*/,
|
1543 | lookbehind: true,
|
1544 | greedy: true
|
1545 | }
|
1546 | ],
|
1547 | 'string': {
|
1548 | pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
1549 | greedy: true
|
1550 | },
|
1551 | 'class-name': {
|
1552 | pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
1553 | lookbehind: true,
|
1554 | inside: {
|
1555 | 'punctuation': /[.\\]/
|
1556 | }
|
1557 | },
|
1558 | 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
1559 | 'boolean': /\b(?:false|true)\b/,
|
1560 | 'function': /\b\w+(?=\()/,
|
1561 | 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
1562 | 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
1563 | 'punctuation': /[{}[\];(),.:]/
|
1564 | };
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 | Prism.languages.javascript = Prism.languages.extend('clike', {
|
1572 | 'class-name': [
|
1573 | Prism.languages.clike['class-name'],
|
1574 | {
|
1575 | pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
1576 | lookbehind: true
|
1577 | }
|
1578 | ],
|
1579 | 'keyword': [
|
1580 | {
|
1581 | pattern: /((?:^|\})\s*)catch\b/,
|
1582 | lookbehind: true
|
1583 | },
|
1584 | {
|
1585 | pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
|
1586 | lookbehind: true
|
1587 | },
|
1588 | ],
|
1589 |
|
1590 | 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
1591 | 'number': {
|
1592 | pattern: RegExp(
|
1593 | /(^|[^\w$])/.source +
|
1594 | '(?:' +
|
1595 | (
|
1596 |
|
1597 | /NaN|Infinity/.source +
|
1598 | '|' +
|
1599 |
|
1600 | /0[bB][01]+(?:_[01]+)*n?/.source +
|
1601 | '|' +
|
1602 |
|
1603 | /0[oO][0-7]+(?:_[0-7]+)*n?/.source +
|
1604 | '|' +
|
1605 |
|
1606 | /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
|
1607 | '|' +
|
1608 |
|
1609 | /\d+(?:_\d+)*n/.source +
|
1610 | '|' +
|
1611 |
|
1612 | /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
|
1613 | ) +
|
1614 | ')' +
|
1615 | /(?![\w$])/.source
|
1616 | ),
|
1617 | lookbehind: true
|
1618 | },
|
1619 | 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
1620 | });
|
1621 |
|
1622 | Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
1623 |
|
1624 | Prism.languages.insertBefore('javascript', 'keyword', {
|
1625 | 'regex': {
|
1626 |
|
1627 | pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
|
1628 | lookbehind: true,
|
1629 | greedy: true,
|
1630 | inside: {
|
1631 | 'regex-source': {
|
1632 | pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
1633 | lookbehind: true,
|
1634 | alias: 'language-regex',
|
1635 | inside: Prism.languages.regex
|
1636 | },
|
1637 | 'regex-delimiter': /^\/|\/$/,
|
1638 | 'regex-flags': /^[a-z]+$/,
|
1639 | }
|
1640 | },
|
1641 |
|
1642 | 'function-variable': {
|
1643 | pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
|
1644 | alias: 'function'
|
1645 | },
|
1646 | 'parameter': [
|
1647 | {
|
1648 | pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
1649 | lookbehind: true,
|
1650 | inside: Prism.languages.javascript
|
1651 | },
|
1652 | {
|
1653 | pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
1654 | lookbehind: true,
|
1655 | inside: Prism.languages.javascript
|
1656 | },
|
1657 | {
|
1658 | pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
1659 | lookbehind: true,
|
1660 | inside: Prism.languages.javascript
|
1661 | },
|
1662 | {
|
1663 | pattern: /((?:\b|\s|^)(?!(?: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|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
|
1664 | lookbehind: true,
|
1665 | inside: Prism.languages.javascript
|
1666 | }
|
1667 | ],
|
1668 | 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
1669 | });
|
1670 |
|
1671 | Prism.languages.insertBefore('javascript', 'string', {
|
1672 | 'hashbang': {
|
1673 | pattern: /^#!.*/,
|
1674 | greedy: true,
|
1675 | alias: 'comment'
|
1676 | },
|
1677 | 'template-string': {
|
1678 | pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
1679 | greedy: true,
|
1680 | inside: {
|
1681 | 'template-punctuation': {
|
1682 | pattern: /^`|`$/,
|
1683 | alias: 'string'
|
1684 | },
|
1685 | 'interpolation': {
|
1686 | pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
1687 | lookbehind: true,
|
1688 | inside: {
|
1689 | 'interpolation-punctuation': {
|
1690 | pattern: /^\$\{|\}$/,
|
1691 | alias: 'punctuation'
|
1692 | },
|
1693 | rest: Prism.languages.javascript
|
1694 | }
|
1695 | },
|
1696 | 'string': /[\s\S]+/
|
1697 | }
|
1698 | },
|
1699 | 'string-property': {
|
1700 | pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
1701 | lookbehind: true,
|
1702 | greedy: true,
|
1703 | alias: 'property'
|
1704 | }
|
1705 | });
|
1706 |
|
1707 | Prism.languages.insertBefore('javascript', 'operator', {
|
1708 | 'literal-property': {
|
1709 | pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
1710 | lookbehind: true,
|
1711 | alias: 'property'
|
1712 | },
|
1713 | });
|
1714 |
|
1715 | if (Prism.languages.markup) {
|
1716 | Prism.languages.markup.tag.addInlined('script', 'javascript');
|
1717 |
|
1718 |
|
1719 |
|
1720 | Prism.languages.markup.tag.addAttribute(
|
1721 | /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
|
1722 | 'javascript'
|
1723 | );
|
1724 | }
|
1725 |
|
1726 | Prism.languages.js = Prism.languages.javascript;
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 | (function () {
|
1734 |
|
1735 | if (typeof Prism === 'undefined' || typeof document === 'undefined') {
|
1736 | return;
|
1737 | }
|
1738 |
|
1739 |
|
1740 | if (!Element.prototype.matches) {
|
1741 | Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
1742 | }
|
1743 |
|
1744 | var LOADING_MESSAGE = 'Loading…';
|
1745 | var FAILURE_MESSAGE = function (status, message) {
|
1746 | return '✖ Error ' + status + ' while fetching file: ' + message;
|
1747 | };
|
1748 | var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
|
1749 |
|
1750 | var EXTENSIONS = {
|
1751 | 'js': 'javascript',
|
1752 | 'py': 'python',
|
1753 | 'rb': 'ruby',
|
1754 | 'ps1': 'powershell',
|
1755 | 'psm1': 'powershell',
|
1756 | 'sh': 'bash',
|
1757 | 'bat': 'batch',
|
1758 | 'h': 'c',
|
1759 | 'tex': 'latex'
|
1760 | };
|
1761 |
|
1762 | var STATUS_ATTR = 'data-src-status';
|
1763 | var STATUS_LOADING = 'loading';
|
1764 | var STATUS_LOADED = 'loaded';
|
1765 | var STATUS_FAILED = 'failed';
|
1766 |
|
1767 | var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
|
1768 | + ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
|
1769 |
|
1770 | |
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 | function loadFile(src, success, error) {
|
1778 | var xhr = new XMLHttpRequest();
|
1779 | xhr.open('GET', src, true);
|
1780 | xhr.onreadystatechange = function () {
|
1781 | if (xhr.readyState == 4) {
|
1782 | if (xhr.status < 400 && xhr.responseText) {
|
1783 | success(xhr.responseText);
|
1784 | } else {
|
1785 | if (xhr.status >= 400) {
|
1786 | error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
|
1787 | } else {
|
1788 | error(FAILURE_EMPTY_MESSAGE);
|
1789 | }
|
1790 | }
|
1791 | }
|
1792 | };
|
1793 | xhr.send(null);
|
1794 | }
|
1795 |
|
1796 | |
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 | function parseRange(range) {
|
1805 | var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || '');
|
1806 | if (m) {
|
1807 | var start = Number(m[1]);
|
1808 | var comma = m[2];
|
1809 | var end = m[3];
|
1810 |
|
1811 | if (!comma) {
|
1812 | return [start, start];
|
1813 | }
|
1814 | if (!end) {
|
1815 | return [start, undefined];
|
1816 | }
|
1817 | return [start, Number(end)];
|
1818 | }
|
1819 | return undefined;
|
1820 | }
|
1821 |
|
1822 | Prism.hooks.add('before-highlightall', function (env) {
|
1823 | env.selector += ', ' + SELECTOR;
|
1824 | });
|
1825 |
|
1826 | Prism.hooks.add('before-sanity-check', function (env) {
|
1827 | var pre = (env.element);
|
1828 | if (pre.matches(SELECTOR)) {
|
1829 | env.code = '';
|
1830 |
|
1831 | pre.setAttribute(STATUS_ATTR, STATUS_LOADING);
|
1832 |
|
1833 |
|
1834 | var code = pre.appendChild(document.createElement('CODE'));
|
1835 | code.textContent = LOADING_MESSAGE;
|
1836 |
|
1837 | var src = pre.getAttribute('data-src');
|
1838 |
|
1839 | var language = env.language;
|
1840 | if (language === 'none') {
|
1841 |
|
1842 |
|
1843 | var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
|
1844 | language = EXTENSIONS[extension] || extension;
|
1845 | }
|
1846 |
|
1847 |
|
1848 | Prism.util.setLanguage(code, language);
|
1849 | Prism.util.setLanguage(pre, language);
|
1850 |
|
1851 |
|
1852 | var autoloader = Prism.plugins.autoloader;
|
1853 | if (autoloader) {
|
1854 | autoloader.loadLanguages(language);
|
1855 | }
|
1856 |
|
1857 |
|
1858 | loadFile(
|
1859 | src,
|
1860 | function (text) {
|
1861 |
|
1862 | pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
|
1863 |
|
1864 |
|
1865 | var range = parseRange(pre.getAttribute('data-range'));
|
1866 | if (range) {
|
1867 | var lines = text.split(/\r\n?|\n/g);
|
1868 |
|
1869 |
|
1870 | var start = range[0];
|
1871 | var end = range[1] == null ? lines.length : range[1];
|
1872 |
|
1873 | if (start < 0) { start += lines.length; }
|
1874 | start = Math.max(0, Math.min(start - 1, lines.length));
|
1875 | if (end < 0) { end += lines.length; }
|
1876 | end = Math.max(0, Math.min(end, lines.length));
|
1877 |
|
1878 | text = lines.slice(start, end).join('\n');
|
1879 |
|
1880 |
|
1881 | if (!pre.hasAttribute('data-start')) {
|
1882 | pre.setAttribute('data-start', String(start + 1));
|
1883 | }
|
1884 | }
|
1885 |
|
1886 |
|
1887 | code.textContent = text;
|
1888 | Prism.highlightElement(code);
|
1889 | },
|
1890 | function (error) {
|
1891 |
|
1892 | pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
|
1893 |
|
1894 | code.textContent = error;
|
1895 | }
|
1896 | );
|
1897 | }
|
1898 | });
|
1899 |
|
1900 | Prism.plugins.fileHighlight = {
|
1901 | |
1902 |
|
1903 |
|
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 | highlight: function highlight(container) {
|
1909 | var elements = (container || document).querySelectorAll(SELECTOR);
|
1910 |
|
1911 | for (var i = 0, element; (element = elements[i++]);) {
|
1912 | Prism.highlightElement(element);
|
1913 | }
|
1914 | }
|
1915 | };
|
1916 |
|
1917 | var logged = false;
|
1918 |
|
1919 | Prism.fileHighlight = function () {
|
1920 | if (!logged) {
|
1921 | console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
|
1922 | logged = true;
|
1923 | }
|
1924 | Prism.plugins.fileHighlight.highlight.apply(this, arguments);
|
1925 | };
|
1926 |
|
1927 | }());
|