@tiptap/extension-code-block-lowlight 2.0.0-beta.209 → 2.0.0-beta.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,1610 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
20
+ mod
21
+ ));
22
+
23
+ // ../../node_modules/highlight.js/lib/core.js
24
+ var require_core = __commonJS({
25
+ "../../node_modules/highlight.js/lib/core.js"(exports, module) {
26
+ var deepFreezeEs6 = { exports: {} };
27
+ function deepFreeze(obj) {
28
+ if (obj instanceof Map) {
29
+ obj.clear = obj.delete = obj.set = function() {
30
+ throw new Error("map is read-only");
31
+ };
32
+ } else if (obj instanceof Set) {
33
+ obj.add = obj.clear = obj.delete = function() {
34
+ throw new Error("set is read-only");
35
+ };
36
+ }
37
+ Object.freeze(obj);
38
+ Object.getOwnPropertyNames(obj).forEach(function(name) {
39
+ var prop = obj[name];
40
+ if (typeof prop == "object" && !Object.isFrozen(prop)) {
41
+ deepFreeze(prop);
42
+ }
43
+ });
44
+ return obj;
45
+ }
46
+ deepFreezeEs6.exports = deepFreeze;
47
+ deepFreezeEs6.exports.default = deepFreeze;
48
+ var Response = class {
49
+ constructor(mode) {
50
+ if (mode.data === void 0)
51
+ mode.data = {};
52
+ this.data = mode.data;
53
+ this.isMatchIgnored = false;
54
+ }
55
+ ignoreMatch() {
56
+ this.isMatchIgnored = true;
57
+ }
58
+ };
59
+ function escapeHTML(value) {
60
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
61
+ }
62
+ function inherit$1(original, ...objects) {
63
+ const result = /* @__PURE__ */ Object.create(null);
64
+ for (const key in original) {
65
+ result[key] = original[key];
66
+ }
67
+ objects.forEach(function(obj) {
68
+ for (const key in obj) {
69
+ result[key] = obj[key];
70
+ }
71
+ });
72
+ return result;
73
+ }
74
+ var SPAN_CLOSE = "</span>";
75
+ var emitsWrappingTags = (node) => {
76
+ return !!node.scope || node.sublanguage && node.language;
77
+ };
78
+ var scopeToCSSClass = (name, { prefix }) => {
79
+ if (name.includes(".")) {
80
+ const pieces = name.split(".");
81
+ return [
82
+ `${prefix}${pieces.shift()}`,
83
+ ...pieces.map((x, i) => `${x}${"_".repeat(i + 1)}`)
84
+ ].join(" ");
85
+ }
86
+ return `${prefix}${name}`;
87
+ };
88
+ var HTMLRenderer = class {
89
+ constructor(parseTree, options) {
90
+ this.buffer = "";
91
+ this.classPrefix = options.classPrefix;
92
+ parseTree.walk(this);
93
+ }
94
+ addText(text) {
95
+ this.buffer += escapeHTML(text);
96
+ }
97
+ openNode(node) {
98
+ if (!emitsWrappingTags(node))
99
+ return;
100
+ let className = "";
101
+ if (node.sublanguage) {
102
+ className = `language-${node.language}`;
103
+ } else {
104
+ className = scopeToCSSClass(node.scope, { prefix: this.classPrefix });
105
+ }
106
+ this.span(className);
107
+ }
108
+ closeNode(node) {
109
+ if (!emitsWrappingTags(node))
110
+ return;
111
+ this.buffer += SPAN_CLOSE;
112
+ }
113
+ value() {
114
+ return this.buffer;
115
+ }
116
+ span(className) {
117
+ this.buffer += `<span class="${className}">`;
118
+ }
119
+ };
120
+ var newNode = (opts = {}) => {
121
+ const result = { children: [] };
122
+ Object.assign(result, opts);
123
+ return result;
124
+ };
125
+ var TokenTree = class {
126
+ constructor() {
127
+ this.rootNode = newNode();
128
+ this.stack = [this.rootNode];
129
+ }
130
+ get top() {
131
+ return this.stack[this.stack.length - 1];
132
+ }
133
+ get root() {
134
+ return this.rootNode;
135
+ }
136
+ add(node) {
137
+ this.top.children.push(node);
138
+ }
139
+ openNode(scope) {
140
+ const node = newNode({ scope });
141
+ this.add(node);
142
+ this.stack.push(node);
143
+ }
144
+ closeNode() {
145
+ if (this.stack.length > 1) {
146
+ return this.stack.pop();
147
+ }
148
+ return void 0;
149
+ }
150
+ closeAllNodes() {
151
+ while (this.closeNode())
152
+ ;
153
+ }
154
+ toJSON() {
155
+ return JSON.stringify(this.rootNode, null, 4);
156
+ }
157
+ walk(builder) {
158
+ return this.constructor._walk(builder, this.rootNode);
159
+ }
160
+ static _walk(builder, node) {
161
+ if (typeof node === "string") {
162
+ builder.addText(node);
163
+ } else if (node.children) {
164
+ builder.openNode(node);
165
+ node.children.forEach((child) => this._walk(builder, child));
166
+ builder.closeNode(node);
167
+ }
168
+ return builder;
169
+ }
170
+ static _collapse(node) {
171
+ if (typeof node === "string")
172
+ return;
173
+ if (!node.children)
174
+ return;
175
+ if (node.children.every((el) => typeof el === "string")) {
176
+ node.children = [node.children.join("")];
177
+ } else {
178
+ node.children.forEach((child) => {
179
+ TokenTree._collapse(child);
180
+ });
181
+ }
182
+ }
183
+ };
184
+ var TokenTreeEmitter = class extends TokenTree {
185
+ constructor(options) {
186
+ super();
187
+ this.options = options;
188
+ }
189
+ addKeyword(text, scope) {
190
+ if (text === "") {
191
+ return;
192
+ }
193
+ this.openNode(scope);
194
+ this.addText(text);
195
+ this.closeNode();
196
+ }
197
+ addText(text) {
198
+ if (text === "") {
199
+ return;
200
+ }
201
+ this.add(text);
202
+ }
203
+ addSublanguage(emitter, name) {
204
+ const node = emitter.root;
205
+ node.sublanguage = true;
206
+ node.language = name;
207
+ this.add(node);
208
+ }
209
+ toHTML() {
210
+ const renderer = new HTMLRenderer(this, this.options);
211
+ return renderer.value();
212
+ }
213
+ finalize() {
214
+ return true;
215
+ }
216
+ };
217
+ function source(re) {
218
+ if (!re)
219
+ return null;
220
+ if (typeof re === "string")
221
+ return re;
222
+ return re.source;
223
+ }
224
+ function lookahead(re) {
225
+ return concat("(?=", re, ")");
226
+ }
227
+ function anyNumberOfTimes(re) {
228
+ return concat("(?:", re, ")*");
229
+ }
230
+ function optional(re) {
231
+ return concat("(?:", re, ")?");
232
+ }
233
+ function concat(...args) {
234
+ const joined = args.map((x) => source(x)).join("");
235
+ return joined;
236
+ }
237
+ function stripOptionsFromArgs(args) {
238
+ const opts = args[args.length - 1];
239
+ if (typeof opts === "object" && opts.constructor === Object) {
240
+ args.splice(args.length - 1, 1);
241
+ return opts;
242
+ } else {
243
+ return {};
244
+ }
245
+ }
246
+ function either(...args) {
247
+ const opts = stripOptionsFromArgs(args);
248
+ const joined = "(" + (opts.capture ? "" : "?:") + args.map((x) => source(x)).join("|") + ")";
249
+ return joined;
250
+ }
251
+ function countMatchGroups(re) {
252
+ return new RegExp(re.toString() + "|").exec("").length - 1;
253
+ }
254
+ function startsWith(re, lexeme) {
255
+ const match = re && re.exec(lexeme);
256
+ return match && match.index === 0;
257
+ }
258
+ var BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
259
+ function _rewriteBackreferences(regexps, { joinWith }) {
260
+ let numCaptures = 0;
261
+ return regexps.map((regex) => {
262
+ numCaptures += 1;
263
+ const offset = numCaptures;
264
+ let re = source(regex);
265
+ let out = "";
266
+ while (re.length > 0) {
267
+ const match = BACKREF_RE.exec(re);
268
+ if (!match) {
269
+ out += re;
270
+ break;
271
+ }
272
+ out += re.substring(0, match.index);
273
+ re = re.substring(match.index + match[0].length);
274
+ if (match[0][0] === "\\" && match[1]) {
275
+ out += "\\" + String(Number(match[1]) + offset);
276
+ } else {
277
+ out += match[0];
278
+ if (match[0] === "(") {
279
+ numCaptures++;
280
+ }
281
+ }
282
+ }
283
+ return out;
284
+ }).map((re) => `(${re})`).join(joinWith);
285
+ }
286
+ var MATCH_NOTHING_RE = /\b\B/;
287
+ var IDENT_RE = "[a-zA-Z]\\w*";
288
+ var UNDERSCORE_IDENT_RE = "[a-zA-Z_]\\w*";
289
+ var NUMBER_RE = "\\b\\d+(\\.\\d+)?";
290
+ var C_NUMBER_RE = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";
291
+ var BINARY_NUMBER_RE = "\\b(0b[01]+)";
292
+ var RE_STARTERS_RE = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";
293
+ var SHEBANG = (opts = {}) => {
294
+ const beginShebang = /^#![ ]*\//;
295
+ if (opts.binary) {
296
+ opts.begin = concat(
297
+ beginShebang,
298
+ /.*\b/,
299
+ opts.binary,
300
+ /\b.*/
301
+ );
302
+ }
303
+ return inherit$1({
304
+ scope: "meta",
305
+ begin: beginShebang,
306
+ end: /$/,
307
+ relevance: 0,
308
+ "on:begin": (m, resp) => {
309
+ if (m.index !== 0)
310
+ resp.ignoreMatch();
311
+ }
312
+ }, opts);
313
+ };
314
+ var BACKSLASH_ESCAPE = {
315
+ begin: "\\\\[\\s\\S]",
316
+ relevance: 0
317
+ };
318
+ var APOS_STRING_MODE = {
319
+ scope: "string",
320
+ begin: "'",
321
+ end: "'",
322
+ illegal: "\\n",
323
+ contains: [BACKSLASH_ESCAPE]
324
+ };
325
+ var QUOTE_STRING_MODE = {
326
+ scope: "string",
327
+ begin: '"',
328
+ end: '"',
329
+ illegal: "\\n",
330
+ contains: [BACKSLASH_ESCAPE]
331
+ };
332
+ var PHRASAL_WORDS_MODE = {
333
+ 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/
334
+ };
335
+ var COMMENT = function(begin, end, modeOptions = {}) {
336
+ const mode = inherit$1(
337
+ {
338
+ scope: "comment",
339
+ begin,
340
+ end,
341
+ contains: []
342
+ },
343
+ modeOptions
344
+ );
345
+ mode.contains.push({
346
+ scope: "doctag",
347
+ begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
348
+ end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
349
+ excludeBegin: true,
350
+ relevance: 0
351
+ });
352
+ const ENGLISH_WORD = either(
353
+ "I",
354
+ "a",
355
+ "is",
356
+ "so",
357
+ "us",
358
+ "to",
359
+ "at",
360
+ "if",
361
+ "in",
362
+ "it",
363
+ "on",
364
+ /[A-Za-z]+['](d|ve|re|ll|t|s|n)/,
365
+ /[A-Za-z]+[-][a-z]+/,
366
+ /[A-Za-z][a-z]{2,}/
367
+ );
368
+ mode.contains.push(
369
+ {
370
+ begin: concat(
371
+ /[ ]+/,
372
+ "(",
373
+ ENGLISH_WORD,
374
+ /[.]?[:]?([.][ ]|[ ])/,
375
+ "){3}"
376
+ )
377
+ }
378
+ );
379
+ return mode;
380
+ };
381
+ var C_LINE_COMMENT_MODE = COMMENT("//", "$");
382
+ var C_BLOCK_COMMENT_MODE = COMMENT("/\\*", "\\*/");
383
+ var HASH_COMMENT_MODE = COMMENT("#", "$");
384
+ var NUMBER_MODE = {
385
+ scope: "number",
386
+ begin: NUMBER_RE,
387
+ relevance: 0
388
+ };
389
+ var C_NUMBER_MODE = {
390
+ scope: "number",
391
+ begin: C_NUMBER_RE,
392
+ relevance: 0
393
+ };
394
+ var BINARY_NUMBER_MODE = {
395
+ scope: "number",
396
+ begin: BINARY_NUMBER_RE,
397
+ relevance: 0
398
+ };
399
+ var REGEXP_MODE = {
400
+ begin: /(?=\/[^/\n]*\/)/,
401
+ contains: [{
402
+ scope: "regexp",
403
+ begin: /\//,
404
+ end: /\/[gimuy]*/,
405
+ illegal: /\n/,
406
+ contains: [
407
+ BACKSLASH_ESCAPE,
408
+ {
409
+ begin: /\[/,
410
+ end: /\]/,
411
+ relevance: 0,
412
+ contains: [BACKSLASH_ESCAPE]
413
+ }
414
+ ]
415
+ }]
416
+ };
417
+ var TITLE_MODE = {
418
+ scope: "title",
419
+ begin: IDENT_RE,
420
+ relevance: 0
421
+ };
422
+ var UNDERSCORE_TITLE_MODE = {
423
+ scope: "title",
424
+ begin: UNDERSCORE_IDENT_RE,
425
+ relevance: 0
426
+ };
427
+ var METHOD_GUARD = {
428
+ begin: "\\.\\s*" + UNDERSCORE_IDENT_RE,
429
+ relevance: 0
430
+ };
431
+ var END_SAME_AS_BEGIN = function(mode) {
432
+ return Object.assign(
433
+ mode,
434
+ {
435
+ "on:begin": (m, resp) => {
436
+ resp.data._beginMatch = m[1];
437
+ },
438
+ "on:end": (m, resp) => {
439
+ if (resp.data._beginMatch !== m[1])
440
+ resp.ignoreMatch();
441
+ }
442
+ }
443
+ );
444
+ };
445
+ var MODES = /* @__PURE__ */ Object.freeze({
446
+ __proto__: null,
447
+ MATCH_NOTHING_RE,
448
+ IDENT_RE,
449
+ UNDERSCORE_IDENT_RE,
450
+ NUMBER_RE,
451
+ C_NUMBER_RE,
452
+ BINARY_NUMBER_RE,
453
+ RE_STARTERS_RE,
454
+ SHEBANG,
455
+ BACKSLASH_ESCAPE,
456
+ APOS_STRING_MODE,
457
+ QUOTE_STRING_MODE,
458
+ PHRASAL_WORDS_MODE,
459
+ COMMENT,
460
+ C_LINE_COMMENT_MODE,
461
+ C_BLOCK_COMMENT_MODE,
462
+ HASH_COMMENT_MODE,
463
+ NUMBER_MODE,
464
+ C_NUMBER_MODE,
465
+ BINARY_NUMBER_MODE,
466
+ REGEXP_MODE,
467
+ TITLE_MODE,
468
+ UNDERSCORE_TITLE_MODE,
469
+ METHOD_GUARD,
470
+ END_SAME_AS_BEGIN
471
+ });
472
+ function skipIfHasPrecedingDot(match, response) {
473
+ const before = match.input[match.index - 1];
474
+ if (before === ".") {
475
+ response.ignoreMatch();
476
+ }
477
+ }
478
+ function scopeClassName(mode, _parent) {
479
+ if (mode.className !== void 0) {
480
+ mode.scope = mode.className;
481
+ delete mode.className;
482
+ }
483
+ }
484
+ function beginKeywords(mode, parent) {
485
+ if (!parent)
486
+ return;
487
+ if (!mode.beginKeywords)
488
+ return;
489
+ mode.begin = "\\b(" + mode.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)";
490
+ mode.__beforeBegin = skipIfHasPrecedingDot;
491
+ mode.keywords = mode.keywords || mode.beginKeywords;
492
+ delete mode.beginKeywords;
493
+ if (mode.relevance === void 0)
494
+ mode.relevance = 0;
495
+ }
496
+ function compileIllegal(mode, _parent) {
497
+ if (!Array.isArray(mode.illegal))
498
+ return;
499
+ mode.illegal = either(...mode.illegal);
500
+ }
501
+ function compileMatch(mode, _parent) {
502
+ if (!mode.match)
503
+ return;
504
+ if (mode.begin || mode.end)
505
+ throw new Error("begin & end are not supported with match");
506
+ mode.begin = mode.match;
507
+ delete mode.match;
508
+ }
509
+ function compileRelevance(mode, _parent) {
510
+ if (mode.relevance === void 0)
511
+ mode.relevance = 1;
512
+ }
513
+ var beforeMatchExt = (mode, parent) => {
514
+ if (!mode.beforeMatch)
515
+ return;
516
+ if (mode.starts)
517
+ throw new Error("beforeMatch cannot be used with starts");
518
+ const originalMode = Object.assign({}, mode);
519
+ Object.keys(mode).forEach((key) => {
520
+ delete mode[key];
521
+ });
522
+ mode.keywords = originalMode.keywords;
523
+ mode.begin = concat(originalMode.beforeMatch, lookahead(originalMode.begin));
524
+ mode.starts = {
525
+ relevance: 0,
526
+ contains: [
527
+ Object.assign(originalMode, { endsParent: true })
528
+ ]
529
+ };
530
+ mode.relevance = 0;
531
+ delete originalMode.beforeMatch;
532
+ };
533
+ var COMMON_KEYWORDS = [
534
+ "of",
535
+ "and",
536
+ "for",
537
+ "in",
538
+ "not",
539
+ "or",
540
+ "if",
541
+ "then",
542
+ "parent",
543
+ "list",
544
+ "value"
545
+ ];
546
+ var DEFAULT_KEYWORD_SCOPE = "keyword";
547
+ function compileKeywords(rawKeywords, caseInsensitive, scopeName = DEFAULT_KEYWORD_SCOPE) {
548
+ const compiledKeywords = /* @__PURE__ */ Object.create(null);
549
+ if (typeof rawKeywords === "string") {
550
+ compileList(scopeName, rawKeywords.split(" "));
551
+ } else if (Array.isArray(rawKeywords)) {
552
+ compileList(scopeName, rawKeywords);
553
+ } else {
554
+ Object.keys(rawKeywords).forEach(function(scopeName2) {
555
+ Object.assign(
556
+ compiledKeywords,
557
+ compileKeywords(rawKeywords[scopeName2], caseInsensitive, scopeName2)
558
+ );
559
+ });
560
+ }
561
+ return compiledKeywords;
562
+ function compileList(scopeName2, keywordList) {
563
+ if (caseInsensitive) {
564
+ keywordList = keywordList.map((x) => x.toLowerCase());
565
+ }
566
+ keywordList.forEach(function(keyword) {
567
+ const pair = keyword.split("|");
568
+ compiledKeywords[pair[0]] = [scopeName2, scoreForKeyword(pair[0], pair[1])];
569
+ });
570
+ }
571
+ }
572
+ function scoreForKeyword(keyword, providedScore) {
573
+ if (providedScore) {
574
+ return Number(providedScore);
575
+ }
576
+ return commonKeyword(keyword) ? 0 : 1;
577
+ }
578
+ function commonKeyword(keyword) {
579
+ return COMMON_KEYWORDS.includes(keyword.toLowerCase());
580
+ }
581
+ var seenDeprecations = {};
582
+ var error = (message) => {
583
+ console.error(message);
584
+ };
585
+ var warn = (message, ...args) => {
586
+ console.log(`WARN: ${message}`, ...args);
587
+ };
588
+ var deprecated = (version2, message) => {
589
+ if (seenDeprecations[`${version2}/${message}`])
590
+ return;
591
+ console.log(`Deprecated as of ${version2}. ${message}`);
592
+ seenDeprecations[`${version2}/${message}`] = true;
593
+ };
594
+ var MultiClassError = new Error();
595
+ function remapScopeNames(mode, regexes, { key }) {
596
+ let offset = 0;
597
+ const scopeNames = mode[key];
598
+ const emit = {};
599
+ const positions = {};
600
+ for (let i = 1; i <= regexes.length; i++) {
601
+ positions[i + offset] = scopeNames[i];
602
+ emit[i + offset] = true;
603
+ offset += countMatchGroups(regexes[i - 1]);
604
+ }
605
+ mode[key] = positions;
606
+ mode[key]._emit = emit;
607
+ mode[key]._multi = true;
608
+ }
609
+ function beginMultiClass(mode) {
610
+ if (!Array.isArray(mode.begin))
611
+ return;
612
+ if (mode.skip || mode.excludeBegin || mode.returnBegin) {
613
+ error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
614
+ throw MultiClassError;
615
+ }
616
+ if (typeof mode.beginScope !== "object" || mode.beginScope === null) {
617
+ error("beginScope must be object");
618
+ throw MultiClassError;
619
+ }
620
+ remapScopeNames(mode, mode.begin, { key: "beginScope" });
621
+ mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
622
+ }
623
+ function endMultiClass(mode) {
624
+ if (!Array.isArray(mode.end))
625
+ return;
626
+ if (mode.skip || mode.excludeEnd || mode.returnEnd) {
627
+ error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
628
+ throw MultiClassError;
629
+ }
630
+ if (typeof mode.endScope !== "object" || mode.endScope === null) {
631
+ error("endScope must be object");
632
+ throw MultiClassError;
633
+ }
634
+ remapScopeNames(mode, mode.end, { key: "endScope" });
635
+ mode.end = _rewriteBackreferences(mode.end, { joinWith: "" });
636
+ }
637
+ function scopeSugar(mode) {
638
+ if (mode.scope && typeof mode.scope === "object" && mode.scope !== null) {
639
+ mode.beginScope = mode.scope;
640
+ delete mode.scope;
641
+ }
642
+ }
643
+ function MultiClass(mode) {
644
+ scopeSugar(mode);
645
+ if (typeof mode.beginScope === "string") {
646
+ mode.beginScope = { _wrap: mode.beginScope };
647
+ }
648
+ if (typeof mode.endScope === "string") {
649
+ mode.endScope = { _wrap: mode.endScope };
650
+ }
651
+ beginMultiClass(mode);
652
+ endMultiClass(mode);
653
+ }
654
+ function compileLanguage(language) {
655
+ function langRe(value, global) {
656
+ return new RegExp(
657
+ source(value),
658
+ "m" + (language.case_insensitive ? "i" : "") + (language.unicodeRegex ? "u" : "") + (global ? "g" : "")
659
+ );
660
+ }
661
+ class MultiRegex {
662
+ constructor() {
663
+ this.matchIndexes = {};
664
+ this.regexes = [];
665
+ this.matchAt = 1;
666
+ this.position = 0;
667
+ }
668
+ addRule(re, opts) {
669
+ opts.position = this.position++;
670
+ this.matchIndexes[this.matchAt] = opts;
671
+ this.regexes.push([opts, re]);
672
+ this.matchAt += countMatchGroups(re) + 1;
673
+ }
674
+ compile() {
675
+ if (this.regexes.length === 0) {
676
+ this.exec = () => null;
677
+ }
678
+ const terminators = this.regexes.map((el) => el[1]);
679
+ this.matcherRe = langRe(_rewriteBackreferences(terminators, { joinWith: "|" }), true);
680
+ this.lastIndex = 0;
681
+ }
682
+ exec(s) {
683
+ this.matcherRe.lastIndex = this.lastIndex;
684
+ const match = this.matcherRe.exec(s);
685
+ if (!match) {
686
+ return null;
687
+ }
688
+ const i = match.findIndex((el, i2) => i2 > 0 && el !== void 0);
689
+ const matchData = this.matchIndexes[i];
690
+ match.splice(0, i);
691
+ return Object.assign(match, matchData);
692
+ }
693
+ }
694
+ class ResumableMultiRegex {
695
+ constructor() {
696
+ this.rules = [];
697
+ this.multiRegexes = [];
698
+ this.count = 0;
699
+ this.lastIndex = 0;
700
+ this.regexIndex = 0;
701
+ }
702
+ getMatcher(index) {
703
+ if (this.multiRegexes[index])
704
+ return this.multiRegexes[index];
705
+ const matcher = new MultiRegex();
706
+ this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
707
+ matcher.compile();
708
+ this.multiRegexes[index] = matcher;
709
+ return matcher;
710
+ }
711
+ resumingScanAtSamePosition() {
712
+ return this.regexIndex !== 0;
713
+ }
714
+ considerAll() {
715
+ this.regexIndex = 0;
716
+ }
717
+ addRule(re, opts) {
718
+ this.rules.push([re, opts]);
719
+ if (opts.type === "begin")
720
+ this.count++;
721
+ }
722
+ exec(s) {
723
+ const m = this.getMatcher(this.regexIndex);
724
+ m.lastIndex = this.lastIndex;
725
+ let result = m.exec(s);
726
+ if (this.resumingScanAtSamePosition()) {
727
+ if (result && result.index === this.lastIndex)
728
+ ;
729
+ else {
730
+ const m2 = this.getMatcher(0);
731
+ m2.lastIndex = this.lastIndex + 1;
732
+ result = m2.exec(s);
733
+ }
734
+ }
735
+ if (result) {
736
+ this.regexIndex += result.position + 1;
737
+ if (this.regexIndex === this.count) {
738
+ this.considerAll();
739
+ }
740
+ }
741
+ return result;
742
+ }
743
+ }
744
+ function buildModeRegex(mode) {
745
+ const mm = new ResumableMultiRegex();
746
+ mode.contains.forEach((term) => mm.addRule(term.begin, { rule: term, type: "begin" }));
747
+ if (mode.terminatorEnd) {
748
+ mm.addRule(mode.terminatorEnd, { type: "end" });
749
+ }
750
+ if (mode.illegal) {
751
+ mm.addRule(mode.illegal, { type: "illegal" });
752
+ }
753
+ return mm;
754
+ }
755
+ function compileMode(mode, parent) {
756
+ const cmode = mode;
757
+ if (mode.isCompiled)
758
+ return cmode;
759
+ [
760
+ scopeClassName,
761
+ compileMatch,
762
+ MultiClass,
763
+ beforeMatchExt
764
+ ].forEach((ext) => ext(mode, parent));
765
+ language.compilerExtensions.forEach((ext) => ext(mode, parent));
766
+ mode.__beforeBegin = null;
767
+ [
768
+ beginKeywords,
769
+ compileIllegal,
770
+ compileRelevance
771
+ ].forEach((ext) => ext(mode, parent));
772
+ mode.isCompiled = true;
773
+ let keywordPattern = null;
774
+ if (typeof mode.keywords === "object" && mode.keywords.$pattern) {
775
+ mode.keywords = Object.assign({}, mode.keywords);
776
+ keywordPattern = mode.keywords.$pattern;
777
+ delete mode.keywords.$pattern;
778
+ }
779
+ keywordPattern = keywordPattern || /\w+/;
780
+ if (mode.keywords) {
781
+ mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
782
+ }
783
+ cmode.keywordPatternRe = langRe(keywordPattern, true);
784
+ if (parent) {
785
+ if (!mode.begin)
786
+ mode.begin = /\B|\b/;
787
+ cmode.beginRe = langRe(cmode.begin);
788
+ if (!mode.end && !mode.endsWithParent)
789
+ mode.end = /\B|\b/;
790
+ if (mode.end)
791
+ cmode.endRe = langRe(cmode.end);
792
+ cmode.terminatorEnd = source(cmode.end) || "";
793
+ if (mode.endsWithParent && parent.terminatorEnd) {
794
+ cmode.terminatorEnd += (mode.end ? "|" : "") + parent.terminatorEnd;
795
+ }
796
+ }
797
+ if (mode.illegal)
798
+ cmode.illegalRe = langRe(mode.illegal);
799
+ if (!mode.contains)
800
+ mode.contains = [];
801
+ mode.contains = [].concat(...mode.contains.map(function(c) {
802
+ return expandOrCloneMode(c === "self" ? mode : c);
803
+ }));
804
+ mode.contains.forEach(function(c) {
805
+ compileMode(c, cmode);
806
+ });
807
+ if (mode.starts) {
808
+ compileMode(mode.starts, parent);
809
+ }
810
+ cmode.matcher = buildModeRegex(cmode);
811
+ return cmode;
812
+ }
813
+ if (!language.compilerExtensions)
814
+ language.compilerExtensions = [];
815
+ if (language.contains && language.contains.includes("self")) {
816
+ throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
817
+ }
818
+ language.classNameAliases = inherit$1(language.classNameAliases || {});
819
+ return compileMode(language);
820
+ }
821
+ function dependencyOnParent(mode) {
822
+ if (!mode)
823
+ return false;
824
+ return mode.endsWithParent || dependencyOnParent(mode.starts);
825
+ }
826
+ function expandOrCloneMode(mode) {
827
+ if (mode.variants && !mode.cachedVariants) {
828
+ mode.cachedVariants = mode.variants.map(function(variant) {
829
+ return inherit$1(mode, { variants: null }, variant);
830
+ });
831
+ }
832
+ if (mode.cachedVariants) {
833
+ return mode.cachedVariants;
834
+ }
835
+ if (dependencyOnParent(mode)) {
836
+ return inherit$1(mode, { starts: mode.starts ? inherit$1(mode.starts) : null });
837
+ }
838
+ if (Object.isFrozen(mode)) {
839
+ return inherit$1(mode);
840
+ }
841
+ return mode;
842
+ }
843
+ var version = "11.6.0";
844
+ var HTMLInjectionError = class extends Error {
845
+ constructor(reason, html) {
846
+ super(reason);
847
+ this.name = "HTMLInjectionError";
848
+ this.html = html;
849
+ }
850
+ };
851
+ var escape = escapeHTML;
852
+ var inherit = inherit$1;
853
+ var NO_MATCH = Symbol("nomatch");
854
+ var MAX_KEYWORD_HITS = 7;
855
+ var HLJS = function(hljs) {
856
+ const languages = /* @__PURE__ */ Object.create(null);
857
+ const aliases = /* @__PURE__ */ Object.create(null);
858
+ const plugins = [];
859
+ let SAFE_MODE = true;
860
+ const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
861
+ const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: "Plain text", contains: [] };
862
+ let options = {
863
+ ignoreUnescapedHTML: false,
864
+ throwUnescapedHTML: false,
865
+ noHighlightRe: /^(no-?highlight)$/i,
866
+ languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
867
+ classPrefix: "hljs-",
868
+ cssSelector: "pre code",
869
+ languages: null,
870
+ __emitter: TokenTreeEmitter
871
+ };
872
+ function shouldNotHighlight(languageName) {
873
+ return options.noHighlightRe.test(languageName);
874
+ }
875
+ function blockLanguage(block) {
876
+ let classes = block.className + " ";
877
+ classes += block.parentNode ? block.parentNode.className : "";
878
+ const match = options.languageDetectRe.exec(classes);
879
+ if (match) {
880
+ const language = getLanguage(match[1]);
881
+ if (!language) {
882
+ warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
883
+ warn("Falling back to no-highlight mode for this block.", block);
884
+ }
885
+ return language ? match[1] : "no-highlight";
886
+ }
887
+ return classes.split(/\s+/).find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
888
+ }
889
+ function highlight2(codeOrLanguageName, optionsOrCode, ignoreIllegals) {
890
+ let code = "";
891
+ let languageName = "";
892
+ if (typeof optionsOrCode === "object") {
893
+ code = codeOrLanguageName;
894
+ ignoreIllegals = optionsOrCode.ignoreIllegals;
895
+ languageName = optionsOrCode.language;
896
+ } else {
897
+ deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
898
+ deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
899
+ languageName = codeOrLanguageName;
900
+ code = optionsOrCode;
901
+ }
902
+ if (ignoreIllegals === void 0) {
903
+ ignoreIllegals = true;
904
+ }
905
+ const context = {
906
+ code,
907
+ language: languageName
908
+ };
909
+ fire("before:highlight", context);
910
+ const result = context.result ? context.result : _highlight(context.language, context.code, ignoreIllegals);
911
+ result.code = context.code;
912
+ fire("after:highlight", result);
913
+ return result;
914
+ }
915
+ function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
916
+ const keywordHits = /* @__PURE__ */ Object.create(null);
917
+ function keywordData(mode, matchText) {
918
+ return mode.keywords[matchText];
919
+ }
920
+ function processKeywords() {
921
+ if (!top.keywords) {
922
+ emitter.addText(modeBuffer);
923
+ return;
924
+ }
925
+ let lastIndex = 0;
926
+ top.keywordPatternRe.lastIndex = 0;
927
+ let match = top.keywordPatternRe.exec(modeBuffer);
928
+ let buf = "";
929
+ while (match) {
930
+ buf += modeBuffer.substring(lastIndex, match.index);
931
+ const word = language.case_insensitive ? match[0].toLowerCase() : match[0];
932
+ const data = keywordData(top, word);
933
+ if (data) {
934
+ const [kind, keywordRelevance] = data;
935
+ emitter.addText(buf);
936
+ buf = "";
937
+ keywordHits[word] = (keywordHits[word] || 0) + 1;
938
+ if (keywordHits[word] <= MAX_KEYWORD_HITS)
939
+ relevance += keywordRelevance;
940
+ if (kind.startsWith("_")) {
941
+ buf += match[0];
942
+ } else {
943
+ const cssClass = language.classNameAliases[kind] || kind;
944
+ emitter.addKeyword(match[0], cssClass);
945
+ }
946
+ } else {
947
+ buf += match[0];
948
+ }
949
+ lastIndex = top.keywordPatternRe.lastIndex;
950
+ match = top.keywordPatternRe.exec(modeBuffer);
951
+ }
952
+ buf += modeBuffer.substring(lastIndex);
953
+ emitter.addText(buf);
954
+ }
955
+ function processSubLanguage() {
956
+ if (modeBuffer === "")
957
+ return;
958
+ let result2 = null;
959
+ if (typeof top.subLanguage === "string") {
960
+ if (!languages[top.subLanguage]) {
961
+ emitter.addText(modeBuffer);
962
+ return;
963
+ }
964
+ result2 = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
965
+ continuations[top.subLanguage] = result2._top;
966
+ } else {
967
+ result2 = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
968
+ }
969
+ if (top.relevance > 0) {
970
+ relevance += result2.relevance;
971
+ }
972
+ emitter.addSublanguage(result2._emitter, result2.language);
973
+ }
974
+ function processBuffer() {
975
+ if (top.subLanguage != null) {
976
+ processSubLanguage();
977
+ } else {
978
+ processKeywords();
979
+ }
980
+ modeBuffer = "";
981
+ }
982
+ function emitMultiClass(scope, match) {
983
+ let i = 1;
984
+ const max = match.length - 1;
985
+ while (i <= max) {
986
+ if (!scope._emit[i]) {
987
+ i++;
988
+ continue;
989
+ }
990
+ const klass = language.classNameAliases[scope[i]] || scope[i];
991
+ const text = match[i];
992
+ if (klass) {
993
+ emitter.addKeyword(text, klass);
994
+ } else {
995
+ modeBuffer = text;
996
+ processKeywords();
997
+ modeBuffer = "";
998
+ }
999
+ i++;
1000
+ }
1001
+ }
1002
+ function startNewMode(mode, match) {
1003
+ if (mode.scope && typeof mode.scope === "string") {
1004
+ emitter.openNode(language.classNameAliases[mode.scope] || mode.scope);
1005
+ }
1006
+ if (mode.beginScope) {
1007
+ if (mode.beginScope._wrap) {
1008
+ emitter.addKeyword(modeBuffer, language.classNameAliases[mode.beginScope._wrap] || mode.beginScope._wrap);
1009
+ modeBuffer = "";
1010
+ } else if (mode.beginScope._multi) {
1011
+ emitMultiClass(mode.beginScope, match);
1012
+ modeBuffer = "";
1013
+ }
1014
+ }
1015
+ top = Object.create(mode, { parent: { value: top } });
1016
+ return top;
1017
+ }
1018
+ function endOfMode(mode, match, matchPlusRemainder) {
1019
+ let matched = startsWith(mode.endRe, matchPlusRemainder);
1020
+ if (matched) {
1021
+ if (mode["on:end"]) {
1022
+ const resp = new Response(mode);
1023
+ mode["on:end"](match, resp);
1024
+ if (resp.isMatchIgnored)
1025
+ matched = false;
1026
+ }
1027
+ if (matched) {
1028
+ while (mode.endsParent && mode.parent) {
1029
+ mode = mode.parent;
1030
+ }
1031
+ return mode;
1032
+ }
1033
+ }
1034
+ if (mode.endsWithParent) {
1035
+ return endOfMode(mode.parent, match, matchPlusRemainder);
1036
+ }
1037
+ }
1038
+ function doIgnore(lexeme) {
1039
+ if (top.matcher.regexIndex === 0) {
1040
+ modeBuffer += lexeme[0];
1041
+ return 1;
1042
+ } else {
1043
+ resumeScanAtSamePosition = true;
1044
+ return 0;
1045
+ }
1046
+ }
1047
+ function doBeginMatch(match) {
1048
+ const lexeme = match[0];
1049
+ const newMode = match.rule;
1050
+ const resp = new Response(newMode);
1051
+ const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
1052
+ for (const cb of beforeCallbacks) {
1053
+ if (!cb)
1054
+ continue;
1055
+ cb(match, resp);
1056
+ if (resp.isMatchIgnored)
1057
+ return doIgnore(lexeme);
1058
+ }
1059
+ if (newMode.skip) {
1060
+ modeBuffer += lexeme;
1061
+ } else {
1062
+ if (newMode.excludeBegin) {
1063
+ modeBuffer += lexeme;
1064
+ }
1065
+ processBuffer();
1066
+ if (!newMode.returnBegin && !newMode.excludeBegin) {
1067
+ modeBuffer = lexeme;
1068
+ }
1069
+ }
1070
+ startNewMode(newMode, match);
1071
+ return newMode.returnBegin ? 0 : lexeme.length;
1072
+ }
1073
+ function doEndMatch(match) {
1074
+ const lexeme = match[0];
1075
+ const matchPlusRemainder = codeToHighlight.substring(match.index);
1076
+ const endMode = endOfMode(top, match, matchPlusRemainder);
1077
+ if (!endMode) {
1078
+ return NO_MATCH;
1079
+ }
1080
+ const origin = top;
1081
+ if (top.endScope && top.endScope._wrap) {
1082
+ processBuffer();
1083
+ emitter.addKeyword(lexeme, top.endScope._wrap);
1084
+ } else if (top.endScope && top.endScope._multi) {
1085
+ processBuffer();
1086
+ emitMultiClass(top.endScope, match);
1087
+ } else if (origin.skip) {
1088
+ modeBuffer += lexeme;
1089
+ } else {
1090
+ if (!(origin.returnEnd || origin.excludeEnd)) {
1091
+ modeBuffer += lexeme;
1092
+ }
1093
+ processBuffer();
1094
+ if (origin.excludeEnd) {
1095
+ modeBuffer = lexeme;
1096
+ }
1097
+ }
1098
+ do {
1099
+ if (top.scope) {
1100
+ emitter.closeNode();
1101
+ }
1102
+ if (!top.skip && !top.subLanguage) {
1103
+ relevance += top.relevance;
1104
+ }
1105
+ top = top.parent;
1106
+ } while (top !== endMode.parent);
1107
+ if (endMode.starts) {
1108
+ startNewMode(endMode.starts, match);
1109
+ }
1110
+ return origin.returnEnd ? 0 : lexeme.length;
1111
+ }
1112
+ function processContinuations() {
1113
+ const list = [];
1114
+ for (let current = top; current !== language; current = current.parent) {
1115
+ if (current.scope) {
1116
+ list.unshift(current.scope);
1117
+ }
1118
+ }
1119
+ list.forEach((item) => emitter.openNode(item));
1120
+ }
1121
+ let lastMatch = {};
1122
+ function processLexeme(textBeforeMatch, match) {
1123
+ const lexeme = match && match[0];
1124
+ modeBuffer += textBeforeMatch;
1125
+ if (lexeme == null) {
1126
+ processBuffer();
1127
+ return 0;
1128
+ }
1129
+ if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
1130
+ modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
1131
+ if (!SAFE_MODE) {
1132
+ const err = new Error(`0 width match regex (${languageName})`);
1133
+ err.languageName = languageName;
1134
+ err.badRule = lastMatch.rule;
1135
+ throw err;
1136
+ }
1137
+ return 1;
1138
+ }
1139
+ lastMatch = match;
1140
+ if (match.type === "begin") {
1141
+ return doBeginMatch(match);
1142
+ } else if (match.type === "illegal" && !ignoreIllegals) {
1143
+ const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.scope || "<unnamed>") + '"');
1144
+ err.mode = top;
1145
+ throw err;
1146
+ } else if (match.type === "end") {
1147
+ const processed = doEndMatch(match);
1148
+ if (processed !== NO_MATCH) {
1149
+ return processed;
1150
+ }
1151
+ }
1152
+ if (match.type === "illegal" && lexeme === "") {
1153
+ return 1;
1154
+ }
1155
+ if (iterations > 1e5 && iterations > match.index * 3) {
1156
+ const err = new Error("potential infinite loop, way more iterations than matches");
1157
+ throw err;
1158
+ }
1159
+ modeBuffer += lexeme;
1160
+ return lexeme.length;
1161
+ }
1162
+ const language = getLanguage(languageName);
1163
+ if (!language) {
1164
+ error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
1165
+ throw new Error('Unknown language: "' + languageName + '"');
1166
+ }
1167
+ const md = compileLanguage(language);
1168
+ let result = "";
1169
+ let top = continuation || md;
1170
+ const continuations = {};
1171
+ const emitter = new options.__emitter(options);
1172
+ processContinuations();
1173
+ let modeBuffer = "";
1174
+ let relevance = 0;
1175
+ let index = 0;
1176
+ let iterations = 0;
1177
+ let resumeScanAtSamePosition = false;
1178
+ try {
1179
+ top.matcher.considerAll();
1180
+ for (; ; ) {
1181
+ iterations++;
1182
+ if (resumeScanAtSamePosition) {
1183
+ resumeScanAtSamePosition = false;
1184
+ } else {
1185
+ top.matcher.considerAll();
1186
+ }
1187
+ top.matcher.lastIndex = index;
1188
+ const match = top.matcher.exec(codeToHighlight);
1189
+ if (!match)
1190
+ break;
1191
+ const beforeMatch = codeToHighlight.substring(index, match.index);
1192
+ const processedCount = processLexeme(beforeMatch, match);
1193
+ index = match.index + processedCount;
1194
+ }
1195
+ processLexeme(codeToHighlight.substring(index));
1196
+ emitter.closeAllNodes();
1197
+ emitter.finalize();
1198
+ result = emitter.toHTML();
1199
+ return {
1200
+ language: languageName,
1201
+ value: result,
1202
+ relevance,
1203
+ illegal: false,
1204
+ _emitter: emitter,
1205
+ _top: top
1206
+ };
1207
+ } catch (err) {
1208
+ if (err.message && err.message.includes("Illegal")) {
1209
+ return {
1210
+ language: languageName,
1211
+ value: escape(codeToHighlight),
1212
+ illegal: true,
1213
+ relevance: 0,
1214
+ _illegalBy: {
1215
+ message: err.message,
1216
+ index,
1217
+ context: codeToHighlight.slice(index - 100, index + 100),
1218
+ mode: err.mode,
1219
+ resultSoFar: result
1220
+ },
1221
+ _emitter: emitter
1222
+ };
1223
+ } else if (SAFE_MODE) {
1224
+ return {
1225
+ language: languageName,
1226
+ value: escape(codeToHighlight),
1227
+ illegal: false,
1228
+ relevance: 0,
1229
+ errorRaised: err,
1230
+ _emitter: emitter,
1231
+ _top: top
1232
+ };
1233
+ } else {
1234
+ throw err;
1235
+ }
1236
+ }
1237
+ }
1238
+ function justTextHighlightResult(code) {
1239
+ const result = {
1240
+ value: escape(code),
1241
+ illegal: false,
1242
+ relevance: 0,
1243
+ _top: PLAINTEXT_LANGUAGE,
1244
+ _emitter: new options.__emitter(options)
1245
+ };
1246
+ result._emitter.addText(code);
1247
+ return result;
1248
+ }
1249
+ function highlightAuto(code, languageSubset) {
1250
+ languageSubset = languageSubset || options.languages || Object.keys(languages);
1251
+ const plaintext = justTextHighlightResult(code);
1252
+ const results = languageSubset.filter(getLanguage).filter(autoDetection).map(
1253
+ (name) => _highlight(name, code, false)
1254
+ );
1255
+ results.unshift(plaintext);
1256
+ const sorted = results.sort((a, b) => {
1257
+ if (a.relevance !== b.relevance)
1258
+ return b.relevance - a.relevance;
1259
+ if (a.language && b.language) {
1260
+ if (getLanguage(a.language).supersetOf === b.language) {
1261
+ return 1;
1262
+ } else if (getLanguage(b.language).supersetOf === a.language) {
1263
+ return -1;
1264
+ }
1265
+ }
1266
+ return 0;
1267
+ });
1268
+ const [best, secondBest] = sorted;
1269
+ const result = best;
1270
+ result.secondBest = secondBest;
1271
+ return result;
1272
+ }
1273
+ function updateClassName(element, currentLang, resultLang) {
1274
+ const language = currentLang && aliases[currentLang] || resultLang;
1275
+ element.classList.add("hljs");
1276
+ element.classList.add(`language-${language}`);
1277
+ }
1278
+ function highlightElement(element) {
1279
+ let node = null;
1280
+ const language = blockLanguage(element);
1281
+ if (shouldNotHighlight(language))
1282
+ return;
1283
+ fire(
1284
+ "before:highlightElement",
1285
+ { el: element, language }
1286
+ );
1287
+ if (element.children.length > 0) {
1288
+ if (!options.ignoreUnescapedHTML) {
1289
+ console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk.");
1290
+ console.warn("https://github.com/highlightjs/highlight.js/wiki/security");
1291
+ console.warn("The element with unescaped HTML:");
1292
+ console.warn(element);
1293
+ }
1294
+ if (options.throwUnescapedHTML) {
1295
+ const err = new HTMLInjectionError(
1296
+ "One of your code blocks includes unescaped HTML.",
1297
+ element.innerHTML
1298
+ );
1299
+ throw err;
1300
+ }
1301
+ }
1302
+ node = element;
1303
+ const text = node.textContent;
1304
+ const result = language ? highlight2(text, { language, ignoreIllegals: true }) : highlightAuto(text);
1305
+ element.innerHTML = result.value;
1306
+ updateClassName(element, language, result.language);
1307
+ element.result = {
1308
+ language: result.language,
1309
+ re: result.relevance,
1310
+ relevance: result.relevance
1311
+ };
1312
+ if (result.secondBest) {
1313
+ element.secondBest = {
1314
+ language: result.secondBest.language,
1315
+ relevance: result.secondBest.relevance
1316
+ };
1317
+ }
1318
+ fire("after:highlightElement", { el: element, result, text });
1319
+ }
1320
+ function configure(userOptions) {
1321
+ options = inherit(options, userOptions);
1322
+ }
1323
+ const initHighlighting = () => {
1324
+ highlightAll();
1325
+ deprecated("10.6.0", "initHighlighting() deprecated. Use highlightAll() now.");
1326
+ };
1327
+ function initHighlightingOnLoad() {
1328
+ highlightAll();
1329
+ deprecated("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now.");
1330
+ }
1331
+ let wantsHighlight = false;
1332
+ function highlightAll() {
1333
+ if (document.readyState === "loading") {
1334
+ wantsHighlight = true;
1335
+ return;
1336
+ }
1337
+ const blocks = document.querySelectorAll(options.cssSelector);
1338
+ blocks.forEach(highlightElement);
1339
+ }
1340
+ function boot() {
1341
+ if (wantsHighlight)
1342
+ highlightAll();
1343
+ }
1344
+ if (typeof window !== "undefined" && window.addEventListener) {
1345
+ window.addEventListener("DOMContentLoaded", boot, false);
1346
+ }
1347
+ function registerLanguage(languageName, languageDefinition) {
1348
+ let lang = null;
1349
+ try {
1350
+ lang = languageDefinition(hljs);
1351
+ } catch (error$1) {
1352
+ error("Language definition for '{}' could not be registered.".replace("{}", languageName));
1353
+ if (!SAFE_MODE) {
1354
+ throw error$1;
1355
+ } else {
1356
+ error(error$1);
1357
+ }
1358
+ lang = PLAINTEXT_LANGUAGE;
1359
+ }
1360
+ if (!lang.name)
1361
+ lang.name = languageName;
1362
+ languages[languageName] = lang;
1363
+ lang.rawDefinition = languageDefinition.bind(null, hljs);
1364
+ if (lang.aliases) {
1365
+ registerAliases(lang.aliases, { languageName });
1366
+ }
1367
+ }
1368
+ function unregisterLanguage(languageName) {
1369
+ delete languages[languageName];
1370
+ for (const alias of Object.keys(aliases)) {
1371
+ if (aliases[alias] === languageName) {
1372
+ delete aliases[alias];
1373
+ }
1374
+ }
1375
+ }
1376
+ function listLanguages() {
1377
+ return Object.keys(languages);
1378
+ }
1379
+ function getLanguage(name) {
1380
+ name = (name || "").toLowerCase();
1381
+ return languages[name] || languages[aliases[name]];
1382
+ }
1383
+ function registerAliases(aliasList, { languageName }) {
1384
+ if (typeof aliasList === "string") {
1385
+ aliasList = [aliasList];
1386
+ }
1387
+ aliasList.forEach((alias) => {
1388
+ aliases[alias.toLowerCase()] = languageName;
1389
+ });
1390
+ }
1391
+ function autoDetection(name) {
1392
+ const lang = getLanguage(name);
1393
+ return lang && !lang.disableAutodetect;
1394
+ }
1395
+ function upgradePluginAPI(plugin) {
1396
+ if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
1397
+ plugin["before:highlightElement"] = (data) => {
1398
+ plugin["before:highlightBlock"](
1399
+ Object.assign({ block: data.el }, data)
1400
+ );
1401
+ };
1402
+ }
1403
+ if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
1404
+ plugin["after:highlightElement"] = (data) => {
1405
+ plugin["after:highlightBlock"](
1406
+ Object.assign({ block: data.el }, data)
1407
+ );
1408
+ };
1409
+ }
1410
+ }
1411
+ function addPlugin(plugin) {
1412
+ upgradePluginAPI(plugin);
1413
+ plugins.push(plugin);
1414
+ }
1415
+ function fire(event, args) {
1416
+ const cb = event;
1417
+ plugins.forEach(function(plugin) {
1418
+ if (plugin[cb]) {
1419
+ plugin[cb](args);
1420
+ }
1421
+ });
1422
+ }
1423
+ function deprecateHighlightBlock(el) {
1424
+ deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
1425
+ deprecated("10.7.0", "Please use highlightElement now.");
1426
+ return highlightElement(el);
1427
+ }
1428
+ Object.assign(hljs, {
1429
+ highlight: highlight2,
1430
+ highlightAuto,
1431
+ highlightAll,
1432
+ highlightElement,
1433
+ highlightBlock: deprecateHighlightBlock,
1434
+ configure,
1435
+ initHighlighting,
1436
+ initHighlightingOnLoad,
1437
+ registerLanguage,
1438
+ unregisterLanguage,
1439
+ listLanguages,
1440
+ getLanguage,
1441
+ registerAliases,
1442
+ autoDetection,
1443
+ inherit,
1444
+ addPlugin
1445
+ });
1446
+ hljs.debugMode = function() {
1447
+ SAFE_MODE = false;
1448
+ };
1449
+ hljs.safeMode = function() {
1450
+ SAFE_MODE = true;
1451
+ };
1452
+ hljs.versionString = version;
1453
+ hljs.regex = {
1454
+ concat,
1455
+ lookahead,
1456
+ either,
1457
+ optional,
1458
+ anyNumberOfTimes
1459
+ };
1460
+ for (const key in MODES) {
1461
+ if (typeof MODES[key] === "object") {
1462
+ deepFreezeEs6.exports(MODES[key]);
1463
+ }
1464
+ }
1465
+ Object.assign(hljs, MODES);
1466
+ return hljs;
1467
+ };
1468
+ var highlight = HLJS({});
1469
+ module.exports = highlight;
1470
+ highlight.HighlightJS = highlight;
1471
+ highlight.default = highlight;
1472
+ }
1473
+ });
1474
+
1475
+ // src/code-block-lowlight.ts
1476
+ var _extensioncodeblock = require('@tiptap/extension-code-block'); var _extensioncodeblock2 = _interopRequireDefault(_extensioncodeblock);
1477
+
1478
+ // src/lowlight-plugin.ts
1479
+ var _core = require('@tiptap/core');
1480
+ var _state = require('@tiptap/pm/state');
1481
+ var _view = require('@tiptap/pm/view');
1482
+
1483
+ // ../../node_modules/highlight.js/es/core.js
1484
+ var import_core = __toESM(require_core(), 1);
1485
+ var core_default = import_core.default;
1486
+
1487
+ // src/lowlight-plugin.ts
1488
+ function parseNodes(nodes, className = []) {
1489
+ return nodes.map((node) => {
1490
+ const classes = [...className, ...node.properties ? node.properties.className : []];
1491
+ if (node.children) {
1492
+ return parseNodes(node.children, classes);
1493
+ }
1494
+ return {
1495
+ text: node.value,
1496
+ classes
1497
+ };
1498
+ }).flat();
1499
+ }
1500
+ function getHighlightNodes(result) {
1501
+ return result.value || result.children || [];
1502
+ }
1503
+ function registered(aliasOrLanguage) {
1504
+ return Boolean(core_default.getLanguage(aliasOrLanguage));
1505
+ }
1506
+ function getDecorations({
1507
+ doc,
1508
+ name,
1509
+ lowlight,
1510
+ defaultLanguage
1511
+ }) {
1512
+ const decorations = [];
1513
+ _core.findChildren.call(void 0, doc, (node) => node.type.name === name).forEach((block) => {
1514
+ let from = block.pos + 1;
1515
+ const language = block.node.attrs.language || defaultLanguage;
1516
+ const languages = lowlight.listLanguages();
1517
+ const nodes = language && (languages.includes(language) || registered(language)) ? getHighlightNodes(lowlight.highlight(language, block.node.textContent)) : getHighlightNodes(lowlight.highlightAuto(block.node.textContent));
1518
+ parseNodes(nodes).forEach((node) => {
1519
+ const to = from + node.text.length;
1520
+ if (node.classes.length) {
1521
+ const decoration = _view.Decoration.inline(from, to, {
1522
+ class: node.classes.join(" ")
1523
+ });
1524
+ decorations.push(decoration);
1525
+ }
1526
+ from = to;
1527
+ });
1528
+ });
1529
+ return _view.DecorationSet.create(doc, decorations);
1530
+ }
1531
+ function isFunction(param) {
1532
+ return typeof param === "function";
1533
+ }
1534
+ function LowlightPlugin({
1535
+ name,
1536
+ lowlight,
1537
+ defaultLanguage
1538
+ }) {
1539
+ if (!["highlight", "highlightAuto", "listLanguages"].every((api) => isFunction(lowlight[api]))) {
1540
+ throw Error(
1541
+ "You should provide an instance of lowlight to use the code-block-lowlight extension"
1542
+ );
1543
+ }
1544
+ const lowlightPlugin = new (0, _state.Plugin)({
1545
+ key: new (0, _state.PluginKey)("lowlight"),
1546
+ state: {
1547
+ init: (_, { doc }) => getDecorations({
1548
+ doc,
1549
+ name,
1550
+ lowlight,
1551
+ defaultLanguage
1552
+ }),
1553
+ apply: (transaction, decorationSet, oldState, newState) => {
1554
+ const oldNodeName = oldState.selection.$head.parent.type.name;
1555
+ const newNodeName = newState.selection.$head.parent.type.name;
1556
+ const oldNodes = _core.findChildren.call(void 0, oldState.doc, (node) => node.type.name === name);
1557
+ const newNodes = _core.findChildren.call(void 0, newState.doc, (node) => node.type.name === name);
1558
+ if (transaction.docChanged && ([oldNodeName, newNodeName].includes(name) || newNodes.length !== oldNodes.length || transaction.steps.some((step) => {
1559
+ return step.from !== void 0 && step.to !== void 0 && oldNodes.some((node) => {
1560
+ return node.pos >= step.from && node.pos + node.node.nodeSize <= step.to;
1561
+ });
1562
+ }))) {
1563
+ return getDecorations({
1564
+ doc: transaction.doc,
1565
+ name,
1566
+ lowlight,
1567
+ defaultLanguage
1568
+ });
1569
+ }
1570
+ return decorationSet.map(transaction.mapping, transaction.doc);
1571
+ }
1572
+ },
1573
+ props: {
1574
+ decorations(state) {
1575
+ return lowlightPlugin.getState(state);
1576
+ }
1577
+ }
1578
+ });
1579
+ return lowlightPlugin;
1580
+ }
1581
+
1582
+ // src/code-block-lowlight.ts
1583
+ var CodeBlockLowlight = _extensioncodeblock2.default.extend({
1584
+ addOptions() {
1585
+ var _a;
1586
+ return {
1587
+ ...(_a = this.parent) == null ? void 0 : _a.call(this),
1588
+ lowlight: {},
1589
+ defaultLanguage: null
1590
+ };
1591
+ },
1592
+ addProseMirrorPlugins() {
1593
+ var _a;
1594
+ return [
1595
+ ...((_a = this.parent) == null ? void 0 : _a.call(this)) || [],
1596
+ LowlightPlugin({
1597
+ name: this.name,
1598
+ lowlight: this.options.lowlight,
1599
+ defaultLanguage: this.options.defaultLanguage
1600
+ })
1601
+ ];
1602
+ }
1603
+ });
1604
+
1605
+ // src/index.ts
1606
+ var src_default = CodeBlockLowlight;
1607
+
1608
+
1609
+
1610
+ exports.CodeBlockLowlight = CodeBlockLowlight; exports.default = src_default;