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