1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var deepFreezeEs6 = {exports: {}};
|
7 |
|
8 | function deepFreeze(obj) {
|
9 | if (obj instanceof Map) {
|
10 | obj.clear = obj.delete = obj.set = function () {
|
11 | throw new Error('map is read-only');
|
12 | };
|
13 | } else if (obj instanceof Set) {
|
14 | obj.add = obj.clear = obj.delete = function () {
|
15 | throw new Error('set is read-only');
|
16 | };
|
17 | }
|
18 |
|
19 |
|
20 | Object.freeze(obj);
|
21 |
|
22 | Object.getOwnPropertyNames(obj).forEach(function (name) {
|
23 | var prop = obj[name];
|
24 |
|
25 |
|
26 | if (typeof prop == 'object' && !Object.isFrozen(prop)) {
|
27 | deepFreeze(prop);
|
28 | }
|
29 | });
|
30 |
|
31 | return obj;
|
32 | }
|
33 |
|
34 | deepFreezeEs6.exports = deepFreeze;
|
35 | deepFreezeEs6.exports.default = deepFreeze;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | class Response {
|
42 | |
43 |
|
44 |
|
45 | constructor(mode) {
|
46 |
|
47 | if (mode.data === undefined) mode.data = {};
|
48 |
|
49 | this.data = mode.data;
|
50 | this.isMatchIgnored = false;
|
51 | }
|
52 |
|
53 | ignoreMatch() {
|
54 | this.isMatchIgnored = true;
|
55 | }
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function escapeHTML(value) {
|
63 | return value
|
64 | .replace(/&/g, '&')
|
65 | .replace(/</g, '<')
|
66 | .replace(/>/g, '>')
|
67 | .replace(/"/g, '"')
|
68 | .replace(/'/g, ''');
|
69 | }
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | function inherit$1(original, ...objects) {
|
80 |
|
81 | const result = Object.create(null);
|
82 |
|
83 | for (const key in original) {
|
84 | result[key] = original[key];
|
85 | }
|
86 | objects.forEach(function(obj) {
|
87 | for (const key in obj) {
|
88 | result[key] = obj[key];
|
89 | }
|
90 | });
|
91 | return (result);
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | const SPAN_CLOSE = '</span>';
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | const emitsWrappingTags = (node) => {
|
113 |
|
114 |
|
115 | return !!node.scope || (node.sublanguage && node.language);
|
116 | };
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | const scopeToCSSClass = (name, { prefix }) => {
|
124 | if (name.includes(".")) {
|
125 | const pieces = name.split(".");
|
126 | return [
|
127 | `${prefix}${pieces.shift()}`,
|
128 | ...(pieces.map((x, i) => `${x}${"_".repeat(i + 1)}`))
|
129 | ].join(" ");
|
130 | }
|
131 | return `${prefix}${name}`;
|
132 | };
|
133 |
|
134 |
|
135 | class HTMLRenderer {
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | constructor(parseTree, options) {
|
143 | this.buffer = "";
|
144 | this.classPrefix = options.classPrefix;
|
145 | parseTree.walk(this);
|
146 | }
|
147 |
|
148 | |
149 |
|
150 |
|
151 |
|
152 | addText(text) {
|
153 | this.buffer += escapeHTML(text);
|
154 | }
|
155 |
|
156 | |
157 |
|
158 |
|
159 |
|
160 | openNode(node) {
|
161 | if (!emitsWrappingTags(node)) return;
|
162 |
|
163 | let className = "";
|
164 | if (node.sublanguage) {
|
165 | className = `language-${node.language}`;
|
166 | } else {
|
167 | className = scopeToCSSClass(node.scope, { prefix: this.classPrefix });
|
168 | }
|
169 | this.span(className);
|
170 | }
|
171 |
|
172 | |
173 |
|
174 |
|
175 |
|
176 | closeNode(node) {
|
177 | if (!emitsWrappingTags(node)) return;
|
178 |
|
179 | this.buffer += SPAN_CLOSE;
|
180 | }
|
181 |
|
182 | |
183 |
|
184 |
|
185 | value() {
|
186 | return this.buffer;
|
187 | }
|
188 |
|
189 |
|
190 |
|
191 | |
192 |
|
193 |
|
194 |
|
195 | span(className) {
|
196 | this.buffer += `<span class="${className}">`;
|
197 | }
|
198 | }
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | const newNode = (opts = {}) => {
|
207 |
|
208 | const result = { children: [] };
|
209 | Object.assign(result, opts);
|
210 | return result;
|
211 | };
|
212 |
|
213 | class TokenTree {
|
214 | constructor() {
|
215 |
|
216 | this.rootNode = newNode();
|
217 | this.stack = [this.rootNode];
|
218 | }
|
219 |
|
220 | get top() {
|
221 | return this.stack[this.stack.length - 1];
|
222 | }
|
223 |
|
224 | get root() { return this.rootNode; }
|
225 |
|
226 |
|
227 | add(node) {
|
228 | this.top.children.push(node);
|
229 | }
|
230 |
|
231 |
|
232 | openNode(scope) {
|
233 |
|
234 | const node = newNode({ scope });
|
235 | this.add(node);
|
236 | this.stack.push(node);
|
237 | }
|
238 |
|
239 | closeNode() {
|
240 | if (this.stack.length > 1) {
|
241 | return this.stack.pop();
|
242 | }
|
243 |
|
244 | return undefined;
|
245 | }
|
246 |
|
247 | closeAllNodes() {
|
248 | while (this.closeNode());
|
249 | }
|
250 |
|
251 | toJSON() {
|
252 | return JSON.stringify(this.rootNode, null, 4);
|
253 | }
|
254 |
|
255 | |
256 |
|
257 |
|
258 |
|
259 | walk(builder) {
|
260 |
|
261 | return this.constructor._walk(builder, this.rootNode);
|
262 |
|
263 |
|
264 | }
|
265 |
|
266 | |
267 |
|
268 |
|
269 |
|
270 | static _walk(builder, node) {
|
271 | if (typeof node === "string") {
|
272 | builder.addText(node);
|
273 | } else if (node.children) {
|
274 | builder.openNode(node);
|
275 | node.children.forEach((child) => this._walk(builder, child));
|
276 | builder.closeNode(node);
|
277 | }
|
278 | return builder;
|
279 | }
|
280 |
|
281 | |
282 |
|
283 |
|
284 | static _collapse(node) {
|
285 | if (typeof node === "string") return;
|
286 | if (!node.children) return;
|
287 |
|
288 | if (node.children.every(el => typeof el === "string")) {
|
289 |
|
290 |
|
291 | node.children = [node.children.join("")];
|
292 | } else {
|
293 | node.children.forEach((child) => {
|
294 | TokenTree._collapse(child);
|
295 | });
|
296 | }
|
297 | }
|
298 | }
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | class TokenTreeEmitter extends TokenTree {
|
321 | |
322 |
|
323 |
|
324 | constructor(options) {
|
325 | super();
|
326 | this.options = options;
|
327 | }
|
328 |
|
329 | |
330 |
|
331 |
|
332 |
|
333 | addKeyword(text, scope) {
|
334 | if (text === "") { return; }
|
335 |
|
336 | this.openNode(scope);
|
337 | this.addText(text);
|
338 | this.closeNode();
|
339 | }
|
340 |
|
341 | |
342 |
|
343 |
|
344 | addText(text) {
|
345 | if (text === "") { return; }
|
346 |
|
347 | this.add(text);
|
348 | }
|
349 |
|
350 | |
351 |
|
352 |
|
353 |
|
354 | addSublanguage(emitter, name) {
|
355 |
|
356 | const node = emitter.root;
|
357 | node.sublanguage = true;
|
358 | node.language = name;
|
359 | this.add(node);
|
360 | }
|
361 |
|
362 | toHTML() {
|
363 | const renderer = new HTMLRenderer(this, this.options);
|
364 | return renderer.value();
|
365 | }
|
366 |
|
367 | finalize() {
|
368 | return true;
|
369 | }
|
370 | }
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 | function source(re) {
|
382 | if (!re) return null;
|
383 | if (typeof re === "string") return re;
|
384 |
|
385 | return re.source;
|
386 | }
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 | function lookahead(re) {
|
393 | return concat('(?=', re, ')');
|
394 | }
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 | function anyNumberOfTimes(re) {
|
401 | return concat('(?:', re, ')*');
|
402 | }
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 | function optional(re) {
|
409 | return concat('(?:', re, ')?');
|
410 | }
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 | function concat(...args) {
|
417 | const joined = args.map((x) => source(x)).join("");
|
418 | return joined;
|
419 | }
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 | function stripOptionsFromArgs(args) {
|
426 | const opts = args[args.length - 1];
|
427 |
|
428 | if (typeof opts === 'object' && opts.constructor === Object) {
|
429 | args.splice(args.length - 1, 1);
|
430 | return opts;
|
431 | } else {
|
432 | return {};
|
433 | }
|
434 | }
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 | function either(...args) {
|
446 |
|
447 | const opts = stripOptionsFromArgs(args);
|
448 | const joined = '('
|
449 | + (opts.capture ? "" : "?:")
|
450 | + args.map((x) => source(x)).join("|") + ")";
|
451 | return joined;
|
452 | }
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 | function countMatchGroups(re) {
|
459 | return (new RegExp(re.toString() + '|')).exec('').length - 1;
|
460 | }
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 | function startsWith(re, lexeme) {
|
468 | const match = re && re.exec(lexeme);
|
469 | return match && match.index === 0;
|
470 | }
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 | const BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 | function _rewriteBackreferences(regexps, { joinWith }) {
|
493 | let numCaptures = 0;
|
494 |
|
495 | return regexps.map((regex) => {
|
496 | numCaptures += 1;
|
497 | const offset = numCaptures;
|
498 | let re = source(regex);
|
499 | let out = '';
|
500 |
|
501 | while (re.length > 0) {
|
502 | const match = BACKREF_RE.exec(re);
|
503 | if (!match) {
|
504 | out += re;
|
505 | break;
|
506 | }
|
507 | out += re.substring(0, match.index);
|
508 | re = re.substring(match.index + match[0].length);
|
509 | if (match[0][0] === '\\' && match[1]) {
|
510 |
|
511 | out += '\\' + String(Number(match[1]) + offset);
|
512 | } else {
|
513 | out += match[0];
|
514 | if (match[0] === '(') {
|
515 | numCaptures++;
|
516 | }
|
517 | }
|
518 | }
|
519 | return out;
|
520 | }).map(re => `(${re})`).join(joinWith);
|
521 | }
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 | const MATCH_NOTHING_RE = /\b\B/;
|
528 | const IDENT_RE = '[a-zA-Z]\\w*';
|
529 | const UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*';
|
530 | const NUMBER_RE = '\\b\\d+(\\.\\d+)?';
|
531 | const C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)';
|
532 | const BINARY_NUMBER_RE = '\\b(0b[01]+)';
|
533 | const RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';
|
534 |
|
535 |
|
536 |
|
537 |
|
538 | const SHEBANG = (opts = {}) => {
|
539 | const beginShebang = /^#![ ]*\//;
|
540 | if (opts.binary) {
|
541 | opts.begin = concat(
|
542 | beginShebang,
|
543 | /.*\b/,
|
544 | opts.binary,
|
545 | /\b.*/);
|
546 | }
|
547 | return inherit$1({
|
548 | scope: 'meta',
|
549 | begin: beginShebang,
|
550 | end: /$/,
|
551 | relevance: 0,
|
552 |
|
553 | "on:begin": (m, resp) => {
|
554 | if (m.index !== 0) resp.ignoreMatch();
|
555 | }
|
556 | }, opts);
|
557 | };
|
558 |
|
559 |
|
560 | const BACKSLASH_ESCAPE = {
|
561 | begin: '\\\\[\\s\\S]', relevance: 0
|
562 | };
|
563 | const APOS_STRING_MODE = {
|
564 | scope: 'string',
|
565 | begin: '\'',
|
566 | end: '\'',
|
567 | illegal: '\\n',
|
568 | contains: [BACKSLASH_ESCAPE]
|
569 | };
|
570 | const QUOTE_STRING_MODE = {
|
571 | scope: 'string',
|
572 | begin: '"',
|
573 | end: '"',
|
574 | illegal: '\\n',
|
575 | contains: [BACKSLASH_ESCAPE]
|
576 | };
|
577 | const PHRASAL_WORDS_MODE = {
|
578 | begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
|
579 | };
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 | const COMMENT = function(begin, end, modeOptions = {}) {
|
589 | const mode = inherit$1(
|
590 | {
|
591 | scope: 'comment',
|
592 | begin,
|
593 | end,
|
594 | contains: []
|
595 | },
|
596 | modeOptions
|
597 | );
|
598 | mode.contains.push({
|
599 | scope: 'doctag',
|
600 |
|
601 |
|
602 | begin: '[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)',
|
603 | end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
|
604 | excludeBegin: true,
|
605 | relevance: 0
|
606 | });
|
607 | const ENGLISH_WORD = either(
|
608 |
|
609 | "I",
|
610 | "a",
|
611 | "is",
|
612 | "so",
|
613 | "us",
|
614 | "to",
|
615 | "at",
|
616 | "if",
|
617 | "in",
|
618 | "it",
|
619 | "on",
|
620 |
|
621 | /[A-Za-z]+['](d|ve|re|ll|t|s|n)/, // contractions - can't we'd they're let's, etc
|
622 | /[A-Za-z]+[-][a-z]+/, // `no-way`, etc.
|
623 | /[A-Za-z][a-z]{2,}/
|
624 | );
|
625 |
|
626 | mode.contains.push(
|
627 | {
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 | begin: concat(
|
644 | /[ ]+/, // necessary to prevent us gobbling up doctags like /* @author Bob Mcgill */
|
645 | '(',
|
646 | ENGLISH_WORD,
|
647 | /[.]?[:]?([.][ ]|[ ])/,
|
648 | '){3}')
|
649 | }
|
650 | );
|
651 | return mode;
|
652 | };
|
653 | const C_LINE_COMMENT_MODE = COMMENT('//', '$');
|
654 | const C_BLOCK_COMMENT_MODE = COMMENT('/\\*', '\\*/');
|
655 | const HASH_COMMENT_MODE = COMMENT('#', '$');
|
656 | const NUMBER_MODE = {
|
657 | scope: 'number',
|
658 | begin: NUMBER_RE,
|
659 | relevance: 0
|
660 | };
|
661 | const C_NUMBER_MODE = {
|
662 | scope: 'number',
|
663 | begin: C_NUMBER_RE,
|
664 | relevance: 0
|
665 | };
|
666 | const BINARY_NUMBER_MODE = {
|
667 | scope: 'number',
|
668 | begin: BINARY_NUMBER_RE,
|
669 | relevance: 0
|
670 | };
|
671 | const REGEXP_MODE = {
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 | begin: /(?=\/[^/\n]*\/)/,
|
679 | contains: [{
|
680 | scope: 'regexp',
|
681 | begin: /\//,
|
682 | end: /\/[gimuy]*/,
|
683 | illegal: /\n/,
|
684 | contains: [
|
685 | BACKSLASH_ESCAPE,
|
686 | {
|
687 | begin: /\[/,
|
688 | end: /\]/,
|
689 | relevance: 0,
|
690 | contains: [BACKSLASH_ESCAPE]
|
691 | }
|
692 | ]
|
693 | }]
|
694 | };
|
695 | const TITLE_MODE = {
|
696 | scope: 'title',
|
697 | begin: IDENT_RE,
|
698 | relevance: 0
|
699 | };
|
700 | const UNDERSCORE_TITLE_MODE = {
|
701 | scope: 'title',
|
702 | begin: UNDERSCORE_IDENT_RE,
|
703 | relevance: 0
|
704 | };
|
705 | const METHOD_GUARD = {
|
706 |
|
707 | begin: '\\.\\s*' + UNDERSCORE_IDENT_RE,
|
708 | relevance: 0
|
709 | };
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 | const END_SAME_AS_BEGIN = function(mode) {
|
719 | return Object.assign(mode,
|
720 | {
|
721 |
|
722 | 'on:begin': (m, resp) => { resp.data._beginMatch = m[1]; },
|
723 |
|
724 | 'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch(); }
|
725 | });
|
726 | };
|
727 |
|
728 | var MODES = Object.freeze({
|
729 | __proto__: null,
|
730 | MATCH_NOTHING_RE: MATCH_NOTHING_RE,
|
731 | IDENT_RE: IDENT_RE,
|
732 | UNDERSCORE_IDENT_RE: UNDERSCORE_IDENT_RE,
|
733 | NUMBER_RE: NUMBER_RE,
|
734 | C_NUMBER_RE: C_NUMBER_RE,
|
735 | BINARY_NUMBER_RE: BINARY_NUMBER_RE,
|
736 | RE_STARTERS_RE: RE_STARTERS_RE,
|
737 | SHEBANG: SHEBANG,
|
738 | BACKSLASH_ESCAPE: BACKSLASH_ESCAPE,
|
739 | APOS_STRING_MODE: APOS_STRING_MODE,
|
740 | QUOTE_STRING_MODE: QUOTE_STRING_MODE,
|
741 | PHRASAL_WORDS_MODE: PHRASAL_WORDS_MODE,
|
742 | COMMENT: COMMENT,
|
743 | C_LINE_COMMENT_MODE: C_LINE_COMMENT_MODE,
|
744 | C_BLOCK_COMMENT_MODE: C_BLOCK_COMMENT_MODE,
|
745 | HASH_COMMENT_MODE: HASH_COMMENT_MODE,
|
746 | NUMBER_MODE: NUMBER_MODE,
|
747 | C_NUMBER_MODE: C_NUMBER_MODE,
|
748 | BINARY_NUMBER_MODE: BINARY_NUMBER_MODE,
|
749 | REGEXP_MODE: REGEXP_MODE,
|
750 | TITLE_MODE: TITLE_MODE,
|
751 | UNDERSCORE_TITLE_MODE: UNDERSCORE_TITLE_MODE,
|
752 | METHOD_GUARD: METHOD_GUARD,
|
753 | END_SAME_AS_BEGIN: END_SAME_AS_BEGIN
|
754 | });
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 | function skipIfHasPrecedingDot(match, response) {
|
786 | const before = match.input[match.index - 1];
|
787 | if (before === ".") {
|
788 | response.ignoreMatch();
|
789 | }
|
790 | }
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 | function scopeClassName(mode, _parent) {
|
797 |
|
798 | if (mode.className !== undefined) {
|
799 | mode.scope = mode.className;
|
800 | delete mode.className;
|
801 | }
|
802 | }
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 | function beginKeywords(mode, parent) {
|
809 | if (!parent) return;
|
810 | if (!mode.beginKeywords) return;
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 | mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\.)(?=\\b|\\s)';
|
818 | mode.__beforeBegin = skipIfHasPrecedingDot;
|
819 | mode.keywords = mode.keywords || mode.beginKeywords;
|
820 | delete mode.beginKeywords;
|
821 |
|
822 |
|
823 |
|
824 |
|
825 | if (mode.relevance === undefined) mode.relevance = 0;
|
826 | }
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 | function compileIllegal(mode, _parent) {
|
833 | if (!Array.isArray(mode.illegal)) return;
|
834 |
|
835 | mode.illegal = either(...mode.illegal);
|
836 | }
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 | function compileMatch(mode, _parent) {
|
843 | if (!mode.match) return;
|
844 | if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
|
845 |
|
846 | mode.begin = mode.match;
|
847 | delete mode.match;
|
848 | }
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 | function compileRelevance(mode, _parent) {
|
855 |
|
856 | if (mode.relevance === undefined) mode.relevance = 1;
|
857 | }
|
858 |
|
859 |
|
860 |
|
861 | const beforeMatchExt = (mode, parent) => {
|
862 | if (!mode.beforeMatch) return;
|
863 |
|
864 |
|
865 | if (mode.starts) throw new Error("beforeMatch cannot be used with starts");
|
866 |
|
867 | const originalMode = Object.assign({}, mode);
|
868 | Object.keys(mode).forEach((key) => { delete mode[key]; });
|
869 |
|
870 | mode.keywords = originalMode.keywords;
|
871 | mode.begin = concat(originalMode.beforeMatch, lookahead(originalMode.begin));
|
872 | mode.starts = {
|
873 | relevance: 0,
|
874 | contains: [
|
875 | Object.assign(originalMode, { endsParent: true })
|
876 | ]
|
877 | };
|
878 | mode.relevance = 0;
|
879 |
|
880 | delete originalMode.beforeMatch;
|
881 | };
|
882 |
|
883 |
|
884 | const COMMON_KEYWORDS = [
|
885 | 'of',
|
886 | 'and',
|
887 | 'for',
|
888 | 'in',
|
889 | 'not',
|
890 | 'or',
|
891 | 'if',
|
892 | 'then',
|
893 | 'parent',
|
894 | 'list',
|
895 | 'value'
|
896 | ];
|
897 |
|
898 | const DEFAULT_KEYWORD_SCOPE = "keyword";
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 | function compileKeywords(rawKeywords, caseInsensitive, scopeName = DEFAULT_KEYWORD_SCOPE) {
|
907 |
|
908 | const compiledKeywords = Object.create(null);
|
909 |
|
910 |
|
911 |
|
912 | if (typeof rawKeywords === 'string') {
|
913 | compileList(scopeName, rawKeywords.split(" "));
|
914 | } else if (Array.isArray(rawKeywords)) {
|
915 | compileList(scopeName, rawKeywords);
|
916 | } else {
|
917 | Object.keys(rawKeywords).forEach(function(scopeName) {
|
918 |
|
919 | Object.assign(
|
920 | compiledKeywords,
|
921 | compileKeywords(rawKeywords[scopeName], caseInsensitive, scopeName)
|
922 | );
|
923 | });
|
924 | }
|
925 | return compiledKeywords;
|
926 |
|
927 |
|
928 |
|
929 | |
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 |
|
937 | function compileList(scopeName, keywordList) {
|
938 | if (caseInsensitive) {
|
939 | keywordList = keywordList.map(x => x.toLowerCase());
|
940 | }
|
941 | keywordList.forEach(function(keyword) {
|
942 | const pair = keyword.split('|');
|
943 | compiledKeywords[pair[0]] = [scopeName, scoreForKeyword(pair[0], pair[1])];
|
944 | });
|
945 | }
|
946 | }
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 | function scoreForKeyword(keyword, providedScore) {
|
957 |
|
958 |
|
959 | if (providedScore) {
|
960 | return Number(providedScore);
|
961 | }
|
962 |
|
963 | return commonKeyword(keyword) ? 0 : 1;
|
964 | }
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 | function commonKeyword(keyword) {
|
971 | return COMMON_KEYWORDS.includes(keyword.toLowerCase());
|
972 | }
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 | const seenDeprecations = {};
|
985 |
|
986 |
|
987 |
|
988 |
|
989 | const error = (message) => {
|
990 | console.error(message);
|
991 | };
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 | const warn = (message, ...args) => {
|
998 | console.log(`WARN: ${message}`, ...args);
|
999 | };
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 | const deprecated = (version, message) => {
|
1006 | if (seenDeprecations[`${version}/${message}`]) return;
|
1007 |
|
1008 | console.log(`Deprecated as of ${version}. ${message}`);
|
1009 | seenDeprecations[`${version}/${message}`] = true;
|
1010 | };
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 | const MultiClassError = new Error();
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 | function remapScopeNames(mode, regexes, { key }) {
|
1049 | let offset = 0;
|
1050 | const scopeNames = mode[key];
|
1051 |
|
1052 | const emit = {};
|
1053 |
|
1054 | const positions = {};
|
1055 |
|
1056 | for (let i = 1; i <= regexes.length; i++) {
|
1057 | positions[i + offset] = scopeNames[i];
|
1058 | emit[i + offset] = true;
|
1059 | offset += countMatchGroups(regexes[i - 1]);
|
1060 | }
|
1061 |
|
1062 |
|
1063 | mode[key] = positions;
|
1064 | mode[key]._emit = emit;
|
1065 | mode[key]._multi = true;
|
1066 | }
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 | function beginMultiClass(mode) {
|
1072 | if (!Array.isArray(mode.begin)) return;
|
1073 |
|
1074 | if (mode.skip || mode.excludeBegin || mode.returnBegin) {
|
1075 | error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
|
1076 | throw MultiClassError;
|
1077 | }
|
1078 |
|
1079 | if (typeof mode.beginScope !== "object" || mode.beginScope === null) {
|
1080 | error("beginScope must be object");
|
1081 | throw MultiClassError;
|
1082 | }
|
1083 |
|
1084 | remapScopeNames(mode, mode.begin, { key: "beginScope" });
|
1085 | mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
|
1086 | }
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 | function endMultiClass(mode) {
|
1092 | if (!Array.isArray(mode.end)) return;
|
1093 |
|
1094 | if (mode.skip || mode.excludeEnd || mode.returnEnd) {
|
1095 | error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
|
1096 | throw MultiClassError;
|
1097 | }
|
1098 |
|
1099 | if (typeof mode.endScope !== "object" || mode.endScope === null) {
|
1100 | error("endScope must be object");
|
1101 | throw MultiClassError;
|
1102 | }
|
1103 |
|
1104 | remapScopeNames(mode, mode.end, { key: "endScope" });
|
1105 | mode.end = _rewriteBackreferences(mode.end, { joinWith: "" });
|
1106 | }
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 | function scopeSugar(mode) {
|
1120 | if (mode.scope && typeof mode.scope === "object" && mode.scope !== null) {
|
1121 | mode.beginScope = mode.scope;
|
1122 | delete mode.scope;
|
1123 | }
|
1124 | }
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 | function MultiClass(mode) {
|
1130 | scopeSugar(mode);
|
1131 |
|
1132 | if (typeof mode.beginScope === "string") {
|
1133 | mode.beginScope = { _wrap: mode.beginScope };
|
1134 | }
|
1135 | if (typeof mode.endScope === "string") {
|
1136 | mode.endScope = { _wrap: mode.endScope };
|
1137 | }
|
1138 |
|
1139 | beginMultiClass(mode);
|
1140 | endMultiClass(mode);
|
1141 | }
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 | function compileLanguage(language) {
|
1162 | |
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 | function langRe(value, global) {
|
1169 | return new RegExp(
|
1170 | source(value),
|
1171 | 'm'
|
1172 | + (language.case_insensitive ? 'i' : '')
|
1173 | + (language.unicodeRegex ? 'u' : '')
|
1174 | + (global ? 'g' : '')
|
1175 | );
|
1176 | }
|
1177 |
|
1178 | |
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 | class MultiRegex {
|
1192 | constructor() {
|
1193 | this.matchIndexes = {};
|
1194 |
|
1195 | this.regexes = [];
|
1196 | this.matchAt = 1;
|
1197 | this.position = 0;
|
1198 | }
|
1199 |
|
1200 |
|
1201 | addRule(re, opts) {
|
1202 | opts.position = this.position++;
|
1203 |
|
1204 | this.matchIndexes[this.matchAt] = opts;
|
1205 | this.regexes.push([opts, re]);
|
1206 | this.matchAt += countMatchGroups(re) + 1;
|
1207 | }
|
1208 |
|
1209 | compile() {
|
1210 | if (this.regexes.length === 0) {
|
1211 |
|
1212 |
|
1213 | this.exec = () => null;
|
1214 | }
|
1215 | const terminators = this.regexes.map(el => el[1]);
|
1216 | this.matcherRe = langRe(_rewriteBackreferences(terminators, { joinWith: '|' }), true);
|
1217 | this.lastIndex = 0;
|
1218 | }
|
1219 |
|
1220 |
|
1221 | exec(s) {
|
1222 | this.matcherRe.lastIndex = this.lastIndex;
|
1223 | const match = this.matcherRe.exec(s);
|
1224 | if (!match) { return null; }
|
1225 |
|
1226 |
|
1227 | const i = match.findIndex((el, i) => i > 0 && el !== undefined);
|
1228 |
|
1229 | const matchData = this.matchIndexes[i];
|
1230 |
|
1231 |
|
1232 | match.splice(0, i);
|
1233 |
|
1234 | return Object.assign(match, matchData);
|
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 | class ResumableMultiRegex {
|
1270 | constructor() {
|
1271 |
|
1272 | this.rules = [];
|
1273 |
|
1274 | this.multiRegexes = [];
|
1275 | this.count = 0;
|
1276 |
|
1277 | this.lastIndex = 0;
|
1278 | this.regexIndex = 0;
|
1279 | }
|
1280 |
|
1281 |
|
1282 | getMatcher(index) {
|
1283 | if (this.multiRegexes[index]) return this.multiRegexes[index];
|
1284 |
|
1285 | const matcher = new MultiRegex();
|
1286 | this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
|
1287 | matcher.compile();
|
1288 | this.multiRegexes[index] = matcher;
|
1289 | return matcher;
|
1290 | }
|
1291 |
|
1292 | resumingScanAtSamePosition() {
|
1293 | return this.regexIndex !== 0;
|
1294 | }
|
1295 |
|
1296 | considerAll() {
|
1297 | this.regexIndex = 0;
|
1298 | }
|
1299 |
|
1300 |
|
1301 | addRule(re, opts) {
|
1302 | this.rules.push([re, opts]);
|
1303 | if (opts.type === "begin") this.count++;
|
1304 | }
|
1305 |
|
1306 |
|
1307 | exec(s) {
|
1308 | const m = this.getMatcher(this.regexIndex);
|
1309 | m.lastIndex = this.lastIndex;
|
1310 | let result = m.exec(s);
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 | if (this.resumingScanAtSamePosition()) {
|
1344 | if (result && result.index === this.lastIndex) ; else {
|
1345 | const m2 = this.getMatcher(0);
|
1346 | m2.lastIndex = this.lastIndex + 1;
|
1347 | result = m2.exec(s);
|
1348 | }
|
1349 | }
|
1350 |
|
1351 | if (result) {
|
1352 | this.regexIndex += result.position + 1;
|
1353 | if (this.regexIndex === this.count) {
|
1354 |
|
1355 | this.considerAll();
|
1356 | }
|
1357 | }
|
1358 |
|
1359 | return result;
|
1360 | }
|
1361 | }
|
1362 |
|
1363 | |
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 | function buildModeRegex(mode) {
|
1371 | const mm = new ResumableMultiRegex();
|
1372 |
|
1373 | mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: "begin" }));
|
1374 |
|
1375 | if (mode.terminatorEnd) {
|
1376 | mm.addRule(mode.terminatorEnd, { type: "end" });
|
1377 | }
|
1378 | if (mode.illegal) {
|
1379 | mm.addRule(mode.illegal, { type: "illegal" });
|
1380 | }
|
1381 |
|
1382 | return mm;
|
1383 | }
|
1384 |
|
1385 | |
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 | |
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 | function compileMode(mode, parent) {
|
1425 | const cmode = (mode);
|
1426 | if (mode.isCompiled) return cmode;
|
1427 |
|
1428 | [
|
1429 | scopeClassName,
|
1430 |
|
1431 |
|
1432 | compileMatch,
|
1433 | MultiClass,
|
1434 | beforeMatchExt
|
1435 | ].forEach(ext => ext(mode, parent));
|
1436 |
|
1437 | language.compilerExtensions.forEach(ext => ext(mode, parent));
|
1438 |
|
1439 |
|
1440 | mode.__beforeBegin = null;
|
1441 |
|
1442 | [
|
1443 | beginKeywords,
|
1444 |
|
1445 |
|
1446 | compileIllegal,
|
1447 |
|
1448 | compileRelevance
|
1449 | ].forEach(ext => ext(mode, parent));
|
1450 |
|
1451 | mode.isCompiled = true;
|
1452 |
|
1453 | let keywordPattern = null;
|
1454 | if (typeof mode.keywords === "object" && mode.keywords.$pattern) {
|
1455 |
|
1456 |
|
1457 |
|
1458 | mode.keywords = Object.assign({}, mode.keywords);
|
1459 | keywordPattern = mode.keywords.$pattern;
|
1460 | delete mode.keywords.$pattern;
|
1461 | }
|
1462 | keywordPattern = keywordPattern || /\w+/;
|
1463 |
|
1464 | if (mode.keywords) {
|
1465 | mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
|
1466 | }
|
1467 |
|
1468 | cmode.keywordPatternRe = langRe(keywordPattern, true);
|
1469 |
|
1470 | if (parent) {
|
1471 | if (!mode.begin) mode.begin = /\B|\b/;
|
1472 | cmode.beginRe = langRe(cmode.begin);
|
1473 | if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
|
1474 | if (mode.end) cmode.endRe = langRe(cmode.end);
|
1475 | cmode.terminatorEnd = source(cmode.end) || '';
|
1476 | if (mode.endsWithParent && parent.terminatorEnd) {
|
1477 | cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;
|
1478 | }
|
1479 | }
|
1480 | if (mode.illegal) cmode.illegalRe = langRe( (mode.illegal));
|
1481 | if (!mode.contains) mode.contains = [];
|
1482 |
|
1483 | mode.contains = [].concat(...mode.contains.map(function(c) {
|
1484 | return expandOrCloneMode(c === 'self' ? mode : c);
|
1485 | }));
|
1486 | mode.contains.forEach(function(c) { compileMode( (c), cmode); });
|
1487 |
|
1488 | if (mode.starts) {
|
1489 | compileMode(mode.starts, parent);
|
1490 | }
|
1491 |
|
1492 | cmode.matcher = buildModeRegex(cmode);
|
1493 | return cmode;
|
1494 | }
|
1495 |
|
1496 | if (!language.compilerExtensions) language.compilerExtensions = [];
|
1497 |
|
1498 |
|
1499 | if (language.contains && language.contains.includes('self')) {
|
1500 | throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
|
1501 | }
|
1502 |
|
1503 |
|
1504 | language.classNameAliases = inherit$1(language.classNameAliases || {});
|
1505 |
|
1506 | return compileMode( (language));
|
1507 | }
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 | function dependencyOnParent(mode) {
|
1521 | if (!mode) return false;
|
1522 |
|
1523 | return mode.endsWithParent || dependencyOnParent(mode.starts);
|
1524 | }
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 | function expandOrCloneMode(mode) {
|
1537 | if (mode.variants && !mode.cachedVariants) {
|
1538 | mode.cachedVariants = mode.variants.map(function(variant) {
|
1539 | return inherit$1(mode, { variants: null }, variant);
|
1540 | });
|
1541 | }
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 | if (mode.cachedVariants) {
|
1547 | return mode.cachedVariants;
|
1548 | }
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 | if (dependencyOnParent(mode)) {
|
1555 | return inherit$1(mode, { starts: mode.starts ? inherit$1(mode.starts) : null });
|
1556 | }
|
1557 |
|
1558 | if (Object.isFrozen(mode)) {
|
1559 | return inherit$1(mode);
|
1560 | }
|
1561 |
|
1562 |
|
1563 | return mode;
|
1564 | }
|
1565 |
|
1566 | var version = "11.6.0";
|
1567 |
|
1568 | class HTMLInjectionError extends Error {
|
1569 | constructor(reason, html) {
|
1570 | super(reason);
|
1571 | this.name = "HTMLInjectionError";
|
1572 | this.html = html;
|
1573 | }
|
1574 | }
|
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 | const escape = escapeHTML;
|
1604 | const inherit = inherit$1;
|
1605 | const NO_MATCH = Symbol("nomatch");
|
1606 | const MAX_KEYWORD_HITS = 7;
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 | const HLJS = function(hljs) {
|
1613 |
|
1614 |
|
1615 | const languages = Object.create(null);
|
1616 |
|
1617 | const aliases = Object.create(null);
|
1618 |
|
1619 | const plugins = [];
|
1620 |
|
1621 |
|
1622 |
|
1623 | let SAFE_MODE = true;
|
1624 | const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
|
1625 |
|
1626 | const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text', contains: [] };
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 | let options = {
|
1632 | ignoreUnescapedHTML: false,
|
1633 | throwUnescapedHTML: false,
|
1634 | noHighlightRe: /^(no-?highlight)$/i,
|
1635 | languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
|
1636 | classPrefix: 'hljs-',
|
1637 | cssSelector: 'pre code',
|
1638 | languages: null,
|
1639 |
|
1640 |
|
1641 | __emitter: TokenTreeEmitter
|
1642 | };
|
1643 |
|
1644 |
|
1645 |
|
1646 | |
1647 |
|
1648 |
|
1649 |
|
1650 | function shouldNotHighlight(languageName) {
|
1651 | return options.noHighlightRe.test(languageName);
|
1652 | }
|
1653 |
|
1654 | |
1655 |
|
1656 |
|
1657 | function blockLanguage(block) {
|
1658 | let classes = block.className + ' ';
|
1659 |
|
1660 | classes += block.parentNode ? block.parentNode.className : '';
|
1661 |
|
1662 |
|
1663 | const match = options.languageDetectRe.exec(classes);
|
1664 | if (match) {
|
1665 | const language = getLanguage(match[1]);
|
1666 | if (!language) {
|
1667 | warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
|
1668 | warn("Falling back to no-highlight mode for this block.", block);
|
1669 | }
|
1670 | return language ? match[1] : 'no-highlight';
|
1671 | }
|
1672 |
|
1673 | return classes
|
1674 | .split(/\s+/)
|
1675 | .find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
|
1676 | }
|
1677 |
|
1678 | |
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 | function highlight(codeOrLanguageName, optionsOrCode, ignoreIllegals) {
|
1700 | let code = "";
|
1701 | let languageName = "";
|
1702 | if (typeof optionsOrCode === "object") {
|
1703 | code = codeOrLanguageName;
|
1704 | ignoreIllegals = optionsOrCode.ignoreIllegals;
|
1705 | languageName = optionsOrCode.language;
|
1706 | } else {
|
1707 |
|
1708 | deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
|
1709 | deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
|
1710 | languageName = codeOrLanguageName;
|
1711 | code = optionsOrCode;
|
1712 | }
|
1713 |
|
1714 |
|
1715 |
|
1716 | if (ignoreIllegals === undefined) { ignoreIllegals = true; }
|
1717 |
|
1718 |
|
1719 | const context = {
|
1720 | code,
|
1721 | language: languageName
|
1722 | };
|
1723 |
|
1724 |
|
1725 | fire("before:highlight", context);
|
1726 |
|
1727 |
|
1728 |
|
1729 | const result = context.result
|
1730 | ? context.result
|
1731 | : _highlight(context.language, context.code, ignoreIllegals);
|
1732 |
|
1733 | result.code = context.code;
|
1734 |
|
1735 | fire("after:highlight", result);
|
1736 |
|
1737 | return result;
|
1738 | }
|
1739 |
|
1740 | |
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 | function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
|
1750 | const keywordHits = Object.create(null);
|
1751 |
|
1752 | |
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 | function keywordData(mode, matchText) {
|
1759 | return mode.keywords[matchText];
|
1760 | }
|
1761 |
|
1762 | function processKeywords() {
|
1763 | if (!top.keywords) {
|
1764 | emitter.addText(modeBuffer);
|
1765 | return;
|
1766 | }
|
1767 |
|
1768 | let lastIndex = 0;
|
1769 | top.keywordPatternRe.lastIndex = 0;
|
1770 | let match = top.keywordPatternRe.exec(modeBuffer);
|
1771 | let buf = "";
|
1772 |
|
1773 | while (match) {
|
1774 | buf += modeBuffer.substring(lastIndex, match.index);
|
1775 | const word = language.case_insensitive ? match[0].toLowerCase() : match[0];
|
1776 | const data = keywordData(top, word);
|
1777 | if (data) {
|
1778 | const [kind, keywordRelevance] = data;
|
1779 | emitter.addText(buf);
|
1780 | buf = "";
|
1781 |
|
1782 | keywordHits[word] = (keywordHits[word] || 0) + 1;
|
1783 | if (keywordHits[word] <= MAX_KEYWORD_HITS) relevance += keywordRelevance;
|
1784 | if (kind.startsWith("_")) {
|
1785 |
|
1786 |
|
1787 | buf += match[0];
|
1788 | } else {
|
1789 | const cssClass = language.classNameAliases[kind] || kind;
|
1790 | emitter.addKeyword(match[0], cssClass);
|
1791 | }
|
1792 | } else {
|
1793 | buf += match[0];
|
1794 | }
|
1795 | lastIndex = top.keywordPatternRe.lastIndex;
|
1796 | match = top.keywordPatternRe.exec(modeBuffer);
|
1797 | }
|
1798 | buf += modeBuffer.substring(lastIndex);
|
1799 | emitter.addText(buf);
|
1800 | }
|
1801 |
|
1802 | function processSubLanguage() {
|
1803 | if (modeBuffer === "") return;
|
1804 |
|
1805 | let result = null;
|
1806 |
|
1807 | if (typeof top.subLanguage === 'string') {
|
1808 | if (!languages[top.subLanguage]) {
|
1809 | emitter.addText(modeBuffer);
|
1810 | return;
|
1811 | }
|
1812 | result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
|
1813 | continuations[top.subLanguage] = (result._top);
|
1814 | } else {
|
1815 | result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
|
1816 | }
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 | if (top.relevance > 0) {
|
1823 | relevance += result.relevance;
|
1824 | }
|
1825 | emitter.addSublanguage(result._emitter, result.language);
|
1826 | }
|
1827 |
|
1828 | function processBuffer() {
|
1829 | if (top.subLanguage != null) {
|
1830 | processSubLanguage();
|
1831 | } else {
|
1832 | processKeywords();
|
1833 | }
|
1834 | modeBuffer = '';
|
1835 | }
|
1836 |
|
1837 | |
1838 |
|
1839 |
|
1840 |
|
1841 | function emitMultiClass(scope, match) {
|
1842 | let i = 1;
|
1843 | const max = match.length - 1;
|
1844 | while (i <= max) {
|
1845 | if (!scope._emit[i]) { i++; continue; }
|
1846 | const klass = language.classNameAliases[scope[i]] || scope[i];
|
1847 | const text = match[i];
|
1848 | if (klass) {
|
1849 | emitter.addKeyword(text, klass);
|
1850 | } else {
|
1851 | modeBuffer = text;
|
1852 | processKeywords();
|
1853 | modeBuffer = "";
|
1854 | }
|
1855 | i++;
|
1856 | }
|
1857 | }
|
1858 |
|
1859 | |
1860 |
|
1861 |
|
1862 |
|
1863 | function startNewMode(mode, match) {
|
1864 | if (mode.scope && typeof mode.scope === "string") {
|
1865 | emitter.openNode(language.classNameAliases[mode.scope] || mode.scope);
|
1866 | }
|
1867 | if (mode.beginScope) {
|
1868 |
|
1869 | if (mode.beginScope._wrap) {
|
1870 | emitter.addKeyword(modeBuffer, language.classNameAliases[mode.beginScope._wrap] || mode.beginScope._wrap);
|
1871 | modeBuffer = "";
|
1872 | } else if (mode.beginScope._multi) {
|
1873 |
|
1874 | emitMultiClass(mode.beginScope, match);
|
1875 | modeBuffer = "";
|
1876 | }
|
1877 | }
|
1878 |
|
1879 | top = Object.create(mode, { parent: { value: top } });
|
1880 | return top;
|
1881 | }
|
1882 |
|
1883 | |
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 | function endOfMode(mode, match, matchPlusRemainder) {
|
1890 | let matched = startsWith(mode.endRe, matchPlusRemainder);
|
1891 |
|
1892 | if (matched) {
|
1893 | if (mode["on:end"]) {
|
1894 | const resp = new Response(mode);
|
1895 | mode["on:end"](match, resp);
|
1896 | if (resp.isMatchIgnored) matched = false;
|
1897 | }
|
1898 |
|
1899 | if (matched) {
|
1900 | while (mode.endsParent && mode.parent) {
|
1901 | mode = mode.parent;
|
1902 | }
|
1903 | return mode;
|
1904 | }
|
1905 | }
|
1906 |
|
1907 |
|
1908 | if (mode.endsWithParent) {
|
1909 | return endOfMode(mode.parent, match, matchPlusRemainder);
|
1910 | }
|
1911 | }
|
1912 |
|
1913 | |
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 | function doIgnore(lexeme) {
|
1919 | if (top.matcher.regexIndex === 0) {
|
1920 |
|
1921 |
|
1922 | modeBuffer += lexeme[0];
|
1923 | return 1;
|
1924 | } else {
|
1925 |
|
1926 |
|
1927 | resumeScanAtSamePosition = true;
|
1928 | return 0;
|
1929 | }
|
1930 | }
|
1931 |
|
1932 | |
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 | function doBeginMatch(match) {
|
1939 | const lexeme = match[0];
|
1940 | const newMode = match.rule;
|
1941 |
|
1942 | const resp = new Response(newMode);
|
1943 |
|
1944 | const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
|
1945 | for (const cb of beforeCallbacks) {
|
1946 | if (!cb) continue;
|
1947 | cb(match, resp);
|
1948 | if (resp.isMatchIgnored) return doIgnore(lexeme);
|
1949 | }
|
1950 |
|
1951 | if (newMode.skip) {
|
1952 | modeBuffer += lexeme;
|
1953 | } else {
|
1954 | if (newMode.excludeBegin) {
|
1955 | modeBuffer += lexeme;
|
1956 | }
|
1957 | processBuffer();
|
1958 | if (!newMode.returnBegin && !newMode.excludeBegin) {
|
1959 | modeBuffer = lexeme;
|
1960 | }
|
1961 | }
|
1962 | startNewMode(newMode, match);
|
1963 | return newMode.returnBegin ? 0 : lexeme.length;
|
1964 | }
|
1965 |
|
1966 | |
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 | function doEndMatch(match) {
|
1972 | const lexeme = match[0];
|
1973 | const matchPlusRemainder = codeToHighlight.substring(match.index);
|
1974 |
|
1975 | const endMode = endOfMode(top, match, matchPlusRemainder);
|
1976 | if (!endMode) { return NO_MATCH; }
|
1977 |
|
1978 | const origin = top;
|
1979 | if (top.endScope && top.endScope._wrap) {
|
1980 | processBuffer();
|
1981 | emitter.addKeyword(lexeme, top.endScope._wrap);
|
1982 | } else if (top.endScope && top.endScope._multi) {
|
1983 | processBuffer();
|
1984 | emitMultiClass(top.endScope, match);
|
1985 | } else if (origin.skip) {
|
1986 | modeBuffer += lexeme;
|
1987 | } else {
|
1988 | if (!(origin.returnEnd || origin.excludeEnd)) {
|
1989 | modeBuffer += lexeme;
|
1990 | }
|
1991 | processBuffer();
|
1992 | if (origin.excludeEnd) {
|
1993 | modeBuffer = lexeme;
|
1994 | }
|
1995 | }
|
1996 | do {
|
1997 | if (top.scope) {
|
1998 | emitter.closeNode();
|
1999 | }
|
2000 | if (!top.skip && !top.subLanguage) {
|
2001 | relevance += top.relevance;
|
2002 | }
|
2003 | top = top.parent;
|
2004 | } while (top !== endMode.parent);
|
2005 | if (endMode.starts) {
|
2006 | startNewMode(endMode.starts, match);
|
2007 | }
|
2008 | return origin.returnEnd ? 0 : lexeme.length;
|
2009 | }
|
2010 |
|
2011 | function processContinuations() {
|
2012 | const list = [];
|
2013 | for (let current = top; current !== language; current = current.parent) {
|
2014 | if (current.scope) {
|
2015 | list.unshift(current.scope);
|
2016 | }
|
2017 | }
|
2018 | list.forEach(item => emitter.openNode(item));
|
2019 | }
|
2020 |
|
2021 |
|
2022 | let lastMatch = {};
|
2023 |
|
2024 | |
2025 |
|
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 | function processLexeme(textBeforeMatch, match) {
|
2031 | const lexeme = match && match[0];
|
2032 |
|
2033 |
|
2034 | modeBuffer += textBeforeMatch;
|
2035 |
|
2036 | if (lexeme == null) {
|
2037 | processBuffer();
|
2038 | return 0;
|
2039 | }
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 | if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
|
2046 |
|
2047 | modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
|
2048 | if (!SAFE_MODE) {
|
2049 |
|
2050 | const err = new Error(`0 width match regex (${languageName})`);
|
2051 | err.languageName = languageName;
|
2052 | err.badRule = lastMatch.rule;
|
2053 | throw err;
|
2054 | }
|
2055 | return 1;
|
2056 | }
|
2057 | lastMatch = match;
|
2058 |
|
2059 | if (match.type === "begin") {
|
2060 | return doBeginMatch(match);
|
2061 | } else if (match.type === "illegal" && !ignoreIllegals) {
|
2062 |
|
2063 |
|
2064 | const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.scope || '<unnamed>') + '"');
|
2065 | err.mode = top;
|
2066 | throw err;
|
2067 | } else if (match.type === "end") {
|
2068 | const processed = doEndMatch(match);
|
2069 | if (processed !== NO_MATCH) {
|
2070 | return processed;
|
2071 | }
|
2072 | }
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 | if (match.type === "illegal" && lexeme === "") {
|
2078 |
|
2079 | return 1;
|
2080 | }
|
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 |
|
2086 | if (iterations > 100000 && iterations > match.index * 3) {
|
2087 | const err = new Error('potential infinite loop, way more iterations than matches');
|
2088 | throw err;
|
2089 | }
|
2090 |
|
2091 | |
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 |
|
2099 | modeBuffer += lexeme;
|
2100 | return lexeme.length;
|
2101 | }
|
2102 |
|
2103 | const language = getLanguage(languageName);
|
2104 | if (!language) {
|
2105 | error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
|
2106 | throw new Error('Unknown language: "' + languageName + '"');
|
2107 | }
|
2108 |
|
2109 | const md = compileLanguage(language);
|
2110 | let result = '';
|
2111 |
|
2112 | let top = continuation || md;
|
2113 |
|
2114 | const continuations = {};
|
2115 | const emitter = new options.__emitter(options);
|
2116 | processContinuations();
|
2117 | let modeBuffer = '';
|
2118 | let relevance = 0;
|
2119 | let index = 0;
|
2120 | let iterations = 0;
|
2121 | let resumeScanAtSamePosition = false;
|
2122 |
|
2123 | try {
|
2124 | top.matcher.considerAll();
|
2125 |
|
2126 | for (;;) {
|
2127 | iterations++;
|
2128 | if (resumeScanAtSamePosition) {
|
2129 |
|
2130 |
|
2131 | resumeScanAtSamePosition = false;
|
2132 | } else {
|
2133 | top.matcher.considerAll();
|
2134 | }
|
2135 | top.matcher.lastIndex = index;
|
2136 |
|
2137 | const match = top.matcher.exec(codeToHighlight);
|
2138 |
|
2139 |
|
2140 | if (!match) break;
|
2141 |
|
2142 | const beforeMatch = codeToHighlight.substring(index, match.index);
|
2143 | const processedCount = processLexeme(beforeMatch, match);
|
2144 | index = match.index + processedCount;
|
2145 | }
|
2146 | processLexeme(codeToHighlight.substring(index));
|
2147 | emitter.closeAllNodes();
|
2148 | emitter.finalize();
|
2149 | result = emitter.toHTML();
|
2150 |
|
2151 | return {
|
2152 | language: languageName,
|
2153 | value: result,
|
2154 | relevance: relevance,
|
2155 | illegal: false,
|
2156 | _emitter: emitter,
|
2157 | _top: top
|
2158 | };
|
2159 | } catch (err) {
|
2160 | if (err.message && err.message.includes('Illegal')) {
|
2161 | return {
|
2162 | language: languageName,
|
2163 | value: escape(codeToHighlight),
|
2164 | illegal: true,
|
2165 | relevance: 0,
|
2166 | _illegalBy: {
|
2167 | message: err.message,
|
2168 | index: index,
|
2169 | context: codeToHighlight.slice(index - 100, index + 100),
|
2170 | mode: err.mode,
|
2171 | resultSoFar: result
|
2172 | },
|
2173 | _emitter: emitter
|
2174 | };
|
2175 | } else if (SAFE_MODE) {
|
2176 | return {
|
2177 | language: languageName,
|
2178 | value: escape(codeToHighlight),
|
2179 | illegal: false,
|
2180 | relevance: 0,
|
2181 | errorRaised: err,
|
2182 | _emitter: emitter,
|
2183 | _top: top
|
2184 | };
|
2185 | } else {
|
2186 | throw err;
|
2187 | }
|
2188 | }
|
2189 | }
|
2190 |
|
2191 | |
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 | function justTextHighlightResult(code) {
|
2199 | const result = {
|
2200 | value: escape(code),
|
2201 | illegal: false,
|
2202 | relevance: 0,
|
2203 | _top: PLAINTEXT_LANGUAGE,
|
2204 | _emitter: new options.__emitter(options)
|
2205 | };
|
2206 | result._emitter.addText(code);
|
2207 | return result;
|
2208 | }
|
2209 |
|
2210 | |
2211 |
|
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 | function highlightAuto(code, languageSubset) {
|
2225 | languageSubset = languageSubset || options.languages || Object.keys(languages);
|
2226 | const plaintext = justTextHighlightResult(code);
|
2227 |
|
2228 | const results = languageSubset.filter(getLanguage).filter(autoDetection).map(name =>
|
2229 | _highlight(name, code, false)
|
2230 | );
|
2231 | results.unshift(plaintext);
|
2232 |
|
2233 | const sorted = results.sort((a, b) => {
|
2234 |
|
2235 | if (a.relevance !== b.relevance) return b.relevance - a.relevance;
|
2236 |
|
2237 |
|
2238 |
|
2239 | if (a.language && b.language) {
|
2240 | if (getLanguage(a.language).supersetOf === b.language) {
|
2241 | return 1;
|
2242 | } else if (getLanguage(b.language).supersetOf === a.language) {
|
2243 | return -1;
|
2244 | }
|
2245 | }
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 | return 0;
|
2252 | });
|
2253 |
|
2254 | const [best, secondBest] = sorted;
|
2255 |
|
2256 |
|
2257 | const result = best;
|
2258 | result.secondBest = secondBest;
|
2259 |
|
2260 | return result;
|
2261 | }
|
2262 |
|
2263 | |
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 | function updateClassName(element, currentLang, resultLang) {
|
2271 | const language = (currentLang && aliases[currentLang]) || resultLang;
|
2272 |
|
2273 | element.classList.add("hljs");
|
2274 | element.classList.add(`language-${language}`);
|
2275 | }
|
2276 |
|
2277 | |
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 | function highlightElement(element) {
|
2283 |
|
2284 | let node = null;
|
2285 | const language = blockLanguage(element);
|
2286 |
|
2287 | if (shouldNotHighlight(language)) return;
|
2288 |
|
2289 | fire("before:highlightElement",
|
2290 | { el: element, language: language });
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 | if (element.children.length > 0) {
|
2298 | if (!options.ignoreUnescapedHTML) {
|
2299 | console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk.");
|
2300 | console.warn("https://github.com/highlightjs/highlight.js/wiki/security");
|
2301 | console.warn("The element with unescaped HTML:");
|
2302 | console.warn(element);
|
2303 | }
|
2304 | if (options.throwUnescapedHTML) {
|
2305 | const err = new HTMLInjectionError(
|
2306 | "One of your code blocks includes unescaped HTML.",
|
2307 | element.innerHTML
|
2308 | );
|
2309 | throw err;
|
2310 | }
|
2311 | }
|
2312 |
|
2313 | node = element;
|
2314 | const text = node.textContent;
|
2315 | const result = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text);
|
2316 |
|
2317 | element.innerHTML = result.value;
|
2318 | updateClassName(element, language, result.language);
|
2319 | element.result = {
|
2320 | language: result.language,
|
2321 |
|
2322 | re: result.relevance,
|
2323 | relevance: result.relevance
|
2324 | };
|
2325 | if (result.secondBest) {
|
2326 | element.secondBest = {
|
2327 | language: result.secondBest.language,
|
2328 | relevance: result.secondBest.relevance
|
2329 | };
|
2330 | }
|
2331 |
|
2332 | fire("after:highlightElement", { el: element, result, text });
|
2333 | }
|
2334 |
|
2335 | |
2336 |
|
2337 |
|
2338 |
|
2339 |
|
2340 | function configure(userOptions) {
|
2341 | options = inherit(options, userOptions);
|
2342 | }
|
2343 |
|
2344 |
|
2345 | const initHighlighting = () => {
|
2346 | highlightAll();
|
2347 | deprecated("10.6.0", "initHighlighting() deprecated. Use highlightAll() now.");
|
2348 | };
|
2349 |
|
2350 |
|
2351 | function initHighlightingOnLoad() {
|
2352 | highlightAll();
|
2353 | deprecated("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now.");
|
2354 | }
|
2355 |
|
2356 | let wantsHighlight = false;
|
2357 |
|
2358 | |
2359 |
|
2360 |
|
2361 | function highlightAll() {
|
2362 |
|
2363 | if (document.readyState === "loading") {
|
2364 | wantsHighlight = true;
|
2365 | return;
|
2366 | }
|
2367 |
|
2368 | const blocks = document.querySelectorAll(options.cssSelector);
|
2369 | blocks.forEach(highlightElement);
|
2370 | }
|
2371 |
|
2372 | function boot() {
|
2373 |
|
2374 | if (wantsHighlight) highlightAll();
|
2375 | }
|
2376 |
|
2377 |
|
2378 | if (typeof window !== 'undefined' && window.addEventListener) {
|
2379 | window.addEventListener('DOMContentLoaded', boot, false);
|
2380 | }
|
2381 |
|
2382 | |
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 | function registerLanguage(languageName, languageDefinition) {
|
2389 | let lang = null;
|
2390 | try {
|
2391 | lang = languageDefinition(hljs);
|
2392 | } catch (error$1) {
|
2393 | error("Language definition for '{}' could not be registered.".replace("{}", languageName));
|
2394 |
|
2395 | if (!SAFE_MODE) { throw error$1; } else { error(error$1); }
|
2396 |
|
2397 |
|
2398 |
|
2399 |
|
2400 | lang = PLAINTEXT_LANGUAGE;
|
2401 | }
|
2402 |
|
2403 | if (!lang.name) lang.name = languageName;
|
2404 | languages[languageName] = lang;
|
2405 | lang.rawDefinition = languageDefinition.bind(null, hljs);
|
2406 |
|
2407 | if (lang.aliases) {
|
2408 | registerAliases(lang.aliases, { languageName });
|
2409 | }
|
2410 | }
|
2411 |
|
2412 | |
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 | function unregisterLanguage(languageName) {
|
2418 | delete languages[languageName];
|
2419 | for (const alias of Object.keys(aliases)) {
|
2420 | if (aliases[alias] === languageName) {
|
2421 | delete aliases[alias];
|
2422 | }
|
2423 | }
|
2424 | }
|
2425 |
|
2426 | |
2427 |
|
2428 |
|
2429 | function listLanguages() {
|
2430 | return Object.keys(languages);
|
2431 | }
|
2432 |
|
2433 | |
2434 |
|
2435 |
|
2436 |
|
2437 | function getLanguage(name) {
|
2438 | name = (name || '').toLowerCase();
|
2439 | return languages[name] || languages[aliases[name]];
|
2440 | }
|
2441 |
|
2442 | |
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 | function registerAliases(aliasList, { languageName }) {
|
2448 | if (typeof aliasList === 'string') {
|
2449 | aliasList = [aliasList];
|
2450 | }
|
2451 | aliasList.forEach(alias => { aliases[alias.toLowerCase()] = languageName; });
|
2452 | }
|
2453 |
|
2454 | |
2455 |
|
2456 |
|
2457 |
|
2458 | function autoDetection(name) {
|
2459 | const lang = getLanguage(name);
|
2460 | return lang && !lang.disableAutodetect;
|
2461 | }
|
2462 |
|
2463 | |
2464 |
|
2465 |
|
2466 |
|
2467 |
|
2468 | function upgradePluginAPI(plugin) {
|
2469 |
|
2470 | if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
|
2471 | plugin["before:highlightElement"] = (data) => {
|
2472 | plugin["before:highlightBlock"](
|
2473 | Object.assign({ block: data.el }, data)
|
2474 | );
|
2475 | };
|
2476 | }
|
2477 | if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
|
2478 | plugin["after:highlightElement"] = (data) => {
|
2479 | plugin["after:highlightBlock"](
|
2480 | Object.assign({ block: data.el }, data)
|
2481 | );
|
2482 | };
|
2483 | }
|
2484 | }
|
2485 |
|
2486 | |
2487 |
|
2488 |
|
2489 | function addPlugin(plugin) {
|
2490 | upgradePluginAPI(plugin);
|
2491 | plugins.push(plugin);
|
2492 | }
|
2493 |
|
2494 | |
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 | function fire(event, args) {
|
2500 | const cb = event;
|
2501 | plugins.forEach(function(plugin) {
|
2502 | if (plugin[cb]) {
|
2503 | plugin[cb](args);
|
2504 | }
|
2505 | });
|
2506 | }
|
2507 |
|
2508 | |
2509 |
|
2510 |
|
2511 |
|
2512 | function deprecateHighlightBlock(el) {
|
2513 | deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
|
2514 | deprecated("10.7.0", "Please use highlightElement now.");
|
2515 |
|
2516 | return highlightElement(el);
|
2517 | }
|
2518 |
|
2519 |
|
2520 | Object.assign(hljs, {
|
2521 | highlight,
|
2522 | highlightAuto,
|
2523 | highlightAll,
|
2524 | highlightElement,
|
2525 |
|
2526 | highlightBlock: deprecateHighlightBlock,
|
2527 | configure,
|
2528 | initHighlighting,
|
2529 | initHighlightingOnLoad,
|
2530 | registerLanguage,
|
2531 | unregisterLanguage,
|
2532 | listLanguages,
|
2533 | getLanguage,
|
2534 | registerAliases,
|
2535 | autoDetection,
|
2536 | inherit,
|
2537 | addPlugin
|
2538 | });
|
2539 |
|
2540 | hljs.debugMode = function() { SAFE_MODE = false; };
|
2541 | hljs.safeMode = function() { SAFE_MODE = true; };
|
2542 | hljs.versionString = version;
|
2543 |
|
2544 | hljs.regex = {
|
2545 | concat: concat,
|
2546 | lookahead: lookahead,
|
2547 | either: either,
|
2548 | optional: optional,
|
2549 | anyNumberOfTimes: anyNumberOfTimes
|
2550 | };
|
2551 |
|
2552 | for (const key in MODES) {
|
2553 |
|
2554 | if (typeof MODES[key] === "object") {
|
2555 |
|
2556 | deepFreezeEs6.exports(MODES[key]);
|
2557 | }
|
2558 | }
|
2559 |
|
2560 |
|
2561 | Object.assign(hljs, MODES);
|
2562 |
|
2563 | return hljs;
|
2564 | };
|
2565 |
|
2566 |
|
2567 | var highlight = HLJS({});
|
2568 |
|
2569 | export { highlight as default };
|