@webskill/chatbot 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chatbot.css +19 -0
- package/dist/config.d.ts +107 -0
- package/dist/config.js +200 -0
- package/dist/core-D3Tq37jA.js +3063 -0
- package/dist/core-DBetA176.js +2035 -0
- package/dist/index-Nnkn73aD.d.ts +398 -0
- package/dist/index.d.ts +253 -397
- package/dist/index.js +1479 -6402
- package/dist/markdown-4gn774sm.js +280 -0
- package/dist/parse-B8D0fl8I.d.ts +280 -0
- package/dist/parse-Bo68XTn_.js +645 -0
- package/dist/tsx-DDiQWvTL.js +28 -0
- package/dist/types-C4dzGOPp.js +511 -0
- package/dist/vite.d.ts +33 -0
- package/dist/vite.js +132 -0
- package/package.json +20 -3
- package/virtual.d.ts +27 -0
|
@@ -0,0 +1,2035 @@
|
|
|
1
|
+
import { t as __commonJSMin } from "./rolldown-runtime-DZ8SGSJo.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/.pnpm/highlight.js@10.7.3/node_modules/highlight.js/lib/core.js
|
|
4
|
+
var require_core$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
5
|
+
function deepFreeze(obj) {
|
|
6
|
+
if (obj instanceof Map) obj.clear = obj.delete = obj.set = function() {
|
|
7
|
+
throw new Error("map is read-only");
|
|
8
|
+
};
|
|
9
|
+
else if (obj instanceof Set) obj.add = obj.clear = obj.delete = function() {
|
|
10
|
+
throw new Error("set is read-only");
|
|
11
|
+
};
|
|
12
|
+
Object.freeze(obj);
|
|
13
|
+
Object.getOwnPropertyNames(obj).forEach(function(name) {
|
|
14
|
+
var prop = obj[name];
|
|
15
|
+
if (typeof prop == "object" && !Object.isFrozen(prop)) deepFreeze(prop);
|
|
16
|
+
});
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
var deepFreezeEs6 = deepFreeze;
|
|
20
|
+
deepFreezeEs6.default = deepFreeze;
|
|
21
|
+
/** @implements CallbackResponse */
|
|
22
|
+
var Response = class {
|
|
23
|
+
/**
|
|
24
|
+
* @param {CompiledMode} mode
|
|
25
|
+
*/
|
|
26
|
+
constructor(mode) {
|
|
27
|
+
if (mode.data === void 0) mode.data = {};
|
|
28
|
+
this.data = mode.data;
|
|
29
|
+
this.isMatchIgnored = false;
|
|
30
|
+
}
|
|
31
|
+
ignoreMatch() {
|
|
32
|
+
this.isMatchIgnored = true;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} value
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
39
|
+
function escapeHTML(value) {
|
|
40
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* performs a shallow merge of multiple objects into one
|
|
44
|
+
*
|
|
45
|
+
* @template T
|
|
46
|
+
* @param {T} original
|
|
47
|
+
* @param {Record<string,any>[]} objects
|
|
48
|
+
* @returns {T} a single new object
|
|
49
|
+
*/
|
|
50
|
+
function inherit(original, ...objects) {
|
|
51
|
+
/** @type Record<string,any> */
|
|
52
|
+
const result = Object.create(null);
|
|
53
|
+
for (const key in original) result[key] = original[key];
|
|
54
|
+
objects.forEach(function(obj) {
|
|
55
|
+
for (const key in obj) result[key] = obj[key];
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @typedef {object} Renderer
|
|
61
|
+
* @property {(text: string) => void} addText
|
|
62
|
+
* @property {(node: Node) => void} openNode
|
|
63
|
+
* @property {(node: Node) => void} closeNode
|
|
64
|
+
* @property {() => string} value
|
|
65
|
+
*/
|
|
66
|
+
/** @typedef {{kind?: string, sublanguage?: boolean}} Node */
|
|
67
|
+
/** @typedef {{walk: (r: Renderer) => void}} Tree */
|
|
68
|
+
/** */
|
|
69
|
+
const SPAN_CLOSE = "</span>";
|
|
70
|
+
/**
|
|
71
|
+
* Determines if a node needs to be wrapped in <span>
|
|
72
|
+
*
|
|
73
|
+
* @param {Node} node */
|
|
74
|
+
const emitsWrappingTags = (node) => {
|
|
75
|
+
return !!node.kind;
|
|
76
|
+
};
|
|
77
|
+
/** @type {Renderer} */
|
|
78
|
+
var HTMLRenderer = class {
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new HTMLRenderer
|
|
81
|
+
*
|
|
82
|
+
* @param {Tree} parseTree - the parse tree (must support `walk` API)
|
|
83
|
+
* @param {{classPrefix: string}} options
|
|
84
|
+
*/
|
|
85
|
+
constructor(parseTree, options) {
|
|
86
|
+
this.buffer = "";
|
|
87
|
+
this.classPrefix = options.classPrefix;
|
|
88
|
+
parseTree.walk(this);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Adds texts to the output stream
|
|
92
|
+
*
|
|
93
|
+
* @param {string} text */
|
|
94
|
+
addText(text) {
|
|
95
|
+
this.buffer += escapeHTML(text);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Adds a node open to the output stream (if needed)
|
|
99
|
+
*
|
|
100
|
+
* @param {Node} node */
|
|
101
|
+
openNode(node) {
|
|
102
|
+
if (!emitsWrappingTags(node)) return;
|
|
103
|
+
let className = node.kind;
|
|
104
|
+
if (!node.sublanguage) className = `${this.classPrefix}${className}`;
|
|
105
|
+
this.span(className);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Adds a node close to the output stream (if needed)
|
|
109
|
+
*
|
|
110
|
+
* @param {Node} node */
|
|
111
|
+
closeNode(node) {
|
|
112
|
+
if (!emitsWrappingTags(node)) return;
|
|
113
|
+
this.buffer += SPAN_CLOSE;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* returns the accumulated buffer
|
|
117
|
+
*/
|
|
118
|
+
value() {
|
|
119
|
+
return this.buffer;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Builds a span element
|
|
123
|
+
*
|
|
124
|
+
* @param {string} className */
|
|
125
|
+
span(className) {
|
|
126
|
+
this.buffer += `<span class="${className}">`;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} | string} Node */
|
|
130
|
+
/** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} } DataNode */
|
|
131
|
+
/** */
|
|
132
|
+
var TokenTree = class TokenTree {
|
|
133
|
+
constructor() {
|
|
134
|
+
/** @type DataNode */
|
|
135
|
+
this.rootNode = { children: [] };
|
|
136
|
+
this.stack = [this.rootNode];
|
|
137
|
+
}
|
|
138
|
+
get top() {
|
|
139
|
+
return this.stack[this.stack.length - 1];
|
|
140
|
+
}
|
|
141
|
+
get root() {
|
|
142
|
+
return this.rootNode;
|
|
143
|
+
}
|
|
144
|
+
/** @param {Node} node */
|
|
145
|
+
add(node) {
|
|
146
|
+
this.top.children.push(node);
|
|
147
|
+
}
|
|
148
|
+
/** @param {string} kind */
|
|
149
|
+
openNode(kind) {
|
|
150
|
+
/** @type Node */
|
|
151
|
+
const node = {
|
|
152
|
+
kind,
|
|
153
|
+
children: []
|
|
154
|
+
};
|
|
155
|
+
this.add(node);
|
|
156
|
+
this.stack.push(node);
|
|
157
|
+
}
|
|
158
|
+
closeNode() {
|
|
159
|
+
if (this.stack.length > 1) return this.stack.pop();
|
|
160
|
+
}
|
|
161
|
+
closeAllNodes() {
|
|
162
|
+
while (this.closeNode());
|
|
163
|
+
}
|
|
164
|
+
toJSON() {
|
|
165
|
+
return JSON.stringify(this.rootNode, null, 4);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @typedef { import("./html_renderer").Renderer } Renderer
|
|
169
|
+
* @param {Renderer} builder
|
|
170
|
+
*/
|
|
171
|
+
walk(builder) {
|
|
172
|
+
return this.constructor._walk(builder, this.rootNode);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @param {Renderer} builder
|
|
176
|
+
* @param {Node} node
|
|
177
|
+
*/
|
|
178
|
+
static _walk(builder, node) {
|
|
179
|
+
if (typeof node === "string") builder.addText(node);
|
|
180
|
+
else if (node.children) {
|
|
181
|
+
builder.openNode(node);
|
|
182
|
+
node.children.forEach((child) => this._walk(builder, child));
|
|
183
|
+
builder.closeNode(node);
|
|
184
|
+
}
|
|
185
|
+
return builder;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @param {Node} node
|
|
189
|
+
*/
|
|
190
|
+
static _collapse(node) {
|
|
191
|
+
if (typeof node === "string") return;
|
|
192
|
+
if (!node.children) return;
|
|
193
|
+
if (node.children.every((el) => typeof el === "string")) node.children = [node.children.join("")];
|
|
194
|
+
else node.children.forEach((child) => {
|
|
195
|
+
TokenTree._collapse(child);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
Currently this is all private API, but this is the minimal API necessary
|
|
201
|
+
that an Emitter must implement to fully support the parser.
|
|
202
|
+
|
|
203
|
+
Minimal interface:
|
|
204
|
+
|
|
205
|
+
- addKeyword(text, kind)
|
|
206
|
+
- addText(text)
|
|
207
|
+
- addSublanguage(emitter, subLanguageName)
|
|
208
|
+
- finalize()
|
|
209
|
+
- openNode(kind)
|
|
210
|
+
- closeNode()
|
|
211
|
+
- closeAllNodes()
|
|
212
|
+
- toHTML()
|
|
213
|
+
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* @implements {Emitter}
|
|
217
|
+
*/
|
|
218
|
+
var TokenTreeEmitter = class extends TokenTree {
|
|
219
|
+
/**
|
|
220
|
+
* @param {*} options
|
|
221
|
+
*/
|
|
222
|
+
constructor(options) {
|
|
223
|
+
super();
|
|
224
|
+
this.options = options;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @param {string} text
|
|
228
|
+
* @param {string} kind
|
|
229
|
+
*/
|
|
230
|
+
addKeyword(text, kind) {
|
|
231
|
+
if (text === "") return;
|
|
232
|
+
this.openNode(kind);
|
|
233
|
+
this.addText(text);
|
|
234
|
+
this.closeNode();
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* @param {string} text
|
|
238
|
+
*/
|
|
239
|
+
addText(text) {
|
|
240
|
+
if (text === "") return;
|
|
241
|
+
this.add(text);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @param {Emitter & {root: DataNode}} emitter
|
|
245
|
+
* @param {string} name
|
|
246
|
+
*/
|
|
247
|
+
addSublanguage(emitter, name) {
|
|
248
|
+
/** @type DataNode */
|
|
249
|
+
const node = emitter.root;
|
|
250
|
+
node.kind = name;
|
|
251
|
+
node.sublanguage = true;
|
|
252
|
+
this.add(node);
|
|
253
|
+
}
|
|
254
|
+
toHTML() {
|
|
255
|
+
return new HTMLRenderer(this, this.options).value();
|
|
256
|
+
}
|
|
257
|
+
finalize() {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* @param {string} value
|
|
263
|
+
* @returns {RegExp}
|
|
264
|
+
* */
|
|
265
|
+
function escape(value) {
|
|
266
|
+
return new RegExp(value.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"), "m");
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* @param {RegExp | string } re
|
|
270
|
+
* @returns {string}
|
|
271
|
+
*/
|
|
272
|
+
function source(re) {
|
|
273
|
+
if (!re) return null;
|
|
274
|
+
if (typeof re === "string") return re;
|
|
275
|
+
return re.source;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* @param {...(RegExp | string) } args
|
|
279
|
+
* @returns {string}
|
|
280
|
+
*/
|
|
281
|
+
function concat(...args) {
|
|
282
|
+
return args.map((x) => source(x)).join("");
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Any of the passed expresssions may match
|
|
286
|
+
*
|
|
287
|
+
* Creates a huge this | this | that | that match
|
|
288
|
+
* @param {(RegExp | string)[] } args
|
|
289
|
+
* @returns {string}
|
|
290
|
+
*/
|
|
291
|
+
function either(...args) {
|
|
292
|
+
return "(" + args.map((x) => source(x)).join("|") + ")";
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @param {RegExp} re
|
|
296
|
+
* @returns {number}
|
|
297
|
+
*/
|
|
298
|
+
function countMatchGroups(re) {
|
|
299
|
+
return new RegExp(re.toString() + "|").exec("").length - 1;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Does lexeme start with a regular expression match at the beginning
|
|
303
|
+
* @param {RegExp} re
|
|
304
|
+
* @param {string} lexeme
|
|
305
|
+
*/
|
|
306
|
+
function startsWith(re, lexeme) {
|
|
307
|
+
const match = re && re.exec(lexeme);
|
|
308
|
+
return match && match.index === 0;
|
|
309
|
+
}
|
|
310
|
+
const BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
|
|
311
|
+
/**
|
|
312
|
+
* @param {(string | RegExp)[]} regexps
|
|
313
|
+
* @param {string} separator
|
|
314
|
+
* @returns {string}
|
|
315
|
+
*/
|
|
316
|
+
function join(regexps, separator = "|") {
|
|
317
|
+
let numCaptures = 0;
|
|
318
|
+
return regexps.map((regex) => {
|
|
319
|
+
numCaptures += 1;
|
|
320
|
+
const offset = numCaptures;
|
|
321
|
+
let re = source(regex);
|
|
322
|
+
let out = "";
|
|
323
|
+
while (re.length > 0) {
|
|
324
|
+
const match = BACKREF_RE.exec(re);
|
|
325
|
+
if (!match) {
|
|
326
|
+
out += re;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
out += re.substring(0, match.index);
|
|
330
|
+
re = re.substring(match.index + match[0].length);
|
|
331
|
+
if (match[0][0] === "\\" && match[1]) out += "\\" + String(Number(match[1]) + offset);
|
|
332
|
+
else {
|
|
333
|
+
out += match[0];
|
|
334
|
+
if (match[0] === "(") numCaptures++;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return out;
|
|
338
|
+
}).map((re) => `(${re})`).join(separator);
|
|
339
|
+
}
|
|
340
|
+
const MATCH_NOTHING_RE = /\b\B/;
|
|
341
|
+
const IDENT_RE = "[a-zA-Z]\\w*";
|
|
342
|
+
const UNDERSCORE_IDENT_RE = "[a-zA-Z_]\\w*";
|
|
343
|
+
const NUMBER_RE = "\\b\\d+(\\.\\d+)?";
|
|
344
|
+
const C_NUMBER_RE = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";
|
|
345
|
+
const BINARY_NUMBER_RE = "\\b(0b[01]+)";
|
|
346
|
+
const RE_STARTERS_RE = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";
|
|
347
|
+
/**
|
|
348
|
+
* @param { Partial<Mode> & {binary?: string | RegExp} } opts
|
|
349
|
+
*/
|
|
350
|
+
const SHEBANG = (opts = {}) => {
|
|
351
|
+
const beginShebang = /^#![ ]*\//;
|
|
352
|
+
if (opts.binary) opts.begin = concat(beginShebang, /.*\b/, opts.binary, /\b.*/);
|
|
353
|
+
return inherit({
|
|
354
|
+
className: "meta",
|
|
355
|
+
begin: beginShebang,
|
|
356
|
+
end: /$/,
|
|
357
|
+
relevance: 0,
|
|
358
|
+
/** @type {ModeCallback} */
|
|
359
|
+
"on:begin": (m, resp) => {
|
|
360
|
+
if (m.index !== 0) resp.ignoreMatch();
|
|
361
|
+
}
|
|
362
|
+
}, opts);
|
|
363
|
+
};
|
|
364
|
+
const BACKSLASH_ESCAPE = {
|
|
365
|
+
begin: "\\\\[\\s\\S]",
|
|
366
|
+
relevance: 0
|
|
367
|
+
};
|
|
368
|
+
const APOS_STRING_MODE = {
|
|
369
|
+
className: "string",
|
|
370
|
+
begin: "'",
|
|
371
|
+
end: "'",
|
|
372
|
+
illegal: "\\n",
|
|
373
|
+
contains: [BACKSLASH_ESCAPE]
|
|
374
|
+
};
|
|
375
|
+
const QUOTE_STRING_MODE = {
|
|
376
|
+
className: "string",
|
|
377
|
+
begin: "\"",
|
|
378
|
+
end: "\"",
|
|
379
|
+
illegal: "\\n",
|
|
380
|
+
contains: [BACKSLASH_ESCAPE]
|
|
381
|
+
};
|
|
382
|
+
const PHRASAL_WORDS_MODE = { 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/ };
|
|
383
|
+
/**
|
|
384
|
+
* Creates a comment mode
|
|
385
|
+
*
|
|
386
|
+
* @param {string | RegExp} begin
|
|
387
|
+
* @param {string | RegExp} end
|
|
388
|
+
* @param {Mode | {}} [modeOptions]
|
|
389
|
+
* @returns {Partial<Mode>}
|
|
390
|
+
*/
|
|
391
|
+
const COMMENT = function(begin, end, modeOptions = {}) {
|
|
392
|
+
const mode = inherit({
|
|
393
|
+
className: "comment",
|
|
394
|
+
begin,
|
|
395
|
+
end,
|
|
396
|
+
contains: []
|
|
397
|
+
}, modeOptions);
|
|
398
|
+
mode.contains.push(PHRASAL_WORDS_MODE);
|
|
399
|
+
mode.contains.push({
|
|
400
|
+
className: "doctag",
|
|
401
|
+
begin: "(?:TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):",
|
|
402
|
+
relevance: 0
|
|
403
|
+
});
|
|
404
|
+
return mode;
|
|
405
|
+
};
|
|
406
|
+
const C_LINE_COMMENT_MODE = COMMENT("//", "$");
|
|
407
|
+
const C_BLOCK_COMMENT_MODE = COMMENT("/\\*", "\\*/");
|
|
408
|
+
const HASH_COMMENT_MODE = COMMENT("#", "$");
|
|
409
|
+
const NUMBER_MODE = {
|
|
410
|
+
className: "number",
|
|
411
|
+
begin: NUMBER_RE,
|
|
412
|
+
relevance: 0
|
|
413
|
+
};
|
|
414
|
+
const C_NUMBER_MODE = {
|
|
415
|
+
className: "number",
|
|
416
|
+
begin: C_NUMBER_RE,
|
|
417
|
+
relevance: 0
|
|
418
|
+
};
|
|
419
|
+
const BINARY_NUMBER_MODE = {
|
|
420
|
+
className: "number",
|
|
421
|
+
begin: BINARY_NUMBER_RE,
|
|
422
|
+
relevance: 0
|
|
423
|
+
};
|
|
424
|
+
const CSS_NUMBER_MODE = {
|
|
425
|
+
className: "number",
|
|
426
|
+
begin: "\\b\\d+(\\.\\d+)?(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",
|
|
427
|
+
relevance: 0
|
|
428
|
+
};
|
|
429
|
+
const REGEXP_MODE = {
|
|
430
|
+
begin: /(?=\/[^/\n]*\/)/,
|
|
431
|
+
contains: [{
|
|
432
|
+
className: "regexp",
|
|
433
|
+
begin: /\//,
|
|
434
|
+
end: /\/[gimuy]*/,
|
|
435
|
+
illegal: /\n/,
|
|
436
|
+
contains: [BACKSLASH_ESCAPE, {
|
|
437
|
+
begin: /\[/,
|
|
438
|
+
end: /\]/,
|
|
439
|
+
relevance: 0,
|
|
440
|
+
contains: [BACKSLASH_ESCAPE]
|
|
441
|
+
}]
|
|
442
|
+
}]
|
|
443
|
+
};
|
|
444
|
+
const TITLE_MODE = {
|
|
445
|
+
className: "title",
|
|
446
|
+
begin: IDENT_RE,
|
|
447
|
+
relevance: 0
|
|
448
|
+
};
|
|
449
|
+
const UNDERSCORE_TITLE_MODE = {
|
|
450
|
+
className: "title",
|
|
451
|
+
begin: UNDERSCORE_IDENT_RE,
|
|
452
|
+
relevance: 0
|
|
453
|
+
};
|
|
454
|
+
const METHOD_GUARD = {
|
|
455
|
+
begin: "\\.\\s*[a-zA-Z_]\\w*",
|
|
456
|
+
relevance: 0
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* Adds end same as begin mechanics to a mode
|
|
460
|
+
*
|
|
461
|
+
* Your mode must include at least a single () match group as that first match
|
|
462
|
+
* group is what is used for comparison
|
|
463
|
+
* @param {Partial<Mode>} mode
|
|
464
|
+
*/
|
|
465
|
+
const END_SAME_AS_BEGIN = function(mode) {
|
|
466
|
+
return Object.assign(mode, {
|
|
467
|
+
/** @type {ModeCallback} */
|
|
468
|
+
"on:begin": (m, resp) => {
|
|
469
|
+
resp.data._beginMatch = m[1];
|
|
470
|
+
},
|
|
471
|
+
/** @type {ModeCallback} */
|
|
472
|
+
"on:end": (m, resp) => {
|
|
473
|
+
if (resp.data._beginMatch !== m[1]) resp.ignoreMatch();
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
};
|
|
477
|
+
var MODES = /*#__PURE__*/ Object.freeze({
|
|
478
|
+
__proto__: null,
|
|
479
|
+
MATCH_NOTHING_RE,
|
|
480
|
+
IDENT_RE,
|
|
481
|
+
UNDERSCORE_IDENT_RE,
|
|
482
|
+
NUMBER_RE,
|
|
483
|
+
C_NUMBER_RE,
|
|
484
|
+
BINARY_NUMBER_RE,
|
|
485
|
+
RE_STARTERS_RE,
|
|
486
|
+
SHEBANG,
|
|
487
|
+
BACKSLASH_ESCAPE,
|
|
488
|
+
APOS_STRING_MODE,
|
|
489
|
+
QUOTE_STRING_MODE,
|
|
490
|
+
PHRASAL_WORDS_MODE,
|
|
491
|
+
COMMENT,
|
|
492
|
+
C_LINE_COMMENT_MODE,
|
|
493
|
+
C_BLOCK_COMMENT_MODE,
|
|
494
|
+
HASH_COMMENT_MODE,
|
|
495
|
+
NUMBER_MODE,
|
|
496
|
+
C_NUMBER_MODE,
|
|
497
|
+
BINARY_NUMBER_MODE,
|
|
498
|
+
CSS_NUMBER_MODE,
|
|
499
|
+
REGEXP_MODE,
|
|
500
|
+
TITLE_MODE,
|
|
501
|
+
UNDERSCORE_TITLE_MODE,
|
|
502
|
+
METHOD_GUARD,
|
|
503
|
+
END_SAME_AS_BEGIN
|
|
504
|
+
});
|
|
505
|
+
/**
|
|
506
|
+
* Skip a match if it has a preceding dot
|
|
507
|
+
*
|
|
508
|
+
* This is used for `beginKeywords` to prevent matching expressions such as
|
|
509
|
+
* `bob.keyword.do()`. The mode compiler automatically wires this up as a
|
|
510
|
+
* special _internal_ 'on:begin' callback for modes with `beginKeywords`
|
|
511
|
+
* @param {RegExpMatchArray} match
|
|
512
|
+
* @param {CallbackResponse} response
|
|
513
|
+
*/
|
|
514
|
+
function skipIfhasPrecedingDot(match, response) {
|
|
515
|
+
if (match.input[match.index - 1] === ".") response.ignoreMatch();
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* `beginKeywords` syntactic sugar
|
|
519
|
+
* @type {CompilerExt}
|
|
520
|
+
*/
|
|
521
|
+
function beginKeywords(mode, parent) {
|
|
522
|
+
if (!parent) return;
|
|
523
|
+
if (!mode.beginKeywords) return;
|
|
524
|
+
mode.begin = "\\b(" + mode.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)";
|
|
525
|
+
mode.__beforeBegin = skipIfhasPrecedingDot;
|
|
526
|
+
mode.keywords = mode.keywords || mode.beginKeywords;
|
|
527
|
+
delete mode.beginKeywords;
|
|
528
|
+
if (mode.relevance === void 0) mode.relevance = 0;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Allow `illegal` to contain an array of illegal values
|
|
532
|
+
* @type {CompilerExt}
|
|
533
|
+
*/
|
|
534
|
+
function compileIllegal(mode, _parent) {
|
|
535
|
+
if (!Array.isArray(mode.illegal)) return;
|
|
536
|
+
mode.illegal = either(...mode.illegal);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* `match` to match a single expression for readability
|
|
540
|
+
* @type {CompilerExt}
|
|
541
|
+
*/
|
|
542
|
+
function compileMatch(mode, _parent) {
|
|
543
|
+
if (!mode.match) return;
|
|
544
|
+
if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
|
|
545
|
+
mode.begin = mode.match;
|
|
546
|
+
delete mode.match;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* provides the default 1 relevance to all modes
|
|
550
|
+
* @type {CompilerExt}
|
|
551
|
+
*/
|
|
552
|
+
function compileRelevance(mode, _parent) {
|
|
553
|
+
if (mode.relevance === void 0) mode.relevance = 1;
|
|
554
|
+
}
|
|
555
|
+
const COMMON_KEYWORDS = [
|
|
556
|
+
"of",
|
|
557
|
+
"and",
|
|
558
|
+
"for",
|
|
559
|
+
"in",
|
|
560
|
+
"not",
|
|
561
|
+
"or",
|
|
562
|
+
"if",
|
|
563
|
+
"then",
|
|
564
|
+
"parent",
|
|
565
|
+
"list",
|
|
566
|
+
"value"
|
|
567
|
+
];
|
|
568
|
+
const DEFAULT_KEYWORD_CLASSNAME = "keyword";
|
|
569
|
+
/**
|
|
570
|
+
* Given raw keywords from a language definition, compile them.
|
|
571
|
+
*
|
|
572
|
+
* @param {string | Record<string,string|string[]> | Array<string>} rawKeywords
|
|
573
|
+
* @param {boolean} caseInsensitive
|
|
574
|
+
*/
|
|
575
|
+
function compileKeywords(rawKeywords, caseInsensitive, className = DEFAULT_KEYWORD_CLASSNAME) {
|
|
576
|
+
/** @type KeywordDict */
|
|
577
|
+
const compiledKeywords = {};
|
|
578
|
+
if (typeof rawKeywords === "string") compileList(className, rawKeywords.split(" "));
|
|
579
|
+
else if (Array.isArray(rawKeywords)) compileList(className, rawKeywords);
|
|
580
|
+
else Object.keys(rawKeywords).forEach(function(className) {
|
|
581
|
+
Object.assign(compiledKeywords, compileKeywords(rawKeywords[className], caseInsensitive, className));
|
|
582
|
+
});
|
|
583
|
+
return compiledKeywords;
|
|
584
|
+
/**
|
|
585
|
+
* Compiles an individual list of keywords
|
|
586
|
+
*
|
|
587
|
+
* Ex: "for if when while|5"
|
|
588
|
+
*
|
|
589
|
+
* @param {string} className
|
|
590
|
+
* @param {Array<string>} keywordList
|
|
591
|
+
*/
|
|
592
|
+
function compileList(className, keywordList) {
|
|
593
|
+
if (caseInsensitive) keywordList = keywordList.map((x) => x.toLowerCase());
|
|
594
|
+
keywordList.forEach(function(keyword) {
|
|
595
|
+
const pair = keyword.split("|");
|
|
596
|
+
compiledKeywords[pair[0]] = [className, scoreForKeyword(pair[0], pair[1])];
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Returns the proper score for a given keyword
|
|
602
|
+
*
|
|
603
|
+
* Also takes into account comment keywords, which will be scored 0 UNLESS
|
|
604
|
+
* another score has been manually assigned.
|
|
605
|
+
* @param {string} keyword
|
|
606
|
+
* @param {string} [providedScore]
|
|
607
|
+
*/
|
|
608
|
+
function scoreForKeyword(keyword, providedScore) {
|
|
609
|
+
if (providedScore) return Number(providedScore);
|
|
610
|
+
return commonKeyword(keyword) ? 0 : 1;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Determines if a given keyword is common or not
|
|
614
|
+
*
|
|
615
|
+
* @param {string} keyword */
|
|
616
|
+
function commonKeyword(keyword) {
|
|
617
|
+
return COMMON_KEYWORDS.includes(keyword.toLowerCase());
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Compiles a language definition result
|
|
621
|
+
*
|
|
622
|
+
* Given the raw result of a language definition (Language), compiles this so
|
|
623
|
+
* that it is ready for highlighting code.
|
|
624
|
+
* @param {Language} language
|
|
625
|
+
* @param {{plugins: HLJSPlugin[]}} opts
|
|
626
|
+
* @returns {CompiledLanguage}
|
|
627
|
+
*/
|
|
628
|
+
function compileLanguage(language, { plugins }) {
|
|
629
|
+
/**
|
|
630
|
+
* Builds a regex with the case sensativility of the current language
|
|
631
|
+
*
|
|
632
|
+
* @param {RegExp | string} value
|
|
633
|
+
* @param {boolean} [global]
|
|
634
|
+
*/
|
|
635
|
+
function langRe(value, global) {
|
|
636
|
+
return new RegExp(source(value), "m" + (language.case_insensitive ? "i" : "") + (global ? "g" : ""));
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
Stores multiple regular expressions and allows you to quickly search for
|
|
640
|
+
them all in a string simultaneously - returning the first match. It does
|
|
641
|
+
this by creating a huge (a|b|c) regex - each individual item wrapped with ()
|
|
642
|
+
and joined by `|` - using match groups to track position. When a match is
|
|
643
|
+
found checking which position in the array has content allows us to figure
|
|
644
|
+
out which of the original regexes / match groups triggered the match.
|
|
645
|
+
|
|
646
|
+
The match object itself (the result of `Regex.exec`) is returned but also
|
|
647
|
+
enhanced by merging in any meta-data that was registered with the regex.
|
|
648
|
+
This is how we keep track of which mode matched, and what type of rule
|
|
649
|
+
(`illegal`, `begin`, end, etc).
|
|
650
|
+
*/
|
|
651
|
+
class MultiRegex {
|
|
652
|
+
constructor() {
|
|
653
|
+
this.matchIndexes = {};
|
|
654
|
+
this.regexes = [];
|
|
655
|
+
this.matchAt = 1;
|
|
656
|
+
this.position = 0;
|
|
657
|
+
}
|
|
658
|
+
addRule(re, opts) {
|
|
659
|
+
opts.position = this.position++;
|
|
660
|
+
this.matchIndexes[this.matchAt] = opts;
|
|
661
|
+
this.regexes.push([opts, re]);
|
|
662
|
+
this.matchAt += countMatchGroups(re) + 1;
|
|
663
|
+
}
|
|
664
|
+
compile() {
|
|
665
|
+
if (this.regexes.length === 0) this.exec = () => null;
|
|
666
|
+
const terminators = this.regexes.map((el) => el[1]);
|
|
667
|
+
this.matcherRe = langRe(join(terminators), true);
|
|
668
|
+
this.lastIndex = 0;
|
|
669
|
+
}
|
|
670
|
+
/** @param {string} s */
|
|
671
|
+
exec(s) {
|
|
672
|
+
this.matcherRe.lastIndex = this.lastIndex;
|
|
673
|
+
const match = this.matcherRe.exec(s);
|
|
674
|
+
if (!match) return null;
|
|
675
|
+
const i = match.findIndex((el, i) => i > 0 && el !== void 0);
|
|
676
|
+
const matchData = this.matchIndexes[i];
|
|
677
|
+
match.splice(0, i);
|
|
678
|
+
return Object.assign(match, matchData);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
class ResumableMultiRegex {
|
|
682
|
+
constructor() {
|
|
683
|
+
this.rules = [];
|
|
684
|
+
this.multiRegexes = [];
|
|
685
|
+
this.count = 0;
|
|
686
|
+
this.lastIndex = 0;
|
|
687
|
+
this.regexIndex = 0;
|
|
688
|
+
}
|
|
689
|
+
getMatcher(index) {
|
|
690
|
+
if (this.multiRegexes[index]) return this.multiRegexes[index];
|
|
691
|
+
const matcher = new MultiRegex();
|
|
692
|
+
this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
|
|
693
|
+
matcher.compile();
|
|
694
|
+
this.multiRegexes[index] = matcher;
|
|
695
|
+
return matcher;
|
|
696
|
+
}
|
|
697
|
+
resumingScanAtSamePosition() {
|
|
698
|
+
return this.regexIndex !== 0;
|
|
699
|
+
}
|
|
700
|
+
considerAll() {
|
|
701
|
+
this.regexIndex = 0;
|
|
702
|
+
}
|
|
703
|
+
addRule(re, opts) {
|
|
704
|
+
this.rules.push([re, opts]);
|
|
705
|
+
if (opts.type === "begin") this.count++;
|
|
706
|
+
}
|
|
707
|
+
/** @param {string} s */
|
|
708
|
+
exec(s) {
|
|
709
|
+
const m = this.getMatcher(this.regexIndex);
|
|
710
|
+
m.lastIndex = this.lastIndex;
|
|
711
|
+
let result = m.exec(s);
|
|
712
|
+
if (this.resumingScanAtSamePosition()) if (result && result.index === this.lastIndex);
|
|
713
|
+
else {
|
|
714
|
+
const m2 = this.getMatcher(0);
|
|
715
|
+
m2.lastIndex = this.lastIndex + 1;
|
|
716
|
+
result = m2.exec(s);
|
|
717
|
+
}
|
|
718
|
+
if (result) {
|
|
719
|
+
this.regexIndex += result.position + 1;
|
|
720
|
+
if (this.regexIndex === this.count) this.considerAll();
|
|
721
|
+
}
|
|
722
|
+
return result;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Given a mode, builds a huge ResumableMultiRegex that can be used to walk
|
|
727
|
+
* the content and find matches.
|
|
728
|
+
*
|
|
729
|
+
* @param {CompiledMode} mode
|
|
730
|
+
* @returns {ResumableMultiRegex}
|
|
731
|
+
*/
|
|
732
|
+
function buildModeRegex(mode) {
|
|
733
|
+
const mm = new ResumableMultiRegex();
|
|
734
|
+
mode.contains.forEach((term) => mm.addRule(term.begin, {
|
|
735
|
+
rule: term,
|
|
736
|
+
type: "begin"
|
|
737
|
+
}));
|
|
738
|
+
if (mode.terminatorEnd) mm.addRule(mode.terminatorEnd, { type: "end" });
|
|
739
|
+
if (mode.illegal) mm.addRule(mode.illegal, { type: "illegal" });
|
|
740
|
+
return mm;
|
|
741
|
+
}
|
|
742
|
+
/** skip vs abort vs ignore
|
|
743
|
+
*
|
|
744
|
+
* @skip - The mode is still entered and exited normally (and contains rules apply),
|
|
745
|
+
* but all content is held and added to the parent buffer rather than being
|
|
746
|
+
* output when the mode ends. Mostly used with `sublanguage` to build up
|
|
747
|
+
* a single large buffer than can be parsed by sublanguage.
|
|
748
|
+
*
|
|
749
|
+
* - The mode begin ands ends normally.
|
|
750
|
+
* - Content matched is added to the parent mode buffer.
|
|
751
|
+
* - The parser cursor is moved forward normally.
|
|
752
|
+
*
|
|
753
|
+
* @abort - A hack placeholder until we have ignore. Aborts the mode (as if it
|
|
754
|
+
* never matched) but DOES NOT continue to match subsequent `contains`
|
|
755
|
+
* modes. Abort is bad/suboptimal because it can result in modes
|
|
756
|
+
* farther down not getting applied because an earlier rule eats the
|
|
757
|
+
* content but then aborts.
|
|
758
|
+
*
|
|
759
|
+
* - The mode does not begin.
|
|
760
|
+
* - Content matched by `begin` is added to the mode buffer.
|
|
761
|
+
* - The parser cursor is moved forward accordingly.
|
|
762
|
+
*
|
|
763
|
+
* @ignore - Ignores the mode (as if it never matched) and continues to match any
|
|
764
|
+
* subsequent `contains` modes. Ignore isn't technically possible with
|
|
765
|
+
* the current parser implementation.
|
|
766
|
+
*
|
|
767
|
+
* - The mode does not begin.
|
|
768
|
+
* - Content matched by `begin` is ignored.
|
|
769
|
+
* - The parser cursor is not moved forward.
|
|
770
|
+
*/
|
|
771
|
+
/**
|
|
772
|
+
* Compiles an individual mode
|
|
773
|
+
*
|
|
774
|
+
* This can raise an error if the mode contains certain detectable known logic
|
|
775
|
+
* issues.
|
|
776
|
+
* @param {Mode} mode
|
|
777
|
+
* @param {CompiledMode | null} [parent]
|
|
778
|
+
* @returns {CompiledMode | never}
|
|
779
|
+
*/
|
|
780
|
+
function compileMode(mode, parent) {
|
|
781
|
+
const cmode = mode;
|
|
782
|
+
if (mode.isCompiled) return cmode;
|
|
783
|
+
[compileMatch].forEach((ext) => ext(mode, parent));
|
|
784
|
+
language.compilerExtensions.forEach((ext) => ext(mode, parent));
|
|
785
|
+
mode.__beforeBegin = null;
|
|
786
|
+
[
|
|
787
|
+
beginKeywords,
|
|
788
|
+
compileIllegal,
|
|
789
|
+
compileRelevance
|
|
790
|
+
].forEach((ext) => ext(mode, parent));
|
|
791
|
+
mode.isCompiled = true;
|
|
792
|
+
let keywordPattern = null;
|
|
793
|
+
if (typeof mode.keywords === "object") {
|
|
794
|
+
keywordPattern = mode.keywords.$pattern;
|
|
795
|
+
delete mode.keywords.$pattern;
|
|
796
|
+
}
|
|
797
|
+
if (mode.keywords) mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
|
|
798
|
+
if (mode.lexemes && keywordPattern) throw new Error("ERR: Prefer `keywords.$pattern` to `mode.lexemes`, BOTH are not allowed. (see mode reference) ");
|
|
799
|
+
keywordPattern = keywordPattern || mode.lexemes || /\w+/;
|
|
800
|
+
cmode.keywordPatternRe = langRe(keywordPattern, true);
|
|
801
|
+
if (parent) {
|
|
802
|
+
if (!mode.begin) mode.begin = /\B|\b/;
|
|
803
|
+
cmode.beginRe = langRe(mode.begin);
|
|
804
|
+
if (mode.endSameAsBegin) mode.end = mode.begin;
|
|
805
|
+
if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
|
|
806
|
+
if (mode.end) cmode.endRe = langRe(mode.end);
|
|
807
|
+
cmode.terminatorEnd = source(mode.end) || "";
|
|
808
|
+
if (mode.endsWithParent && parent.terminatorEnd) cmode.terminatorEnd += (mode.end ? "|" : "") + parent.terminatorEnd;
|
|
809
|
+
}
|
|
810
|
+
if (mode.illegal) cmode.illegalRe = langRe(mode.illegal);
|
|
811
|
+
if (!mode.contains) mode.contains = [];
|
|
812
|
+
mode.contains = [].concat(...mode.contains.map(function(c) {
|
|
813
|
+
return expandOrCloneMode(c === "self" ? mode : c);
|
|
814
|
+
}));
|
|
815
|
+
mode.contains.forEach(function(c) {
|
|
816
|
+
compileMode(c, cmode);
|
|
817
|
+
});
|
|
818
|
+
if (mode.starts) compileMode(mode.starts, parent);
|
|
819
|
+
cmode.matcher = buildModeRegex(cmode);
|
|
820
|
+
return cmode;
|
|
821
|
+
}
|
|
822
|
+
if (!language.compilerExtensions) language.compilerExtensions = [];
|
|
823
|
+
if (language.contains && language.contains.includes("self")) throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
|
|
824
|
+
language.classNameAliases = inherit(language.classNameAliases || {});
|
|
825
|
+
return compileMode(language);
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Determines if a mode has a dependency on it's parent or not
|
|
829
|
+
*
|
|
830
|
+
* If a mode does have a parent dependency then often we need to clone it if
|
|
831
|
+
* it's used in multiple places so that each copy points to the correct parent,
|
|
832
|
+
* where-as modes without a parent can often safely be re-used at the bottom of
|
|
833
|
+
* a mode chain.
|
|
834
|
+
*
|
|
835
|
+
* @param {Mode | null} mode
|
|
836
|
+
* @returns {boolean} - is there a dependency on the parent?
|
|
837
|
+
* */
|
|
838
|
+
function dependencyOnParent(mode) {
|
|
839
|
+
if (!mode) return false;
|
|
840
|
+
return mode.endsWithParent || dependencyOnParent(mode.starts);
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Expands a mode or clones it if necessary
|
|
844
|
+
*
|
|
845
|
+
* This is necessary for modes with parental dependenceis (see notes on
|
|
846
|
+
* `dependencyOnParent`) and for nodes that have `variants` - which must then be
|
|
847
|
+
* exploded into their own individual modes at compile time.
|
|
848
|
+
*
|
|
849
|
+
* @param {Mode} mode
|
|
850
|
+
* @returns {Mode | Mode[]}
|
|
851
|
+
* */
|
|
852
|
+
function expandOrCloneMode(mode) {
|
|
853
|
+
if (mode.variants && !mode.cachedVariants) mode.cachedVariants = mode.variants.map(function(variant) {
|
|
854
|
+
return inherit(mode, { variants: null }, variant);
|
|
855
|
+
});
|
|
856
|
+
if (mode.cachedVariants) return mode.cachedVariants;
|
|
857
|
+
if (dependencyOnParent(mode)) return inherit(mode, { starts: mode.starts ? inherit(mode.starts) : null });
|
|
858
|
+
if (Object.isFrozen(mode)) return inherit(mode);
|
|
859
|
+
return mode;
|
|
860
|
+
}
|
|
861
|
+
var version = "10.7.3";
|
|
862
|
+
function hasValueOrEmptyAttribute(value) {
|
|
863
|
+
return Boolean(value || value === "");
|
|
864
|
+
}
|
|
865
|
+
function BuildVuePlugin(hljs) {
|
|
866
|
+
const Component = {
|
|
867
|
+
props: [
|
|
868
|
+
"language",
|
|
869
|
+
"code",
|
|
870
|
+
"autodetect"
|
|
871
|
+
],
|
|
872
|
+
data: function() {
|
|
873
|
+
return {
|
|
874
|
+
detectedLanguage: "",
|
|
875
|
+
unknownLanguage: false
|
|
876
|
+
};
|
|
877
|
+
},
|
|
878
|
+
computed: {
|
|
879
|
+
className() {
|
|
880
|
+
if (this.unknownLanguage) return "";
|
|
881
|
+
return "hljs " + this.detectedLanguage;
|
|
882
|
+
},
|
|
883
|
+
highlighted() {
|
|
884
|
+
if (!this.autoDetect && !hljs.getLanguage(this.language)) {
|
|
885
|
+
console.warn(`The language "${this.language}" you specified could not be found.`);
|
|
886
|
+
this.unknownLanguage = true;
|
|
887
|
+
return escapeHTML(this.code);
|
|
888
|
+
}
|
|
889
|
+
let result = {};
|
|
890
|
+
if (this.autoDetect) {
|
|
891
|
+
result = hljs.highlightAuto(this.code);
|
|
892
|
+
this.detectedLanguage = result.language;
|
|
893
|
+
} else {
|
|
894
|
+
result = hljs.highlight(this.language, this.code, this.ignoreIllegals);
|
|
895
|
+
this.detectedLanguage = this.language;
|
|
896
|
+
}
|
|
897
|
+
return result.value;
|
|
898
|
+
},
|
|
899
|
+
autoDetect() {
|
|
900
|
+
return !this.language || hasValueOrEmptyAttribute(this.autodetect);
|
|
901
|
+
},
|
|
902
|
+
ignoreIllegals() {
|
|
903
|
+
return true;
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
render(createElement) {
|
|
907
|
+
return createElement("pre", {}, [createElement("code", {
|
|
908
|
+
class: this.className,
|
|
909
|
+
domProps: { innerHTML: this.highlighted }
|
|
910
|
+
})]);
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
return {
|
|
914
|
+
Component,
|
|
915
|
+
VuePlugin: { install(Vue) {
|
|
916
|
+
Vue.component("highlightjs", Component);
|
|
917
|
+
} }
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
/** @type {HLJSPlugin} */
|
|
921
|
+
const mergeHTMLPlugin = { "after:highlightElement": ({ el, result, text }) => {
|
|
922
|
+
const originalStream = nodeStream(el);
|
|
923
|
+
if (!originalStream.length) return;
|
|
924
|
+
const resultNode = document.createElement("div");
|
|
925
|
+
resultNode.innerHTML = result.value;
|
|
926
|
+
result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
|
|
927
|
+
} };
|
|
928
|
+
/**
|
|
929
|
+
* @typedef Event
|
|
930
|
+
* @property {'start'|'stop'} event
|
|
931
|
+
* @property {number} offset
|
|
932
|
+
* @property {Node} node
|
|
933
|
+
*/
|
|
934
|
+
/**
|
|
935
|
+
* @param {Node} node
|
|
936
|
+
*/
|
|
937
|
+
function tag(node) {
|
|
938
|
+
return node.nodeName.toLowerCase();
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* @param {Node} node
|
|
942
|
+
*/
|
|
943
|
+
function nodeStream(node) {
|
|
944
|
+
/** @type Event[] */
|
|
945
|
+
const result = [];
|
|
946
|
+
(function _nodeStream(node, offset) {
|
|
947
|
+
for (let child = node.firstChild; child; child = child.nextSibling) if (child.nodeType === 3) offset += child.nodeValue.length;
|
|
948
|
+
else if (child.nodeType === 1) {
|
|
949
|
+
result.push({
|
|
950
|
+
event: "start",
|
|
951
|
+
offset,
|
|
952
|
+
node: child
|
|
953
|
+
});
|
|
954
|
+
offset = _nodeStream(child, offset);
|
|
955
|
+
if (!tag(child).match(/br|hr|img|input/)) result.push({
|
|
956
|
+
event: "stop",
|
|
957
|
+
offset,
|
|
958
|
+
node: child
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
return offset;
|
|
962
|
+
})(node, 0);
|
|
963
|
+
return result;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* @param {any} original - the original stream
|
|
967
|
+
* @param {any} highlighted - stream of the highlighted source
|
|
968
|
+
* @param {string} value - the original source itself
|
|
969
|
+
*/
|
|
970
|
+
function mergeStreams(original, highlighted, value) {
|
|
971
|
+
let processed = 0;
|
|
972
|
+
let result = "";
|
|
973
|
+
const nodeStack = [];
|
|
974
|
+
function selectStream() {
|
|
975
|
+
if (!original.length || !highlighted.length) return original.length ? original : highlighted;
|
|
976
|
+
if (original[0].offset !== highlighted[0].offset) return original[0].offset < highlighted[0].offset ? original : highlighted;
|
|
977
|
+
return highlighted[0].event === "start" ? original : highlighted;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* @param {Node} node
|
|
981
|
+
*/
|
|
982
|
+
function open(node) {
|
|
983
|
+
/** @param {Attr} attr */
|
|
984
|
+
function attributeString(attr) {
|
|
985
|
+
return " " + attr.nodeName + "=\"" + escapeHTML(attr.value) + "\"";
|
|
986
|
+
}
|
|
987
|
+
result += "<" + tag(node) + [].map.call(node.attributes, attributeString).join("") + ">";
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* @param {Node} node
|
|
991
|
+
*/
|
|
992
|
+
function close(node) {
|
|
993
|
+
result += "</" + tag(node) + ">";
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* @param {Event} event
|
|
997
|
+
*/
|
|
998
|
+
function render(event) {
|
|
999
|
+
(event.event === "start" ? open : close)(event.node);
|
|
1000
|
+
}
|
|
1001
|
+
while (original.length || highlighted.length) {
|
|
1002
|
+
let stream = selectStream();
|
|
1003
|
+
result += escapeHTML(value.substring(processed, stream[0].offset));
|
|
1004
|
+
processed = stream[0].offset;
|
|
1005
|
+
if (stream === original) {
|
|
1006
|
+
nodeStack.reverse().forEach(close);
|
|
1007
|
+
do {
|
|
1008
|
+
render(stream.splice(0, 1)[0]);
|
|
1009
|
+
stream = selectStream();
|
|
1010
|
+
} while (stream === original && stream.length && stream[0].offset === processed);
|
|
1011
|
+
nodeStack.reverse().forEach(open);
|
|
1012
|
+
} else {
|
|
1013
|
+
if (stream[0].event === "start") nodeStack.push(stream[0].node);
|
|
1014
|
+
else nodeStack.pop();
|
|
1015
|
+
render(stream.splice(0, 1)[0]);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return result + escapeHTML(value.substr(processed));
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* @type {Record<string, boolean>}
|
|
1022
|
+
*/
|
|
1023
|
+
const seenDeprecations = {};
|
|
1024
|
+
/**
|
|
1025
|
+
* @param {string} message
|
|
1026
|
+
*/
|
|
1027
|
+
const error = (message) => {
|
|
1028
|
+
console.error(message);
|
|
1029
|
+
};
|
|
1030
|
+
/**
|
|
1031
|
+
* @param {string} message
|
|
1032
|
+
* @param {any} args
|
|
1033
|
+
*/
|
|
1034
|
+
const warn = (message, ...args) => {
|
|
1035
|
+
console.log(`WARN: ${message}`, ...args);
|
|
1036
|
+
};
|
|
1037
|
+
/**
|
|
1038
|
+
* @param {string} version
|
|
1039
|
+
* @param {string} message
|
|
1040
|
+
*/
|
|
1041
|
+
const deprecated = (version, message) => {
|
|
1042
|
+
if (seenDeprecations[`${version}/${message}`]) return;
|
|
1043
|
+
console.log(`Deprecated as of ${version}. ${message}`);
|
|
1044
|
+
seenDeprecations[`${version}/${message}`] = true;
|
|
1045
|
+
};
|
|
1046
|
+
const escape$1 = escapeHTML;
|
|
1047
|
+
const inherit$1 = inherit;
|
|
1048
|
+
const NO_MATCH = Symbol("nomatch");
|
|
1049
|
+
/**
|
|
1050
|
+
* @param {any} hljs - object that is extended (legacy)
|
|
1051
|
+
* @returns {HLJSApi}
|
|
1052
|
+
*/
|
|
1053
|
+
const HLJS = function(hljs) {
|
|
1054
|
+
/** @type {Record<string, Language>} */
|
|
1055
|
+
const languages = Object.create(null);
|
|
1056
|
+
/** @type {Record<string, string>} */
|
|
1057
|
+
const aliases = Object.create(null);
|
|
1058
|
+
/** @type {HLJSPlugin[]} */
|
|
1059
|
+
const plugins = [];
|
|
1060
|
+
let SAFE_MODE = true;
|
|
1061
|
+
const fixMarkupRe = /(^(<[^>]+>|\t|)+|\n)/gm;
|
|
1062
|
+
const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
|
|
1063
|
+
/** @type {Language} */
|
|
1064
|
+
const PLAINTEXT_LANGUAGE = {
|
|
1065
|
+
disableAutodetect: true,
|
|
1066
|
+
name: "Plain text",
|
|
1067
|
+
contains: []
|
|
1068
|
+
};
|
|
1069
|
+
/** @type HLJSOptions */
|
|
1070
|
+
let options = {
|
|
1071
|
+
noHighlightRe: /^(no-?highlight)$/i,
|
|
1072
|
+
languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
|
|
1073
|
+
classPrefix: "hljs-",
|
|
1074
|
+
tabReplace: null,
|
|
1075
|
+
useBR: false,
|
|
1076
|
+
languages: null,
|
|
1077
|
+
__emitter: TokenTreeEmitter
|
|
1078
|
+
};
|
|
1079
|
+
/**
|
|
1080
|
+
* Tests a language name to see if highlighting should be skipped
|
|
1081
|
+
* @param {string} languageName
|
|
1082
|
+
*/
|
|
1083
|
+
function shouldNotHighlight(languageName) {
|
|
1084
|
+
return options.noHighlightRe.test(languageName);
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* @param {HighlightedHTMLElement} block - the HTML element to determine language for
|
|
1088
|
+
*/
|
|
1089
|
+
function blockLanguage(block) {
|
|
1090
|
+
let classes = block.className + " ";
|
|
1091
|
+
classes += block.parentNode ? block.parentNode.className : "";
|
|
1092
|
+
const match = options.languageDetectRe.exec(classes);
|
|
1093
|
+
if (match) {
|
|
1094
|
+
const language = getLanguage(match[1]);
|
|
1095
|
+
if (!language) {
|
|
1096
|
+
warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
|
|
1097
|
+
warn("Falling back to no-highlight mode for this block.", block);
|
|
1098
|
+
}
|
|
1099
|
+
return language ? match[1] : "no-highlight";
|
|
1100
|
+
}
|
|
1101
|
+
return classes.split(/\s+/).find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Core highlighting function.
|
|
1105
|
+
*
|
|
1106
|
+
* OLD API
|
|
1107
|
+
* highlight(lang, code, ignoreIllegals, continuation)
|
|
1108
|
+
*
|
|
1109
|
+
* NEW API
|
|
1110
|
+
* highlight(code, {lang, ignoreIllegals})
|
|
1111
|
+
*
|
|
1112
|
+
* @param {string} codeOrlanguageName - the language to use for highlighting
|
|
1113
|
+
* @param {string | HighlightOptions} optionsOrCode - the code to highlight
|
|
1114
|
+
* @param {boolean} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
|
|
1115
|
+
* @param {CompiledMode} [continuation] - current continuation mode, if any
|
|
1116
|
+
*
|
|
1117
|
+
* @returns {HighlightResult} Result - an object that represents the result
|
|
1118
|
+
* @property {string} language - the language name
|
|
1119
|
+
* @property {number} relevance - the relevance score
|
|
1120
|
+
* @property {string} value - the highlighted HTML code
|
|
1121
|
+
* @property {string} code - the original raw code
|
|
1122
|
+
* @property {CompiledMode} top - top of the current mode stack
|
|
1123
|
+
* @property {boolean} illegal - indicates whether any illegal matches were found
|
|
1124
|
+
*/
|
|
1125
|
+
function highlight(codeOrlanguageName, optionsOrCode, ignoreIllegals, continuation) {
|
|
1126
|
+
let code = "";
|
|
1127
|
+
let languageName = "";
|
|
1128
|
+
if (typeof optionsOrCode === "object") {
|
|
1129
|
+
code = codeOrlanguageName;
|
|
1130
|
+
ignoreIllegals = optionsOrCode.ignoreIllegals;
|
|
1131
|
+
languageName = optionsOrCode.language;
|
|
1132
|
+
continuation = void 0;
|
|
1133
|
+
} else {
|
|
1134
|
+
deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
|
|
1135
|
+
deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
|
|
1136
|
+
languageName = codeOrlanguageName;
|
|
1137
|
+
code = optionsOrCode;
|
|
1138
|
+
}
|
|
1139
|
+
/** @type {BeforeHighlightContext} */
|
|
1140
|
+
const context = {
|
|
1141
|
+
code,
|
|
1142
|
+
language: languageName
|
|
1143
|
+
};
|
|
1144
|
+
fire("before:highlight", context);
|
|
1145
|
+
const result = context.result ? context.result : _highlight(context.language, context.code, ignoreIllegals, continuation);
|
|
1146
|
+
result.code = context.code;
|
|
1147
|
+
fire("after:highlight", result);
|
|
1148
|
+
return result;
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* private highlight that's used internally and does not fire callbacks
|
|
1152
|
+
*
|
|
1153
|
+
* @param {string} languageName - the language to use for highlighting
|
|
1154
|
+
* @param {string} codeToHighlight - the code to highlight
|
|
1155
|
+
* @param {boolean?} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
|
|
1156
|
+
* @param {CompiledMode?} [continuation] - current continuation mode, if any
|
|
1157
|
+
* @returns {HighlightResult} - result of the highlight operation
|
|
1158
|
+
*/
|
|
1159
|
+
function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
|
|
1160
|
+
/**
|
|
1161
|
+
* Return keyword data if a match is a keyword
|
|
1162
|
+
* @param {CompiledMode} mode - current mode
|
|
1163
|
+
* @param {RegExpMatchArray} match - regexp match data
|
|
1164
|
+
* @returns {KeywordData | false}
|
|
1165
|
+
*/
|
|
1166
|
+
function keywordData(mode, match) {
|
|
1167
|
+
const matchText = language.case_insensitive ? match[0].toLowerCase() : match[0];
|
|
1168
|
+
return Object.prototype.hasOwnProperty.call(mode.keywords, matchText) && mode.keywords[matchText];
|
|
1169
|
+
}
|
|
1170
|
+
function processKeywords() {
|
|
1171
|
+
if (!top.keywords) {
|
|
1172
|
+
emitter.addText(modeBuffer);
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
let lastIndex = 0;
|
|
1176
|
+
top.keywordPatternRe.lastIndex = 0;
|
|
1177
|
+
let match = top.keywordPatternRe.exec(modeBuffer);
|
|
1178
|
+
let buf = "";
|
|
1179
|
+
while (match) {
|
|
1180
|
+
buf += modeBuffer.substring(lastIndex, match.index);
|
|
1181
|
+
const data = keywordData(top, match);
|
|
1182
|
+
if (data) {
|
|
1183
|
+
const [kind, keywordRelevance] = data;
|
|
1184
|
+
emitter.addText(buf);
|
|
1185
|
+
buf = "";
|
|
1186
|
+
relevance += keywordRelevance;
|
|
1187
|
+
if (kind.startsWith("_")) buf += match[0];
|
|
1188
|
+
else {
|
|
1189
|
+
const cssClass = language.classNameAliases[kind] || kind;
|
|
1190
|
+
emitter.addKeyword(match[0], cssClass);
|
|
1191
|
+
}
|
|
1192
|
+
} else buf += match[0];
|
|
1193
|
+
lastIndex = top.keywordPatternRe.lastIndex;
|
|
1194
|
+
match = top.keywordPatternRe.exec(modeBuffer);
|
|
1195
|
+
}
|
|
1196
|
+
buf += modeBuffer.substr(lastIndex);
|
|
1197
|
+
emitter.addText(buf);
|
|
1198
|
+
}
|
|
1199
|
+
function processSubLanguage() {
|
|
1200
|
+
if (modeBuffer === "") return;
|
|
1201
|
+
/** @type HighlightResult */
|
|
1202
|
+
let result = null;
|
|
1203
|
+
if (typeof top.subLanguage === "string") {
|
|
1204
|
+
if (!languages[top.subLanguage]) {
|
|
1205
|
+
emitter.addText(modeBuffer);
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
|
|
1209
|
+
continuations[top.subLanguage] = result.top;
|
|
1210
|
+
} else result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
|
|
1211
|
+
if (top.relevance > 0) relevance += result.relevance;
|
|
1212
|
+
emitter.addSublanguage(result.emitter, result.language);
|
|
1213
|
+
}
|
|
1214
|
+
function processBuffer() {
|
|
1215
|
+
if (top.subLanguage != null) processSubLanguage();
|
|
1216
|
+
else processKeywords();
|
|
1217
|
+
modeBuffer = "";
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* @param {Mode} mode - new mode to start
|
|
1221
|
+
*/
|
|
1222
|
+
function startNewMode(mode) {
|
|
1223
|
+
if (mode.className) emitter.openNode(language.classNameAliases[mode.className] || mode.className);
|
|
1224
|
+
top = Object.create(mode, { parent: { value: top } });
|
|
1225
|
+
return top;
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* @param {CompiledMode } mode - the mode to potentially end
|
|
1229
|
+
* @param {RegExpMatchArray} match - the latest match
|
|
1230
|
+
* @param {string} matchPlusRemainder - match plus remainder of content
|
|
1231
|
+
* @returns {CompiledMode | void} - the next mode, or if void continue on in current mode
|
|
1232
|
+
*/
|
|
1233
|
+
function endOfMode(mode, match, matchPlusRemainder) {
|
|
1234
|
+
let matched = startsWith(mode.endRe, matchPlusRemainder);
|
|
1235
|
+
if (matched) {
|
|
1236
|
+
if (mode["on:end"]) {
|
|
1237
|
+
const resp = new Response(mode);
|
|
1238
|
+
mode["on:end"](match, resp);
|
|
1239
|
+
if (resp.isMatchIgnored) matched = false;
|
|
1240
|
+
}
|
|
1241
|
+
if (matched) {
|
|
1242
|
+
while (mode.endsParent && mode.parent) mode = mode.parent;
|
|
1243
|
+
return mode;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
if (mode.endsWithParent) return endOfMode(mode.parent, match, matchPlusRemainder);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Handle matching but then ignoring a sequence of text
|
|
1250
|
+
*
|
|
1251
|
+
* @param {string} lexeme - string containing full match text
|
|
1252
|
+
*/
|
|
1253
|
+
function doIgnore(lexeme) {
|
|
1254
|
+
if (top.matcher.regexIndex === 0) {
|
|
1255
|
+
modeBuffer += lexeme[0];
|
|
1256
|
+
return 1;
|
|
1257
|
+
} else {
|
|
1258
|
+
resumeScanAtSamePosition = true;
|
|
1259
|
+
return 0;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Handle the start of a new potential mode match
|
|
1264
|
+
*
|
|
1265
|
+
* @param {EnhancedMatch} match - the current match
|
|
1266
|
+
* @returns {number} how far to advance the parse cursor
|
|
1267
|
+
*/
|
|
1268
|
+
function doBeginMatch(match) {
|
|
1269
|
+
const lexeme = match[0];
|
|
1270
|
+
const newMode = match.rule;
|
|
1271
|
+
const resp = new Response(newMode);
|
|
1272
|
+
const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
|
|
1273
|
+
for (const cb of beforeCallbacks) {
|
|
1274
|
+
if (!cb) continue;
|
|
1275
|
+
cb(match, resp);
|
|
1276
|
+
if (resp.isMatchIgnored) return doIgnore(lexeme);
|
|
1277
|
+
}
|
|
1278
|
+
if (newMode && newMode.endSameAsBegin) newMode.endRe = escape(lexeme);
|
|
1279
|
+
if (newMode.skip) modeBuffer += lexeme;
|
|
1280
|
+
else {
|
|
1281
|
+
if (newMode.excludeBegin) modeBuffer += lexeme;
|
|
1282
|
+
processBuffer();
|
|
1283
|
+
if (!newMode.returnBegin && !newMode.excludeBegin) modeBuffer = lexeme;
|
|
1284
|
+
}
|
|
1285
|
+
startNewMode(newMode);
|
|
1286
|
+
return newMode.returnBegin ? 0 : lexeme.length;
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Handle the potential end of mode
|
|
1290
|
+
*
|
|
1291
|
+
* @param {RegExpMatchArray} match - the current match
|
|
1292
|
+
*/
|
|
1293
|
+
function doEndMatch(match) {
|
|
1294
|
+
const lexeme = match[0];
|
|
1295
|
+
const matchPlusRemainder = codeToHighlight.substr(match.index);
|
|
1296
|
+
const endMode = endOfMode(top, match, matchPlusRemainder);
|
|
1297
|
+
if (!endMode) return NO_MATCH;
|
|
1298
|
+
const origin = top;
|
|
1299
|
+
if (origin.skip) modeBuffer += lexeme;
|
|
1300
|
+
else {
|
|
1301
|
+
if (!(origin.returnEnd || origin.excludeEnd)) modeBuffer += lexeme;
|
|
1302
|
+
processBuffer();
|
|
1303
|
+
if (origin.excludeEnd) modeBuffer = lexeme;
|
|
1304
|
+
}
|
|
1305
|
+
do {
|
|
1306
|
+
if (top.className) emitter.closeNode();
|
|
1307
|
+
if (!top.skip && !top.subLanguage) relevance += top.relevance;
|
|
1308
|
+
top = top.parent;
|
|
1309
|
+
} while (top !== endMode.parent);
|
|
1310
|
+
if (endMode.starts) {
|
|
1311
|
+
if (endMode.endSameAsBegin) endMode.starts.endRe = endMode.endRe;
|
|
1312
|
+
startNewMode(endMode.starts);
|
|
1313
|
+
}
|
|
1314
|
+
return origin.returnEnd ? 0 : lexeme.length;
|
|
1315
|
+
}
|
|
1316
|
+
function processContinuations() {
|
|
1317
|
+
const list = [];
|
|
1318
|
+
for (let current = top; current !== language; current = current.parent) if (current.className) list.unshift(current.className);
|
|
1319
|
+
list.forEach((item) => emitter.openNode(item));
|
|
1320
|
+
}
|
|
1321
|
+
/** @type {{type?: MatchType, index?: number, rule?: Mode}}} */
|
|
1322
|
+
let lastMatch = {};
|
|
1323
|
+
/**
|
|
1324
|
+
* Process an individual match
|
|
1325
|
+
*
|
|
1326
|
+
* @param {string} textBeforeMatch - text preceeding the match (since the last match)
|
|
1327
|
+
* @param {EnhancedMatch} [match] - the match itself
|
|
1328
|
+
*/
|
|
1329
|
+
function processLexeme(textBeforeMatch, match) {
|
|
1330
|
+
const lexeme = match && match[0];
|
|
1331
|
+
modeBuffer += textBeforeMatch;
|
|
1332
|
+
if (lexeme == null) {
|
|
1333
|
+
processBuffer();
|
|
1334
|
+
return 0;
|
|
1335
|
+
}
|
|
1336
|
+
if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
|
|
1337
|
+
modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
|
|
1338
|
+
if (!SAFE_MODE) {
|
|
1339
|
+
/** @type {AnnotatedError} */
|
|
1340
|
+
const err = /* @__PURE__ */ new Error("0 width match regex");
|
|
1341
|
+
err.languageName = languageName;
|
|
1342
|
+
err.badRule = lastMatch.rule;
|
|
1343
|
+
throw err;
|
|
1344
|
+
}
|
|
1345
|
+
return 1;
|
|
1346
|
+
}
|
|
1347
|
+
lastMatch = match;
|
|
1348
|
+
if (match.type === "begin") return doBeginMatch(match);
|
|
1349
|
+
else if (match.type === "illegal" && !ignoreIllegals) {
|
|
1350
|
+
/** @type {AnnotatedError} */
|
|
1351
|
+
const err = /* @__PURE__ */ new Error("Illegal lexeme \"" + lexeme + "\" for mode \"" + (top.className || "<unnamed>") + "\"");
|
|
1352
|
+
err.mode = top;
|
|
1353
|
+
throw err;
|
|
1354
|
+
} else if (match.type === "end") {
|
|
1355
|
+
const processed = doEndMatch(match);
|
|
1356
|
+
if (processed !== NO_MATCH) return processed;
|
|
1357
|
+
}
|
|
1358
|
+
if (match.type === "illegal" && lexeme === "") return 1;
|
|
1359
|
+
if (iterations > 1e5 && iterations > match.index * 3) throw /* @__PURE__ */ new Error("potential infinite loop, way more iterations than matches");
|
|
1360
|
+
modeBuffer += lexeme;
|
|
1361
|
+
return lexeme.length;
|
|
1362
|
+
}
|
|
1363
|
+
const language = getLanguage(languageName);
|
|
1364
|
+
if (!language) {
|
|
1365
|
+
error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
|
|
1366
|
+
throw new Error("Unknown language: \"" + languageName + "\"");
|
|
1367
|
+
}
|
|
1368
|
+
const md = compileLanguage(language, { plugins });
|
|
1369
|
+
let result = "";
|
|
1370
|
+
/** @type {CompiledMode} */
|
|
1371
|
+
let top = continuation || md;
|
|
1372
|
+
/** @type Record<string,CompiledMode> */
|
|
1373
|
+
const continuations = {};
|
|
1374
|
+
const emitter = new options.__emitter(options);
|
|
1375
|
+
processContinuations();
|
|
1376
|
+
let modeBuffer = "";
|
|
1377
|
+
let relevance = 0;
|
|
1378
|
+
let index = 0;
|
|
1379
|
+
let iterations = 0;
|
|
1380
|
+
let resumeScanAtSamePosition = false;
|
|
1381
|
+
try {
|
|
1382
|
+
top.matcher.considerAll();
|
|
1383
|
+
for (;;) {
|
|
1384
|
+
iterations++;
|
|
1385
|
+
if (resumeScanAtSamePosition) resumeScanAtSamePosition = false;
|
|
1386
|
+
else top.matcher.considerAll();
|
|
1387
|
+
top.matcher.lastIndex = index;
|
|
1388
|
+
const match = top.matcher.exec(codeToHighlight);
|
|
1389
|
+
if (!match) break;
|
|
1390
|
+
const processedCount = processLexeme(codeToHighlight.substring(index, match.index), match);
|
|
1391
|
+
index = match.index + processedCount;
|
|
1392
|
+
}
|
|
1393
|
+
processLexeme(codeToHighlight.substr(index));
|
|
1394
|
+
emitter.closeAllNodes();
|
|
1395
|
+
emitter.finalize();
|
|
1396
|
+
result = emitter.toHTML();
|
|
1397
|
+
return {
|
|
1398
|
+
relevance: Math.floor(relevance),
|
|
1399
|
+
value: result,
|
|
1400
|
+
language: languageName,
|
|
1401
|
+
illegal: false,
|
|
1402
|
+
emitter,
|
|
1403
|
+
top
|
|
1404
|
+
};
|
|
1405
|
+
} catch (err) {
|
|
1406
|
+
if (err.message && err.message.includes("Illegal")) return {
|
|
1407
|
+
illegal: true,
|
|
1408
|
+
illegalBy: {
|
|
1409
|
+
msg: err.message,
|
|
1410
|
+
context: codeToHighlight.slice(index - 100, index + 100),
|
|
1411
|
+
mode: err.mode
|
|
1412
|
+
},
|
|
1413
|
+
sofar: result,
|
|
1414
|
+
relevance: 0,
|
|
1415
|
+
value: escape$1(codeToHighlight),
|
|
1416
|
+
emitter
|
|
1417
|
+
};
|
|
1418
|
+
else if (SAFE_MODE) return {
|
|
1419
|
+
illegal: false,
|
|
1420
|
+
relevance: 0,
|
|
1421
|
+
value: escape$1(codeToHighlight),
|
|
1422
|
+
emitter,
|
|
1423
|
+
language: languageName,
|
|
1424
|
+
top,
|
|
1425
|
+
errorRaised: err
|
|
1426
|
+
};
|
|
1427
|
+
else throw err;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* returns a valid highlight result, without actually doing any actual work,
|
|
1432
|
+
* auto highlight starts with this and it's possible for small snippets that
|
|
1433
|
+
* auto-detection may not find a better match
|
|
1434
|
+
* @param {string} code
|
|
1435
|
+
* @returns {HighlightResult}
|
|
1436
|
+
*/
|
|
1437
|
+
function justTextHighlightResult(code) {
|
|
1438
|
+
const result = {
|
|
1439
|
+
relevance: 0,
|
|
1440
|
+
emitter: new options.__emitter(options),
|
|
1441
|
+
value: escape$1(code),
|
|
1442
|
+
illegal: false,
|
|
1443
|
+
top: PLAINTEXT_LANGUAGE
|
|
1444
|
+
};
|
|
1445
|
+
result.emitter.addText(code);
|
|
1446
|
+
return result;
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
Highlighting with language detection. Accepts a string with the code to
|
|
1450
|
+
highlight. Returns an object with the following properties:
|
|
1451
|
+
|
|
1452
|
+
- language (detected language)
|
|
1453
|
+
- relevance (int)
|
|
1454
|
+
- value (an HTML string with highlighting markup)
|
|
1455
|
+
- second_best (object with the same structure for second-best heuristically
|
|
1456
|
+
detected language, may be absent)
|
|
1457
|
+
|
|
1458
|
+
@param {string} code
|
|
1459
|
+
@param {Array<string>} [languageSubset]
|
|
1460
|
+
@returns {AutoHighlightResult}
|
|
1461
|
+
*/
|
|
1462
|
+
function highlightAuto(code, languageSubset) {
|
|
1463
|
+
languageSubset = languageSubset || options.languages || Object.keys(languages);
|
|
1464
|
+
const plaintext = justTextHighlightResult(code);
|
|
1465
|
+
const results = languageSubset.filter(getLanguage).filter(autoDetection).map((name) => _highlight(name, code, false));
|
|
1466
|
+
results.unshift(plaintext);
|
|
1467
|
+
const [best, secondBest] = results.sort((a, b) => {
|
|
1468
|
+
if (a.relevance !== b.relevance) return b.relevance - a.relevance;
|
|
1469
|
+
if (a.language && b.language) {
|
|
1470
|
+
if (getLanguage(a.language).supersetOf === b.language) return 1;
|
|
1471
|
+
else if (getLanguage(b.language).supersetOf === a.language) return -1;
|
|
1472
|
+
}
|
|
1473
|
+
return 0;
|
|
1474
|
+
});
|
|
1475
|
+
/** @type {AutoHighlightResult} */
|
|
1476
|
+
const result = best;
|
|
1477
|
+
result.second_best = secondBest;
|
|
1478
|
+
return result;
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
Post-processing of the highlighted markup:
|
|
1482
|
+
|
|
1483
|
+
- replace TABs with something more useful
|
|
1484
|
+
- replace real line-breaks with '<br>' for non-pre containers
|
|
1485
|
+
|
|
1486
|
+
@param {string} html
|
|
1487
|
+
@returns {string}
|
|
1488
|
+
*/
|
|
1489
|
+
function fixMarkup(html) {
|
|
1490
|
+
if (!(options.tabReplace || options.useBR)) return html;
|
|
1491
|
+
return html.replace(fixMarkupRe, (match) => {
|
|
1492
|
+
if (match === "\n") return options.useBR ? "<br>" : match;
|
|
1493
|
+
else if (options.tabReplace) return match.replace(/\t/g, options.tabReplace);
|
|
1494
|
+
return match;
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Builds new class name for block given the language name
|
|
1499
|
+
*
|
|
1500
|
+
* @param {HTMLElement} element
|
|
1501
|
+
* @param {string} [currentLang]
|
|
1502
|
+
* @param {string} [resultLang]
|
|
1503
|
+
*/
|
|
1504
|
+
function updateClassName(element, currentLang, resultLang) {
|
|
1505
|
+
const language = currentLang ? aliases[currentLang] : resultLang;
|
|
1506
|
+
element.classList.add("hljs");
|
|
1507
|
+
if (language) element.classList.add(language);
|
|
1508
|
+
}
|
|
1509
|
+
/** @type {HLJSPlugin} */
|
|
1510
|
+
const brPlugin = {
|
|
1511
|
+
"before:highlightElement": ({ el }) => {
|
|
1512
|
+
if (options.useBR) el.innerHTML = el.innerHTML.replace(/\n/g, "").replace(/<br[ /]*>/g, "\n");
|
|
1513
|
+
},
|
|
1514
|
+
"after:highlightElement": ({ result }) => {
|
|
1515
|
+
if (options.useBR) result.value = result.value.replace(/\n/g, "<br>");
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
const TAB_REPLACE_RE = /^(<[^>]+>|\t)+/gm;
|
|
1519
|
+
/** @type {HLJSPlugin} */
|
|
1520
|
+
const tabReplacePlugin = { "after:highlightElement": ({ result }) => {
|
|
1521
|
+
if (options.tabReplace) result.value = result.value.replace(TAB_REPLACE_RE, (m) => m.replace(/\t/g, options.tabReplace));
|
|
1522
|
+
} };
|
|
1523
|
+
/**
|
|
1524
|
+
* Applies highlighting to a DOM node containing code. Accepts a DOM node and
|
|
1525
|
+
* two optional parameters for fixMarkup.
|
|
1526
|
+
*
|
|
1527
|
+
* @param {HighlightedHTMLElement} element - the HTML element to highlight
|
|
1528
|
+
*/
|
|
1529
|
+
function highlightElement(element) {
|
|
1530
|
+
/** @type HTMLElement */
|
|
1531
|
+
let node = null;
|
|
1532
|
+
const language = blockLanguage(element);
|
|
1533
|
+
if (shouldNotHighlight(language)) return;
|
|
1534
|
+
fire("before:highlightElement", {
|
|
1535
|
+
el: element,
|
|
1536
|
+
language
|
|
1537
|
+
});
|
|
1538
|
+
node = element;
|
|
1539
|
+
const text = node.textContent;
|
|
1540
|
+
const result = language ? highlight(text, {
|
|
1541
|
+
language,
|
|
1542
|
+
ignoreIllegals: true
|
|
1543
|
+
}) : highlightAuto(text);
|
|
1544
|
+
fire("after:highlightElement", {
|
|
1545
|
+
el: element,
|
|
1546
|
+
result,
|
|
1547
|
+
text
|
|
1548
|
+
});
|
|
1549
|
+
element.innerHTML = result.value;
|
|
1550
|
+
updateClassName(element, language, result.language);
|
|
1551
|
+
element.result = {
|
|
1552
|
+
language: result.language,
|
|
1553
|
+
re: result.relevance,
|
|
1554
|
+
relavance: result.relevance
|
|
1555
|
+
};
|
|
1556
|
+
if (result.second_best) element.second_best = {
|
|
1557
|
+
language: result.second_best.language,
|
|
1558
|
+
re: result.second_best.relevance,
|
|
1559
|
+
relavance: result.second_best.relevance
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Updates highlight.js global options with the passed options
|
|
1564
|
+
*
|
|
1565
|
+
* @param {Partial<HLJSOptions>} userOptions
|
|
1566
|
+
*/
|
|
1567
|
+
function configure(userOptions) {
|
|
1568
|
+
if (userOptions.useBR) {
|
|
1569
|
+
deprecated("10.3.0", "'useBR' will be removed entirely in v11.0");
|
|
1570
|
+
deprecated("10.3.0", "Please see https://github.com/highlightjs/highlight.js/issues/2559");
|
|
1571
|
+
}
|
|
1572
|
+
options = inherit$1(options, userOptions);
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Highlights to all <pre><code> blocks on a page
|
|
1576
|
+
*
|
|
1577
|
+
* @type {Function & {called?: boolean}}
|
|
1578
|
+
*/
|
|
1579
|
+
const initHighlighting = () => {
|
|
1580
|
+
if (initHighlighting.called) return;
|
|
1581
|
+
initHighlighting.called = true;
|
|
1582
|
+
deprecated("10.6.0", "initHighlighting() is deprecated. Use highlightAll() instead.");
|
|
1583
|
+
document.querySelectorAll("pre code").forEach(highlightElement);
|
|
1584
|
+
};
|
|
1585
|
+
function initHighlightingOnLoad() {
|
|
1586
|
+
deprecated("10.6.0", "initHighlightingOnLoad() is deprecated. Use highlightAll() instead.");
|
|
1587
|
+
wantsHighlight = true;
|
|
1588
|
+
}
|
|
1589
|
+
let wantsHighlight = false;
|
|
1590
|
+
/**
|
|
1591
|
+
* auto-highlights all pre>code elements on the page
|
|
1592
|
+
*/
|
|
1593
|
+
function highlightAll() {
|
|
1594
|
+
if (document.readyState === "loading") {
|
|
1595
|
+
wantsHighlight = true;
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
document.querySelectorAll("pre code").forEach(highlightElement);
|
|
1599
|
+
}
|
|
1600
|
+
function boot() {
|
|
1601
|
+
if (wantsHighlight) highlightAll();
|
|
1602
|
+
}
|
|
1603
|
+
if (typeof window !== "undefined" && window.addEventListener) window.addEventListener("DOMContentLoaded", boot, false);
|
|
1604
|
+
/**
|
|
1605
|
+
* Register a language grammar module
|
|
1606
|
+
*
|
|
1607
|
+
* @param {string} languageName
|
|
1608
|
+
* @param {LanguageFn} languageDefinition
|
|
1609
|
+
*/
|
|
1610
|
+
function registerLanguage(languageName, languageDefinition) {
|
|
1611
|
+
let lang = null;
|
|
1612
|
+
try {
|
|
1613
|
+
lang = languageDefinition(hljs);
|
|
1614
|
+
} catch (error$1) {
|
|
1615
|
+
error("Language definition for '{}' could not be registered.".replace("{}", languageName));
|
|
1616
|
+
if (!SAFE_MODE) throw error$1;
|
|
1617
|
+
else error(error$1);
|
|
1618
|
+
lang = PLAINTEXT_LANGUAGE;
|
|
1619
|
+
}
|
|
1620
|
+
if (!lang.name) lang.name = languageName;
|
|
1621
|
+
languages[languageName] = lang;
|
|
1622
|
+
lang.rawDefinition = languageDefinition.bind(null, hljs);
|
|
1623
|
+
if (lang.aliases) registerAliases(lang.aliases, { languageName });
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Remove a language grammar module
|
|
1627
|
+
*
|
|
1628
|
+
* @param {string} languageName
|
|
1629
|
+
*/
|
|
1630
|
+
function unregisterLanguage(languageName) {
|
|
1631
|
+
delete languages[languageName];
|
|
1632
|
+
for (const alias of Object.keys(aliases)) if (aliases[alias] === languageName) delete aliases[alias];
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* @returns {string[]} List of language internal names
|
|
1636
|
+
*/
|
|
1637
|
+
function listLanguages() {
|
|
1638
|
+
return Object.keys(languages);
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
intended usage: When one language truly requires another
|
|
1642
|
+
|
|
1643
|
+
Unlike `getLanguage`, this will throw when the requested language
|
|
1644
|
+
is not available.
|
|
1645
|
+
|
|
1646
|
+
@param {string} name - name of the language to fetch/require
|
|
1647
|
+
@returns {Language | never}
|
|
1648
|
+
*/
|
|
1649
|
+
function requireLanguage(name) {
|
|
1650
|
+
deprecated("10.4.0", "requireLanguage will be removed entirely in v11.");
|
|
1651
|
+
deprecated("10.4.0", "Please see https://github.com/highlightjs/highlight.js/pull/2844");
|
|
1652
|
+
const lang = getLanguage(name);
|
|
1653
|
+
if (lang) return lang;
|
|
1654
|
+
throw new Error("The '{}' language is required, but not loaded.".replace("{}", name));
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* @param {string} name - name of the language to retrieve
|
|
1658
|
+
* @returns {Language | undefined}
|
|
1659
|
+
*/
|
|
1660
|
+
function getLanguage(name) {
|
|
1661
|
+
name = (name || "").toLowerCase();
|
|
1662
|
+
return languages[name] || languages[aliases[name]];
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
*
|
|
1666
|
+
* @param {string|string[]} aliasList - single alias or list of aliases
|
|
1667
|
+
* @param {{languageName: string}} opts
|
|
1668
|
+
*/
|
|
1669
|
+
function registerAliases(aliasList, { languageName }) {
|
|
1670
|
+
if (typeof aliasList === "string") aliasList = [aliasList];
|
|
1671
|
+
aliasList.forEach((alias) => {
|
|
1672
|
+
aliases[alias.toLowerCase()] = languageName;
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Determines if a given language has auto-detection enabled
|
|
1677
|
+
* @param {string} name - name of the language
|
|
1678
|
+
*/
|
|
1679
|
+
function autoDetection(name) {
|
|
1680
|
+
const lang = getLanguage(name);
|
|
1681
|
+
return lang && !lang.disableAutodetect;
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Upgrades the old highlightBlock plugins to the new
|
|
1685
|
+
* highlightElement API
|
|
1686
|
+
* @param {HLJSPlugin} plugin
|
|
1687
|
+
*/
|
|
1688
|
+
function upgradePluginAPI(plugin) {
|
|
1689
|
+
if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) plugin["before:highlightElement"] = (data) => {
|
|
1690
|
+
plugin["before:highlightBlock"](Object.assign({ block: data.el }, data));
|
|
1691
|
+
};
|
|
1692
|
+
if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) plugin["after:highlightElement"] = (data) => {
|
|
1693
|
+
plugin["after:highlightBlock"](Object.assign({ block: data.el }, data));
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* @param {HLJSPlugin} plugin
|
|
1698
|
+
*/
|
|
1699
|
+
function addPlugin(plugin) {
|
|
1700
|
+
upgradePluginAPI(plugin);
|
|
1701
|
+
plugins.push(plugin);
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
*
|
|
1705
|
+
* @param {PluginEvent} event
|
|
1706
|
+
* @param {any} args
|
|
1707
|
+
*/
|
|
1708
|
+
function fire(event, args) {
|
|
1709
|
+
const cb = event;
|
|
1710
|
+
plugins.forEach(function(plugin) {
|
|
1711
|
+
if (plugin[cb]) plugin[cb](args);
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
Note: fixMarkup is deprecated and will be removed entirely in v11
|
|
1716
|
+
|
|
1717
|
+
@param {string} arg
|
|
1718
|
+
@returns {string}
|
|
1719
|
+
*/
|
|
1720
|
+
function deprecateFixMarkup(arg) {
|
|
1721
|
+
deprecated("10.2.0", "fixMarkup will be removed entirely in v11.0");
|
|
1722
|
+
deprecated("10.2.0", "Please see https://github.com/highlightjs/highlight.js/issues/2534");
|
|
1723
|
+
return fixMarkup(arg);
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
*
|
|
1727
|
+
* @param {HighlightedHTMLElement} el
|
|
1728
|
+
*/
|
|
1729
|
+
function deprecateHighlightBlock(el) {
|
|
1730
|
+
deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
|
|
1731
|
+
deprecated("10.7.0", "Please use highlightElement now.");
|
|
1732
|
+
return highlightElement(el);
|
|
1733
|
+
}
|
|
1734
|
+
Object.assign(hljs, {
|
|
1735
|
+
highlight,
|
|
1736
|
+
highlightAuto,
|
|
1737
|
+
highlightAll,
|
|
1738
|
+
fixMarkup: deprecateFixMarkup,
|
|
1739
|
+
highlightElement,
|
|
1740
|
+
highlightBlock: deprecateHighlightBlock,
|
|
1741
|
+
configure,
|
|
1742
|
+
initHighlighting,
|
|
1743
|
+
initHighlightingOnLoad,
|
|
1744
|
+
registerLanguage,
|
|
1745
|
+
unregisterLanguage,
|
|
1746
|
+
listLanguages,
|
|
1747
|
+
getLanguage,
|
|
1748
|
+
registerAliases,
|
|
1749
|
+
requireLanguage,
|
|
1750
|
+
autoDetection,
|
|
1751
|
+
inherit: inherit$1,
|
|
1752
|
+
addPlugin,
|
|
1753
|
+
vuePlugin: BuildVuePlugin(hljs).VuePlugin
|
|
1754
|
+
});
|
|
1755
|
+
hljs.debugMode = function() {
|
|
1756
|
+
SAFE_MODE = false;
|
|
1757
|
+
};
|
|
1758
|
+
hljs.safeMode = function() {
|
|
1759
|
+
SAFE_MODE = true;
|
|
1760
|
+
};
|
|
1761
|
+
hljs.versionString = version;
|
|
1762
|
+
for (const key in MODES) if (typeof MODES[key] === "object") deepFreezeEs6(MODES[key]);
|
|
1763
|
+
Object.assign(hljs, MODES);
|
|
1764
|
+
hljs.addPlugin(brPlugin);
|
|
1765
|
+
hljs.addPlugin(mergeHTMLPlugin);
|
|
1766
|
+
hljs.addPlugin(tabReplacePlugin);
|
|
1767
|
+
return hljs;
|
|
1768
|
+
};
|
|
1769
|
+
var highlight = HLJS({});
|
|
1770
|
+
module.exports = highlight;
|
|
1771
|
+
}));
|
|
1772
|
+
|
|
1773
|
+
//#endregion
|
|
1774
|
+
//#region ../../node_modules/.pnpm/format@0.2.2/node_modules/format/format.js
|
|
1775
|
+
var require_format = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1776
|
+
(function() {
|
|
1777
|
+
var namespace;
|
|
1778
|
+
if (typeof module !== "undefined") namespace = module.exports = format;
|
|
1779
|
+
else namespace = function() {
|
|
1780
|
+
return this || (0, eval)("this");
|
|
1781
|
+
}();
|
|
1782
|
+
namespace.format = format;
|
|
1783
|
+
namespace.vsprintf = vsprintf;
|
|
1784
|
+
if (typeof console !== "undefined" && typeof console.log === "function") namespace.printf = printf;
|
|
1785
|
+
function printf() {
|
|
1786
|
+
console.log(format.apply(null, arguments));
|
|
1787
|
+
}
|
|
1788
|
+
function vsprintf(fmt, replacements) {
|
|
1789
|
+
return format.apply(null, [fmt].concat(replacements));
|
|
1790
|
+
}
|
|
1791
|
+
function format(fmt) {
|
|
1792
|
+
var argIndex = 1, args = [].slice.call(arguments), i = 0, n = fmt.length, result = "", c, escaped = false, arg, tmp, leadingZero = false, precision, nextArg = function() {
|
|
1793
|
+
return args[argIndex++];
|
|
1794
|
+
}, slurpNumber = function() {
|
|
1795
|
+
var digits = "";
|
|
1796
|
+
while (/\d/.test(fmt[i])) {
|
|
1797
|
+
digits += fmt[i++];
|
|
1798
|
+
c = fmt[i];
|
|
1799
|
+
}
|
|
1800
|
+
return digits.length > 0 ? parseInt(digits) : null;
|
|
1801
|
+
};
|
|
1802
|
+
for (; i < n; ++i) {
|
|
1803
|
+
c = fmt[i];
|
|
1804
|
+
if (escaped) {
|
|
1805
|
+
escaped = false;
|
|
1806
|
+
if (c == ".") {
|
|
1807
|
+
leadingZero = false;
|
|
1808
|
+
c = fmt[++i];
|
|
1809
|
+
} else if (c == "0" && fmt[i + 1] == ".") {
|
|
1810
|
+
leadingZero = true;
|
|
1811
|
+
i += 2;
|
|
1812
|
+
c = fmt[i];
|
|
1813
|
+
} else leadingZero = true;
|
|
1814
|
+
precision = slurpNumber();
|
|
1815
|
+
switch (c) {
|
|
1816
|
+
case "b":
|
|
1817
|
+
result += parseInt(nextArg(), 10).toString(2);
|
|
1818
|
+
break;
|
|
1819
|
+
case "c":
|
|
1820
|
+
arg = nextArg();
|
|
1821
|
+
if (typeof arg === "string" || arg instanceof String) result += arg;
|
|
1822
|
+
else result += String.fromCharCode(parseInt(arg, 10));
|
|
1823
|
+
break;
|
|
1824
|
+
case "d":
|
|
1825
|
+
result += parseInt(nextArg(), 10);
|
|
1826
|
+
break;
|
|
1827
|
+
case "f":
|
|
1828
|
+
tmp = String(parseFloat(nextArg()).toFixed(precision || 6));
|
|
1829
|
+
result += leadingZero ? tmp : tmp.replace(/^0/, "");
|
|
1830
|
+
break;
|
|
1831
|
+
case "j":
|
|
1832
|
+
result += JSON.stringify(nextArg());
|
|
1833
|
+
break;
|
|
1834
|
+
case "o":
|
|
1835
|
+
result += "0" + parseInt(nextArg(), 10).toString(8);
|
|
1836
|
+
break;
|
|
1837
|
+
case "s":
|
|
1838
|
+
result += nextArg();
|
|
1839
|
+
break;
|
|
1840
|
+
case "x":
|
|
1841
|
+
result += "0x" + parseInt(nextArg(), 10).toString(16);
|
|
1842
|
+
break;
|
|
1843
|
+
case "X":
|
|
1844
|
+
result += "0x" + parseInt(nextArg(), 10).toString(16).toUpperCase();
|
|
1845
|
+
break;
|
|
1846
|
+
default:
|
|
1847
|
+
result += c;
|
|
1848
|
+
break;
|
|
1849
|
+
}
|
|
1850
|
+
} else if (c === "%") escaped = true;
|
|
1851
|
+
else result += c;
|
|
1852
|
+
}
|
|
1853
|
+
return result;
|
|
1854
|
+
}
|
|
1855
|
+
})();
|
|
1856
|
+
}));
|
|
1857
|
+
|
|
1858
|
+
//#endregion
|
|
1859
|
+
//#region ../../node_modules/.pnpm/fault@1.0.4/node_modules/fault/index.js
|
|
1860
|
+
var require_fault = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1861
|
+
var formatter = require_format();
|
|
1862
|
+
var fault = create(Error);
|
|
1863
|
+
module.exports = fault;
|
|
1864
|
+
fault.eval = create(EvalError);
|
|
1865
|
+
fault.range = create(RangeError);
|
|
1866
|
+
fault.reference = create(ReferenceError);
|
|
1867
|
+
fault.syntax = create(SyntaxError);
|
|
1868
|
+
fault.type = create(TypeError);
|
|
1869
|
+
fault.uri = create(URIError);
|
|
1870
|
+
fault.create = create;
|
|
1871
|
+
function create(EConstructor) {
|
|
1872
|
+
FormattedError.displayName = EConstructor.displayName || EConstructor.name;
|
|
1873
|
+
return FormattedError;
|
|
1874
|
+
function FormattedError(format) {
|
|
1875
|
+
if (format) format = formatter.apply(null, arguments);
|
|
1876
|
+
return new EConstructor(format);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}));
|
|
1880
|
+
|
|
1881
|
+
//#endregion
|
|
1882
|
+
//#region ../../node_modules/.pnpm/lowlight@1.20.0/node_modules/lowlight/lib/core.js
|
|
1883
|
+
var require_core = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1884
|
+
var high = require_core$1();
|
|
1885
|
+
var fault = require_fault();
|
|
1886
|
+
exports.highlight = highlight;
|
|
1887
|
+
exports.highlightAuto = highlightAuto;
|
|
1888
|
+
exports.registerLanguage = registerLanguage;
|
|
1889
|
+
exports.listLanguages = listLanguages;
|
|
1890
|
+
exports.registerAlias = registerAlias;
|
|
1891
|
+
Emitter.prototype.addText = text;
|
|
1892
|
+
Emitter.prototype.addKeyword = addKeyword;
|
|
1893
|
+
Emitter.prototype.addSublanguage = addSublanguage;
|
|
1894
|
+
Emitter.prototype.openNode = open;
|
|
1895
|
+
Emitter.prototype.closeNode = close;
|
|
1896
|
+
Emitter.prototype.closeAllNodes = noop;
|
|
1897
|
+
Emitter.prototype.finalize = noop;
|
|
1898
|
+
Emitter.prototype.toHTML = toHtmlNoop;
|
|
1899
|
+
var defaultPrefix = "hljs-";
|
|
1900
|
+
function highlight(name, value, options) {
|
|
1901
|
+
var before = high.configure({});
|
|
1902
|
+
var prefix = (options || {}).prefix;
|
|
1903
|
+
var result;
|
|
1904
|
+
if (typeof name !== "string") throw fault("Expected `string` for name, got `%s`", name);
|
|
1905
|
+
if (!high.getLanguage(name)) throw fault("Unknown language: `%s` is not registered", name);
|
|
1906
|
+
if (typeof value !== "string") throw fault("Expected `string` for value, got `%s`", value);
|
|
1907
|
+
if (prefix === null || prefix === void 0) prefix = defaultPrefix;
|
|
1908
|
+
high.configure({
|
|
1909
|
+
__emitter: Emitter,
|
|
1910
|
+
classPrefix: prefix
|
|
1911
|
+
});
|
|
1912
|
+
result = high.highlight(value, {
|
|
1913
|
+
language: name,
|
|
1914
|
+
ignoreIllegals: true
|
|
1915
|
+
});
|
|
1916
|
+
high.configure(before || {});
|
|
1917
|
+
/* istanbul ignore if - Highlight.js seems to use this (currently) for broken
|
|
1918
|
+
* grammars, so let’s keep it in there just to be sure. */
|
|
1919
|
+
if (result.errorRaised) throw result.errorRaised;
|
|
1920
|
+
return {
|
|
1921
|
+
relevance: result.relevance,
|
|
1922
|
+
language: result.language,
|
|
1923
|
+
value: result.emitter.rootNode.children
|
|
1924
|
+
};
|
|
1925
|
+
}
|
|
1926
|
+
function highlightAuto(value, options) {
|
|
1927
|
+
var settings = options || {};
|
|
1928
|
+
var subset = settings.subset || high.listLanguages();
|
|
1929
|
+
var prefix = settings.prefix;
|
|
1930
|
+
var length = subset.length;
|
|
1931
|
+
var index = -1;
|
|
1932
|
+
var result;
|
|
1933
|
+
var secondBest;
|
|
1934
|
+
var current;
|
|
1935
|
+
var name;
|
|
1936
|
+
if (prefix === null || prefix === void 0) prefix = defaultPrefix;
|
|
1937
|
+
if (typeof value !== "string") throw fault("Expected `string` for value, got `%s`", value);
|
|
1938
|
+
secondBest = {
|
|
1939
|
+
relevance: 0,
|
|
1940
|
+
language: null,
|
|
1941
|
+
value: []
|
|
1942
|
+
};
|
|
1943
|
+
result = {
|
|
1944
|
+
relevance: 0,
|
|
1945
|
+
language: null,
|
|
1946
|
+
value: []
|
|
1947
|
+
};
|
|
1948
|
+
while (++index < length) {
|
|
1949
|
+
name = subset[index];
|
|
1950
|
+
if (!high.getLanguage(name)) continue;
|
|
1951
|
+
current = highlight(name, value, options);
|
|
1952
|
+
current.language = name;
|
|
1953
|
+
if (current.relevance > secondBest.relevance) secondBest = current;
|
|
1954
|
+
if (current.relevance > result.relevance) {
|
|
1955
|
+
secondBest = result;
|
|
1956
|
+
result = current;
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
if (secondBest.language) result.secondBest = secondBest;
|
|
1960
|
+
return result;
|
|
1961
|
+
}
|
|
1962
|
+
function registerLanguage(name, syntax) {
|
|
1963
|
+
high.registerLanguage(name, syntax);
|
|
1964
|
+
}
|
|
1965
|
+
function listLanguages() {
|
|
1966
|
+
return high.listLanguages();
|
|
1967
|
+
}
|
|
1968
|
+
function registerAlias(name, alias) {
|
|
1969
|
+
var map = name;
|
|
1970
|
+
var key;
|
|
1971
|
+
if (alias) {
|
|
1972
|
+
map = {};
|
|
1973
|
+
map[name] = alias;
|
|
1974
|
+
}
|
|
1975
|
+
for (key in map) high.registerAliases(map[key], { languageName: key });
|
|
1976
|
+
}
|
|
1977
|
+
function Emitter(options) {
|
|
1978
|
+
this.options = options;
|
|
1979
|
+
this.rootNode = { children: [] };
|
|
1980
|
+
this.stack = [this.rootNode];
|
|
1981
|
+
}
|
|
1982
|
+
function addKeyword(value, name) {
|
|
1983
|
+
this.openNode(name);
|
|
1984
|
+
this.addText(value);
|
|
1985
|
+
this.closeNode();
|
|
1986
|
+
}
|
|
1987
|
+
function addSublanguage(other, name) {
|
|
1988
|
+
var stack = this.stack;
|
|
1989
|
+
var current = stack[stack.length - 1];
|
|
1990
|
+
var results = other.rootNode.children;
|
|
1991
|
+
var node = name ? {
|
|
1992
|
+
type: "element",
|
|
1993
|
+
tagName: "span",
|
|
1994
|
+
properties: { className: [name] },
|
|
1995
|
+
children: results
|
|
1996
|
+
} : results;
|
|
1997
|
+
current.children = current.children.concat(node);
|
|
1998
|
+
}
|
|
1999
|
+
function text(value) {
|
|
2000
|
+
var stack = this.stack;
|
|
2001
|
+
var current;
|
|
2002
|
+
var tail;
|
|
2003
|
+
if (value === "") return;
|
|
2004
|
+
current = stack[stack.length - 1];
|
|
2005
|
+
tail = current.children[current.children.length - 1];
|
|
2006
|
+
if (tail && tail.type === "text") tail.value += value;
|
|
2007
|
+
else current.children.push({
|
|
2008
|
+
type: "text",
|
|
2009
|
+
value
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
function open(name) {
|
|
2013
|
+
var stack = this.stack;
|
|
2014
|
+
var className = this.options.classPrefix + name;
|
|
2015
|
+
var current = stack[stack.length - 1];
|
|
2016
|
+
var child = {
|
|
2017
|
+
type: "element",
|
|
2018
|
+
tagName: "span",
|
|
2019
|
+
properties: { className: [className] },
|
|
2020
|
+
children: []
|
|
2021
|
+
};
|
|
2022
|
+
current.children.push(child);
|
|
2023
|
+
stack.push(child);
|
|
2024
|
+
}
|
|
2025
|
+
function close() {
|
|
2026
|
+
this.stack.pop();
|
|
2027
|
+
}
|
|
2028
|
+
function toHtmlNoop() {
|
|
2029
|
+
return "";
|
|
2030
|
+
}
|
|
2031
|
+
function noop() {}
|
|
2032
|
+
}));
|
|
2033
|
+
|
|
2034
|
+
//#endregion
|
|
2035
|
+
export { require_core as t };
|