@terafina/tffa-sfdx-plugin 0.1.2 → 1.0.3

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.
Files changed (123) hide show
  1. package/README.md +7 -0
  2. package/assets/favicon.png +0 -0
  3. package/assets/highlight.css +68 -0
  4. package/assets/highlight.js +2801 -0
  5. package/assets/icon.png +0 -0
  6. package/assets/index.css +447 -0
  7. package/assets/index.js +411 -0
  8. package/assets/logo.png +0 -0
  9. package/assets/lunr.js +3471 -0
  10. package/assets/mark.js +13 -0
  11. package/assets/menu.js +34 -0
  12. package/assets/search.js +98 -0
  13. package/lib/apexdoc/common/apex-docs-error.d.ts +23 -0
  14. package/lib/apexdoc/common/apex-docs-error.js +28 -0
  15. package/lib/apexdoc/common/apex-docs-error.js.map +1 -0
  16. package/lib/apexdoc/common/array-utils.d.ts +9 -0
  17. package/lib/apexdoc/common/array-utils.js +36 -0
  18. package/lib/apexdoc/common/array-utils.js.map +1 -0
  19. package/lib/apexdoc/common/line-reader.d.ts +40 -0
  20. package/lib/apexdoc/common/line-reader.js +92 -0
  21. package/lib/apexdoc/common/line-reader.js.map +1 -0
  22. package/lib/apexdoc/common/models/apex-model.d.ts +51 -0
  23. package/lib/apexdoc/common/models/apex-model.js +264 -0
  24. package/lib/apexdoc/common/models/apex-model.js.map +1 -0
  25. package/lib/apexdoc/common/models/class-group.d.ts +10 -0
  26. package/lib/apexdoc/common/models/class-group.js +32 -0
  27. package/lib/apexdoc/common/models/class-group.js.map +1 -0
  28. package/lib/apexdoc/common/models/class-model.d.ts +38 -0
  29. package/lib/apexdoc/common/models/class-model.js +216 -0
  30. package/lib/apexdoc/common/models/class-model.js.map +1 -0
  31. package/lib/apexdoc/common/models/engine-config.d.ts +21 -0
  32. package/lib/apexdoc/common/models/engine-config.js +29 -0
  33. package/lib/apexdoc/common/models/engine-config.js.map +1 -0
  34. package/lib/apexdoc/common/models/enum-model.d.ts +15 -0
  35. package/lib/apexdoc/common/models/enum-model.js +47 -0
  36. package/lib/apexdoc/common/models/enum-model.js.map +1 -0
  37. package/lib/apexdoc/common/models/index.d.ts +10 -0
  38. package/lib/apexdoc/common/models/index.js +14 -0
  39. package/lib/apexdoc/common/models/index.js.map +1 -0
  40. package/lib/apexdoc/common/models/method-model.d.ts +26 -0
  41. package/lib/apexdoc/common/models/method-model.js +309 -0
  42. package/lib/apexdoc/common/models/method-model.js.map +1 -0
  43. package/lib/apexdoc/common/models/property-model.d.ts +12 -0
  44. package/lib/apexdoc/common/models/property-model.js +47 -0
  45. package/lib/apexdoc/common/models/property-model.js.map +1 -0
  46. package/lib/apexdoc/common/models/top-level-model.d.ts +19 -0
  47. package/lib/apexdoc/common/models/top-level-model.js +32 -0
  48. package/lib/apexdoc/common/models/top-level-model.js.map +1 -0
  49. package/lib/apexdoc/common/settings.d.ts +55 -0
  50. package/lib/apexdoc/common/settings.js +124 -0
  51. package/lib/apexdoc/common/settings.js.map +1 -0
  52. package/lib/apexdoc/common/tags.d.ts +22 -0
  53. package/lib/apexdoc/common/tags.js +168 -0
  54. package/lib/apexdoc/common/tags.js.map +1 -0
  55. package/lib/apexdoc/common/utils.d.ts +38 -0
  56. package/lib/apexdoc/common/utils.js +198 -0
  57. package/lib/apexdoc/common/utils.js.map +1 -0
  58. package/lib/apexdoc/common/validator-engine.d.ts +24 -0
  59. package/lib/apexdoc/common/validator-engine.js +162 -0
  60. package/lib/apexdoc/common/validator-engine.js.map +1 -0
  61. package/lib/apexdoc/common/validator.d.ts +16 -0
  62. package/lib/apexdoc/common/validator.js +35 -0
  63. package/lib/apexdoc/common/validator.js.map +1 -0
  64. package/lib/apexdoc/engine/file-manager.d.ts +52 -0
  65. package/lib/apexdoc/engine/file-manager.js +390 -0
  66. package/lib/apexdoc/engine/file-manager.js.map +1 -0
  67. package/lib/apexdoc/engine/generators/generator-utils.d.ts +12 -0
  68. package/lib/apexdoc/engine/generators/generator-utils.js +100 -0
  69. package/lib/apexdoc/engine/generators/generator-utils.js.map +1 -0
  70. package/lib/apexdoc/engine/generators/menu-generator.d.ts +9 -0
  71. package/lib/apexdoc/engine/generators/menu-generator.js +81 -0
  72. package/lib/apexdoc/engine/generators/menu-generator.js.map +1 -0
  73. package/lib/apexdoc/engine/generators/models/child-enum-markup-generator.d.ts +10 -0
  74. package/lib/apexdoc/engine/generators/models/child-enum-markup-generator.js +65 -0
  75. package/lib/apexdoc/engine/generators/models/child-enum-markup-generator.js.map +1 -0
  76. package/lib/apexdoc/engine/generators/models/class-markup-generator.d.ts +8 -0
  77. package/lib/apexdoc/engine/generators/models/class-markup-generator.js +49 -0
  78. package/lib/apexdoc/engine/generators/models/class-markup-generator.js.map +1 -0
  79. package/lib/apexdoc/engine/generators/models/enum-markup-generator.d.ts +9 -0
  80. package/lib/apexdoc/engine/generators/models/enum-markup-generator.js +40 -0
  81. package/lib/apexdoc/engine/generators/models/enum-markup-generator.js.map +1 -0
  82. package/lib/apexdoc/engine/generators/models/markup-generator.d.ts +27 -0
  83. package/lib/apexdoc/engine/generators/models/markup-generator.js +148 -0
  84. package/lib/apexdoc/engine/generators/models/markup-generator.js.map +1 -0
  85. package/lib/apexdoc/engine/generators/models/method-markup-generator.d.ts +22 -0
  86. package/lib/apexdoc/engine/generators/models/method-markup-generator.js +224 -0
  87. package/lib/apexdoc/engine/generators/models/method-markup-generator.js.map +1 -0
  88. package/lib/apexdoc/engine/generators/models/property-markup-generator.d.ts +11 -0
  89. package/lib/apexdoc/engine/generators/models/property-markup-generator.js +66 -0
  90. package/lib/apexdoc/engine/generators/models/property-markup-generator.js.map +1 -0
  91. package/lib/apexdoc/engine/generators/models/source-markup-generator.d.ts +10 -0
  92. package/lib/apexdoc/engine/generators/models/source-markup-generator.js +39 -0
  93. package/lib/apexdoc/engine/generators/models/source-markup-generator.js.map +1 -0
  94. package/lib/apexdoc/engine/generators/models/top-level-markup-generator.d.ts +10 -0
  95. package/lib/apexdoc/engine/generators/models/top-level-markup-generator.js +49 -0
  96. package/lib/apexdoc/engine/generators/models/top-level-markup-generator.js.map +1 -0
  97. package/lib/apexdoc/engine/generators/see-link-generator.d.ts +20 -0
  98. package/lib/apexdoc/engine/generators/see-link-generator.js +183 -0
  99. package/lib/apexdoc/engine/generators/see-link-generator.js.map +1 -0
  100. package/lib/commands/tffa/apexdoc.d.ts +29 -0
  101. package/lib/commands/tffa/apexdoc.js +272 -0
  102. package/lib/commands/tffa/apexdoc.js.map +1 -0
  103. package/lib/commands/tffa/ping.d.ts +3 -0
  104. package/lib/commands/tffa/ping.js +4 -0
  105. package/lib/commands/tffa/ping.js.map +1 -1
  106. package/lib/commands/tffa/scan.d.ts +52 -0
  107. package/lib/commands/tffa/scan.js +348 -0
  108. package/lib/commands/tffa/scan.js.map +1 -0
  109. package/lib/index.d.ts +3 -0
  110. package/lib/index.js +3 -0
  111. package/lib/index.js.map +1 -1
  112. package/lib/shared/model.d.ts +30 -0
  113. package/lib/shared/model.js +17 -0
  114. package/lib/shared/model.js.map +1 -0
  115. package/lib/shared/parser.d.ts +3 -0
  116. package/lib/shared/parser.js +101 -0
  117. package/lib/shared/parser.js.map +1 -0
  118. package/lib/shared/rules.d.ts +3 -0
  119. package/lib/shared/rules.js +5 -0
  120. package/lib/shared/rules.js.map +1 -0
  121. package/oclif.manifest.json +1 -1
  122. package/package.json +47 -25
  123. package/CHANGELOG.md +0 -14
@@ -0,0 +1,2801 @@
1
+ /*!
2
+ Highlight.js v11.2.0 (git: bb4fb2291b)
3
+ (c) 2006-2021 Ivan Sagalaev and other contributors
4
+ License: BSD-3-Clause
5
+ */
6
+ var hljs = (function () {
7
+ 'use strict';
8
+
9
+ var deepFreezeEs6 = {exports: {}};
10
+
11
+ function deepFreeze(obj) {
12
+ if (obj instanceof Map) {
13
+ obj.clear = obj.delete = obj.set = function () {
14
+ throw new Error('map is read-only');
15
+ };
16
+ } else if (obj instanceof Set) {
17
+ obj.add = obj.clear = obj.delete = function () {
18
+ throw new Error('set is read-only');
19
+ };
20
+ }
21
+
22
+ // Freeze self
23
+ Object.freeze(obj);
24
+
25
+ Object.getOwnPropertyNames(obj).forEach(function (name) {
26
+ var prop = obj[name];
27
+
28
+ // Freeze prop if it is an object
29
+ if (typeof prop == 'object' && !Object.isFrozen(prop)) {
30
+ deepFreeze(prop);
31
+ }
32
+ });
33
+
34
+ return obj;
35
+ }
36
+
37
+ deepFreezeEs6.exports = deepFreeze;
38
+ deepFreezeEs6.exports.default = deepFreeze;
39
+
40
+ var deepFreeze$1 = deepFreezeEs6.exports;
41
+
42
+ /** @typedef {import('highlight.js').CallbackResponse} CallbackResponse */
43
+ /** @typedef {import('highlight.js').CompiledMode} CompiledMode */
44
+ /** @implements CallbackResponse */
45
+
46
+ class Response {
47
+ /**
48
+ * @param {CompiledMode} mode
49
+ */
50
+ constructor(mode) {
51
+ // eslint-disable-next-line no-undefined
52
+ if (mode.data === undefined) mode.data = {};
53
+
54
+ this.data = mode.data;
55
+ this.isMatchIgnored = false;
56
+ }
57
+
58
+ ignoreMatch() {
59
+ this.isMatchIgnored = true;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * @param {string} value
65
+ * @returns {string}
66
+ */
67
+ function escapeHTML(value) {
68
+ return value
69
+ .replace(/&/g, '&')
70
+ .replace(/</g, '&lt;')
71
+ .replace(/>/g, '&gt;')
72
+ .replace(/"/g, '&quot;')
73
+ .replace(/'/g, '&#x27;');
74
+ }
75
+
76
+ /**
77
+ * performs a shallow merge of multiple objects into one
78
+ *
79
+ * @template T
80
+ * @param {T} original
81
+ * @param {Record<string,any>[]} objects
82
+ * @returns {T} a single new object
83
+ */
84
+ function inherit$1(original, ...objects) {
85
+ /** @type Record<string,any> */
86
+ const result = Object.create(null);
87
+
88
+ for (const key in original) {
89
+ result[key] = original[key];
90
+ }
91
+ objects.forEach(function(obj) {
92
+ for (const key in obj) {
93
+ result[key] = obj[key];
94
+ }
95
+ });
96
+ return /** @type {T} */ (result);
97
+ }
98
+
99
+ /**
100
+ * @typedef {object} Renderer
101
+ * @property {(text: string) => void} addText
102
+ * @property {(node: Node) => void} openNode
103
+ * @property {(node: Node) => void} closeNode
104
+ * @property {() => string} value
105
+ */
106
+
107
+ /** @typedef {{kind?: string, sublanguage?: boolean}} Node */
108
+ /** @typedef {{walk: (r: Renderer) => void}} Tree */
109
+ /** */
110
+
111
+ const SPAN_CLOSE = '</span>';
112
+
113
+ /**
114
+ * Determines if a node needs to be wrapped in <span>
115
+ *
116
+ * @param {Node} node */
117
+ const emitsWrappingTags = (node) => {
118
+ return !!node.kind;
119
+ };
120
+
121
+ /**
122
+ *
123
+ * @param {string} name
124
+ * @param {{prefix:string}} options
125
+ */
126
+ const expandScopeName = (name, { prefix }) => {
127
+ if (name.includes(".")) {
128
+ const pieces = name.split(".");
129
+ return [
130
+ `${prefix}${pieces.shift()}`,
131
+ ...(pieces.map((x, i) => `${x}${"_".repeat(i + 1)}`))
132
+ ].join(" ");
133
+ }
134
+ return `${prefix}${name}`;
135
+ };
136
+
137
+ /** @type {Renderer} */
138
+ class HTMLRenderer {
139
+ /**
140
+ * Creates a new HTMLRenderer
141
+ *
142
+ * @param {Tree} parseTree - the parse tree (must support `walk` API)
143
+ * @param {{classPrefix: string}} options
144
+ */
145
+ constructor(parseTree, options) {
146
+ this.buffer = "";
147
+ this.classPrefix = options.classPrefix;
148
+ parseTree.walk(this);
149
+ }
150
+
151
+ /**
152
+ * Adds texts to the output stream
153
+ *
154
+ * @param {string} text */
155
+ addText(text) {
156
+ this.buffer += escapeHTML(text);
157
+ }
158
+
159
+ /**
160
+ * Adds a node open to the output stream (if needed)
161
+ *
162
+ * @param {Node} node */
163
+ openNode(node) {
164
+ if (!emitsWrappingTags(node)) return;
165
+
166
+ let scope = node.kind;
167
+ if (node.sublanguage) {
168
+ scope = `language-${scope}`;
169
+ } else {
170
+ scope = expandScopeName(scope, { prefix: this.classPrefix });
171
+ }
172
+ this.span(scope);
173
+ }
174
+
175
+ /**
176
+ * Adds a node close to the output stream (if needed)
177
+ *
178
+ * @param {Node} node */
179
+ closeNode(node) {
180
+ if (!emitsWrappingTags(node)) return;
181
+
182
+ this.buffer += SPAN_CLOSE;
183
+ }
184
+
185
+ /**
186
+ * returns the accumulated buffer
187
+ */
188
+ value() {
189
+ return this.buffer;
190
+ }
191
+
192
+ // helpers
193
+
194
+ /**
195
+ * Builds a span element
196
+ *
197
+ * @param {string} className */
198
+ span(className) {
199
+ this.buffer += `<span class="${className}">`;
200
+ }
201
+ }
202
+
203
+ /** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} | string} Node */
204
+ /** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} } DataNode */
205
+ /** @typedef {import('highlight.js').Emitter} Emitter */
206
+ /** */
207
+
208
+ class TokenTree {
209
+ constructor() {
210
+ /** @type DataNode */
211
+ this.rootNode = { children: [] };
212
+ this.stack = [this.rootNode];
213
+ }
214
+
215
+ get top() {
216
+ return this.stack[this.stack.length - 1];
217
+ }
218
+
219
+ get root() { return this.rootNode; }
220
+
221
+ /** @param {Node} node */
222
+ add(node) {
223
+ this.top.children.push(node);
224
+ }
225
+
226
+ /** @param {string} kind */
227
+ openNode(kind) {
228
+ /** @type Node */
229
+ const node = { kind, children: [] };
230
+ this.add(node);
231
+ this.stack.push(node);
232
+ }
233
+
234
+ closeNode() {
235
+ if (this.stack.length > 1) {
236
+ return this.stack.pop();
237
+ }
238
+ // eslint-disable-next-line no-undefined
239
+ return undefined;
240
+ }
241
+
242
+ closeAllNodes() {
243
+ while (this.closeNode());
244
+ }
245
+
246
+ toJSON() {
247
+ return JSON.stringify(this.rootNode, null, 4);
248
+ }
249
+
250
+ /**
251
+ * @typedef { import("./html_renderer").Renderer } Renderer
252
+ * @param {Renderer} builder
253
+ */
254
+ walk(builder) {
255
+ // this does not
256
+ return this.constructor._walk(builder, this.rootNode);
257
+ // this works
258
+ // return TokenTree._walk(builder, this.rootNode);
259
+ }
260
+
261
+ /**
262
+ * @param {Renderer} builder
263
+ * @param {Node} node
264
+ */
265
+ static _walk(builder, node) {
266
+ if (typeof node === "string") {
267
+ builder.addText(node);
268
+ } else if (node.children) {
269
+ builder.openNode(node);
270
+ node.children.forEach((child) => this._walk(builder, child));
271
+ builder.closeNode(node);
272
+ }
273
+ return builder;
274
+ }
275
+
276
+ /**
277
+ * @param {Node} node
278
+ */
279
+ static _collapse(node) {
280
+ if (typeof node === "string") return;
281
+ if (!node.children) return;
282
+
283
+ if (node.children.every(el => typeof el === "string")) {
284
+ // node.text = node.children.join("");
285
+ // delete node.children;
286
+ node.children = [node.children.join("")];
287
+ } else {
288
+ node.children.forEach((child) => {
289
+ TokenTree._collapse(child);
290
+ });
291
+ }
292
+ }
293
+ }
294
+
295
+ /**
296
+ Currently this is all private API, but this is the minimal API necessary
297
+ that an Emitter must implement to fully support the parser.
298
+
299
+ Minimal interface:
300
+
301
+ - addKeyword(text, kind)
302
+ - addText(text)
303
+ - addSublanguage(emitter, subLanguageName)
304
+ - finalize()
305
+ - openNode(kind)
306
+ - closeNode()
307
+ - closeAllNodes()
308
+ - toHTML()
309
+
310
+ */
311
+
312
+ /**
313
+ * @implements {Emitter}
314
+ */
315
+ class TokenTreeEmitter extends TokenTree {
316
+ /**
317
+ * @param {*} options
318
+ */
319
+ constructor(options) {
320
+ super();
321
+ this.options = options;
322
+ }
323
+
324
+ /**
325
+ * @param {string} text
326
+ * @param {string} kind
327
+ */
328
+ addKeyword(text, kind) {
329
+ if (text === "") { return; }
330
+
331
+ this.openNode(kind);
332
+ this.addText(text);
333
+ this.closeNode();
334
+ }
335
+
336
+ /**
337
+ * @param {string} text
338
+ */
339
+ addText(text) {
340
+ if (text === "") { return; }
341
+
342
+ this.add(text);
343
+ }
344
+
345
+ /**
346
+ * @param {Emitter & {root: DataNode}} emitter
347
+ * @param {string} name
348
+ */
349
+ addSublanguage(emitter, name) {
350
+ /** @type DataNode */
351
+ const node = emitter.root;
352
+ node.kind = name;
353
+ node.sublanguage = true;
354
+ this.add(node);
355
+ }
356
+
357
+ toHTML() {
358
+ const renderer = new HTMLRenderer(this, this.options);
359
+ return renderer.value();
360
+ }
361
+
362
+ finalize() {
363
+ return true;
364
+ }
365
+ }
366
+
367
+ /**
368
+ * @param {string} value
369
+ * @returns {RegExp}
370
+ * */
371
+
372
+ /**
373
+ * @param {RegExp | string } re
374
+ * @returns {string}
375
+ */
376
+ function source(re) {
377
+ if (!re) return null;
378
+ if (typeof re === "string") return re;
379
+
380
+ return re.source;
381
+ }
382
+
383
+ /**
384
+ * @param {RegExp | string } re
385
+ * @returns {string}
386
+ */
387
+ function lookahead(re) {
388
+ return concat('(?=', re, ')');
389
+ }
390
+
391
+ /**
392
+ * @param {...(RegExp | string) } args
393
+ * @returns {string}
394
+ */
395
+ function concat(...args) {
396
+ const joined = args.map((x) => source(x)).join("");
397
+ return joined;
398
+ }
399
+
400
+ function stripOptionsFromArgs(args) {
401
+ const opts = args[args.length - 1];
402
+
403
+ if (typeof opts === 'object' && opts.constructor === Object) {
404
+ args.splice(args.length - 1, 1);
405
+ return opts;
406
+ } else {
407
+ return {};
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Any of the passed expresssions may match
413
+ *
414
+ * Creates a huge this | this | that | that match
415
+ * @param {(RegExp | string)[] } args
416
+ * @returns {string}
417
+ */
418
+ function either(...args) {
419
+ const opts = stripOptionsFromArgs(args);
420
+ const joined = '(' +
421
+ (opts.capture ? "" : "?:") +
422
+ args.map((x) => source(x)).join("|") + ")";
423
+ return joined;
424
+ }
425
+
426
+ /**
427
+ * @param {RegExp} re
428
+ * @returns {number}
429
+ */
430
+ function countMatchGroups(re) {
431
+ return (new RegExp(re.toString() + '|')).exec('').length - 1;
432
+ }
433
+
434
+ /**
435
+ * Does lexeme start with a regular expression match at the beginning
436
+ * @param {RegExp} re
437
+ * @param {string} lexeme
438
+ */
439
+ function startsWith(re, lexeme) {
440
+ const match = re && re.exec(lexeme);
441
+ return match && match.index === 0;
442
+ }
443
+
444
+ // BACKREF_RE matches an open parenthesis or backreference. To avoid
445
+ // an incorrect parse, it additionally matches the following:
446
+ // - [...] elements, where the meaning of parentheses and escapes change
447
+ // - other escape sequences, so we do not misparse escape sequences as
448
+ // interesting elements
449
+ // - non-matching or lookahead parentheses, which do not capture. These
450
+ // follow the '(' with a '?'.
451
+ const BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
452
+
453
+ // **INTERNAL** Not intended for outside usage
454
+ // join logically computes regexps.join(separator), but fixes the
455
+ // backreferences so they continue to match.
456
+ // it also places each individual regular expression into it's own
457
+ // match group, keeping track of the sequencing of those match groups
458
+ // is currently an exercise for the caller. :-)
459
+ /**
460
+ * @param {(string | RegExp)[]} regexps
461
+ * @param {{joinWith: string}} opts
462
+ * @returns {string}
463
+ */
464
+ function _rewriteBackreferences(regexps, { joinWith }) {
465
+ let numCaptures = 0;
466
+
467
+ return regexps.map((regex) => {
468
+ numCaptures += 1;
469
+ const offset = numCaptures;
470
+ let re = source(regex);
471
+ let out = '';
472
+
473
+ while (re.length > 0) {
474
+ const match = BACKREF_RE.exec(re);
475
+ if (!match) {
476
+ out += re;
477
+ break;
478
+ }
479
+ out += re.substring(0, match.index);
480
+ re = re.substring(match.index + match[0].length);
481
+ if (match[0][0] === '\\' && match[1]) {
482
+ // Adjust the backreference.
483
+ out += '\\' + String(Number(match[1]) + offset);
484
+ } else {
485
+ out += match[0];
486
+ if (match[0] === '(') {
487
+ numCaptures++;
488
+ }
489
+ }
490
+ }
491
+ return out;
492
+ }).map(re => `(${re})`).join(joinWith);
493
+ }
494
+
495
+ /** @typedef {import('highlight.js').Mode} Mode */
496
+ /** @typedef {import('highlight.js').ModeCallback} ModeCallback */
497
+
498
+ // Common regexps
499
+ const MATCH_NOTHING_RE = /\b\B/;
500
+ const IDENT_RE = '[a-zA-Z]\\w*';
501
+ const UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*';
502
+ const NUMBER_RE = '\\b\\d+(\\.\\d+)?';
503
+ const C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float
504
+ const BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b...
505
+ const RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';
506
+
507
+ /**
508
+ * @param { Partial<Mode> & {binary?: string | RegExp} } opts
509
+ */
510
+ const SHEBANG = (opts = {}) => {
511
+ const beginShebang = /^#![ ]*\//;
512
+ if (opts.binary) {
513
+ opts.begin = concat(
514
+ beginShebang,
515
+ /.*\b/,
516
+ opts.binary,
517
+ /\b.*/);
518
+ }
519
+ return inherit$1({
520
+ scope: 'meta',
521
+ begin: beginShebang,
522
+ end: /$/,
523
+ relevance: 0,
524
+ /** @type {ModeCallback} */
525
+ "on:begin": (m, resp) => {
526
+ if (m.index !== 0) resp.ignoreMatch();
527
+ }
528
+ }, opts);
529
+ };
530
+
531
+ // Common modes
532
+ const BACKSLASH_ESCAPE = {
533
+ begin: '\\\\[\\s\\S]', relevance: 0
534
+ };
535
+ const APOS_STRING_MODE = {
536
+ scope: 'string',
537
+ begin: '\'',
538
+ end: '\'',
539
+ illegal: '\\n',
540
+ contains: [BACKSLASH_ESCAPE]
541
+ };
542
+ const QUOTE_STRING_MODE = {
543
+ scope: 'string',
544
+ begin: '"',
545
+ end: '"',
546
+ illegal: '\\n',
547
+ contains: [BACKSLASH_ESCAPE]
548
+ };
549
+ const PHRASAL_WORDS_MODE = {
550
+ 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/
551
+ };
552
+ /**
553
+ * Creates a comment mode
554
+ *
555
+ * @param {string | RegExp} begin
556
+ * @param {string | RegExp} end
557
+ * @param {Mode | {}} [modeOptions]
558
+ * @returns {Partial<Mode>}
559
+ */
560
+ const COMMENT = function(begin, end, modeOptions = {}) {
561
+ const mode = inherit$1(
562
+ {
563
+ scope: 'comment',
564
+ begin,
565
+ end,
566
+ contains: []
567
+ },
568
+ modeOptions
569
+ );
570
+ mode.contains.push({
571
+ scope: 'doctag',
572
+ // hack to avoid the space from being included. the space is necessary to
573
+ // match here to prevent the plain text rule below from gobbling up doctags
574
+ begin: '[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)',
575
+ end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
576
+ excludeBegin: true,
577
+ relevance: 0
578
+ });
579
+ const ENGLISH_WORD = either(
580
+ // list of common 1 and 2 letter words in English
581
+ "I",
582
+ "a",
583
+ "is",
584
+ "so",
585
+ "us",
586
+ "to",
587
+ "at",
588
+ "if",
589
+ "in",
590
+ "it",
591
+ "on",
592
+ // note: this is not an exhaustive list of contractions, just popular ones
593
+ /[A-Za-z]+['](d|ve|re|ll|t|s|n)/, // contractions - can't we'd they're let's, etc
594
+ /[A-Za-z]+[-][a-z]+/, // `no-way`, etc.
595
+ /[A-Za-z][a-z]{2,}/ // allow capitalized words at beginning of sentences
596
+ );
597
+ // looking like plain text, more likely to be a comment
598
+ mode.contains.push(
599
+ {
600
+ // TODO: how to include ", (, ) without breaking grammars that use these for
601
+ // comment delimiters?
602
+ // begin: /[ ]+([()"]?([A-Za-z'-]{3,}|is|a|I|so|us|[tT][oO]|at|if|in|it|on)[.]?[()":]?([.][ ]|[ ]|\))){3}/
603
+ // ---
604
+
605
+ // this tries to find sequences of 3 english words in a row (without any
606
+ // "programming" type syntax) this gives us a strong signal that we've
607
+ // TRULY found a comment - vs perhaps scanning with the wrong language.
608
+ // It's possible to find something that LOOKS like the start of the
609
+ // comment - but then if there is no readable text - good chance it is a
610
+ // false match and not a comment.
611
+ //
612
+ // for a visual example please see:
613
+ // https://github.com/highlightjs/highlight.js/issues/2827
614
+
615
+ begin: concat(
616
+ /[ ]+/, // necessary to prevent us gobbling up doctags like /* @author Bob Mcgill */
617
+ '(',
618
+ ENGLISH_WORD,
619
+ /[.]?[:]?([.][ ]|[ ])/,
620
+ '){3}') // look for 3 words in a row
621
+ }
622
+ );
623
+ return mode;
624
+ };
625
+ const C_LINE_COMMENT_MODE = COMMENT('//', '$');
626
+ const C_BLOCK_COMMENT_MODE = COMMENT('/\\*', '\\*/');
627
+ const HASH_COMMENT_MODE = COMMENT('#', '$');
628
+ const NUMBER_MODE = {
629
+ scope: 'number',
630
+ begin: NUMBER_RE,
631
+ relevance: 0
632
+ };
633
+ const C_NUMBER_MODE = {
634
+ scope: 'number',
635
+ begin: C_NUMBER_RE,
636
+ relevance: 0
637
+ };
638
+ const BINARY_NUMBER_MODE = {
639
+ scope: 'number',
640
+ begin: BINARY_NUMBER_RE,
641
+ relevance: 0
642
+ };
643
+ const REGEXP_MODE = {
644
+ // this outer rule makes sure we actually have a WHOLE regex and not simply
645
+ // an expression such as:
646
+ //
647
+ // 3 / something
648
+ //
649
+ // (which will then blow up when regex's `illegal` sees the newline)
650
+ begin: /(?=\/[^/\n]*\/)/,
651
+ contains: [{
652
+ scope: 'regexp',
653
+ begin: /\//,
654
+ end: /\/[gimuy]*/,
655
+ illegal: /\n/,
656
+ contains: [
657
+ BACKSLASH_ESCAPE,
658
+ {
659
+ begin: /\[/,
660
+ end: /\]/,
661
+ relevance: 0,
662
+ contains: [BACKSLASH_ESCAPE]
663
+ }
664
+ ]
665
+ }]
666
+ };
667
+ const TITLE_MODE = {
668
+ scope: 'title',
669
+ begin: IDENT_RE,
670
+ relevance: 0
671
+ };
672
+ const UNDERSCORE_TITLE_MODE = {
673
+ scope: 'title',
674
+ begin: UNDERSCORE_IDENT_RE,
675
+ relevance: 0
676
+ };
677
+ const METHOD_GUARD = {
678
+ // excludes method names from keyword processing
679
+ begin: '\\.\\s*' + UNDERSCORE_IDENT_RE,
680
+ relevance: 0
681
+ };
682
+
683
+ /**
684
+ * Adds end same as begin mechanics to a mode
685
+ *
686
+ * Your mode must include at least a single () match group as that first match
687
+ * group is what is used for comparison
688
+ * @param {Partial<Mode>} mode
689
+ */
690
+ const END_SAME_AS_BEGIN = function(mode) {
691
+ return Object.assign(mode,
692
+ {
693
+ /** @type {ModeCallback} */
694
+ 'on:begin': (m, resp) => { resp.data._beginMatch = m[1]; },
695
+ /** @type {ModeCallback} */
696
+ 'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch(); }
697
+ });
698
+ };
699
+
700
+ var MODES = /*#__PURE__*/Object.freeze({
701
+ __proto__: null,
702
+ MATCH_NOTHING_RE: MATCH_NOTHING_RE,
703
+ IDENT_RE: IDENT_RE,
704
+ UNDERSCORE_IDENT_RE: UNDERSCORE_IDENT_RE,
705
+ NUMBER_RE: NUMBER_RE,
706
+ C_NUMBER_RE: C_NUMBER_RE,
707
+ BINARY_NUMBER_RE: BINARY_NUMBER_RE,
708
+ RE_STARTERS_RE: RE_STARTERS_RE,
709
+ SHEBANG: SHEBANG,
710
+ BACKSLASH_ESCAPE: BACKSLASH_ESCAPE,
711
+ APOS_STRING_MODE: APOS_STRING_MODE,
712
+ QUOTE_STRING_MODE: QUOTE_STRING_MODE,
713
+ PHRASAL_WORDS_MODE: PHRASAL_WORDS_MODE,
714
+ COMMENT: COMMENT,
715
+ C_LINE_COMMENT_MODE: C_LINE_COMMENT_MODE,
716
+ C_BLOCK_COMMENT_MODE: C_BLOCK_COMMENT_MODE,
717
+ HASH_COMMENT_MODE: HASH_COMMENT_MODE,
718
+ NUMBER_MODE: NUMBER_MODE,
719
+ C_NUMBER_MODE: C_NUMBER_MODE,
720
+ BINARY_NUMBER_MODE: BINARY_NUMBER_MODE,
721
+ REGEXP_MODE: REGEXP_MODE,
722
+ TITLE_MODE: TITLE_MODE,
723
+ UNDERSCORE_TITLE_MODE: UNDERSCORE_TITLE_MODE,
724
+ METHOD_GUARD: METHOD_GUARD,
725
+ END_SAME_AS_BEGIN: END_SAME_AS_BEGIN
726
+ });
727
+
728
+ /**
729
+ @typedef {import('highlight.js').CallbackResponse} CallbackResponse
730
+ @typedef {import('highlight.js').CompilerExt} CompilerExt
731
+ */
732
+
733
+ // Grammar extensions / plugins
734
+ // See: https://github.com/highlightjs/highlight.js/issues/2833
735
+
736
+ // Grammar extensions allow "syntactic sugar" to be added to the grammar modes
737
+ // without requiring any underlying changes to the compiler internals.
738
+
739
+ // `compileMatch` being the perfect small example of now allowing a grammar
740
+ // author to write `match` when they desire to match a single expression rather
741
+ // than being forced to use `begin`. The extension then just moves `match` into
742
+ // `begin` when it runs. Ie, no features have been added, but we've just made
743
+ // the experience of writing (and reading grammars) a little bit nicer.
744
+
745
+ // ------
746
+
747
+ // TODO: We need negative look-behind support to do this properly
748
+ /**
749
+ * Skip a match if it has a preceding dot
750
+ *
751
+ * This is used for `beginKeywords` to prevent matching expressions such as
752
+ * `bob.keyword.do()`. The mode compiler automatically wires this up as a
753
+ * special _internal_ 'on:begin' callback for modes with `beginKeywords`
754
+ * @param {RegExpMatchArray} match
755
+ * @param {CallbackResponse} response
756
+ */
757
+ function skipIfHasPrecedingDot(match, response) {
758
+ const before = match.input[match.index - 1];
759
+ if (before === ".") {
760
+ response.ignoreMatch();
761
+ }
762
+ }
763
+
764
+ /**
765
+ *
766
+ * @type {CompilerExt}
767
+ */
768
+ function scopeClassName(mode, _parent) {
769
+ // eslint-disable-next-line no-undefined
770
+ if (mode.className !== undefined) {
771
+ mode.scope = mode.className;
772
+ delete mode.className;
773
+ }
774
+ }
775
+
776
+ /**
777
+ * `beginKeywords` syntactic sugar
778
+ * @type {CompilerExt}
779
+ */
780
+ function beginKeywords(mode, parent) {
781
+ if (!parent) return;
782
+ if (!mode.beginKeywords) return;
783
+
784
+ // for languages with keywords that include non-word characters checking for
785
+ // a word boundary is not sufficient, so instead we check for a word boundary
786
+ // or whitespace - this does no harm in any case since our keyword engine
787
+ // doesn't allow spaces in keywords anyways and we still check for the boundary
788
+ // first
789
+ mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\.)(?=\\b|\\s)';
790
+ mode.__beforeBegin = skipIfHasPrecedingDot;
791
+ mode.keywords = mode.keywords || mode.beginKeywords;
792
+ delete mode.beginKeywords;
793
+
794
+ // prevents double relevance, the keywords themselves provide
795
+ // relevance, the mode doesn't need to double it
796
+ // eslint-disable-next-line no-undefined
797
+ if (mode.relevance === undefined) mode.relevance = 0;
798
+ }
799
+
800
+ /**
801
+ * Allow `illegal` to contain an array of illegal values
802
+ * @type {CompilerExt}
803
+ */
804
+ function compileIllegal(mode, _parent) {
805
+ if (!Array.isArray(mode.illegal)) return;
806
+
807
+ mode.illegal = either(...mode.illegal);
808
+ }
809
+
810
+ /**
811
+ * `match` to match a single expression for readability
812
+ * @type {CompilerExt}
813
+ */
814
+ function compileMatch(mode, _parent) {
815
+ if (!mode.match) return;
816
+ if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
817
+
818
+ mode.begin = mode.match;
819
+ delete mode.match;
820
+ }
821
+
822
+ /**
823
+ * provides the default 1 relevance to all modes
824
+ * @type {CompilerExt}
825
+ */
826
+ function compileRelevance(mode, _parent) {
827
+ // eslint-disable-next-line no-undefined
828
+ if (mode.relevance === undefined) mode.relevance = 1;
829
+ }
830
+
831
+ // allow beforeMatch to act as a "qualifier" for the match
832
+ // the full match begin must be [beforeMatch][begin]
833
+ const beforeMatchExt = (mode, parent) => {
834
+ if (!mode.beforeMatch) return;
835
+ // starts conflicts with endsParent which we need to make sure the child
836
+ // rule is not matched multiple times
837
+ if (mode.starts) throw new Error("beforeMatch cannot be used with starts");
838
+
839
+ const originalMode = Object.assign({}, mode);
840
+ Object.keys(mode).forEach((key) => { delete mode[key]; });
841
+
842
+ mode.keywords = originalMode.keywords;
843
+ mode.begin = concat(originalMode.beforeMatch, lookahead(originalMode.begin));
844
+ mode.starts = {
845
+ relevance: 0,
846
+ contains: [
847
+ Object.assign(originalMode, { endsParent: true })
848
+ ]
849
+ };
850
+ mode.relevance = 0;
851
+
852
+ delete originalMode.beforeMatch;
853
+ };
854
+
855
+ // keywords that should have no default relevance value
856
+ const COMMON_KEYWORDS = [
857
+ 'of',
858
+ 'and',
859
+ 'for',
860
+ 'in',
861
+ 'not',
862
+ 'or',
863
+ 'if',
864
+ 'then',
865
+ 'parent', // common variable name
866
+ 'list', // common variable name
867
+ 'value' // common variable name
868
+ ];
869
+
870
+ const DEFAULT_KEYWORD_SCOPE = "keyword";
871
+
872
+ /**
873
+ * Given raw keywords from a language definition, compile them.
874
+ *
875
+ * @param {string | Record<string,string|string[]> | Array<string>} rawKeywords
876
+ * @param {boolean} caseInsensitive
877
+ */
878
+ function compileKeywords(rawKeywords, caseInsensitive, scopeName = DEFAULT_KEYWORD_SCOPE) {
879
+ /** @type KeywordDict */
880
+ const compiledKeywords = Object.create(null);
881
+
882
+ // input can be a string of keywords, an array of keywords, or a object with
883
+ // named keys representing scopeName (which can then point to a string or array)
884
+ if (typeof rawKeywords === 'string') {
885
+ compileList(scopeName, rawKeywords.split(" "));
886
+ } else if (Array.isArray(rawKeywords)) {
887
+ compileList(scopeName, rawKeywords);
888
+ } else {
889
+ Object.keys(rawKeywords).forEach(function(scopeName) {
890
+ // collapse all our objects back into the parent object
891
+ Object.assign(
892
+ compiledKeywords,
893
+ compileKeywords(rawKeywords[scopeName], caseInsensitive, scopeName)
894
+ );
895
+ });
896
+ }
897
+ return compiledKeywords;
898
+
899
+ // ---
900
+
901
+ /**
902
+ * Compiles an individual list of keywords
903
+ *
904
+ * Ex: "for if when while|5"
905
+ *
906
+ * @param {string} scopeName
907
+ * @param {Array<string>} keywordList
908
+ */
909
+ function compileList(scopeName, keywordList) {
910
+ if (caseInsensitive) {
911
+ keywordList = keywordList.map(x => x.toLowerCase());
912
+ }
913
+ keywordList.forEach(function(keyword) {
914
+ const pair = keyword.split('|');
915
+ compiledKeywords[pair[0]] = [scopeName, scoreForKeyword(pair[0], pair[1])];
916
+ });
917
+ }
918
+ }
919
+
920
+ /**
921
+ * Returns the proper score for a given keyword
922
+ *
923
+ * Also takes into account comment keywords, which will be scored 0 UNLESS
924
+ * another score has been manually assigned.
925
+ * @param {string} keyword
926
+ * @param {string} [providedScore]
927
+ */
928
+ function scoreForKeyword(keyword, providedScore) {
929
+ // manual scores always win over common keywords
930
+ // so you can force a score of 1 if you really insist
931
+ if (providedScore) {
932
+ return Number(providedScore);
933
+ }
934
+
935
+ return commonKeyword(keyword) ? 0 : 1;
936
+ }
937
+
938
+ /**
939
+ * Determines if a given keyword is common or not
940
+ *
941
+ * @param {string} keyword */
942
+ function commonKeyword(keyword) {
943
+ return COMMON_KEYWORDS.includes(keyword.toLowerCase());
944
+ }
945
+
946
+ /*
947
+
948
+ For the reasoning behind this please see:
949
+ https://github.com/highlightjs/highlight.js/issues/2880#issuecomment-747275419
950
+
951
+ */
952
+
953
+ /**
954
+ * @type {Record<string, boolean>}
955
+ */
956
+ const seenDeprecations = {};
957
+
958
+ /**
959
+ * @param {string} message
960
+ */
961
+ const error = (message) => {
962
+ console.error(message);
963
+ };
964
+
965
+ /**
966
+ * @param {string} message
967
+ * @param {any} args
968
+ */
969
+ const warn = (message, ...args) => {
970
+ console.log(`WARN: ${message}`, ...args);
971
+ };
972
+
973
+ /**
974
+ * @param {string} version
975
+ * @param {string} message
976
+ */
977
+ const deprecated = (version, message) => {
978
+ if (seenDeprecations[`${version}/${message}`]) return;
979
+
980
+ console.log(`Deprecated as of ${version}. ${message}`);
981
+ seenDeprecations[`${version}/${message}`] = true;
982
+ };
983
+
984
+ /* eslint-disable no-throw-literal */
985
+
986
+ /**
987
+ @typedef {import('highlight.js').CompiledMode} CompiledMode
988
+ */
989
+
990
+ const MultiClassError = new Error();
991
+
992
+ /**
993
+ * Renumbers labeled scope names to account for additional inner match
994
+ * groups that otherwise would break everything.
995
+ *
996
+ * Lets say we 3 match scopes:
997
+ *
998
+ * { 1 => ..., 2 => ..., 3 => ... }
999
+ *
1000
+ * So what we need is a clean match like this:
1001
+ *
1002
+ * (a)(b)(c) => [ "a", "b", "c" ]
1003
+ *
1004
+ * But this falls apart with inner match groups:
1005
+ *
1006
+ * (a)(((b)))(c) => ["a", "b", "b", "b", "c" ]
1007
+ *
1008
+ * Our scopes are now "out of alignment" and we're repeating `b` 3 times.
1009
+ * What needs to happen is the numbers are remapped:
1010
+ *
1011
+ * { 1 => ..., 2 => ..., 5 => ... }
1012
+ *
1013
+ * We also need to know that the ONLY groups that should be output
1014
+ * are 1, 2, and 5. This function handles this behavior.
1015
+ *
1016
+ * @param {CompiledMode} mode
1017
+ * @param {Array<RegExp>} regexes
1018
+ * @param {{key: "beginScope"|"endScope"}} opts
1019
+ */
1020
+ function remapScopeNames(mode, regexes, { key }) {
1021
+ let offset = 0;
1022
+ const scopeNames = mode[key];
1023
+ /** @type Record<number,boolean> */
1024
+ const emit = {};
1025
+ /** @type Record<number,string> */
1026
+ const positions = {};
1027
+
1028
+ for (let i = 1; i <= regexes.length; i++) {
1029
+ positions[i + offset] = scopeNames[i];
1030
+ emit[i + offset] = true;
1031
+ offset += countMatchGroups(regexes[i - 1]);
1032
+ }
1033
+ // we use _emit to keep track of which match groups are "top-level" to avoid double
1034
+ // output from inside match groups
1035
+ mode[key] = positions;
1036
+ mode[key]._emit = emit;
1037
+ mode[key]._multi = true;
1038
+ }
1039
+
1040
+ /**
1041
+ * @param {CompiledMode} mode
1042
+ */
1043
+ function beginMultiClass(mode) {
1044
+ if (!Array.isArray(mode.begin)) return;
1045
+
1046
+ if (mode.skip || mode.excludeBegin || mode.returnBegin) {
1047
+ error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
1048
+ throw MultiClassError;
1049
+ }
1050
+
1051
+ if (typeof mode.beginScope !== "object" || mode.beginScope === null) {
1052
+ error("beginScope must be object");
1053
+ throw MultiClassError;
1054
+ }
1055
+
1056
+ remapScopeNames(mode, mode.begin, {key: "beginScope"});
1057
+ mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
1058
+ }
1059
+
1060
+ /**
1061
+ * @param {CompiledMode} mode
1062
+ */
1063
+ function endMultiClass(mode) {
1064
+ if (!Array.isArray(mode.end)) return;
1065
+
1066
+ if (mode.skip || mode.excludeEnd || mode.returnEnd) {
1067
+ error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
1068
+ throw MultiClassError;
1069
+ }
1070
+
1071
+ if (typeof mode.endScope !== "object" || mode.endScope === null) {
1072
+ error("endScope must be object");
1073
+ throw MultiClassError;
1074
+ }
1075
+
1076
+ remapScopeNames(mode, mode.end, {key: "endScope"});
1077
+ mode.end = _rewriteBackreferences(mode.end, { joinWith: "" });
1078
+ }
1079
+
1080
+ /**
1081
+ * this exists only to allow `scope: {}` to be used beside `match:`
1082
+ * Otherwise `beginScope` would necessary and that would look weird
1083
+
1084
+ {
1085
+ match: [ /def/, /\w+/ ]
1086
+ scope: { 1: "keyword" , 2: "title" }
1087
+ }
1088
+
1089
+ * @param {CompiledMode} mode
1090
+ */
1091
+ function scopeSugar(mode) {
1092
+ if (mode.scope && typeof mode.scope === "object" && mode.scope !== null) {
1093
+ mode.beginScope = mode.scope;
1094
+ delete mode.scope;
1095
+ }
1096
+ }
1097
+
1098
+ /**
1099
+ * @param {CompiledMode} mode
1100
+ */
1101
+ function MultiClass(mode) {
1102
+ scopeSugar(mode);
1103
+
1104
+ if (typeof mode.beginScope === "string") {
1105
+ mode.beginScope = { _wrap: mode.beginScope };
1106
+ }
1107
+ if (typeof mode.endScope === "string") {
1108
+ mode.endScope = { _wrap: mode.endScope };
1109
+ }
1110
+
1111
+ beginMultiClass(mode);
1112
+ endMultiClass(mode);
1113
+ }
1114
+
1115
+ /**
1116
+ @typedef {import('highlight.js').Mode} Mode
1117
+ @typedef {import('highlight.js').CompiledMode} CompiledMode
1118
+ @typedef {import('highlight.js').Language} Language
1119
+ @typedef {import('highlight.js').HLJSPlugin} HLJSPlugin
1120
+ @typedef {import('highlight.js').CompiledLanguage} CompiledLanguage
1121
+ */
1122
+
1123
+ // compilation
1124
+
1125
+ /**
1126
+ * Compiles a language definition result
1127
+ *
1128
+ * Given the raw result of a language definition (Language), compiles this so
1129
+ * that it is ready for highlighting code.
1130
+ * @param {Language} language
1131
+ * @returns {CompiledLanguage}
1132
+ */
1133
+ function compileLanguage(language) {
1134
+ /**
1135
+ * Builds a regex with the case sensitivity of the current language
1136
+ *
1137
+ * @param {RegExp | string} value
1138
+ * @param {boolean} [global]
1139
+ */
1140
+ function langRe(value, global) {
1141
+ return new RegExp(
1142
+ source(value),
1143
+ 'm' + (language.case_insensitive ? 'i' : '') + (language.unicodeRegex ? 'u' : '') + (global ? 'g' : '')
1144
+ );
1145
+ }
1146
+
1147
+ /**
1148
+ Stores multiple regular expressions and allows you to quickly search for
1149
+ them all in a string simultaneously - returning the first match. It does
1150
+ this by creating a huge (a|b|c) regex - each individual item wrapped with ()
1151
+ and joined by `|` - using match groups to track position. When a match is
1152
+ found checking which position in the array has content allows us to figure
1153
+ out which of the original regexes / match groups triggered the match.
1154
+
1155
+ The match object itself (the result of `Regex.exec`) is returned but also
1156
+ enhanced by merging in any meta-data that was registered with the regex.
1157
+ This is how we keep track of which mode matched, and what type of rule
1158
+ (`illegal`, `begin`, end, etc).
1159
+ */
1160
+ class MultiRegex {
1161
+ constructor() {
1162
+ this.matchIndexes = {};
1163
+ // @ts-ignore
1164
+ this.regexes = [];
1165
+ this.matchAt = 1;
1166
+ this.position = 0;
1167
+ }
1168
+
1169
+ // @ts-ignore
1170
+ addRule(re, opts) {
1171
+ opts.position = this.position++;
1172
+ // @ts-ignore
1173
+ this.matchIndexes[this.matchAt] = opts;
1174
+ this.regexes.push([opts, re]);
1175
+ this.matchAt += countMatchGroups(re) + 1;
1176
+ }
1177
+
1178
+ compile() {
1179
+ if (this.regexes.length === 0) {
1180
+ // avoids the need to check length every time exec is called
1181
+ // @ts-ignore
1182
+ this.exec = () => null;
1183
+ }
1184
+ const terminators = this.regexes.map(el => el[1]);
1185
+ this.matcherRe = langRe(_rewriteBackreferences(terminators, { joinWith: '|' }), true);
1186
+ this.lastIndex = 0;
1187
+ }
1188
+
1189
+ /** @param {string} s */
1190
+ exec(s) {
1191
+ this.matcherRe.lastIndex = this.lastIndex;
1192
+ const match = this.matcherRe.exec(s);
1193
+ if (!match) { return null; }
1194
+
1195
+ // eslint-disable-next-line no-undefined
1196
+ const i = match.findIndex((el, i) => i > 0 && el !== undefined);
1197
+ // @ts-ignore
1198
+ const matchData = this.matchIndexes[i];
1199
+ // trim off any earlier non-relevant match groups (ie, the other regex
1200
+ // match groups that make up the multi-matcher)
1201
+ match.splice(0, i);
1202
+
1203
+ return Object.assign(match, matchData);
1204
+ }
1205
+ }
1206
+
1207
+ /*
1208
+ Created to solve the key deficiently with MultiRegex - there is no way to
1209
+ test for multiple matches at a single location. Why would we need to do
1210
+ that? In the future a more dynamic engine will allow certain matches to be
1211
+ ignored. An example: if we matched say the 3rd regex in a large group but
1212
+ decided to ignore it - we'd need to started testing again at the 4th
1213
+ regex... but MultiRegex itself gives us no real way to do that.
1214
+
1215
+ So what this class creates MultiRegexs on the fly for whatever search
1216
+ position they are needed.
1217
+
1218
+ NOTE: These additional MultiRegex objects are created dynamically. For most
1219
+ grammars most of the time we will never actually need anything more than the
1220
+ first MultiRegex - so this shouldn't have too much overhead.
1221
+
1222
+ Say this is our search group, and we match regex3, but wish to ignore it.
1223
+
1224
+ regex1 | regex2 | regex3 | regex4 | regex5 ' ie, startAt = 0
1225
+
1226
+ What we need is a new MultiRegex that only includes the remaining
1227
+ possibilities:
1228
+
1229
+ regex4 | regex5 ' ie, startAt = 3
1230
+
1231
+ This class wraps all that complexity up in a simple API... `startAt` decides
1232
+ where in the array of expressions to start doing the matching. It
1233
+ auto-increments, so if a match is found at position 2, then startAt will be
1234
+ set to 3. If the end is reached startAt will return to 0.
1235
+
1236
+ MOST of the time the parser will be setting startAt manually to 0.
1237
+ */
1238
+ class ResumableMultiRegex {
1239
+ constructor() {
1240
+ // @ts-ignore
1241
+ this.rules = [];
1242
+ // @ts-ignore
1243
+ this.multiRegexes = [];
1244
+ this.count = 0;
1245
+
1246
+ this.lastIndex = 0;
1247
+ this.regexIndex = 0;
1248
+ }
1249
+
1250
+ // @ts-ignore
1251
+ getMatcher(index) {
1252
+ if (this.multiRegexes[index]) return this.multiRegexes[index];
1253
+
1254
+ const matcher = new MultiRegex();
1255
+ this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
1256
+ matcher.compile();
1257
+ this.multiRegexes[index] = matcher;
1258
+ return matcher;
1259
+ }
1260
+
1261
+ resumingScanAtSamePosition() {
1262
+ return this.regexIndex !== 0;
1263
+ }
1264
+
1265
+ considerAll() {
1266
+ this.regexIndex = 0;
1267
+ }
1268
+
1269
+ // @ts-ignore
1270
+ addRule(re, opts) {
1271
+ this.rules.push([re, opts]);
1272
+ if (opts.type === "begin") this.count++;
1273
+ }
1274
+
1275
+ /** @param {string} s */
1276
+ exec(s) {
1277
+ const m = this.getMatcher(this.regexIndex);
1278
+ m.lastIndex = this.lastIndex;
1279
+ let result = m.exec(s);
1280
+
1281
+ // The following is because we have no easy way to say "resume scanning at the
1282
+ // existing position but also skip the current rule ONLY". What happens is
1283
+ // all prior rules are also skipped which can result in matching the wrong
1284
+ // thing. Example of matching "booger":
1285
+
1286
+ // our matcher is [string, "booger", number]
1287
+ //
1288
+ // ....booger....
1289
+
1290
+ // if "booger" is ignored then we'd really need a regex to scan from the
1291
+ // SAME position for only: [string, number] but ignoring "booger" (if it
1292
+ // was the first match), a simple resume would scan ahead who knows how
1293
+ // far looking only for "number", ignoring potential string matches (or
1294
+ // future "booger" matches that might be valid.)
1295
+
1296
+ // So what we do: We execute two matchers, one resuming at the same
1297
+ // position, but the second full matcher starting at the position after:
1298
+
1299
+ // /--- resume first regex match here (for [number])
1300
+ // |/---- full match here for [string, "booger", number]
1301
+ // vv
1302
+ // ....booger....
1303
+
1304
+ // Which ever results in a match first is then used. So this 3-4 step
1305
+ // process essentially allows us to say "match at this position, excluding
1306
+ // a prior rule that was ignored".
1307
+ //
1308
+ // 1. Match "booger" first, ignore. Also proves that [string] does non match.
1309
+ // 2. Resume matching for [number]
1310
+ // 3. Match at index + 1 for [string, "booger", number]
1311
+ // 4. If #2 and #3 result in matches, which came first?
1312
+ if (this.resumingScanAtSamePosition()) {
1313
+ if (result && result.index === this.lastIndex) ; else { // use the second matcher result
1314
+ const m2 = this.getMatcher(0);
1315
+ m2.lastIndex = this.lastIndex + 1;
1316
+ result = m2.exec(s);
1317
+ }
1318
+ }
1319
+
1320
+ if (result) {
1321
+ this.regexIndex += result.position + 1;
1322
+ if (this.regexIndex === this.count) {
1323
+ // wrap-around to considering all matches again
1324
+ this.considerAll();
1325
+ }
1326
+ }
1327
+
1328
+ return result;
1329
+ }
1330
+ }
1331
+
1332
+ /**
1333
+ * Given a mode, builds a huge ResumableMultiRegex that can be used to walk
1334
+ * the content and find matches.
1335
+ *
1336
+ * @param {CompiledMode} mode
1337
+ * @returns {ResumableMultiRegex}
1338
+ */
1339
+ function buildModeRegex(mode) {
1340
+ const mm = new ResumableMultiRegex();
1341
+
1342
+ mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: "begin" }));
1343
+
1344
+ if (mode.terminatorEnd) {
1345
+ mm.addRule(mode.terminatorEnd, { type: "end" });
1346
+ }
1347
+ if (mode.illegal) {
1348
+ mm.addRule(mode.illegal, { type: "illegal" });
1349
+ }
1350
+
1351
+ return mm;
1352
+ }
1353
+
1354
+ /** skip vs abort vs ignore
1355
+ *
1356
+ * @skip - The mode is still entered and exited normally (and contains rules apply),
1357
+ * but all content is held and added to the parent buffer rather than being
1358
+ * output when the mode ends. Mostly used with `sublanguage` to build up
1359
+ * a single large buffer than can be parsed by sublanguage.
1360
+ *
1361
+ * - The mode begin ands ends normally.
1362
+ * - Content matched is added to the parent mode buffer.
1363
+ * - The parser cursor is moved forward normally.
1364
+ *
1365
+ * @abort - A hack placeholder until we have ignore. Aborts the mode (as if it
1366
+ * never matched) but DOES NOT continue to match subsequent `contains`
1367
+ * modes. Abort is bad/suboptimal because it can result in modes
1368
+ * farther down not getting applied because an earlier rule eats the
1369
+ * content but then aborts.
1370
+ *
1371
+ * - The mode does not begin.
1372
+ * - Content matched by `begin` is added to the mode buffer.
1373
+ * - The parser cursor is moved forward accordingly.
1374
+ *
1375
+ * @ignore - Ignores the mode (as if it never matched) and continues to match any
1376
+ * subsequent `contains` modes. Ignore isn't technically possible with
1377
+ * the current parser implementation.
1378
+ *
1379
+ * - The mode does not begin.
1380
+ * - Content matched by `begin` is ignored.
1381
+ * - The parser cursor is not moved forward.
1382
+ */
1383
+
1384
+ /**
1385
+ * Compiles an individual mode
1386
+ *
1387
+ * This can raise an error if the mode contains certain detectable known logic
1388
+ * issues.
1389
+ * @param {Mode} mode
1390
+ * @param {CompiledMode | null} [parent]
1391
+ * @returns {CompiledMode | never}
1392
+ */
1393
+ function compileMode(mode, parent) {
1394
+ const cmode = /** @type CompiledMode */ (mode);
1395
+ if (mode.isCompiled) return cmode;
1396
+
1397
+ [
1398
+ scopeClassName,
1399
+ // do this early so compiler extensions generally don't have to worry about
1400
+ // the distinction between match/begin
1401
+ compileMatch,
1402
+ MultiClass,
1403
+ beforeMatchExt
1404
+ ].forEach(ext => ext(mode, parent));
1405
+
1406
+ language.compilerExtensions.forEach(ext => ext(mode, parent));
1407
+
1408
+ // __beforeBegin is considered private API, internal use only
1409
+ mode.__beforeBegin = null;
1410
+
1411
+ [
1412
+ beginKeywords,
1413
+ // do this later so compiler extensions that come earlier have access to the
1414
+ // raw array if they wanted to perhaps manipulate it, etc.
1415
+ compileIllegal,
1416
+ // default to 1 relevance if not specified
1417
+ compileRelevance
1418
+ ].forEach(ext => ext(mode, parent));
1419
+
1420
+ mode.isCompiled = true;
1421
+
1422
+ let keywordPattern = null;
1423
+ if (typeof mode.keywords === "object" && mode.keywords.$pattern) {
1424
+ // we need a copy because keywords might be compiled multiple times
1425
+ // so we can't go deleting $pattern from the original on the first
1426
+ // pass
1427
+ mode.keywords = Object.assign({}, mode.keywords);
1428
+ keywordPattern = mode.keywords.$pattern;
1429
+ delete mode.keywords.$pattern;
1430
+ }
1431
+ keywordPattern = keywordPattern || /\w+/;
1432
+
1433
+ if (mode.keywords) {
1434
+ mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
1435
+ }
1436
+
1437
+ cmode.keywordPatternRe = langRe(keywordPattern, true);
1438
+
1439
+ if (parent) {
1440
+ if (!mode.begin) mode.begin = /\B|\b/;
1441
+ cmode.beginRe = langRe(mode.begin);
1442
+ if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
1443
+ if (mode.end) cmode.endRe = langRe(mode.end);
1444
+ cmode.terminatorEnd = source(mode.end) || '';
1445
+ if (mode.endsWithParent && parent.terminatorEnd) {
1446
+ cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;
1447
+ }
1448
+ }
1449
+ if (mode.illegal) cmode.illegalRe = langRe(/** @type {RegExp | string} */ (mode.illegal));
1450
+ if (!mode.contains) mode.contains = [];
1451
+
1452
+ mode.contains = [].concat(...mode.contains.map(function(c) {
1453
+ return expandOrCloneMode(c === 'self' ? mode : c);
1454
+ }));
1455
+ mode.contains.forEach(function(c) { compileMode(/** @type Mode */ (c), cmode); });
1456
+
1457
+ if (mode.starts) {
1458
+ compileMode(mode.starts, parent);
1459
+ }
1460
+
1461
+ cmode.matcher = buildModeRegex(cmode);
1462
+ return cmode;
1463
+ }
1464
+
1465
+ if (!language.compilerExtensions) language.compilerExtensions = [];
1466
+
1467
+ // self is not valid at the top-level
1468
+ if (language.contains && language.contains.includes('self')) {
1469
+ throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
1470
+ }
1471
+
1472
+ // we need a null object, which inherit will guarantee
1473
+ language.classNameAliases = inherit$1(language.classNameAliases || {});
1474
+
1475
+ return compileMode(/** @type Mode */ (language));
1476
+ }
1477
+
1478
+ /**
1479
+ * Determines if a mode has a dependency on it's parent or not
1480
+ *
1481
+ * If a mode does have a parent dependency then often we need to clone it if
1482
+ * it's used in multiple places so that each copy points to the correct parent,
1483
+ * where-as modes without a parent can often safely be re-used at the bottom of
1484
+ * a mode chain.
1485
+ *
1486
+ * @param {Mode | null} mode
1487
+ * @returns {boolean} - is there a dependency on the parent?
1488
+ * */
1489
+ function dependencyOnParent(mode) {
1490
+ if (!mode) return false;
1491
+
1492
+ return mode.endsWithParent || dependencyOnParent(mode.starts);
1493
+ }
1494
+
1495
+ /**
1496
+ * Expands a mode or clones it if necessary
1497
+ *
1498
+ * This is necessary for modes with parental dependenceis (see notes on
1499
+ * `dependencyOnParent`) and for nodes that have `variants` - which must then be
1500
+ * exploded into their own individual modes at compile time.
1501
+ *
1502
+ * @param {Mode} mode
1503
+ * @returns {Mode | Mode[]}
1504
+ * */
1505
+ function expandOrCloneMode(mode) {
1506
+ if (mode.variants && !mode.cachedVariants) {
1507
+ mode.cachedVariants = mode.variants.map(function(variant) {
1508
+ return inherit$1(mode, { variants: null }, variant);
1509
+ });
1510
+ }
1511
+
1512
+ // EXPAND
1513
+ // if we have variants then essentially "replace" the mode with the variants
1514
+ // this happens in compileMode, where this function is called from
1515
+ if (mode.cachedVariants) {
1516
+ return mode.cachedVariants;
1517
+ }
1518
+
1519
+ // CLONE
1520
+ // if we have dependencies on parents then we need a unique
1521
+ // instance of ourselves, so we can be reused with many
1522
+ // different parents without issue
1523
+ if (dependencyOnParent(mode)) {
1524
+ return inherit$1(mode, { starts: mode.starts ? inherit$1(mode.starts) : null });
1525
+ }
1526
+
1527
+ if (Object.isFrozen(mode)) {
1528
+ return inherit$1(mode);
1529
+ }
1530
+
1531
+ // no special dependency issues, just return ourselves
1532
+ return mode;
1533
+ }
1534
+
1535
+ var version = "11.2.0";
1536
+
1537
+ /*
1538
+ Syntax highlighting with language autodetection.
1539
+ https://highlightjs.org/
1540
+ */
1541
+
1542
+ /**
1543
+ @typedef {import('highlight.js').Mode} Mode
1544
+ @typedef {import('highlight.js').CompiledMode} CompiledMode
1545
+ @typedef {import('highlight.js').Language} Language
1546
+ @typedef {import('highlight.js').HLJSApi} HLJSApi
1547
+ @typedef {import('highlight.js').HLJSPlugin} HLJSPlugin
1548
+ @typedef {import('highlight.js').PluginEvent} PluginEvent
1549
+ @typedef {import('highlight.js').HLJSOptions} HLJSOptions
1550
+ @typedef {import('highlight.js').LanguageFn} LanguageFn
1551
+ @typedef {import('highlight.js').HighlightedHTMLElement} HighlightedHTMLElement
1552
+ @typedef {import('highlight.js').BeforeHighlightContext} BeforeHighlightContext
1553
+ @typedef {import('highlight.js/private').MatchType} MatchType
1554
+ @typedef {import('highlight.js/private').KeywordData} KeywordData
1555
+ @typedef {import('highlight.js/private').EnhancedMatch} EnhancedMatch
1556
+ @typedef {import('highlight.js/private').AnnotatedError} AnnotatedError
1557
+ @typedef {import('highlight.js').AutoHighlightResult} AutoHighlightResult
1558
+ @typedef {import('highlight.js').HighlightOptions} HighlightOptions
1559
+ @typedef {import('highlight.js').HighlightResult} HighlightResult
1560
+ */
1561
+
1562
+
1563
+ const escape = escapeHTML;
1564
+ const inherit = inherit$1;
1565
+ const NO_MATCH = Symbol("nomatch");
1566
+ const MAX_KEYWORD_HITS = 7;
1567
+
1568
+ /**
1569
+ * @param {any} hljs - object that is extended (legacy)
1570
+ * @returns {HLJSApi}
1571
+ */
1572
+ const HLJS = function(hljs) {
1573
+ // Global internal variables used within the highlight.js library.
1574
+ /** @type {Record<string, Language>} */
1575
+ const languages = Object.create(null);
1576
+ /** @type {Record<string, string>} */
1577
+ const aliases = Object.create(null);
1578
+ /** @type {HLJSPlugin[]} */
1579
+ const plugins = [];
1580
+
1581
+ // safe/production mode - swallows more errors, tries to keep running
1582
+ // even if a single syntax or parse hits a fatal error
1583
+ let SAFE_MODE = true;
1584
+ const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
1585
+ /** @type {Language} */
1586
+ const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text', contains: [] };
1587
+
1588
+ // Global options used when within external APIs. This is modified when
1589
+ // calling the `hljs.configure` function.
1590
+ /** @type HLJSOptions */
1591
+ let options = {
1592
+ ignoreUnescapedHTML: false,
1593
+ noHighlightRe: /^(no-?highlight)$/i,
1594
+ languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
1595
+ classPrefix: 'hljs-',
1596
+ cssSelector: 'pre code',
1597
+ languages: null,
1598
+ // beta configuration options, subject to change, welcome to discuss
1599
+ // https://github.com/highlightjs/highlight.js/issues/1086
1600
+ __emitter: TokenTreeEmitter
1601
+ };
1602
+
1603
+ /* Utility functions */
1604
+
1605
+ /**
1606
+ * Tests a language name to see if highlighting should be skipped
1607
+ * @param {string} languageName
1608
+ */
1609
+ function shouldNotHighlight(languageName) {
1610
+ return options.noHighlightRe.test(languageName);
1611
+ }
1612
+
1613
+ /**
1614
+ * @param {HighlightedHTMLElement} block - the HTML element to determine language for
1615
+ */
1616
+ function blockLanguage(block) {
1617
+ let classes = block.className + ' ';
1618
+
1619
+ classes += block.parentNode ? block.parentNode.className : '';
1620
+
1621
+ // language-* takes precedence over non-prefixed class names.
1622
+ const match = options.languageDetectRe.exec(classes);
1623
+ if (match) {
1624
+ const language = getLanguage(match[1]);
1625
+ if (!language) {
1626
+ warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
1627
+ warn("Falling back to no-highlight mode for this block.", block);
1628
+ }
1629
+ return language ? match[1] : 'no-highlight';
1630
+ }
1631
+
1632
+ return classes
1633
+ .split(/\s+/)
1634
+ .find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
1635
+ }
1636
+
1637
+ /**
1638
+ * Core highlighting function.
1639
+ *
1640
+ * OLD API
1641
+ * highlight(lang, code, ignoreIllegals, continuation)
1642
+ *
1643
+ * NEW API
1644
+ * highlight(code, {lang, ignoreIllegals})
1645
+ *
1646
+ * @param {string} codeOrLanguageName - the language to use for highlighting
1647
+ * @param {string | HighlightOptions} optionsOrCode - the code to highlight
1648
+ * @param {boolean} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
1649
+ *
1650
+ * @returns {HighlightResult} Result - an object that represents the result
1651
+ * @property {string} language - the language name
1652
+ * @property {number} relevance - the relevance score
1653
+ * @property {string} value - the highlighted HTML code
1654
+ * @property {string} code - the original raw code
1655
+ * @property {CompiledMode} top - top of the current mode stack
1656
+ * @property {boolean} illegal - indicates whether any illegal matches were found
1657
+ */
1658
+ function highlight(codeOrLanguageName, optionsOrCode, ignoreIllegals) {
1659
+ let code = "";
1660
+ let languageName = "";
1661
+ if (typeof optionsOrCode === "object") {
1662
+ code = codeOrLanguageName;
1663
+ ignoreIllegals = optionsOrCode.ignoreIllegals;
1664
+ languageName = optionsOrCode.language;
1665
+ } else {
1666
+ // old API
1667
+ deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
1668
+ deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
1669
+ languageName = codeOrLanguageName;
1670
+ code = optionsOrCode;
1671
+ }
1672
+
1673
+ // https://github.com/highlightjs/highlight.js/issues/3149
1674
+ // eslint-disable-next-line no-undefined
1675
+ if (ignoreIllegals === undefined) { ignoreIllegals = true; }
1676
+
1677
+ /** @type {BeforeHighlightContext} */
1678
+ const context = {
1679
+ code,
1680
+ language: languageName
1681
+ };
1682
+ // the plugin can change the desired language or the code to be highlighted
1683
+ // just be changing the object it was passed
1684
+ fire("before:highlight", context);
1685
+
1686
+ // a before plugin can usurp the result completely by providing it's own
1687
+ // in which case we don't even need to call highlight
1688
+ const result = context.result
1689
+ ? context.result
1690
+ : _highlight(context.language, context.code, ignoreIllegals);
1691
+
1692
+ result.code = context.code;
1693
+ // the plugin can change anything in result to suite it
1694
+ fire("after:highlight", result);
1695
+
1696
+ return result;
1697
+ }
1698
+
1699
+ /**
1700
+ * private highlight that's used internally and does not fire callbacks
1701
+ *
1702
+ * @param {string} languageName - the language to use for highlighting
1703
+ * @param {string} codeToHighlight - the code to highlight
1704
+ * @param {boolean?} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
1705
+ * @param {CompiledMode?} [continuation] - current continuation mode, if any
1706
+ * @returns {HighlightResult} - result of the highlight operation
1707
+ */
1708
+ function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
1709
+ const keywordHits = Object.create(null);
1710
+
1711
+ /**
1712
+ * Return keyword data if a match is a keyword
1713
+ * @param {CompiledMode} mode - current mode
1714
+ * @param {string} matchText - the textual match
1715
+ * @returns {KeywordData | false}
1716
+ */
1717
+ function keywordData(mode, matchText) {
1718
+ return mode.keywords[matchText];
1719
+ }
1720
+
1721
+ function processKeywords() {
1722
+ if (!top.keywords) {
1723
+ emitter.addText(modeBuffer);
1724
+ return;
1725
+ }
1726
+
1727
+ let lastIndex = 0;
1728
+ top.keywordPatternRe.lastIndex = 0;
1729
+ let match = top.keywordPatternRe.exec(modeBuffer);
1730
+ let buf = "";
1731
+
1732
+ while (match) {
1733
+ buf += modeBuffer.substring(lastIndex, match.index);
1734
+ const word = language.case_insensitive ? match[0].toLowerCase() : match[0];
1735
+ const data = keywordData(top, word);
1736
+ if (data) {
1737
+ const [kind, keywordRelevance] = data;
1738
+ emitter.addText(buf);
1739
+ buf = "";
1740
+
1741
+ keywordHits[word] = (keywordHits[word] || 0) + 1;
1742
+ if (keywordHits[word] <= MAX_KEYWORD_HITS) relevance += keywordRelevance;
1743
+ if (kind.startsWith("_")) {
1744
+ // _ implied for relevance only, do not highlight
1745
+ // by applying a class name
1746
+ buf += match[0];
1747
+ } else {
1748
+ const cssClass = language.classNameAliases[kind] || kind;
1749
+ emitter.addKeyword(match[0], cssClass);
1750
+ }
1751
+ } else {
1752
+ buf += match[0];
1753
+ }
1754
+ lastIndex = top.keywordPatternRe.lastIndex;
1755
+ match = top.keywordPatternRe.exec(modeBuffer);
1756
+ }
1757
+ buf += modeBuffer.substr(lastIndex);
1758
+ emitter.addText(buf);
1759
+ }
1760
+
1761
+ function processSubLanguage() {
1762
+ if (modeBuffer === "") return;
1763
+ /** @type HighlightResult */
1764
+ let result = null;
1765
+
1766
+ if (typeof top.subLanguage === 'string') {
1767
+ if (!languages[top.subLanguage]) {
1768
+ emitter.addText(modeBuffer);
1769
+ return;
1770
+ }
1771
+ result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
1772
+ continuations[top.subLanguage] = /** @type {CompiledMode} */ (result._top);
1773
+ } else {
1774
+ result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
1775
+ }
1776
+
1777
+ // Counting embedded language score towards the host language may be disabled
1778
+ // with zeroing the containing mode relevance. Use case in point is Markdown that
1779
+ // allows XML everywhere and makes every XML snippet to have a much larger Markdown
1780
+ // score.
1781
+ if (top.relevance > 0) {
1782
+ relevance += result.relevance;
1783
+ }
1784
+ emitter.addSublanguage(result._emitter, result.language);
1785
+ }
1786
+
1787
+ function processBuffer() {
1788
+ if (top.subLanguage != null) {
1789
+ processSubLanguage();
1790
+ } else {
1791
+ processKeywords();
1792
+ }
1793
+ modeBuffer = '';
1794
+ }
1795
+
1796
+ /**
1797
+ * @param {CompiledMode} mode
1798
+ * @param {RegExpMatchArray} match
1799
+ */
1800
+ function emitMultiClass(scope, match) {
1801
+ let i = 1;
1802
+ // eslint-disable-next-line no-undefined
1803
+ while (match[i] !== undefined) {
1804
+ if (!scope._emit[i]) { i++; continue; }
1805
+ const klass = language.classNameAliases[scope[i]] || scope[i];
1806
+ const text = match[i];
1807
+ if (klass) {
1808
+ emitter.addKeyword(text, klass);
1809
+ } else {
1810
+ modeBuffer = text;
1811
+ processKeywords();
1812
+ modeBuffer = "";
1813
+ }
1814
+ i++;
1815
+ }
1816
+ }
1817
+
1818
+ /**
1819
+ * @param {CompiledMode} mode - new mode to start
1820
+ * @param {RegExpMatchArray} match
1821
+ */
1822
+ function startNewMode(mode, match) {
1823
+ if (mode.scope && typeof mode.scope === "string") {
1824
+ emitter.openNode(language.classNameAliases[mode.scope] || mode.scope);
1825
+ }
1826
+ if (mode.beginScope) {
1827
+ // beginScope just wraps the begin match itself in a scope
1828
+ if (mode.beginScope._wrap) {
1829
+ emitter.addKeyword(modeBuffer, language.classNameAliases[mode.beginScope._wrap] || mode.beginScope._wrap);
1830
+ modeBuffer = "";
1831
+ } else if (mode.beginScope._multi) {
1832
+ // at this point modeBuffer should just be the match
1833
+ emitMultiClass(mode.beginScope, match);
1834
+ modeBuffer = "";
1835
+ }
1836
+ }
1837
+
1838
+ top = Object.create(mode, { parent: { value: top } });
1839
+ return top;
1840
+ }
1841
+
1842
+ /**
1843
+ * @param {CompiledMode } mode - the mode to potentially end
1844
+ * @param {RegExpMatchArray} match - the latest match
1845
+ * @param {string} matchPlusRemainder - match plus remainder of content
1846
+ * @returns {CompiledMode | void} - the next mode, or if void continue on in current mode
1847
+ */
1848
+ function endOfMode(mode, match, matchPlusRemainder) {
1849
+ let matched = startsWith(mode.endRe, matchPlusRemainder);
1850
+
1851
+ if (matched) {
1852
+ if (mode["on:end"]) {
1853
+ const resp = new Response(mode);
1854
+ mode["on:end"](match, resp);
1855
+ if (resp.isMatchIgnored) matched = false;
1856
+ }
1857
+
1858
+ if (matched) {
1859
+ while (mode.endsParent && mode.parent) {
1860
+ mode = mode.parent;
1861
+ }
1862
+ return mode;
1863
+ }
1864
+ }
1865
+ // even if on:end fires an `ignore` it's still possible
1866
+ // that we might trigger the end node because of a parent mode
1867
+ if (mode.endsWithParent) {
1868
+ return endOfMode(mode.parent, match, matchPlusRemainder);
1869
+ }
1870
+ }
1871
+
1872
+ /**
1873
+ * Handle matching but then ignoring a sequence of text
1874
+ *
1875
+ * @param {string} lexeme - string containing full match text
1876
+ */
1877
+ function doIgnore(lexeme) {
1878
+ if (top.matcher.regexIndex === 0) {
1879
+ // no more regexes to potentially match here, so we move the cursor forward one
1880
+ // space
1881
+ modeBuffer += lexeme[0];
1882
+ return 1;
1883
+ } else {
1884
+ // no need to move the cursor, we still have additional regexes to try and
1885
+ // match at this very spot
1886
+ resumeScanAtSamePosition = true;
1887
+ return 0;
1888
+ }
1889
+ }
1890
+
1891
+ /**
1892
+ * Handle the start of a new potential mode match
1893
+ *
1894
+ * @param {EnhancedMatch} match - the current match
1895
+ * @returns {number} how far to advance the parse cursor
1896
+ */
1897
+ function doBeginMatch(match) {
1898
+ const lexeme = match[0];
1899
+ const newMode = match.rule;
1900
+
1901
+ const resp = new Response(newMode);
1902
+ // first internal before callbacks, then the public ones
1903
+ const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
1904
+ for (const cb of beforeCallbacks) {
1905
+ if (!cb) continue;
1906
+ cb(match, resp);
1907
+ if (resp.isMatchIgnored) return doIgnore(lexeme);
1908
+ }
1909
+
1910
+ if (newMode.skip) {
1911
+ modeBuffer += lexeme;
1912
+ } else {
1913
+ if (newMode.excludeBegin) {
1914
+ modeBuffer += lexeme;
1915
+ }
1916
+ processBuffer();
1917
+ if (!newMode.returnBegin && !newMode.excludeBegin) {
1918
+ modeBuffer = lexeme;
1919
+ }
1920
+ }
1921
+ startNewMode(newMode, match);
1922
+ return newMode.returnBegin ? 0 : lexeme.length;
1923
+ }
1924
+
1925
+ /**
1926
+ * Handle the potential end of mode
1927
+ *
1928
+ * @param {RegExpMatchArray} match - the current match
1929
+ */
1930
+ function doEndMatch(match) {
1931
+ const lexeme = match[0];
1932
+ const matchPlusRemainder = codeToHighlight.substr(match.index);
1933
+
1934
+ const endMode = endOfMode(top, match, matchPlusRemainder);
1935
+ if (!endMode) { return NO_MATCH; }
1936
+
1937
+ const origin = top;
1938
+ if (top.endScope && top.endScope._wrap) {
1939
+ processBuffer();
1940
+ emitter.addKeyword(lexeme, top.endScope._wrap);
1941
+ } else if (top.endScope && top.endScope._multi) {
1942
+ processBuffer();
1943
+ emitMultiClass(top.endScope, match);
1944
+ } else if (origin.skip) {
1945
+ modeBuffer += lexeme;
1946
+ } else {
1947
+ if (!(origin.returnEnd || origin.excludeEnd)) {
1948
+ modeBuffer += lexeme;
1949
+ }
1950
+ processBuffer();
1951
+ if (origin.excludeEnd) {
1952
+ modeBuffer = lexeme;
1953
+ }
1954
+ }
1955
+ do {
1956
+ if (top.scope) {
1957
+ emitter.closeNode();
1958
+ }
1959
+ if (!top.skip && !top.subLanguage) {
1960
+ relevance += top.relevance;
1961
+ }
1962
+ top = top.parent;
1963
+ } while (top !== endMode.parent);
1964
+ if (endMode.starts) {
1965
+ startNewMode(endMode.starts, match);
1966
+ }
1967
+ return origin.returnEnd ? 0 : lexeme.length;
1968
+ }
1969
+
1970
+ function processContinuations() {
1971
+ const list = [];
1972
+ for (let current = top; current !== language; current = current.parent) {
1973
+ if (current.scope) {
1974
+ list.unshift(current.scope);
1975
+ }
1976
+ }
1977
+ list.forEach(item => emitter.openNode(item));
1978
+ }
1979
+
1980
+ /** @type {{type?: MatchType, index?: number, rule?: Mode}}} */
1981
+ let lastMatch = {};
1982
+
1983
+ /**
1984
+ * Process an individual match
1985
+ *
1986
+ * @param {string} textBeforeMatch - text preceding the match (since the last match)
1987
+ * @param {EnhancedMatch} [match] - the match itself
1988
+ */
1989
+ function processLexeme(textBeforeMatch, match) {
1990
+ const lexeme = match && match[0];
1991
+
1992
+ // add non-matched text to the current mode buffer
1993
+ modeBuffer += textBeforeMatch;
1994
+
1995
+ if (lexeme == null) {
1996
+ processBuffer();
1997
+ return 0;
1998
+ }
1999
+
2000
+ // we've found a 0 width match and we're stuck, so we need to advance
2001
+ // this happens when we have badly behaved rules that have optional matchers to the degree that
2002
+ // sometimes they can end up matching nothing at all
2003
+ // Ref: https://github.com/highlightjs/highlight.js/issues/2140
2004
+ if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
2005
+ // spit the "skipped" character that our regex choked on back into the output sequence
2006
+ modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
2007
+ if (!SAFE_MODE) {
2008
+ /** @type {AnnotatedError} */
2009
+ const err = new Error(`0 width match regex (${languageName})`);
2010
+ err.languageName = languageName;
2011
+ err.badRule = lastMatch.rule;
2012
+ throw err;
2013
+ }
2014
+ return 1;
2015
+ }
2016
+ lastMatch = match;
2017
+
2018
+ if (match.type === "begin") {
2019
+ return doBeginMatch(match);
2020
+ } else if (match.type === "illegal" && !ignoreIllegals) {
2021
+ // illegal match, we do not continue processing
2022
+ /** @type {AnnotatedError} */
2023
+ const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.scope || '<unnamed>') + '"');
2024
+ err.mode = top;
2025
+ throw err;
2026
+ } else if (match.type === "end") {
2027
+ const processed = doEndMatch(match);
2028
+ if (processed !== NO_MATCH) {
2029
+ return processed;
2030
+ }
2031
+ }
2032
+
2033
+ // edge case for when illegal matches $ (end of line) which is technically
2034
+ // a 0 width match but not a begin/end match so it's not caught by the
2035
+ // first handler (when ignoreIllegals is true)
2036
+ if (match.type === "illegal" && lexeme === "") {
2037
+ // advance so we aren't stuck in an infinite loop
2038
+ return 1;
2039
+ }
2040
+
2041
+ // infinite loops are BAD, this is a last ditch catch all. if we have a
2042
+ // decent number of iterations yet our index (cursor position in our
2043
+ // parsing) still 3x behind our index then something is very wrong
2044
+ // so we bail
2045
+ if (iterations > 100000 && iterations > match.index * 3) {
2046
+ const err = new Error('potential infinite loop, way more iterations than matches');
2047
+ throw err;
2048
+ }
2049
+
2050
+ /*
2051
+ Why might be find ourselves here? An potential end match that was
2052
+ triggered but could not be completed. IE, `doEndMatch` returned NO_MATCH.
2053
+ (this could be because a callback requests the match be ignored, etc)
2054
+
2055
+ This causes no real harm other than stopping a few times too many.
2056
+ */
2057
+
2058
+ modeBuffer += lexeme;
2059
+ return lexeme.length;
2060
+ }
2061
+
2062
+ const language = getLanguage(languageName);
2063
+ if (!language) {
2064
+ error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
2065
+ throw new Error('Unknown language: "' + languageName + '"');
2066
+ }
2067
+
2068
+ const md = compileLanguage(language);
2069
+ let result = '';
2070
+ /** @type {CompiledMode} */
2071
+ let top = continuation || md;
2072
+ /** @type Record<string,CompiledMode> */
2073
+ const continuations = {}; // keep continuations for sub-languages
2074
+ const emitter = new options.__emitter(options);
2075
+ processContinuations();
2076
+ let modeBuffer = '';
2077
+ let relevance = 0;
2078
+ let index = 0;
2079
+ let iterations = 0;
2080
+ let resumeScanAtSamePosition = false;
2081
+
2082
+ try {
2083
+ top.matcher.considerAll();
2084
+
2085
+ for (;;) {
2086
+ iterations++;
2087
+ if (resumeScanAtSamePosition) {
2088
+ // only regexes not matched previously will now be
2089
+ // considered for a potential match
2090
+ resumeScanAtSamePosition = false;
2091
+ } else {
2092
+ top.matcher.considerAll();
2093
+ }
2094
+ top.matcher.lastIndex = index;
2095
+
2096
+ const match = top.matcher.exec(codeToHighlight);
2097
+ // console.log("match", match[0], match.rule && match.rule.begin)
2098
+
2099
+ if (!match) break;
2100
+
2101
+ const beforeMatch = codeToHighlight.substring(index, match.index);
2102
+ const processedCount = processLexeme(beforeMatch, match);
2103
+ index = match.index + processedCount;
2104
+ }
2105
+ processLexeme(codeToHighlight.substr(index));
2106
+ emitter.closeAllNodes();
2107
+ emitter.finalize();
2108
+ result = emitter.toHTML();
2109
+
2110
+ return {
2111
+ language: languageName,
2112
+ value: result,
2113
+ relevance: relevance,
2114
+ illegal: false,
2115
+ _emitter: emitter,
2116
+ _top: top
2117
+ };
2118
+ } catch (err) {
2119
+ if (err.message && err.message.includes('Illegal')) {
2120
+ return {
2121
+ language: languageName,
2122
+ value: escape(codeToHighlight),
2123
+ illegal: true,
2124
+ relevance: 0,
2125
+ _illegalBy: {
2126
+ message: err.message,
2127
+ index: index,
2128
+ context: codeToHighlight.slice(index - 100, index + 100),
2129
+ mode: err.mode,
2130
+ resultSoFar: result
2131
+ },
2132
+ _emitter: emitter
2133
+ };
2134
+ } else if (SAFE_MODE) {
2135
+ return {
2136
+ language: languageName,
2137
+ value: escape(codeToHighlight),
2138
+ illegal: false,
2139
+ relevance: 0,
2140
+ errorRaised: err,
2141
+ _emitter: emitter,
2142
+ _top: top
2143
+ };
2144
+ } else {
2145
+ throw err;
2146
+ }
2147
+ }
2148
+ }
2149
+
2150
+ /**
2151
+ * returns a valid highlight result, without actually doing any actual work,
2152
+ * auto highlight starts with this and it's possible for small snippets that
2153
+ * auto-detection may not find a better match
2154
+ * @param {string} code
2155
+ * @returns {HighlightResult}
2156
+ */
2157
+ function justTextHighlightResult(code) {
2158
+ const result = {
2159
+ value: escape(code),
2160
+ illegal: false,
2161
+ relevance: 0,
2162
+ _top: PLAINTEXT_LANGUAGE,
2163
+ _emitter: new options.__emitter(options)
2164
+ };
2165
+ result._emitter.addText(code);
2166
+ return result;
2167
+ }
2168
+
2169
+ /**
2170
+ Highlighting with language detection. Accepts a string with the code to
2171
+ highlight. Returns an object with the following properties:
2172
+
2173
+ - language (detected language)
2174
+ - relevance (int)
2175
+ - value (an HTML string with highlighting markup)
2176
+ - secondBest (object with the same structure for second-best heuristically
2177
+ detected language, may be absent)
2178
+
2179
+ @param {string} code
2180
+ @param {Array<string>} [languageSubset]
2181
+ @returns {AutoHighlightResult}
2182
+ */
2183
+ function highlightAuto(code, languageSubset) {
2184
+ languageSubset = languageSubset || options.languages || Object.keys(languages);
2185
+ const plaintext = justTextHighlightResult(code);
2186
+
2187
+ const results = languageSubset.filter(getLanguage).filter(autoDetection).map(name =>
2188
+ _highlight(name, code, false)
2189
+ );
2190
+ results.unshift(plaintext); // plaintext is always an option
2191
+
2192
+ const sorted = results.sort((a, b) => {
2193
+ // sort base on relevance
2194
+ if (a.relevance !== b.relevance) return b.relevance - a.relevance;
2195
+
2196
+ // always award the tie to the base language
2197
+ // ie if C++ and Arduino are tied, it's more likely to be C++
2198
+ if (a.language && b.language) {
2199
+ if (getLanguage(a.language).supersetOf === b.language) {
2200
+ return 1;
2201
+ } else if (getLanguage(b.language).supersetOf === a.language) {
2202
+ return -1;
2203
+ }
2204
+ }
2205
+
2206
+ // otherwise say they are equal, which has the effect of sorting on
2207
+ // relevance while preserving the original ordering - which is how ties
2208
+ // have historically been settled, ie the language that comes first always
2209
+ // wins in the case of a tie
2210
+ return 0;
2211
+ });
2212
+
2213
+ const [best, secondBest] = sorted;
2214
+
2215
+ /** @type {AutoHighlightResult} */
2216
+ const result = best;
2217
+ result.secondBest = secondBest;
2218
+
2219
+ return result;
2220
+ }
2221
+
2222
+ /**
2223
+ * Builds new class name for block given the language name
2224
+ *
2225
+ * @param {HTMLElement} element
2226
+ * @param {string} [currentLang]
2227
+ * @param {string} [resultLang]
2228
+ */
2229
+ function updateClassName(element, currentLang, resultLang) {
2230
+ const language = (currentLang && aliases[currentLang]) || resultLang;
2231
+
2232
+ element.classList.add("hljs");
2233
+ element.classList.add(`language-${language}`);
2234
+ }
2235
+
2236
+ /**
2237
+ * Applies highlighting to a DOM node containing code.
2238
+ *
2239
+ * @param {HighlightedHTMLElement} element - the HTML element to highlight
2240
+ */
2241
+ function highlightElement(element) {
2242
+ /** @type HTMLElement */
2243
+ let node = null;
2244
+ const language = blockLanguage(element);
2245
+
2246
+ if (shouldNotHighlight(language)) return;
2247
+
2248
+ fire("before:highlightElement",
2249
+ { el: element, language: language });
2250
+
2251
+ // we should be all text, no child nodes
2252
+ if (!options.ignoreUnescapedHTML && element.children.length > 0) {
2253
+ console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk.");
2254
+ console.warn("https://github.com/highlightjs/highlight.js/issues/2886");
2255
+ console.warn(element);
2256
+ }
2257
+
2258
+ node = element;
2259
+ const text = node.textContent;
2260
+ const result = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text);
2261
+
2262
+ element.innerHTML = result.value;
2263
+ updateClassName(element, language, result.language);
2264
+ element.result = {
2265
+ language: result.language,
2266
+ // TODO: remove with version 11.0
2267
+ re: result.relevance,
2268
+ relevance: result.relevance
2269
+ };
2270
+ if (result.secondBest) {
2271
+ element.secondBest = {
2272
+ language: result.secondBest.language,
2273
+ relevance: result.secondBest.relevance
2274
+ };
2275
+ }
2276
+
2277
+ fire("after:highlightElement", { el: element, result, text });
2278
+ }
2279
+
2280
+ /**
2281
+ * Updates highlight.js global options with the passed options
2282
+ *
2283
+ * @param {Partial<HLJSOptions>} userOptions
2284
+ */
2285
+ function configure(userOptions) {
2286
+ options = inherit(options, userOptions);
2287
+ }
2288
+
2289
+ // TODO: remove v12, deprecated
2290
+ const initHighlighting = () => {
2291
+ highlightAll();
2292
+ deprecated("10.6.0", "initHighlighting() deprecated. Use highlightAll() now.");
2293
+ };
2294
+
2295
+ // TODO: remove v12, deprecated
2296
+ function initHighlightingOnLoad() {
2297
+ highlightAll();
2298
+ deprecated("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now.");
2299
+ }
2300
+
2301
+ let wantsHighlight = false;
2302
+
2303
+ /**
2304
+ * auto-highlights all pre>code elements on the page
2305
+ */
2306
+ function highlightAll() {
2307
+ // if we are called too early in the loading process
2308
+ if (document.readyState === "loading") {
2309
+ wantsHighlight = true;
2310
+ return;
2311
+ }
2312
+
2313
+ const blocks = document.querySelectorAll(options.cssSelector);
2314
+ blocks.forEach(highlightElement);
2315
+ }
2316
+
2317
+ function boot() {
2318
+ // if a highlight was requested before DOM was loaded, do now
2319
+ if (wantsHighlight) highlightAll();
2320
+ }
2321
+
2322
+ // make sure we are in the browser environment
2323
+ if (typeof window !== 'undefined' && window.addEventListener) {
2324
+ window.addEventListener('DOMContentLoaded', boot, false);
2325
+ }
2326
+
2327
+ /**
2328
+ * Register a language grammar module
2329
+ *
2330
+ * @param {string} languageName
2331
+ * @param {LanguageFn} languageDefinition
2332
+ */
2333
+ function registerLanguage(languageName, languageDefinition) {
2334
+ let lang = null;
2335
+ try {
2336
+ lang = languageDefinition(hljs);
2337
+ } catch (error$1) {
2338
+ error("Language definition for '{}' could not be registered.".replace("{}", languageName));
2339
+ // hard or soft error
2340
+ if (!SAFE_MODE) { throw error$1; } else { error(error$1); }
2341
+ // languages that have serious errors are replaced with essentially a
2342
+ // "plaintext" stand-in so that the code blocks will still get normal
2343
+ // css classes applied to them - and one bad language won't break the
2344
+ // entire highlighter
2345
+ lang = PLAINTEXT_LANGUAGE;
2346
+ }
2347
+ // give it a temporary name if it doesn't have one in the meta-data
2348
+ if (!lang.name) lang.name = languageName;
2349
+ languages[languageName] = lang;
2350
+ lang.rawDefinition = languageDefinition.bind(null, hljs);
2351
+
2352
+ if (lang.aliases) {
2353
+ registerAliases(lang.aliases, { languageName });
2354
+ }
2355
+ }
2356
+
2357
+ /**
2358
+ * Remove a language grammar module
2359
+ *
2360
+ * @param {string} languageName
2361
+ */
2362
+ function unregisterLanguage(languageName) {
2363
+ delete languages[languageName];
2364
+ for (const alias of Object.keys(aliases)) {
2365
+ if (aliases[alias] === languageName) {
2366
+ delete aliases[alias];
2367
+ }
2368
+ }
2369
+ }
2370
+
2371
+ /**
2372
+ * @returns {string[]} List of language internal names
2373
+ */
2374
+ function listLanguages() {
2375
+ return Object.keys(languages);
2376
+ }
2377
+
2378
+ /**
2379
+ * @param {string} name - name of the language to retrieve
2380
+ * @returns {Language | undefined}
2381
+ */
2382
+ function getLanguage(name) {
2383
+ name = (name || '').toLowerCase();
2384
+ return languages[name] || languages[aliases[name]];
2385
+ }
2386
+
2387
+ /**
2388
+ *
2389
+ * @param {string|string[]} aliasList - single alias or list of aliases
2390
+ * @param {{languageName: string}} opts
2391
+ */
2392
+ function registerAliases(aliasList, { languageName }) {
2393
+ if (typeof aliasList === 'string') {
2394
+ aliasList = [aliasList];
2395
+ }
2396
+ aliasList.forEach(alias => { aliases[alias.toLowerCase()] = languageName; });
2397
+ }
2398
+
2399
+ /**
2400
+ * Determines if a given language has auto-detection enabled
2401
+ * @param {string} name - name of the language
2402
+ */
2403
+ function autoDetection(name) {
2404
+ const lang = getLanguage(name);
2405
+ return lang && !lang.disableAutodetect;
2406
+ }
2407
+
2408
+ /**
2409
+ * Upgrades the old highlightBlock plugins to the new
2410
+ * highlightElement API
2411
+ * @param {HLJSPlugin} plugin
2412
+ */
2413
+ function upgradePluginAPI(plugin) {
2414
+ // TODO: remove with v12
2415
+ if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
2416
+ plugin["before:highlightElement"] = (data) => {
2417
+ plugin["before:highlightBlock"](
2418
+ Object.assign({ block: data.el }, data)
2419
+ );
2420
+ };
2421
+ }
2422
+ if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
2423
+ plugin["after:highlightElement"] = (data) => {
2424
+ plugin["after:highlightBlock"](
2425
+ Object.assign({ block: data.el }, data)
2426
+ );
2427
+ };
2428
+ }
2429
+ }
2430
+
2431
+ /**
2432
+ * @param {HLJSPlugin} plugin
2433
+ */
2434
+ function addPlugin(plugin) {
2435
+ upgradePluginAPI(plugin);
2436
+ plugins.push(plugin);
2437
+ }
2438
+
2439
+ /**
2440
+ *
2441
+ * @param {PluginEvent} event
2442
+ * @param {any} args
2443
+ */
2444
+ function fire(event, args) {
2445
+ const cb = event;
2446
+ plugins.forEach(function(plugin) {
2447
+ if (plugin[cb]) {
2448
+ plugin[cb](args);
2449
+ }
2450
+ });
2451
+ }
2452
+
2453
+ /**
2454
+ * DEPRECATED
2455
+ * @param {HighlightedHTMLElement} el
2456
+ */
2457
+ function deprecateHighlightBlock(el) {
2458
+ deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
2459
+ deprecated("10.7.0", "Please use highlightElement now.");
2460
+
2461
+ return highlightElement(el);
2462
+ }
2463
+
2464
+ /* Interface definition */
2465
+ Object.assign(hljs, {
2466
+ highlight,
2467
+ highlightAuto,
2468
+ highlightAll,
2469
+ highlightElement,
2470
+ // TODO: Remove with v12 API
2471
+ highlightBlock: deprecateHighlightBlock,
2472
+ configure,
2473
+ initHighlighting,
2474
+ initHighlightingOnLoad,
2475
+ registerLanguage,
2476
+ unregisterLanguage,
2477
+ listLanguages,
2478
+ getLanguage,
2479
+ registerAliases,
2480
+ autoDetection,
2481
+ inherit,
2482
+ addPlugin
2483
+ });
2484
+
2485
+ hljs.debugMode = function() { SAFE_MODE = false; };
2486
+ hljs.safeMode = function() { SAFE_MODE = true; };
2487
+ hljs.versionString = version;
2488
+
2489
+ for (const key in MODES) {
2490
+ // @ts-ignore
2491
+ if (typeof MODES[key] === "object") {
2492
+ // @ts-ignore
2493
+ deepFreeze$1(MODES[key]);
2494
+ }
2495
+ }
2496
+
2497
+ // merge all the modes/regexes into our main object
2498
+ Object.assign(hljs, MODES);
2499
+
2500
+ return hljs;
2501
+ };
2502
+
2503
+ // export an "instance" of the highlighter
2504
+ var HighlightJS = HLJS({});
2505
+
2506
+ // https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.10
2507
+ var decimalDigits = '[0-9](_*[0-9])*';
2508
+ var frac = `\\.(${decimalDigits})`;
2509
+ var hexDigits = '[0-9a-fA-F](_*[0-9a-fA-F])*';
2510
+ var NUMERIC = {
2511
+ className: 'number',
2512
+ variants: [
2513
+ // DecimalFloatingPointLiteral
2514
+ // including ExponentPart
2515
+ { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))` +
2516
+ `[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
2517
+ // excluding ExponentPart
2518
+ { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
2519
+ { begin: `(${frac})[fFdD]?\\b` },
2520
+ { begin: `\\b(${decimalDigits})[fFdD]\\b` },
2521
+
2522
+ // HexadecimalFloatingPointLiteral
2523
+ { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))` +
2524
+ `[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
2525
+
2526
+ // DecimalIntegerLiteral
2527
+ { begin: '\\b(0|[1-9](_*[0-9])*)[lL]?\\b' },
2528
+
2529
+ // HexIntegerLiteral
2530
+ { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
2531
+
2532
+ // OctalIntegerLiteral
2533
+ { begin: '\\b0(_*[0-7])*[lL]?\\b' },
2534
+
2535
+ // BinaryIntegerLiteral
2536
+ { begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },
2537
+ ],
2538
+ relevance: 0
2539
+ };
2540
+
2541
+ /*
2542
+ Language: Java
2543
+ Author: Vsevolod Solovyov <vsevolod.solovyov@gmail.com>
2544
+ Category: common, enterprise
2545
+ Website: https://www.java.com/
2546
+ */
2547
+
2548
+ /**
2549
+ * Allows recursive regex expressions to a given depth
2550
+ *
2551
+ * ie: recurRegex("(abc~~~)", /~~~/g, 2) becomes:
2552
+ * (abc(abc(abc)))
2553
+ *
2554
+ * @param {string} re
2555
+ * @param {RegExp} substitution (should be a g mode regex)
2556
+ * @param {number} depth
2557
+ * @returns {string}``
2558
+ */
2559
+ function recurRegex(re, substitution, depth) {
2560
+ if (depth === -1) return "";
2561
+
2562
+ return re.replace(substitution, _ => {
2563
+ return recurRegex(re, substitution, depth - 1);
2564
+ });
2565
+ }
2566
+
2567
+ /** @type LanguageFn */
2568
+ function java(hljs) {
2569
+ const JAVA_IDENT_RE = '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*';
2570
+ const GENERIC_IDENT_RE = JAVA_IDENT_RE +
2571
+ recurRegex('(?:<' + JAVA_IDENT_RE + '~~~(?:\\s*,\\s*' + JAVA_IDENT_RE + '~~~)*>)?', /~~~/g, 2);
2572
+ const MAIN_KEYWORDS = [
2573
+ 'synchronized',
2574
+ 'abstract',
2575
+ 'private',
2576
+ 'var',
2577
+ 'static',
2578
+ 'if',
2579
+ 'const ',
2580
+ 'for',
2581
+ 'while',
2582
+ 'strictfp',
2583
+ 'finally',
2584
+ 'protected',
2585
+ 'import',
2586
+ 'native',
2587
+ 'final',
2588
+ 'void',
2589
+ 'enum',
2590
+ 'else',
2591
+ 'break',
2592
+ 'transient',
2593
+ 'catch',
2594
+ 'instanceof',
2595
+ 'volatile',
2596
+ 'case',
2597
+ 'assert',
2598
+ 'package',
2599
+ 'default',
2600
+ 'public',
2601
+ 'try',
2602
+ 'switch',
2603
+ 'continue',
2604
+ 'throws',
2605
+ 'protected',
2606
+ 'public',
2607
+ 'private',
2608
+ 'module',
2609
+ 'requires',
2610
+ 'exports',
2611
+ 'do'
2612
+ ];
2613
+
2614
+ const BUILT_INS = [
2615
+ 'super',
2616
+ 'this'
2617
+ ];
2618
+
2619
+ const LITERALS = [
2620
+ 'false',
2621
+ 'true',
2622
+ 'null'
2623
+ ];
2624
+
2625
+ const TYPES = [
2626
+ 'char',
2627
+ 'boolean',
2628
+ 'long',
2629
+ 'float',
2630
+ 'int',
2631
+ 'byte',
2632
+ 'short',
2633
+ 'double'
2634
+ ];
2635
+
2636
+ const KEYWORDS = {
2637
+ keyword: MAIN_KEYWORDS,
2638
+ literal: LITERALS,
2639
+ type: TYPES,
2640
+ built_in: BUILT_INS
2641
+ };
2642
+
2643
+ const ANNOTATION = {
2644
+ className: 'meta',
2645
+ begin: '@' + JAVA_IDENT_RE,
2646
+ contains: [
2647
+ {
2648
+ begin: /\(/,
2649
+ end: /\)/,
2650
+ contains: [ "self" ] // allow nested () inside our annotation
2651
+ }
2652
+ ]
2653
+ };
2654
+ const PARAMS = {
2655
+ className: 'params',
2656
+ begin: /\(/,
2657
+ end: /\)/,
2658
+ keywords: KEYWORDS,
2659
+ relevance: 0,
2660
+ contains: [
2661
+ hljs.C_BLOCK_COMMENT_MODE
2662
+ ],
2663
+ endsParent: true
2664
+ };
2665
+
2666
+ return {
2667
+ name: 'Java',
2668
+ aliases: [ 'jsp' ],
2669
+ keywords: KEYWORDS,
2670
+ illegal: /<\/|#/,
2671
+ contains: [
2672
+ hljs.COMMENT(
2673
+ '/\\*\\*',
2674
+ '\\*/',
2675
+ {
2676
+ relevance: 0,
2677
+ contains: [
2678
+ {
2679
+ // eat up @'s in emails to prevent them to be recognized as doctags
2680
+ begin: /\w+@/,
2681
+ relevance: 0
2682
+ },
2683
+ {
2684
+ className: 'doctag',
2685
+ begin: '@[A-Za-z]+'
2686
+ }
2687
+ ]
2688
+ }
2689
+ ),
2690
+ // relevance boost
2691
+ {
2692
+ begin: /import java\.[a-z]+\./,
2693
+ keywords: "import",
2694
+ relevance: 2
2695
+ },
2696
+ hljs.C_LINE_COMMENT_MODE,
2697
+ hljs.C_BLOCK_COMMENT_MODE,
2698
+ hljs.APOS_STRING_MODE,
2699
+ hljs.QUOTE_STRING_MODE,
2700
+ {
2701
+ match: [
2702
+ /\b(?:class|interface|enum|extends|implements|new)/,
2703
+ /\s+/,
2704
+ JAVA_IDENT_RE
2705
+ ],
2706
+ className: {
2707
+ 1: "keyword",
2708
+ 3: "title.class"
2709
+ }
2710
+ },
2711
+ {
2712
+ begin: [
2713
+ JAVA_IDENT_RE,
2714
+ /\s+/,
2715
+ JAVA_IDENT_RE,
2716
+ /\s+/,
2717
+ /=/
2718
+ ],
2719
+ className: {
2720
+ 1: "type",
2721
+ 3: "variable",
2722
+ 5: "operator"
2723
+ }
2724
+ },
2725
+ {
2726
+ begin: [
2727
+ /record/,
2728
+ /\s+/,
2729
+ JAVA_IDENT_RE
2730
+ ],
2731
+ className: {
2732
+ 1: "keyword",
2733
+ 3: "title.class"
2734
+ },
2735
+ contains: [
2736
+ PARAMS,
2737
+ hljs.C_LINE_COMMENT_MODE,
2738
+ hljs.C_BLOCK_COMMENT_MODE
2739
+ ]
2740
+ },
2741
+ {
2742
+ // Expression keywords prevent 'keyword Name(...)' from being
2743
+ // recognized as a function definition
2744
+ beginKeywords: 'new throw return else',
2745
+ relevance: 0
2746
+ },
2747
+ {
2748
+ begin: [
2749
+ '(?:' + GENERIC_IDENT_RE + '\\s+)',
2750
+ hljs.UNDERSCORE_IDENT_RE,
2751
+ /\s*(?=\()/
2752
+ ],
2753
+ className: {
2754
+ 2: "title.function"
2755
+ },
2756
+ keywords: KEYWORDS,
2757
+ contains: [
2758
+ {
2759
+ className: 'params',
2760
+ begin: /\(/,
2761
+ end: /\)/,
2762
+ keywords: KEYWORDS,
2763
+ relevance: 0,
2764
+ contains: [
2765
+ ANNOTATION,
2766
+ hljs.APOS_STRING_MODE,
2767
+ hljs.QUOTE_STRING_MODE,
2768
+ NUMERIC,
2769
+ hljs.C_BLOCK_COMMENT_MODE
2770
+ ]
2771
+ },
2772
+ hljs.C_LINE_COMMENT_MODE,
2773
+ hljs.C_BLOCK_COMMENT_MODE
2774
+ ]
2775
+ },
2776
+ NUMERIC,
2777
+ ANNOTATION
2778
+ ]
2779
+ };
2780
+ }
2781
+
2782
+ var builtIns = /*#__PURE__*/Object.freeze({
2783
+ __proto__: null,
2784
+ grmr_java: java
2785
+ });
2786
+
2787
+ const hljs = HighlightJS;
2788
+
2789
+ for (const key of Object.keys(builtIns)) {
2790
+ // our builtInLanguages Rollup plugin has to use `_` to allow identifiers to be
2791
+ // compatible with `export` naming conventions, so we need to convert the
2792
+ // identifiers back into the more typical dash style that we use for language
2793
+ // naming via the API
2794
+ const languageName = key.replace("grmr_", "").replace("_", "-");
2795
+ hljs.registerLanguage(languageName, builtIns[key]);
2796
+ }
2797
+
2798
+ return hljs;
2799
+
2800
+ }());
2801
+ if (typeof exports === 'object' && typeof module !== 'undefined') { module.exports = hljs; }