bajo-spatial 2.2.0 → 2.3.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/docs/BajoSpatial.html +1 -1
- package/docs/data/search.json +1 -1
- package/docs/global.html +1 -1
- package/docs/index.js.html +57 -17
- package/docs/scripts/core.js +477 -476
- package/docs/scripts/resize.js +36 -36
- package/docs/scripts/search.js +105 -105
- package/docs/scripts/third-party/fuse.js +1 -1
- package/docs/scripts/third-party/hljs-line-num-original.js +285 -282
- package/docs/scripts/third-party/hljs-line-num.js +1 -1
- package/docs/scripts/third-party/hljs-original.js +1202 -1195
- package/docs/scripts/third-party/hljs.js +1 -1
- package/docs/scripts/third-party/popper.js +1 -1
- package/docs/scripts/third-party/tippy.js +1 -1
- package/docs/scripts/third-party/tocbot.js +509 -508
- package/index.js +44 -4
- package/package.json +4 -2
- package/test/bajo-spatial.test.js +181 -0
- package/wiki/CHANGES.md +5 -0
|
@@ -3,41 +3,42 @@
|
|
|
3
3
|
(c) 2006-2021 Ivan Sagalaev and other contributors
|
|
4
4
|
License: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
'use strict'
|
|
6
|
+
var hljs = (function () {
|
|
7
|
+
'use strict';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
var deepFreezeEs6 = { exports: {} };
|
|
10
10
|
|
|
11
|
-
function deepFreeze
|
|
11
|
+
function deepFreeze(obj) {
|
|
12
12
|
if (obj instanceof Map) {
|
|
13
13
|
obj.clear = obj.delete = obj.set = function () {
|
|
14
|
-
throw new Error('map is read-only')
|
|
15
|
-
}
|
|
14
|
+
throw new Error('map is read-only');
|
|
15
|
+
};
|
|
16
16
|
} else if (obj instanceof Set) {
|
|
17
17
|
obj.add = obj.clear = obj.delete = function () {
|
|
18
|
-
throw new Error('set is read-only')
|
|
19
|
-
}
|
|
18
|
+
throw new Error('set is read-only');
|
|
19
|
+
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// Freeze self
|
|
23
|
-
Object.freeze(obj)
|
|
23
|
+
Object.freeze(obj);
|
|
24
24
|
|
|
25
25
|
Object.getOwnPropertyNames(obj).forEach(function (name) {
|
|
26
|
-
|
|
26
|
+
var prop = obj[name];
|
|
27
27
|
|
|
28
28
|
// Freeze prop if it is an object
|
|
29
|
-
if (typeof prop
|
|
30
|
-
deepFreeze(prop)
|
|
29
|
+
if (typeof prop == 'object' && !Object.isFrozen(prop)) {
|
|
30
|
+
deepFreeze(prop);
|
|
31
31
|
}
|
|
32
|
-
})
|
|
32
|
+
});
|
|
33
33
|
|
|
34
|
-
return obj
|
|
34
|
+
return obj;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
deepFreezeEs6.exports = deepFreeze
|
|
38
|
-
deepFreezeEs6.exports.default = deepFreeze
|
|
37
|
+
deepFreezeEs6.exports = deepFreeze;
|
|
38
|
+
deepFreezeEs6.exports.default = deepFreeze;
|
|
39
|
+
|
|
40
|
+
var deepFreeze$1 = deepFreezeEs6.exports;
|
|
39
41
|
|
|
40
|
-
const deepFreeze$1 = deepFreezeEs6.exports
|
|
41
42
|
|
|
42
43
|
/** @typedef {import('highlight.js').CompiledMode} CompiledMode */
|
|
43
44
|
/** @implements CallbackResponse */
|
|
@@ -46,16 +47,16 @@ const hljs = (function () {
|
|
|
46
47
|
/**
|
|
47
48
|
* @param {CompiledMode} mode
|
|
48
49
|
*/
|
|
49
|
-
constructor
|
|
50
|
+
constructor(mode) {
|
|
50
51
|
// eslint-disable-next-line no-undefined
|
|
51
|
-
if (mode.data === undefined) mode.data = {}
|
|
52
|
+
if (mode.data === undefined) mode.data = {};
|
|
52
53
|
|
|
53
|
-
this.data = mode.data
|
|
54
|
-
this.isMatchIgnored = false
|
|
54
|
+
this.data = mode.data;
|
|
55
|
+
this.isMatchIgnored = false;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
ignoreMatch
|
|
58
|
-
this.isMatchIgnored = true
|
|
58
|
+
ignoreMatch() {
|
|
59
|
+
this.isMatchIgnored = true;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -63,13 +64,13 @@ const hljs = (function () {
|
|
|
63
64
|
* @param {string} value
|
|
64
65
|
* @returns {string}
|
|
65
66
|
*/
|
|
66
|
-
function escapeHTML
|
|
67
|
+
function escapeHTML(value) {
|
|
67
68
|
return value
|
|
68
69
|
.replace(/&/g, '&')
|
|
69
70
|
.replace(/</g, '<')
|
|
70
71
|
.replace(/>/g, '>')
|
|
71
72
|
.replace(/"/g, '"')
|
|
72
|
-
.replace(/'/g, ''')
|
|
73
|
+
.replace(/'/g, ''');
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/**
|
|
@@ -80,19 +81,19 @@ const hljs = (function () {
|
|
|
80
81
|
* @param {Record<string,any>[]} objects
|
|
81
82
|
* @returns {T} a single new object
|
|
82
83
|
*/
|
|
83
|
-
function inherit$1
|
|
84
|
+
function inherit$1(original, ...objects) {
|
|
84
85
|
/** @type Record<string,any> */
|
|
85
|
-
const result = Object.create(null)
|
|
86
|
+
const result = Object.create(null);
|
|
86
87
|
|
|
87
88
|
for (const key in original) {
|
|
88
|
-
result[key] = original[key]
|
|
89
|
+
result[key] = original[key];
|
|
89
90
|
}
|
|
90
91
|
objects.forEach(function (obj) {
|
|
91
92
|
for (const key in obj) {
|
|
92
|
-
result[key] = obj[key]
|
|
93
|
+
result[key] = obj[key];
|
|
93
94
|
}
|
|
94
|
-
})
|
|
95
|
-
return /** @type {T} */ (result)
|
|
95
|
+
});
|
|
96
|
+
return /** @type {T} */ (result);
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
/**
|
|
@@ -107,15 +108,15 @@ const hljs = (function () {
|
|
|
107
108
|
/** @typedef {{walk: (r: Renderer) => void}} Tree */
|
|
108
109
|
/** */
|
|
109
110
|
|
|
110
|
-
const SPAN_CLOSE = '</span>'
|
|
111
|
+
const SPAN_CLOSE = '</span>';
|
|
111
112
|
|
|
112
113
|
/**
|
|
113
114
|
* Determines if a node needs to be wrapped in <span>
|
|
114
115
|
*
|
|
115
116
|
* @param {Node} node */
|
|
116
117
|
const emitsWrappingTags = (node) => {
|
|
117
|
-
return !!node.kind
|
|
118
|
-
}
|
|
118
|
+
return !!node.kind;
|
|
119
|
+
};
|
|
119
120
|
|
|
120
121
|
/**
|
|
121
122
|
*
|
|
@@ -123,15 +124,15 @@ const hljs = (function () {
|
|
|
123
124
|
* @param {{prefix:string}} options
|
|
124
125
|
*/
|
|
125
126
|
const expandScopeName = (name, { prefix }) => {
|
|
126
|
-
if (name.includes(
|
|
127
|
-
const pieces = name.split(
|
|
127
|
+
if (name.includes(".")) {
|
|
128
|
+
const pieces = name.split(".");
|
|
128
129
|
return [
|
|
129
130
|
`${prefix}${pieces.shift()}`,
|
|
130
|
-
...(pieces.map((x, i) => `${x}${
|
|
131
|
-
].join(
|
|
131
|
+
...(pieces.map((x, i) => `${x}${"_".repeat(i + 1)}`))
|
|
132
|
+
].join(" ");
|
|
132
133
|
}
|
|
133
|
-
return `${prefix}${name}
|
|
134
|
-
}
|
|
134
|
+
return `${prefix}${name}`;
|
|
135
|
+
};
|
|
135
136
|
|
|
136
137
|
/** @type {Renderer} */
|
|
137
138
|
class HTMLRenderer {
|
|
@@ -141,51 +142,51 @@ const hljs = (function () {
|
|
|
141
142
|
* @param {Tree} parseTree - the parse tree (must support `walk` API)
|
|
142
143
|
* @param {{classPrefix: string}} options
|
|
143
144
|
*/
|
|
144
|
-
constructor
|
|
145
|
-
this.buffer =
|
|
146
|
-
this.classPrefix = options.classPrefix
|
|
147
|
-
parseTree.walk(this)
|
|
145
|
+
constructor(parseTree, options) {
|
|
146
|
+
this.buffer = "";
|
|
147
|
+
this.classPrefix = options.classPrefix;
|
|
148
|
+
parseTree.walk(this);
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
/**
|
|
151
152
|
* Adds texts to the output stream
|
|
152
153
|
*
|
|
153
154
|
* @param {string} text */
|
|
154
|
-
addText
|
|
155
|
-
this.buffer += escapeHTML(text)
|
|
155
|
+
addText(text) {
|
|
156
|
+
this.buffer += escapeHTML(text);
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
/**
|
|
159
160
|
* Adds a node open to the output stream (if needed)
|
|
160
161
|
*
|
|
161
162
|
* @param {Node} node */
|
|
162
|
-
openNode
|
|
163
|
-
if (!emitsWrappingTags(node)) return
|
|
163
|
+
openNode(node) {
|
|
164
|
+
if (!emitsWrappingTags(node)) return;
|
|
164
165
|
|
|
165
|
-
let scope = node.kind
|
|
166
|
+
let scope = node.kind;
|
|
166
167
|
if (node.sublanguage) {
|
|
167
|
-
scope = `language-${scope}
|
|
168
|
+
scope = `language-${scope}`;
|
|
168
169
|
} else {
|
|
169
|
-
scope = expandScopeName(scope, { prefix: this.classPrefix })
|
|
170
|
+
scope = expandScopeName(scope, { prefix: this.classPrefix });
|
|
170
171
|
}
|
|
171
|
-
this.span(scope)
|
|
172
|
+
this.span(scope);
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
/**
|
|
175
176
|
* Adds a node close to the output stream (if needed)
|
|
176
177
|
*
|
|
177
178
|
* @param {Node} node */
|
|
178
|
-
closeNode
|
|
179
|
-
if (!emitsWrappingTags(node)) return
|
|
179
|
+
closeNode(node) {
|
|
180
|
+
if (!emitsWrappingTags(node)) return;
|
|
180
181
|
|
|
181
|
-
this.buffer += SPAN_CLOSE
|
|
182
|
+
this.buffer += SPAN_CLOSE;
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
/**
|
|
185
186
|
* returns the accumulated buffer
|
|
186
187
|
*/
|
|
187
|
-
value
|
|
188
|
-
return this.buffer
|
|
188
|
+
value() {
|
|
189
|
+
return this.buffer;
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
// helpers
|
|
@@ -194,8 +195,8 @@ const hljs = (function () {
|
|
|
194
195
|
* Builds a span element
|
|
195
196
|
*
|
|
196
197
|
* @param {string} className */
|
|
197
|
-
span
|
|
198
|
-
this.buffer += `<span class="${className}"
|
|
198
|
+
span(className) {
|
|
199
|
+
this.buffer += `<span class="${className}">`;
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
|
|
@@ -205,54 +206,54 @@ const hljs = (function () {
|
|
|
205
206
|
/** */
|
|
206
207
|
|
|
207
208
|
class TokenTree {
|
|
208
|
-
constructor
|
|
209
|
+
constructor() {
|
|
209
210
|
/** @type DataNode */
|
|
210
|
-
this.rootNode = { children: [] }
|
|
211
|
-
this.stack = [this.rootNode]
|
|
211
|
+
this.rootNode = { children: [] };
|
|
212
|
+
this.stack = [this.rootNode];
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
get top
|
|
215
|
-
return this.stack[this.stack.length - 1]
|
|
215
|
+
get top() {
|
|
216
|
+
return this.stack[this.stack.length - 1];
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
get root
|
|
219
|
+
get root() { return this.rootNode; }
|
|
219
220
|
|
|
220
221
|
/** @param {Node} node */
|
|
221
|
-
add
|
|
222
|
-
this.top.children.push(node)
|
|
222
|
+
add(node) {
|
|
223
|
+
this.top.children.push(node);
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
/** @param {string} kind */
|
|
226
|
-
openNode
|
|
227
|
+
openNode(kind) {
|
|
227
228
|
/** @type Node */
|
|
228
|
-
const node = { kind, children: [] }
|
|
229
|
-
this.add(node)
|
|
230
|
-
this.stack.push(node)
|
|
229
|
+
const node = { kind, children: [] };
|
|
230
|
+
this.add(node);
|
|
231
|
+
this.stack.push(node);
|
|
231
232
|
}
|
|
232
233
|
|
|
233
|
-
closeNode
|
|
234
|
+
closeNode() {
|
|
234
235
|
if (this.stack.length > 1) {
|
|
235
|
-
return this.stack.pop()
|
|
236
|
+
return this.stack.pop();
|
|
236
237
|
}
|
|
237
238
|
// eslint-disable-next-line no-undefined
|
|
238
|
-
return undefined
|
|
239
|
+
return undefined;
|
|
239
240
|
}
|
|
240
241
|
|
|
241
|
-
closeAllNodes
|
|
242
|
+
closeAllNodes() {
|
|
242
243
|
while (this.closeNode());
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
toJSON
|
|
246
|
-
return JSON.stringify(this.rootNode, null, 4)
|
|
246
|
+
toJSON() {
|
|
247
|
+
return JSON.stringify(this.rootNode, null, 4);
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
/**
|
|
250
251
|
* @typedef { import("./html_renderer").Renderer } Renderer
|
|
251
252
|
* @param {Renderer} builder
|
|
252
253
|
*/
|
|
253
|
-
walk
|
|
254
|
+
walk(builder) {
|
|
254
255
|
// this does not
|
|
255
|
-
return this.constructor._walk(builder, this.rootNode)
|
|
256
|
+
return this.constructor._walk(builder, this.rootNode);
|
|
256
257
|
// this works
|
|
257
258
|
// return TokenTree._walk(builder, this.rootNode);
|
|
258
259
|
}
|
|
@@ -261,32 +262,32 @@ const hljs = (function () {
|
|
|
261
262
|
* @param {Renderer} builder
|
|
262
263
|
* @param {Node} node
|
|
263
264
|
*/
|
|
264
|
-
static _walk
|
|
265
|
-
if (typeof node ===
|
|
266
|
-
builder.addText(node)
|
|
265
|
+
static _walk(builder, node) {
|
|
266
|
+
if (typeof node === "string") {
|
|
267
|
+
builder.addText(node);
|
|
267
268
|
} else if (node.children) {
|
|
268
|
-
builder.openNode(node)
|
|
269
|
-
node.children.forEach((child) => this._walk(builder, child))
|
|
270
|
-
builder.closeNode(node)
|
|
269
|
+
builder.openNode(node);
|
|
270
|
+
node.children.forEach((child) => this._walk(builder, child));
|
|
271
|
+
builder.closeNode(node);
|
|
271
272
|
}
|
|
272
|
-
return builder
|
|
273
|
+
return builder;
|
|
273
274
|
}
|
|
274
275
|
|
|
275
276
|
/**
|
|
276
277
|
* @param {Node} node
|
|
277
278
|
*/
|
|
278
|
-
static _collapse
|
|
279
|
-
if (typeof node ===
|
|
280
|
-
if (!node.children) return
|
|
279
|
+
static _collapse(node) {
|
|
280
|
+
if (typeof node === "string") return;
|
|
281
|
+
if (!node.children) return;
|
|
281
282
|
|
|
282
|
-
if (node.children.every(el => typeof el ===
|
|
283
|
+
if (node.children.every(el => typeof el === "string")) {
|
|
283
284
|
// node.text = node.children.join("");
|
|
284
285
|
// delete node.children;
|
|
285
|
-
node.children = [node.children.join(
|
|
286
|
+
node.children = [node.children.join("")];
|
|
286
287
|
} else {
|
|
287
288
|
node.children.forEach((child) => {
|
|
288
|
-
TokenTree._collapse(child)
|
|
289
|
-
})
|
|
289
|
+
TokenTree._collapse(child);
|
|
290
|
+
});
|
|
290
291
|
}
|
|
291
292
|
}
|
|
292
293
|
}
|
|
@@ -315,51 +316,51 @@ const hljs = (function () {
|
|
|
315
316
|
/**
|
|
316
317
|
* @param {*} options
|
|
317
318
|
*/
|
|
318
|
-
constructor
|
|
319
|
-
super()
|
|
320
|
-
this.options = options
|
|
319
|
+
constructor(options) {
|
|
320
|
+
super();
|
|
321
|
+
this.options = options;
|
|
321
322
|
}
|
|
322
323
|
|
|
323
324
|
/**
|
|
324
325
|
* @param {string} text
|
|
325
326
|
* @param {string} kind
|
|
326
327
|
*/
|
|
327
|
-
addKeyword
|
|
328
|
-
if (text ===
|
|
328
|
+
addKeyword(text, kind) {
|
|
329
|
+
if (text === "") { return; }
|
|
329
330
|
|
|
330
|
-
this.openNode(kind)
|
|
331
|
-
this.addText(text)
|
|
332
|
-
this.closeNode()
|
|
331
|
+
this.openNode(kind);
|
|
332
|
+
this.addText(text);
|
|
333
|
+
this.closeNode();
|
|
333
334
|
}
|
|
334
335
|
|
|
335
336
|
/**
|
|
336
337
|
* @param {string} text
|
|
337
338
|
*/
|
|
338
|
-
addText
|
|
339
|
-
if (text ===
|
|
339
|
+
addText(text) {
|
|
340
|
+
if (text === "") { return; }
|
|
340
341
|
|
|
341
|
-
this.add(text)
|
|
342
|
+
this.add(text);
|
|
342
343
|
}
|
|
343
344
|
|
|
344
345
|
/**
|
|
345
346
|
* @param {Emitter & {root: DataNode}} emitter
|
|
346
347
|
* @param {string} name
|
|
347
348
|
*/
|
|
348
|
-
addSublanguage
|
|
349
|
+
addSublanguage(emitter, name) {
|
|
349
350
|
/** @type DataNode */
|
|
350
|
-
const node = emitter.root
|
|
351
|
-
node.kind = name
|
|
352
|
-
node.sublanguage = true
|
|
353
|
-
this.add(node)
|
|
351
|
+
const node = emitter.root;
|
|
352
|
+
node.kind = name;
|
|
353
|
+
node.sublanguage = true;
|
|
354
|
+
this.add(node);
|
|
354
355
|
}
|
|
355
356
|
|
|
356
|
-
toHTML
|
|
357
|
-
const renderer = new HTMLRenderer(this, this.options)
|
|
358
|
-
return renderer.value()
|
|
357
|
+
toHTML() {
|
|
358
|
+
const renderer = new HTMLRenderer(this, this.options);
|
|
359
|
+
return renderer.value();
|
|
359
360
|
}
|
|
360
361
|
|
|
361
|
-
finalize
|
|
362
|
-
return true
|
|
362
|
+
finalize() {
|
|
363
|
+
return true;
|
|
363
364
|
}
|
|
364
365
|
}
|
|
365
366
|
|
|
@@ -372,46 +373,46 @@ const hljs = (function () {
|
|
|
372
373
|
* @param {RegExp | string } re
|
|
373
374
|
* @returns {string}
|
|
374
375
|
*/
|
|
375
|
-
function source
|
|
376
|
-
if (!re) return null
|
|
377
|
-
if (typeof re ===
|
|
376
|
+
function source(re) {
|
|
377
|
+
if (!re) return null;
|
|
378
|
+
if (typeof re === "string") return re;
|
|
378
379
|
|
|
379
|
-
return re.source
|
|
380
|
+
return re.source;
|
|
380
381
|
}
|
|
381
382
|
|
|
382
383
|
/**
|
|
383
384
|
* @param {RegExp | string } re
|
|
384
385
|
* @returns {string}
|
|
385
386
|
*/
|
|
386
|
-
function lookahead
|
|
387
|
-
return concat('(?=', re, ')')
|
|
387
|
+
function lookahead(re) {
|
|
388
|
+
return concat('(?=', re, ')');
|
|
388
389
|
}
|
|
389
390
|
|
|
390
391
|
/**
|
|
391
392
|
* @param {RegExp | string } re
|
|
392
393
|
* @returns {string}
|
|
393
394
|
*/
|
|
394
|
-
function optional
|
|
395
|
-
return concat('(?:', re, ')?')
|
|
395
|
+
function optional(re) {
|
|
396
|
+
return concat('(?:', re, ')?');
|
|
396
397
|
}
|
|
397
398
|
|
|
398
399
|
/**
|
|
399
400
|
* @param {...(RegExp | string) } args
|
|
400
401
|
* @returns {string}
|
|
401
402
|
*/
|
|
402
|
-
function concat
|
|
403
|
-
const joined = args.map((x) => source(x)).join(
|
|
404
|
-
return joined
|
|
403
|
+
function concat(...args) {
|
|
404
|
+
const joined = args.map((x) => source(x)).join("");
|
|
405
|
+
return joined;
|
|
405
406
|
}
|
|
406
407
|
|
|
407
|
-
function stripOptionsFromArgs
|
|
408
|
-
const opts = args[args.length - 1]
|
|
408
|
+
function stripOptionsFromArgs(args) {
|
|
409
|
+
const opts = args[args.length - 1];
|
|
409
410
|
|
|
410
411
|
if (typeof opts === 'object' && opts.constructor === Object) {
|
|
411
|
-
args.splice(args.length - 1, 1)
|
|
412
|
-
return opts
|
|
412
|
+
args.splice(args.length - 1, 1);
|
|
413
|
+
return opts;
|
|
413
414
|
} else {
|
|
414
|
-
return {}
|
|
415
|
+
return {};
|
|
415
416
|
}
|
|
416
417
|
}
|
|
417
418
|
|
|
@@ -422,20 +423,20 @@ const hljs = (function () {
|
|
|
422
423
|
* @param {(RegExp | string)[] } args
|
|
423
424
|
* @returns {string}
|
|
424
425
|
*/
|
|
425
|
-
function either
|
|
426
|
-
const opts = stripOptionsFromArgs(args)
|
|
426
|
+
function either(...args) {
|
|
427
|
+
const opts = stripOptionsFromArgs(args);
|
|
427
428
|
const joined = '(' +
|
|
428
|
-
(opts.capture ?
|
|
429
|
-
args.map((x) => source(x)).join(
|
|
430
|
-
return joined
|
|
429
|
+
(opts.capture ? "" : "?:") +
|
|
430
|
+
args.map((x) => source(x)).join("|") + ")";
|
|
431
|
+
return joined;
|
|
431
432
|
}
|
|
432
433
|
|
|
433
434
|
/**
|
|
434
435
|
* @param {RegExp} re
|
|
435
436
|
* @returns {number}
|
|
436
437
|
*/
|
|
437
|
-
function countMatchGroups
|
|
438
|
-
return (new RegExp(re.toString() + '|')).exec('').length - 1
|
|
438
|
+
function countMatchGroups(re) {
|
|
439
|
+
return (new RegExp(re.toString() + '|')).exec('').length - 1;
|
|
439
440
|
}
|
|
440
441
|
|
|
441
442
|
/**
|
|
@@ -443,9 +444,9 @@ const hljs = (function () {
|
|
|
443
444
|
* @param {RegExp} re
|
|
444
445
|
* @param {string} lexeme
|
|
445
446
|
*/
|
|
446
|
-
function startsWith
|
|
447
|
-
const match = re && re.exec(lexeme)
|
|
448
|
-
return match && match.index === 0
|
|
447
|
+
function startsWith(re, lexeme) {
|
|
448
|
+
const match = re && re.exec(lexeme);
|
|
449
|
+
return match && match.index === 0;
|
|
449
450
|
}
|
|
450
451
|
|
|
451
452
|
// BACKREF_RE matches an open parenthesis or backreference. To avoid
|
|
@@ -455,7 +456,7 @@ const hljs = (function () {
|
|
|
455
456
|
// interesting elements
|
|
456
457
|
// - non-matching or lookahead parentheses, which do not capture. These
|
|
457
458
|
// follow the '(' with a '?'.
|
|
458
|
-
const BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)
|
|
459
|
+
const BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
|
|
459
460
|
|
|
460
461
|
// **INTERNAL** Not intended for outside usage
|
|
461
462
|
// join logically computes regexps.join(separator), but fixes the
|
|
@@ -468,60 +469,60 @@ const hljs = (function () {
|
|
|
468
469
|
* @param {{joinWith: string}} opts
|
|
469
470
|
* @returns {string}
|
|
470
471
|
*/
|
|
471
|
-
function _rewriteBackreferences
|
|
472
|
-
let numCaptures = 0
|
|
472
|
+
function _rewriteBackreferences(regexps, { joinWith }) {
|
|
473
|
+
let numCaptures = 0;
|
|
473
474
|
|
|
474
475
|
return regexps.map((regex) => {
|
|
475
|
-
numCaptures += 1
|
|
476
|
-
const offset = numCaptures
|
|
477
|
-
let re = source(regex)
|
|
478
|
-
let out = ''
|
|
476
|
+
numCaptures += 1;
|
|
477
|
+
const offset = numCaptures;
|
|
478
|
+
let re = source(regex);
|
|
479
|
+
let out = '';
|
|
479
480
|
|
|
480
481
|
while (re.length > 0) {
|
|
481
|
-
const match = BACKREF_RE.exec(re)
|
|
482
|
+
const match = BACKREF_RE.exec(re);
|
|
482
483
|
if (!match) {
|
|
483
|
-
out += re
|
|
484
|
-
break
|
|
484
|
+
out += re;
|
|
485
|
+
break;
|
|
485
486
|
}
|
|
486
|
-
out += re.substring(0, match.index)
|
|
487
|
-
re = re.substring(match.index + match[0].length)
|
|
487
|
+
out += re.substring(0, match.index);
|
|
488
|
+
re = re.substring(match.index + match[0].length);
|
|
488
489
|
if (match[0][0] === '\\' && match[1]) {
|
|
489
490
|
// Adjust the backreference.
|
|
490
|
-
out += '\\' + String(Number(match[1]) + offset)
|
|
491
|
+
out += '\\' + String(Number(match[1]) + offset);
|
|
491
492
|
} else {
|
|
492
|
-
out += match[0]
|
|
493
|
+
out += match[0];
|
|
493
494
|
if (match[0] === '(') {
|
|
494
|
-
numCaptures
|
|
495
|
+
numCaptures++;
|
|
495
496
|
}
|
|
496
497
|
}
|
|
497
498
|
}
|
|
498
|
-
return out
|
|
499
|
-
}).map(re => `(${re})`).join(joinWith)
|
|
499
|
+
return out;
|
|
500
|
+
}).map(re => `(${re})`).join(joinWith);
|
|
500
501
|
}
|
|
501
502
|
|
|
502
503
|
/** @typedef {import('highlight.js').Mode} Mode */
|
|
503
504
|
/** @typedef {import('highlight.js').ModeCallback} ModeCallback */
|
|
504
505
|
|
|
505
506
|
// Common regexps
|
|
506
|
-
const MATCH_NOTHING_RE = /\b\B
|
|
507
|
-
const IDENT_RE$1 = '[a-zA-Z]\\w*'
|
|
508
|
-
const UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*'
|
|
509
|
-
const NUMBER_RE = '\\b\\d+(\\.\\d+)?'
|
|
510
|
-
const C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)' // 0x..., 0..., decimal, float
|
|
511
|
-
const BINARY_NUMBER_RE = '\\b(0b[01]+)' // 0b...
|
|
512
|
-
const RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~'
|
|
507
|
+
const MATCH_NOTHING_RE = /\b\B/;
|
|
508
|
+
const IDENT_RE$1 = '[a-zA-Z]\\w*';
|
|
509
|
+
const UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*';
|
|
510
|
+
const NUMBER_RE = '\\b\\d+(\\.\\d+)?';
|
|
511
|
+
const C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float
|
|
512
|
+
const BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b...
|
|
513
|
+
const RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';
|
|
513
514
|
|
|
514
515
|
/**
|
|
515
516
|
* @param { Partial<Mode> & {binary?: string | RegExp} } opts
|
|
516
517
|
*/
|
|
517
518
|
const SHEBANG = (opts = {}) => {
|
|
518
|
-
const beginShebang = /^#![ ]
|
|
519
|
+
const beginShebang = /^#![ ]*\//;
|
|
519
520
|
if (opts.binary) {
|
|
520
521
|
opts.begin = concat(
|
|
521
522
|
beginShebang,
|
|
522
523
|
/.*\b/,
|
|
523
524
|
opts.binary,
|
|
524
|
-
/\b.*/)
|
|
525
|
+
/\b.*/);
|
|
525
526
|
}
|
|
526
527
|
return inherit$1({
|
|
527
528
|
scope: 'meta',
|
|
@@ -529,33 +530,33 @@ const hljs = (function () {
|
|
|
529
530
|
end: /$/,
|
|
530
531
|
relevance: 0,
|
|
531
532
|
/** @type {ModeCallback} */
|
|
532
|
-
|
|
533
|
-
if (m.index !== 0) resp.ignoreMatch()
|
|
533
|
+
"on:begin": (m, resp) => {
|
|
534
|
+
if (m.index !== 0) resp.ignoreMatch();
|
|
534
535
|
}
|
|
535
|
-
}, opts)
|
|
536
|
-
}
|
|
536
|
+
}, opts);
|
|
537
|
+
};
|
|
537
538
|
|
|
538
539
|
// Common modes
|
|
539
540
|
const BACKSLASH_ESCAPE = {
|
|
540
541
|
begin: '\\\\[\\s\\S]', relevance: 0
|
|
541
|
-
}
|
|
542
|
+
};
|
|
542
543
|
const APOS_STRING_MODE = {
|
|
543
544
|
scope: 'string',
|
|
544
545
|
begin: '\'',
|
|
545
546
|
end: '\'',
|
|
546
547
|
illegal: '\\n',
|
|
547
548
|
contains: [BACKSLASH_ESCAPE]
|
|
548
|
-
}
|
|
549
|
+
};
|
|
549
550
|
const QUOTE_STRING_MODE = {
|
|
550
551
|
scope: 'string',
|
|
551
552
|
begin: '"',
|
|
552
553
|
end: '"',
|
|
553
554
|
illegal: '\\n',
|
|
554
555
|
contains: [BACKSLASH_ESCAPE]
|
|
555
|
-
}
|
|
556
|
+
};
|
|
556
557
|
const PHRASAL_WORDS_MODE = {
|
|
557
558
|
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/
|
|
558
|
-
}
|
|
559
|
+
};
|
|
559
560
|
/**
|
|
560
561
|
* Creates a comment mode
|
|
561
562
|
*
|
|
@@ -573,7 +574,7 @@ const hljs = (function () {
|
|
|
573
574
|
contains: []
|
|
574
575
|
},
|
|
575
576
|
modeOptions
|
|
576
|
-
)
|
|
577
|
+
);
|
|
577
578
|
mode.contains.push({
|
|
578
579
|
scope: 'doctag',
|
|
579
580
|
// hack to avoid the space from being included. the space is necessary to
|
|
@@ -582,25 +583,25 @@ const hljs = (function () {
|
|
|
582
583
|
end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
|
|
583
584
|
excludeBegin: true,
|
|
584
585
|
relevance: 0
|
|
585
|
-
})
|
|
586
|
+
});
|
|
586
587
|
const ENGLISH_WORD = either(
|
|
587
588
|
// list of common 1 and 2 letter words in English
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
589
|
+
"I",
|
|
590
|
+
"a",
|
|
591
|
+
"is",
|
|
592
|
+
"so",
|
|
593
|
+
"us",
|
|
594
|
+
"to",
|
|
595
|
+
"at",
|
|
596
|
+
"if",
|
|
597
|
+
"in",
|
|
598
|
+
"it",
|
|
599
|
+
"on",
|
|
599
600
|
// note: this is not an exhaustive list of contractions, just popular ones
|
|
600
601
|
/[A-Za-z]+['](d|ve|re|ll|t|s|n)/, // contractions - can't we'd they're let's, etc
|
|
601
602
|
/[A-Za-z]+[-][a-z]+/, // `no-way`, etc.
|
|
602
603
|
/[A-Za-z][a-z]{2,}/ // allow capitalized words at beginning of sentences
|
|
603
|
-
)
|
|
604
|
+
);
|
|
604
605
|
// looking like plain text, more likely to be a comment
|
|
605
606
|
mode.contains.push(
|
|
606
607
|
{
|
|
@@ -626,27 +627,27 @@ const hljs = (function () {
|
|
|
626
627
|
/[.]?[:]?([.][ ]|[ ])/,
|
|
627
628
|
'){3}') // look for 3 words in a row
|
|
628
629
|
}
|
|
629
|
-
)
|
|
630
|
-
return mode
|
|
631
|
-
}
|
|
632
|
-
const C_LINE_COMMENT_MODE = COMMENT('//', '$')
|
|
633
|
-
const C_BLOCK_COMMENT_MODE = COMMENT('/\\*', '\\*/')
|
|
634
|
-
const HASH_COMMENT_MODE = COMMENT('#', '$')
|
|
630
|
+
);
|
|
631
|
+
return mode;
|
|
632
|
+
};
|
|
633
|
+
const C_LINE_COMMENT_MODE = COMMENT('//', '$');
|
|
634
|
+
const C_BLOCK_COMMENT_MODE = COMMENT('/\\*', '\\*/');
|
|
635
|
+
const HASH_COMMENT_MODE = COMMENT('#', '$');
|
|
635
636
|
const NUMBER_MODE = {
|
|
636
637
|
scope: 'number',
|
|
637
638
|
begin: NUMBER_RE,
|
|
638
639
|
relevance: 0
|
|
639
|
-
}
|
|
640
|
+
};
|
|
640
641
|
const C_NUMBER_MODE = {
|
|
641
642
|
scope: 'number',
|
|
642
643
|
begin: C_NUMBER_RE,
|
|
643
644
|
relevance: 0
|
|
644
|
-
}
|
|
645
|
+
};
|
|
645
646
|
const BINARY_NUMBER_MODE = {
|
|
646
647
|
scope: 'number',
|
|
647
648
|
begin: BINARY_NUMBER_RE,
|
|
648
649
|
relevance: 0
|
|
649
|
-
}
|
|
650
|
+
};
|
|
650
651
|
const REGEXP_MODE = {
|
|
651
652
|
// this outer rule makes sure we actually have a WHOLE regex and not simply
|
|
652
653
|
// an expression such as:
|
|
@@ -670,22 +671,22 @@ const hljs = (function () {
|
|
|
670
671
|
}
|
|
671
672
|
]
|
|
672
673
|
}]
|
|
673
|
-
}
|
|
674
|
+
};
|
|
674
675
|
const TITLE_MODE = {
|
|
675
676
|
scope: 'title',
|
|
676
677
|
begin: IDENT_RE$1,
|
|
677
678
|
relevance: 0
|
|
678
|
-
}
|
|
679
|
+
};
|
|
679
680
|
const UNDERSCORE_TITLE_MODE = {
|
|
680
681
|
scope: 'title',
|
|
681
682
|
begin: UNDERSCORE_IDENT_RE,
|
|
682
683
|
relevance: 0
|
|
683
|
-
}
|
|
684
|
+
};
|
|
684
685
|
const METHOD_GUARD = {
|
|
685
686
|
// excludes method names from keyword processing
|
|
686
687
|
begin: '\\.\\s*' + UNDERSCORE_IDENT_RE,
|
|
687
688
|
relevance: 0
|
|
688
|
-
}
|
|
689
|
+
};
|
|
689
690
|
|
|
690
691
|
/**
|
|
691
692
|
* Adds end same as begin mechanics to a mode
|
|
@@ -698,39 +699,39 @@ const hljs = (function () {
|
|
|
698
699
|
return Object.assign(mode,
|
|
699
700
|
{
|
|
700
701
|
/** @type {ModeCallback} */
|
|
701
|
-
'on:begin': (m, resp) => { resp.data._beginMatch = m[1] },
|
|
702
|
+
'on:begin': (m, resp) => { resp.data._beginMatch = m[1]; },
|
|
702
703
|
/** @type {ModeCallback} */
|
|
703
|
-
'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch() }
|
|
704
|
-
})
|
|
705
|
-
}
|
|
704
|
+
'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch(); }
|
|
705
|
+
});
|
|
706
|
+
};
|
|
706
707
|
|
|
707
|
-
|
|
708
|
+
var MODES$1 = /*#__PURE__*/Object.freeze({
|
|
708
709
|
__proto__: null,
|
|
709
|
-
MATCH_NOTHING_RE,
|
|
710
|
+
MATCH_NOTHING_RE: MATCH_NOTHING_RE,
|
|
710
711
|
IDENT_RE: IDENT_RE$1,
|
|
711
|
-
UNDERSCORE_IDENT_RE,
|
|
712
|
-
NUMBER_RE,
|
|
713
|
-
C_NUMBER_RE,
|
|
714
|
-
BINARY_NUMBER_RE,
|
|
715
|
-
RE_STARTERS_RE,
|
|
716
|
-
SHEBANG,
|
|
717
|
-
BACKSLASH_ESCAPE,
|
|
718
|
-
APOS_STRING_MODE,
|
|
719
|
-
QUOTE_STRING_MODE,
|
|
720
|
-
PHRASAL_WORDS_MODE,
|
|
721
|
-
COMMENT,
|
|
722
|
-
C_LINE_COMMENT_MODE,
|
|
723
|
-
C_BLOCK_COMMENT_MODE,
|
|
724
|
-
HASH_COMMENT_MODE,
|
|
725
|
-
NUMBER_MODE,
|
|
726
|
-
C_NUMBER_MODE,
|
|
727
|
-
BINARY_NUMBER_MODE,
|
|
728
|
-
REGEXP_MODE,
|
|
729
|
-
TITLE_MODE,
|
|
730
|
-
UNDERSCORE_TITLE_MODE,
|
|
731
|
-
METHOD_GUARD,
|
|
732
|
-
END_SAME_AS_BEGIN
|
|
733
|
-
})
|
|
712
|
+
UNDERSCORE_IDENT_RE: UNDERSCORE_IDENT_RE,
|
|
713
|
+
NUMBER_RE: NUMBER_RE,
|
|
714
|
+
C_NUMBER_RE: C_NUMBER_RE,
|
|
715
|
+
BINARY_NUMBER_RE: BINARY_NUMBER_RE,
|
|
716
|
+
RE_STARTERS_RE: RE_STARTERS_RE,
|
|
717
|
+
SHEBANG: SHEBANG,
|
|
718
|
+
BACKSLASH_ESCAPE: BACKSLASH_ESCAPE,
|
|
719
|
+
APOS_STRING_MODE: APOS_STRING_MODE,
|
|
720
|
+
QUOTE_STRING_MODE: QUOTE_STRING_MODE,
|
|
721
|
+
PHRASAL_WORDS_MODE: PHRASAL_WORDS_MODE,
|
|
722
|
+
COMMENT: COMMENT,
|
|
723
|
+
C_LINE_COMMENT_MODE: C_LINE_COMMENT_MODE,
|
|
724
|
+
C_BLOCK_COMMENT_MODE: C_BLOCK_COMMENT_MODE,
|
|
725
|
+
HASH_COMMENT_MODE: HASH_COMMENT_MODE,
|
|
726
|
+
NUMBER_MODE: NUMBER_MODE,
|
|
727
|
+
C_NUMBER_MODE: C_NUMBER_MODE,
|
|
728
|
+
BINARY_NUMBER_MODE: BINARY_NUMBER_MODE,
|
|
729
|
+
REGEXP_MODE: REGEXP_MODE,
|
|
730
|
+
TITLE_MODE: TITLE_MODE,
|
|
731
|
+
UNDERSCORE_TITLE_MODE: UNDERSCORE_TITLE_MODE,
|
|
732
|
+
METHOD_GUARD: METHOD_GUARD,
|
|
733
|
+
END_SAME_AS_BEGIN: END_SAME_AS_BEGIN
|
|
734
|
+
});
|
|
734
735
|
|
|
735
736
|
/**
|
|
736
737
|
@typedef {import('highlight.js').CallbackResponse} CallbackResponse
|
|
@@ -761,10 +762,10 @@ const hljs = (function () {
|
|
|
761
762
|
* @param {RegExpMatchArray} match
|
|
762
763
|
* @param {CallbackResponse} response
|
|
763
764
|
*/
|
|
764
|
-
function skipIfHasPrecedingDot
|
|
765
|
-
const before = match.input[match.index - 1]
|
|
766
|
-
if (before ===
|
|
767
|
-
response.ignoreMatch()
|
|
765
|
+
function skipIfHasPrecedingDot(match, response) {
|
|
766
|
+
const before = match.input[match.index - 1];
|
|
767
|
+
if (before === ".") {
|
|
768
|
+
response.ignoreMatch();
|
|
768
769
|
}
|
|
769
770
|
}
|
|
770
771
|
|
|
@@ -772,11 +773,11 @@ const hljs = (function () {
|
|
|
772
773
|
*
|
|
773
774
|
* @type {CompilerExt}
|
|
774
775
|
*/
|
|
775
|
-
function scopeClassName
|
|
776
|
+
function scopeClassName(mode, _parent) {
|
|
776
777
|
// eslint-disable-next-line no-undefined
|
|
777
778
|
if (mode.className !== undefined) {
|
|
778
|
-
mode.scope = mode.className
|
|
779
|
-
delete mode.className
|
|
779
|
+
mode.scope = mode.className;
|
|
780
|
+
delete mode.className;
|
|
780
781
|
}
|
|
781
782
|
}
|
|
782
783
|
|
|
@@ -784,80 +785,80 @@ const hljs = (function () {
|
|
|
784
785
|
* `beginKeywords` syntactic sugar
|
|
785
786
|
* @type {CompilerExt}
|
|
786
787
|
*/
|
|
787
|
-
function beginKeywords
|
|
788
|
-
if (!parent) return
|
|
789
|
-
if (!mode.beginKeywords) return
|
|
788
|
+
function beginKeywords(mode, parent) {
|
|
789
|
+
if (!parent) return;
|
|
790
|
+
if (!mode.beginKeywords) return;
|
|
790
791
|
|
|
791
792
|
// for languages with keywords that include non-word characters checking for
|
|
792
793
|
// a word boundary is not sufficient, so instead we check for a word boundary
|
|
793
794
|
// or whitespace - this does no harm in any case since our keyword engine
|
|
794
795
|
// doesn't allow spaces in keywords anyways and we still check for the boundary
|
|
795
796
|
// first
|
|
796
|
-
mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\.)(?=\\b|\\s)'
|
|
797
|
-
mode.__beforeBegin = skipIfHasPrecedingDot
|
|
798
|
-
mode.keywords = mode.keywords || mode.beginKeywords
|
|
799
|
-
delete mode.beginKeywords
|
|
797
|
+
mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\.)(?=\\b|\\s)';
|
|
798
|
+
mode.__beforeBegin = skipIfHasPrecedingDot;
|
|
799
|
+
mode.keywords = mode.keywords || mode.beginKeywords;
|
|
800
|
+
delete mode.beginKeywords;
|
|
800
801
|
|
|
801
802
|
// prevents double relevance, the keywords themselves provide
|
|
802
803
|
// relevance, the mode doesn't need to double it
|
|
803
804
|
// eslint-disable-next-line no-undefined
|
|
804
|
-
if (mode.relevance === undefined) mode.relevance = 0
|
|
805
|
+
if (mode.relevance === undefined) mode.relevance = 0;
|
|
805
806
|
}
|
|
806
807
|
|
|
807
808
|
/**
|
|
808
809
|
* Allow `illegal` to contain an array of illegal values
|
|
809
810
|
* @type {CompilerExt}
|
|
810
811
|
*/
|
|
811
|
-
function compileIllegal
|
|
812
|
-
if (!Array.isArray(mode.illegal)) return
|
|
812
|
+
function compileIllegal(mode, _parent) {
|
|
813
|
+
if (!Array.isArray(mode.illegal)) return;
|
|
813
814
|
|
|
814
|
-
mode.illegal = either(...mode.illegal)
|
|
815
|
+
mode.illegal = either(...mode.illegal);
|
|
815
816
|
}
|
|
816
817
|
|
|
817
818
|
/**
|
|
818
819
|
* `match` to match a single expression for readability
|
|
819
820
|
* @type {CompilerExt}
|
|
820
821
|
*/
|
|
821
|
-
function compileMatch
|
|
822
|
-
if (!mode.match) return
|
|
823
|
-
if (mode.begin || mode.end) throw new Error(
|
|
822
|
+
function compileMatch(mode, _parent) {
|
|
823
|
+
if (!mode.match) return;
|
|
824
|
+
if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
|
|
824
825
|
|
|
825
|
-
mode.begin = mode.match
|
|
826
|
-
delete mode.match
|
|
826
|
+
mode.begin = mode.match;
|
|
827
|
+
delete mode.match;
|
|
827
828
|
}
|
|
828
829
|
|
|
829
830
|
/**
|
|
830
831
|
* provides the default 1 relevance to all modes
|
|
831
832
|
* @type {CompilerExt}
|
|
832
833
|
*/
|
|
833
|
-
function compileRelevance
|
|
834
|
+
function compileRelevance(mode, _parent) {
|
|
834
835
|
// eslint-disable-next-line no-undefined
|
|
835
|
-
if (mode.relevance === undefined) mode.relevance = 1
|
|
836
|
+
if (mode.relevance === undefined) mode.relevance = 1;
|
|
836
837
|
}
|
|
837
838
|
|
|
838
839
|
// allow beforeMatch to act as a "qualifier" for the match
|
|
839
840
|
// the full match begin must be [beforeMatch][begin]
|
|
840
841
|
const beforeMatchExt = (mode, parent) => {
|
|
841
|
-
if (!mode.beforeMatch) return
|
|
842
|
+
if (!mode.beforeMatch) return;
|
|
842
843
|
// starts conflicts with endsParent which we need to make sure the child
|
|
843
844
|
// rule is not matched multiple times
|
|
844
|
-
if (mode.starts) throw new Error(
|
|
845
|
+
if (mode.starts) throw new Error("beforeMatch cannot be used with starts");
|
|
845
846
|
|
|
846
|
-
const originalMode = Object.assign({}, mode)
|
|
847
|
-
Object.keys(mode).forEach((key) => { delete mode[key] })
|
|
847
|
+
const originalMode = Object.assign({}, mode);
|
|
848
|
+
Object.keys(mode).forEach((key) => { delete mode[key]; });
|
|
848
849
|
|
|
849
|
-
mode.keywords = originalMode.keywords
|
|
850
|
-
mode.begin = concat(originalMode.beforeMatch, lookahead(originalMode.begin))
|
|
850
|
+
mode.keywords = originalMode.keywords;
|
|
851
|
+
mode.begin = concat(originalMode.beforeMatch, lookahead(originalMode.begin));
|
|
851
852
|
mode.starts = {
|
|
852
853
|
relevance: 0,
|
|
853
854
|
contains: [
|
|
854
855
|
Object.assign(originalMode, { endsParent: true })
|
|
855
856
|
]
|
|
856
|
-
}
|
|
857
|
-
mode.relevance = 0
|
|
857
|
+
};
|
|
858
|
+
mode.relevance = 0;
|
|
858
859
|
|
|
859
|
-
delete originalMode.beforeMatch
|
|
860
|
-
}
|
|
860
|
+
delete originalMode.beforeMatch;
|
|
861
|
+
};
|
|
861
862
|
|
|
862
863
|
// keywords that should have no default relevance value
|
|
863
864
|
const COMMON_KEYWORDS = [
|
|
@@ -872,9 +873,9 @@ const hljs = (function () {
|
|
|
872
873
|
'parent', // common variable name
|
|
873
874
|
'list', // common variable name
|
|
874
875
|
'value' // common variable name
|
|
875
|
-
]
|
|
876
|
+
];
|
|
876
877
|
|
|
877
|
-
const DEFAULT_KEYWORD_SCOPE =
|
|
878
|
+
const DEFAULT_KEYWORD_SCOPE = "keyword";
|
|
878
879
|
|
|
879
880
|
/**
|
|
880
881
|
* Given raw keywords from a language definition, compile them.
|
|
@@ -882,26 +883,26 @@ const hljs = (function () {
|
|
|
882
883
|
* @param {string | Record<string,string|string[]> | Array<string>} rawKeywords
|
|
883
884
|
* @param {boolean} caseInsensitive
|
|
884
885
|
*/
|
|
885
|
-
function compileKeywords
|
|
886
|
+
function compileKeywords(rawKeywords, caseInsensitive, scopeName = DEFAULT_KEYWORD_SCOPE) {
|
|
886
887
|
/** @type KeywordDict */
|
|
887
|
-
const compiledKeywords = Object.create(null)
|
|
888
|
+
const compiledKeywords = Object.create(null);
|
|
888
889
|
|
|
889
890
|
// input can be a string of keywords, an array of keywords, or a object with
|
|
890
891
|
// named keys representing scopeName (which can then point to a string or array)
|
|
891
892
|
if (typeof rawKeywords === 'string') {
|
|
892
|
-
compileList(scopeName, rawKeywords.split(
|
|
893
|
+
compileList(scopeName, rawKeywords.split(" "));
|
|
893
894
|
} else if (Array.isArray(rawKeywords)) {
|
|
894
|
-
compileList(scopeName, rawKeywords)
|
|
895
|
+
compileList(scopeName, rawKeywords);
|
|
895
896
|
} else {
|
|
896
897
|
Object.keys(rawKeywords).forEach(function (scopeName) {
|
|
897
898
|
// collapse all our objects back into the parent object
|
|
898
899
|
Object.assign(
|
|
899
900
|
compiledKeywords,
|
|
900
901
|
compileKeywords(rawKeywords[scopeName], caseInsensitive, scopeName)
|
|
901
|
-
)
|
|
902
|
-
})
|
|
902
|
+
);
|
|
903
|
+
});
|
|
903
904
|
}
|
|
904
|
-
return compiledKeywords
|
|
905
|
+
return compiledKeywords;
|
|
905
906
|
|
|
906
907
|
// ---
|
|
907
908
|
|
|
@@ -913,14 +914,14 @@ const hljs = (function () {
|
|
|
913
914
|
* @param {string} scopeName
|
|
914
915
|
* @param {Array<string>} keywordList
|
|
915
916
|
*/
|
|
916
|
-
function compileList
|
|
917
|
+
function compileList(scopeName, keywordList) {
|
|
917
918
|
if (caseInsensitive) {
|
|
918
|
-
keywordList = keywordList.map(x => x.toLowerCase())
|
|
919
|
+
keywordList = keywordList.map(x => x.toLowerCase());
|
|
919
920
|
}
|
|
920
921
|
keywordList.forEach(function (keyword) {
|
|
921
|
-
const pair = keyword.split('|')
|
|
922
|
-
compiledKeywords[pair[0]] = [scopeName, scoreForKeyword(pair[0], pair[1])]
|
|
923
|
-
})
|
|
922
|
+
const pair = keyword.split('|');
|
|
923
|
+
compiledKeywords[pair[0]] = [scopeName, scoreForKeyword(pair[0], pair[1])];
|
|
924
|
+
});
|
|
924
925
|
}
|
|
925
926
|
}
|
|
926
927
|
|
|
@@ -932,22 +933,22 @@ const hljs = (function () {
|
|
|
932
933
|
* @param {string} keyword
|
|
933
934
|
* @param {string} [providedScore]
|
|
934
935
|
*/
|
|
935
|
-
function scoreForKeyword
|
|
936
|
+
function scoreForKeyword(keyword, providedScore) {
|
|
936
937
|
// manual scores always win over common keywords
|
|
937
938
|
// so you can force a score of 1 if you really insist
|
|
938
939
|
if (providedScore) {
|
|
939
|
-
return Number(providedScore)
|
|
940
|
+
return Number(providedScore);
|
|
940
941
|
}
|
|
941
942
|
|
|
942
|
-
return commonKeyword(keyword) ? 0 : 1
|
|
943
|
+
return commonKeyword(keyword) ? 0 : 1;
|
|
943
944
|
}
|
|
944
945
|
|
|
945
946
|
/**
|
|
946
947
|
* Determines if a given keyword is common or not
|
|
947
948
|
*
|
|
948
949
|
* @param {string} keyword */
|
|
949
|
-
function commonKeyword
|
|
950
|
-
return COMMON_KEYWORDS.includes(keyword.toLowerCase())
|
|
950
|
+
function commonKeyword(keyword) {
|
|
951
|
+
return COMMON_KEYWORDS.includes(keyword.toLowerCase());
|
|
951
952
|
}
|
|
952
953
|
|
|
953
954
|
/*
|
|
@@ -960,33 +961,33 @@ const hljs = (function () {
|
|
|
960
961
|
/**
|
|
961
962
|
* @type {Record<string, boolean>}
|
|
962
963
|
*/
|
|
963
|
-
const seenDeprecations = {}
|
|
964
|
+
const seenDeprecations = {};
|
|
964
965
|
|
|
965
966
|
/**
|
|
966
967
|
* @param {string} message
|
|
967
968
|
*/
|
|
968
969
|
const error = (message) => {
|
|
969
|
-
console.error(message)
|
|
970
|
-
}
|
|
970
|
+
console.error(message);
|
|
971
|
+
};
|
|
971
972
|
|
|
972
973
|
/**
|
|
973
974
|
* @param {string} message
|
|
974
975
|
* @param {any} args
|
|
975
976
|
*/
|
|
976
977
|
const warn = (message, ...args) => {
|
|
977
|
-
console.log(`WARN: ${message}`, ...args)
|
|
978
|
-
}
|
|
978
|
+
console.log(`WARN: ${message}`, ...args);
|
|
979
|
+
};
|
|
979
980
|
|
|
980
981
|
/**
|
|
981
982
|
* @param {string} version
|
|
982
983
|
* @param {string} message
|
|
983
984
|
*/
|
|
984
985
|
const deprecated = (version, message) => {
|
|
985
|
-
if (seenDeprecations[`${version}/${message}`]) return
|
|
986
|
+
if (seenDeprecations[`${version}/${message}`]) return;
|
|
986
987
|
|
|
987
|
-
console.log(`Deprecated as of ${version}. ${message}`)
|
|
988
|
-
seenDeprecations[`${version}/${message}`] = true
|
|
989
|
-
}
|
|
988
|
+
console.log(`Deprecated as of ${version}. ${message}`);
|
|
989
|
+
seenDeprecations[`${version}/${message}`] = true;
|
|
990
|
+
};
|
|
990
991
|
|
|
991
992
|
/* eslint-disable no-throw-literal */
|
|
992
993
|
|
|
@@ -994,7 +995,7 @@ const hljs = (function () {
|
|
|
994
995
|
@typedef {import('highlight.js').CompiledMode} CompiledMode
|
|
995
996
|
*/
|
|
996
997
|
|
|
997
|
-
const MultiClassError = new Error()
|
|
998
|
+
const MultiClassError = new Error();
|
|
998
999
|
|
|
999
1000
|
/**
|
|
1000
1001
|
* Renumbers labeled scope names to account for additional inner match
|
|
@@ -1024,64 +1025,64 @@ const hljs = (function () {
|
|
|
1024
1025
|
* @param {Array<RegExp>} regexes
|
|
1025
1026
|
* @param {{key: "beginScope"|"endScope"}} opts
|
|
1026
1027
|
*/
|
|
1027
|
-
function remapScopeNames
|
|
1028
|
-
let offset = 0
|
|
1029
|
-
const scopeNames = mode[key]
|
|
1028
|
+
function remapScopeNames(mode, regexes, { key }) {
|
|
1029
|
+
let offset = 0;
|
|
1030
|
+
const scopeNames = mode[key];
|
|
1030
1031
|
/** @type Record<number,boolean> */
|
|
1031
|
-
const emit = {}
|
|
1032
|
+
const emit = {};
|
|
1032
1033
|
/** @type Record<number,string> */
|
|
1033
|
-
const positions = {}
|
|
1034
|
+
const positions = {};
|
|
1034
1035
|
|
|
1035
1036
|
for (let i = 1; i <= regexes.length; i++) {
|
|
1036
|
-
positions[i + offset] = scopeNames[i]
|
|
1037
|
-
emit[i + offset] = true
|
|
1038
|
-
offset += countMatchGroups(regexes[i - 1])
|
|
1037
|
+
positions[i + offset] = scopeNames[i];
|
|
1038
|
+
emit[i + offset] = true;
|
|
1039
|
+
offset += countMatchGroups(regexes[i - 1]);
|
|
1039
1040
|
}
|
|
1040
1041
|
// we use _emit to keep track of which match groups are "top-level" to avoid double
|
|
1041
1042
|
// output from inside match groups
|
|
1042
|
-
mode[key] = positions
|
|
1043
|
-
mode[key]._emit = emit
|
|
1044
|
-
mode[key]._multi = true
|
|
1043
|
+
mode[key] = positions;
|
|
1044
|
+
mode[key]._emit = emit;
|
|
1045
|
+
mode[key]._multi = true;
|
|
1045
1046
|
}
|
|
1046
1047
|
|
|
1047
1048
|
/**
|
|
1048
1049
|
* @param {CompiledMode} mode
|
|
1049
1050
|
*/
|
|
1050
|
-
function beginMultiClass
|
|
1051
|
-
if (!Array.isArray(mode.begin)) return
|
|
1051
|
+
function beginMultiClass(mode) {
|
|
1052
|
+
if (!Array.isArray(mode.begin)) return;
|
|
1052
1053
|
|
|
1053
1054
|
if (mode.skip || mode.excludeBegin || mode.returnBegin) {
|
|
1054
|
-
error(
|
|
1055
|
-
throw MultiClassError
|
|
1055
|
+
error("skip, excludeBegin, returnBegin not compatible with beginScope: {}");
|
|
1056
|
+
throw MultiClassError;
|
|
1056
1057
|
}
|
|
1057
1058
|
|
|
1058
|
-
if (typeof mode.beginScope !==
|
|
1059
|
-
error(
|
|
1060
|
-
throw MultiClassError
|
|
1059
|
+
if (typeof mode.beginScope !== "object" || mode.beginScope === null) {
|
|
1060
|
+
error("beginScope must be object");
|
|
1061
|
+
throw MultiClassError;
|
|
1061
1062
|
}
|
|
1062
1063
|
|
|
1063
|
-
remapScopeNames(mode, mode.begin, { key:
|
|
1064
|
-
mode.begin = _rewriteBackreferences(mode.begin, { joinWith:
|
|
1064
|
+
remapScopeNames(mode, mode.begin, { key: "beginScope" });
|
|
1065
|
+
mode.begin = _rewriteBackreferences(mode.begin, { joinWith: "" });
|
|
1065
1066
|
}
|
|
1066
1067
|
|
|
1067
1068
|
/**
|
|
1068
1069
|
* @param {CompiledMode} mode
|
|
1069
1070
|
*/
|
|
1070
|
-
function endMultiClass
|
|
1071
|
-
if (!Array.isArray(mode.end)) return
|
|
1071
|
+
function endMultiClass(mode) {
|
|
1072
|
+
if (!Array.isArray(mode.end)) return;
|
|
1072
1073
|
|
|
1073
1074
|
if (mode.skip || mode.excludeEnd || mode.returnEnd) {
|
|
1074
|
-
error(
|
|
1075
|
-
throw MultiClassError
|
|
1075
|
+
error("skip, excludeEnd, returnEnd not compatible with endScope: {}");
|
|
1076
|
+
throw MultiClassError;
|
|
1076
1077
|
}
|
|
1077
1078
|
|
|
1078
|
-
if (typeof mode.endScope !==
|
|
1079
|
-
error(
|
|
1080
|
-
throw MultiClassError
|
|
1079
|
+
if (typeof mode.endScope !== "object" || mode.endScope === null) {
|
|
1080
|
+
error("endScope must be object");
|
|
1081
|
+
throw MultiClassError;
|
|
1081
1082
|
}
|
|
1082
1083
|
|
|
1083
|
-
remapScopeNames(mode, mode.end, { key:
|
|
1084
|
-
mode.end = _rewriteBackreferences(mode.end, { joinWith:
|
|
1084
|
+
remapScopeNames(mode, mode.end, { key: "endScope" });
|
|
1085
|
+
mode.end = _rewriteBackreferences(mode.end, { joinWith: "" });
|
|
1085
1086
|
}
|
|
1086
1087
|
|
|
1087
1088
|
/**
|
|
@@ -1095,28 +1096,28 @@ const hljs = (function () {
|
|
|
1095
1096
|
|
|
1096
1097
|
* @param {CompiledMode} mode
|
|
1097
1098
|
*/
|
|
1098
|
-
function scopeSugar
|
|
1099
|
-
if (mode.scope && typeof mode.scope ===
|
|
1100
|
-
mode.beginScope = mode.scope
|
|
1101
|
-
delete mode.scope
|
|
1099
|
+
function scopeSugar(mode) {
|
|
1100
|
+
if (mode.scope && typeof mode.scope === "object" && mode.scope !== null) {
|
|
1101
|
+
mode.beginScope = mode.scope;
|
|
1102
|
+
delete mode.scope;
|
|
1102
1103
|
}
|
|
1103
1104
|
}
|
|
1104
1105
|
|
|
1105
1106
|
/**
|
|
1106
1107
|
* @param {CompiledMode} mode
|
|
1107
1108
|
*/
|
|
1108
|
-
function MultiClass
|
|
1109
|
-
scopeSugar(mode)
|
|
1109
|
+
function MultiClass(mode) {
|
|
1110
|
+
scopeSugar(mode);
|
|
1110
1111
|
|
|
1111
|
-
if (typeof mode.beginScope ===
|
|
1112
|
-
mode.beginScope = { _wrap: mode.beginScope }
|
|
1112
|
+
if (typeof mode.beginScope === "string") {
|
|
1113
|
+
mode.beginScope = { _wrap: mode.beginScope };
|
|
1113
1114
|
}
|
|
1114
|
-
if (typeof mode.endScope ===
|
|
1115
|
-
mode.endScope = { _wrap: mode.endScope }
|
|
1115
|
+
if (typeof mode.endScope === "string") {
|
|
1116
|
+
mode.endScope = { _wrap: mode.endScope };
|
|
1116
1117
|
}
|
|
1117
1118
|
|
|
1118
|
-
beginMultiClass(mode)
|
|
1119
|
-
endMultiClass(mode)
|
|
1119
|
+
beginMultiClass(mode);
|
|
1120
|
+
endMultiClass(mode);
|
|
1120
1121
|
}
|
|
1121
1122
|
|
|
1122
1123
|
/**
|
|
@@ -1137,18 +1138,18 @@ const hljs = (function () {
|
|
|
1137
1138
|
* @param {Language} language
|
|
1138
1139
|
* @returns {CompiledLanguage}
|
|
1139
1140
|
*/
|
|
1140
|
-
function compileLanguage
|
|
1141
|
+
function compileLanguage(language) {
|
|
1141
1142
|
/**
|
|
1142
1143
|
* Builds a regex with the case sensitivity of the current language
|
|
1143
1144
|
*
|
|
1144
1145
|
* @param {RegExp | string} value
|
|
1145
1146
|
* @param {boolean} [global]
|
|
1146
1147
|
*/
|
|
1147
|
-
function langRe
|
|
1148
|
+
function langRe(value, global) {
|
|
1148
1149
|
return new RegExp(
|
|
1149
1150
|
source(value),
|
|
1150
1151
|
'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')
|
|
1151
|
-
)
|
|
1152
|
+
);
|
|
1152
1153
|
}
|
|
1153
1154
|
|
|
1154
1155
|
/**
|
|
@@ -1165,49 +1166,49 @@ const hljs = (function () {
|
|
|
1165
1166
|
(`illegal`, `begin`, end, etc).
|
|
1166
1167
|
*/
|
|
1167
1168
|
class MultiRegex {
|
|
1168
|
-
constructor
|
|
1169
|
-
this.matchIndexes = {}
|
|
1169
|
+
constructor() {
|
|
1170
|
+
this.matchIndexes = {};
|
|
1170
1171
|
// @ts-ignore
|
|
1171
|
-
this.regexes = []
|
|
1172
|
-
this.matchAt = 1
|
|
1173
|
-
this.position = 0
|
|
1172
|
+
this.regexes = [];
|
|
1173
|
+
this.matchAt = 1;
|
|
1174
|
+
this.position = 0;
|
|
1174
1175
|
}
|
|
1175
1176
|
|
|
1176
1177
|
// @ts-ignore
|
|
1177
|
-
addRule
|
|
1178
|
-
opts.position = this.position
|
|
1178
|
+
addRule(re, opts) {
|
|
1179
|
+
opts.position = this.position++;
|
|
1179
1180
|
// @ts-ignore
|
|
1180
|
-
this.matchIndexes[this.matchAt] = opts
|
|
1181
|
-
this.regexes.push([opts, re])
|
|
1182
|
-
this.matchAt += countMatchGroups(re) + 1
|
|
1181
|
+
this.matchIndexes[this.matchAt] = opts;
|
|
1182
|
+
this.regexes.push([opts, re]);
|
|
1183
|
+
this.matchAt += countMatchGroups(re) + 1;
|
|
1183
1184
|
}
|
|
1184
1185
|
|
|
1185
|
-
compile
|
|
1186
|
+
compile() {
|
|
1186
1187
|
if (this.regexes.length === 0) {
|
|
1187
1188
|
// avoids the need to check length every time exec is called
|
|
1188
1189
|
// @ts-ignore
|
|
1189
|
-
this.exec = () => null
|
|
1190
|
+
this.exec = () => null;
|
|
1190
1191
|
}
|
|
1191
|
-
const terminators = this.regexes.map(el => el[1])
|
|
1192
|
-
this.matcherRe = langRe(_rewriteBackreferences(terminators, { joinWith: '|' }), true)
|
|
1193
|
-
this.lastIndex = 0
|
|
1192
|
+
const terminators = this.regexes.map(el => el[1]);
|
|
1193
|
+
this.matcherRe = langRe(_rewriteBackreferences(terminators, { joinWith: '|' }), true);
|
|
1194
|
+
this.lastIndex = 0;
|
|
1194
1195
|
}
|
|
1195
1196
|
|
|
1196
1197
|
/** @param {string} s */
|
|
1197
|
-
exec
|
|
1198
|
-
this.matcherRe.lastIndex = this.lastIndex
|
|
1199
|
-
const match = this.matcherRe.exec(s)
|
|
1200
|
-
if (!match) { return null }
|
|
1198
|
+
exec(s) {
|
|
1199
|
+
this.matcherRe.lastIndex = this.lastIndex;
|
|
1200
|
+
const match = this.matcherRe.exec(s);
|
|
1201
|
+
if (!match) { return null; }
|
|
1201
1202
|
|
|
1202
1203
|
// eslint-disable-next-line no-undefined
|
|
1203
|
-
const i = match.findIndex((el, i) => i > 0 && el !== undefined)
|
|
1204
|
+
const i = match.findIndex((el, i) => i > 0 && el !== undefined);
|
|
1204
1205
|
// @ts-ignore
|
|
1205
|
-
const matchData = this.matchIndexes[i]
|
|
1206
|
+
const matchData = this.matchIndexes[i];
|
|
1206
1207
|
// trim off any earlier non-relevant match groups (ie, the other regex
|
|
1207
1208
|
// match groups that make up the multi-matcher)
|
|
1208
|
-
match.splice(0, i)
|
|
1209
|
+
match.splice(0, i);
|
|
1209
1210
|
|
|
1210
|
-
return Object.assign(match, matchData)
|
|
1211
|
+
return Object.assign(match, matchData);
|
|
1211
1212
|
}
|
|
1212
1213
|
}
|
|
1213
1214
|
|
|
@@ -1243,47 +1244,47 @@ const hljs = (function () {
|
|
|
1243
1244
|
MOST of the time the parser will be setting startAt manually to 0.
|
|
1244
1245
|
*/
|
|
1245
1246
|
class ResumableMultiRegex {
|
|
1246
|
-
constructor
|
|
1247
|
+
constructor() {
|
|
1247
1248
|
// @ts-ignore
|
|
1248
|
-
this.rules = []
|
|
1249
|
+
this.rules = [];
|
|
1249
1250
|
// @ts-ignore
|
|
1250
|
-
this.multiRegexes = []
|
|
1251
|
-
this.count = 0
|
|
1251
|
+
this.multiRegexes = [];
|
|
1252
|
+
this.count = 0;
|
|
1252
1253
|
|
|
1253
|
-
this.lastIndex = 0
|
|
1254
|
-
this.regexIndex = 0
|
|
1254
|
+
this.lastIndex = 0;
|
|
1255
|
+
this.regexIndex = 0;
|
|
1255
1256
|
}
|
|
1256
1257
|
|
|
1257
1258
|
// @ts-ignore
|
|
1258
|
-
getMatcher
|
|
1259
|
-
if (this.multiRegexes[index]) return this.multiRegexes[index]
|
|
1260
|
-
|
|
1261
|
-
const matcher = new MultiRegex()
|
|
1262
|
-
this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts))
|
|
1263
|
-
matcher.compile()
|
|
1264
|
-
this.multiRegexes[index] = matcher
|
|
1265
|
-
return matcher
|
|
1259
|
+
getMatcher(index) {
|
|
1260
|
+
if (this.multiRegexes[index]) return this.multiRegexes[index];
|
|
1261
|
+
|
|
1262
|
+
const matcher = new MultiRegex();
|
|
1263
|
+
this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
|
|
1264
|
+
matcher.compile();
|
|
1265
|
+
this.multiRegexes[index] = matcher;
|
|
1266
|
+
return matcher;
|
|
1266
1267
|
}
|
|
1267
1268
|
|
|
1268
|
-
resumingScanAtSamePosition
|
|
1269
|
-
return this.regexIndex !== 0
|
|
1269
|
+
resumingScanAtSamePosition() {
|
|
1270
|
+
return this.regexIndex !== 0;
|
|
1270
1271
|
}
|
|
1271
1272
|
|
|
1272
|
-
considerAll
|
|
1273
|
-
this.regexIndex = 0
|
|
1273
|
+
considerAll() {
|
|
1274
|
+
this.regexIndex = 0;
|
|
1274
1275
|
}
|
|
1275
1276
|
|
|
1276
1277
|
// @ts-ignore
|
|
1277
|
-
addRule
|
|
1278
|
-
this.rules.push([re, opts])
|
|
1279
|
-
if (opts.type ===
|
|
1278
|
+
addRule(re, opts) {
|
|
1279
|
+
this.rules.push([re, opts]);
|
|
1280
|
+
if (opts.type === "begin") this.count++;
|
|
1280
1281
|
}
|
|
1281
1282
|
|
|
1282
1283
|
/** @param {string} s */
|
|
1283
|
-
exec
|
|
1284
|
-
const m = this.getMatcher(this.regexIndex)
|
|
1285
|
-
m.lastIndex = this.lastIndex
|
|
1286
|
-
let result = m.exec(s)
|
|
1284
|
+
exec(s) {
|
|
1285
|
+
const m = this.getMatcher(this.regexIndex);
|
|
1286
|
+
m.lastIndex = this.lastIndex;
|
|
1287
|
+
let result = m.exec(s);
|
|
1287
1288
|
|
|
1288
1289
|
// The following is because we have no easy way to say "resume scanning at the
|
|
1289
1290
|
// existing position but also skip the current rule ONLY". What happens is
|
|
@@ -1318,21 +1319,21 @@ const hljs = (function () {
|
|
|
1318
1319
|
// 4. If #2 and #3 result in matches, which came first?
|
|
1319
1320
|
if (this.resumingScanAtSamePosition()) {
|
|
1320
1321
|
if (result && result.index === this.lastIndex); else { // use the second matcher result
|
|
1321
|
-
const m2 = this.getMatcher(0)
|
|
1322
|
-
m2.lastIndex = this.lastIndex + 1
|
|
1323
|
-
result = m2.exec(s)
|
|
1322
|
+
const m2 = this.getMatcher(0);
|
|
1323
|
+
m2.lastIndex = this.lastIndex + 1;
|
|
1324
|
+
result = m2.exec(s);
|
|
1324
1325
|
}
|
|
1325
1326
|
}
|
|
1326
1327
|
|
|
1327
1328
|
if (result) {
|
|
1328
|
-
this.regexIndex += result.position + 1
|
|
1329
|
+
this.regexIndex += result.position + 1;
|
|
1329
1330
|
if (this.regexIndex === this.count) {
|
|
1330
1331
|
// wrap-around to considering all matches again
|
|
1331
|
-
this.considerAll()
|
|
1332
|
+
this.considerAll();
|
|
1332
1333
|
}
|
|
1333
1334
|
}
|
|
1334
1335
|
|
|
1335
|
-
return result
|
|
1336
|
+
return result;
|
|
1336
1337
|
}
|
|
1337
1338
|
}
|
|
1338
1339
|
|
|
@@ -1343,19 +1344,19 @@ const hljs = (function () {
|
|
|
1343
1344
|
* @param {CompiledMode} mode
|
|
1344
1345
|
* @returns {ResumableMultiRegex}
|
|
1345
1346
|
*/
|
|
1346
|
-
function buildModeRegex
|
|
1347
|
-
const mm = new ResumableMultiRegex()
|
|
1347
|
+
function buildModeRegex(mode) {
|
|
1348
|
+
const mm = new ResumableMultiRegex();
|
|
1348
1349
|
|
|
1349
|
-
mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type:
|
|
1350
|
+
mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: "begin" }));
|
|
1350
1351
|
|
|
1351
1352
|
if (mode.terminatorEnd) {
|
|
1352
|
-
mm.addRule(mode.terminatorEnd, { type:
|
|
1353
|
+
mm.addRule(mode.terminatorEnd, { type: "end" });
|
|
1353
1354
|
}
|
|
1354
1355
|
if (mode.illegal) {
|
|
1355
|
-
mm.addRule(mode.illegal, { type:
|
|
1356
|
+
mm.addRule(mode.illegal, { type: "illegal" });
|
|
1356
1357
|
}
|
|
1357
1358
|
|
|
1358
|
-
return mm
|
|
1359
|
+
return mm;
|
|
1359
1360
|
}
|
|
1360
1361
|
|
|
1361
1362
|
/** skip vs abort vs ignore
|
|
@@ -1397,8 +1398,8 @@ const hljs = (function () {
|
|
|
1397
1398
|
* @param {CompiledMode | null} [parent]
|
|
1398
1399
|
* @returns {CompiledMode | never}
|
|
1399
1400
|
*/
|
|
1400
|
-
function compileMode
|
|
1401
|
-
const cmode = /** @type CompiledMode */ (mode)
|
|
1401
|
+
function compileMode(mode, parent) {
|
|
1402
|
+
const cmode = /** @type CompiledMode */ (mode);
|
|
1402
1403
|
if (mode.isCompiled) return cmode;
|
|
1403
1404
|
|
|
1404
1405
|
[
|
|
@@ -1408,9 +1409,9 @@ const hljs = (function () {
|
|
|
1408
1409
|
compileMatch,
|
|
1409
1410
|
MultiClass,
|
|
1410
1411
|
beforeMatchExt
|
|
1411
|
-
].forEach(ext => ext(mode, parent))
|
|
1412
|
+
].forEach(ext => ext(mode, parent));
|
|
1412
1413
|
|
|
1413
|
-
language.compilerExtensions.forEach(ext => ext(mode, parent))
|
|
1414
|
+
language.compilerExtensions.forEach(ext => ext(mode, parent));
|
|
1414
1415
|
|
|
1415
1416
|
// __beforeBegin is considered private API, internal use only
|
|
1416
1417
|
mode.__beforeBegin = null;
|
|
@@ -1422,64 +1423,64 @@ const hljs = (function () {
|
|
|
1422
1423
|
compileIllegal,
|
|
1423
1424
|
// default to 1 relevance if not specified
|
|
1424
1425
|
compileRelevance
|
|
1425
|
-
].forEach(ext => ext(mode, parent))
|
|
1426
|
+
].forEach(ext => ext(mode, parent));
|
|
1426
1427
|
|
|
1427
|
-
mode.isCompiled = true
|
|
1428
|
+
mode.isCompiled = true;
|
|
1428
1429
|
|
|
1429
|
-
let keywordPattern = null
|
|
1430
|
-
if (typeof mode.keywords ===
|
|
1430
|
+
let keywordPattern = null;
|
|
1431
|
+
if (typeof mode.keywords === "object" && mode.keywords.$pattern) {
|
|
1431
1432
|
// we need a copy because keywords might be compiled multiple times
|
|
1432
1433
|
// so we can't go deleting $pattern from the original on the first
|
|
1433
1434
|
// pass
|
|
1434
|
-
mode.keywords = Object.assign({}, mode.keywords)
|
|
1435
|
-
keywordPattern = mode.keywords.$pattern
|
|
1436
|
-
delete mode.keywords.$pattern
|
|
1435
|
+
mode.keywords = Object.assign({}, mode.keywords);
|
|
1436
|
+
keywordPattern = mode.keywords.$pattern;
|
|
1437
|
+
delete mode.keywords.$pattern;
|
|
1437
1438
|
}
|
|
1438
|
-
keywordPattern = keywordPattern || /\w
|
|
1439
|
+
keywordPattern = keywordPattern || /\w+/;
|
|
1439
1440
|
|
|
1440
1441
|
if (mode.keywords) {
|
|
1441
|
-
mode.keywords = compileKeywords(mode.keywords, language.case_insensitive)
|
|
1442
|
+
mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
|
|
1442
1443
|
}
|
|
1443
1444
|
|
|
1444
|
-
cmode.keywordPatternRe = langRe(keywordPattern, true)
|
|
1445
|
+
cmode.keywordPatternRe = langRe(keywordPattern, true);
|
|
1445
1446
|
|
|
1446
1447
|
if (parent) {
|
|
1447
|
-
if (!mode.begin) mode.begin = /\B|\b
|
|
1448
|
-
cmode.beginRe = langRe(mode.begin)
|
|
1449
|
-
if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b
|
|
1450
|
-
if (mode.end) cmode.endRe = langRe(mode.end)
|
|
1451
|
-
cmode.terminatorEnd = source(mode.end) || ''
|
|
1448
|
+
if (!mode.begin) mode.begin = /\B|\b/;
|
|
1449
|
+
cmode.beginRe = langRe(mode.begin);
|
|
1450
|
+
if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
|
|
1451
|
+
if (mode.end) cmode.endRe = langRe(mode.end);
|
|
1452
|
+
cmode.terminatorEnd = source(mode.end) || '';
|
|
1452
1453
|
if (mode.endsWithParent && parent.terminatorEnd) {
|
|
1453
|
-
cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd
|
|
1454
|
+
cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;
|
|
1454
1455
|
}
|
|
1455
1456
|
}
|
|
1456
|
-
if (mode.illegal) cmode.illegalRe = langRe(/** @type {RegExp | string} */(mode.illegal))
|
|
1457
|
-
if (!mode.contains) mode.contains = []
|
|
1457
|
+
if (mode.illegal) cmode.illegalRe = langRe(/** @type {RegExp | string} */(mode.illegal));
|
|
1458
|
+
if (!mode.contains) mode.contains = [];
|
|
1458
1459
|
|
|
1459
1460
|
mode.contains = [].concat(...mode.contains.map(function (c) {
|
|
1460
|
-
return expandOrCloneMode(c === 'self' ? mode : c)
|
|
1461
|
-
}))
|
|
1462
|
-
mode.contains.forEach(function (c) { compileMode(/** @type Mode */(c), cmode) })
|
|
1461
|
+
return expandOrCloneMode(c === 'self' ? mode : c);
|
|
1462
|
+
}));
|
|
1463
|
+
mode.contains.forEach(function (c) { compileMode(/** @type Mode */(c), cmode); });
|
|
1463
1464
|
|
|
1464
1465
|
if (mode.starts) {
|
|
1465
|
-
compileMode(mode.starts, parent)
|
|
1466
|
+
compileMode(mode.starts, parent);
|
|
1466
1467
|
}
|
|
1467
1468
|
|
|
1468
|
-
cmode.matcher = buildModeRegex(cmode)
|
|
1469
|
-
return cmode
|
|
1469
|
+
cmode.matcher = buildModeRegex(cmode);
|
|
1470
|
+
return cmode;
|
|
1470
1471
|
}
|
|
1471
1472
|
|
|
1472
|
-
if (!language.compilerExtensions) language.compilerExtensions = []
|
|
1473
|
+
if (!language.compilerExtensions) language.compilerExtensions = [];
|
|
1473
1474
|
|
|
1474
1475
|
// self is not valid at the top-level
|
|
1475
1476
|
if (language.contains && language.contains.includes('self')) {
|
|
1476
|
-
throw new Error(
|
|
1477
|
+
throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
|
|
1477
1478
|
}
|
|
1478
1479
|
|
|
1479
1480
|
// we need a null object, which inherit will guarantee
|
|
1480
|
-
language.classNameAliases = inherit$1(language.classNameAliases || {})
|
|
1481
|
+
language.classNameAliases = inherit$1(language.classNameAliases || {});
|
|
1481
1482
|
|
|
1482
|
-
return compileMode(/** @type Mode */(language))
|
|
1483
|
+
return compileMode(/** @type Mode */(language));
|
|
1483
1484
|
}
|
|
1484
1485
|
|
|
1485
1486
|
/**
|
|
@@ -1493,10 +1494,10 @@ const hljs = (function () {
|
|
|
1493
1494
|
* @param {Mode | null} mode
|
|
1494
1495
|
* @returns {boolean} - is there a dependency on the parent?
|
|
1495
1496
|
* */
|
|
1496
|
-
function dependencyOnParent
|
|
1497
|
-
if (!mode) return false
|
|
1497
|
+
function dependencyOnParent(mode) {
|
|
1498
|
+
if (!mode) return false;
|
|
1498
1499
|
|
|
1499
|
-
return mode.endsWithParent || dependencyOnParent(mode.starts)
|
|
1500
|
+
return mode.endsWithParent || dependencyOnParent(mode.starts);
|
|
1500
1501
|
}
|
|
1501
1502
|
|
|
1502
1503
|
/**
|
|
@@ -1509,18 +1510,18 @@ const hljs = (function () {
|
|
|
1509
1510
|
* @param {Mode} mode
|
|
1510
1511
|
* @returns {Mode | Mode[]}
|
|
1511
1512
|
* */
|
|
1512
|
-
function expandOrCloneMode
|
|
1513
|
+
function expandOrCloneMode(mode) {
|
|
1513
1514
|
if (mode.variants && !mode.cachedVariants) {
|
|
1514
1515
|
mode.cachedVariants = mode.variants.map(function (variant) {
|
|
1515
|
-
return inherit$1(mode, { variants: null }, variant)
|
|
1516
|
-
})
|
|
1516
|
+
return inherit$1(mode, { variants: null }, variant);
|
|
1517
|
+
});
|
|
1517
1518
|
}
|
|
1518
1519
|
|
|
1519
1520
|
// EXPAND
|
|
1520
1521
|
// if we have variants then essentially "replace" the mode with the variants
|
|
1521
1522
|
// this happens in compileMode, where this function is called from
|
|
1522
1523
|
if (mode.cachedVariants) {
|
|
1523
|
-
return mode.cachedVariants
|
|
1524
|
+
return mode.cachedVariants;
|
|
1524
1525
|
}
|
|
1525
1526
|
|
|
1526
1527
|
// CLONE
|
|
@@ -1528,18 +1529,18 @@ const hljs = (function () {
|
|
|
1528
1529
|
// instance of ourselves, so we can be reused with many
|
|
1529
1530
|
// different parents without issue
|
|
1530
1531
|
if (dependencyOnParent(mode)) {
|
|
1531
|
-
return inherit$1(mode, { starts: mode.starts ? inherit$1(mode.starts) : null })
|
|
1532
|
+
return inherit$1(mode, { starts: mode.starts ? inherit$1(mode.starts) : null });
|
|
1532
1533
|
}
|
|
1533
1534
|
|
|
1534
1535
|
if (Object.isFrozen(mode)) {
|
|
1535
|
-
return inherit$1(mode)
|
|
1536
|
+
return inherit$1(mode);
|
|
1536
1537
|
}
|
|
1537
1538
|
|
|
1538
1539
|
// no special dependency issues, just return ourselves
|
|
1539
|
-
return mode
|
|
1540
|
+
return mode;
|
|
1540
1541
|
}
|
|
1541
1542
|
|
|
1542
|
-
|
|
1543
|
+
var version = "11.0.0-beta1";
|
|
1543
1544
|
|
|
1544
1545
|
/*
|
|
1545
1546
|
Syntax highlighting with language autodetection.
|
|
@@ -1566,10 +1567,11 @@ const hljs = (function () {
|
|
|
1566
1567
|
@typedef {import('highlight.js').HighlightResult} HighlightResult
|
|
1567
1568
|
*/
|
|
1568
1569
|
|
|
1569
|
-
|
|
1570
|
-
const
|
|
1571
|
-
const
|
|
1572
|
-
const
|
|
1570
|
+
|
|
1571
|
+
const escape = escapeHTML;
|
|
1572
|
+
const inherit = inherit$1;
|
|
1573
|
+
const NO_MATCH = Symbol("nomatch");
|
|
1574
|
+
const MAX_KEYWORD_HITS = 7;
|
|
1573
1575
|
|
|
1574
1576
|
/**
|
|
1575
1577
|
* @param {any} hljs - object that is extended (legacy)
|
|
@@ -1578,18 +1580,18 @@ const hljs = (function () {
|
|
|
1578
1580
|
const HLJS = function (hljs) {
|
|
1579
1581
|
// Global internal variables used within the highlight.js library.
|
|
1580
1582
|
/** @type {Record<string, Language>} */
|
|
1581
|
-
const languages = Object.create(null)
|
|
1583
|
+
const languages = Object.create(null);
|
|
1582
1584
|
/** @type {Record<string, string>} */
|
|
1583
|
-
const aliases = Object.create(null)
|
|
1585
|
+
const aliases = Object.create(null);
|
|
1584
1586
|
/** @type {HLJSPlugin[]} */
|
|
1585
|
-
const plugins = []
|
|
1587
|
+
const plugins = [];
|
|
1586
1588
|
|
|
1587
1589
|
// safe/production mode - swallows more errors, tries to keep running
|
|
1588
1590
|
// even if a single syntax or parse hits a fatal error
|
|
1589
|
-
let SAFE_MODE = true
|
|
1590
|
-
const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?"
|
|
1591
|
+
let SAFE_MODE = true;
|
|
1592
|
+
const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
|
|
1591
1593
|
/** @type {Language} */
|
|
1592
|
-
const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text', contains: [] }
|
|
1594
|
+
const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text', contains: [] };
|
|
1593
1595
|
|
|
1594
1596
|
// Global options used when within external APIs. This is modified when
|
|
1595
1597
|
// calling the `hljs.configure` function.
|
|
@@ -1604,7 +1606,7 @@ const hljs = (function () {
|
|
|
1604
1606
|
// beta configuration options, subject to change, welcome to discuss
|
|
1605
1607
|
// https://github.com/highlightjs/highlight.js/issues/1086
|
|
1606
1608
|
__emitter: TokenTreeEmitter
|
|
1607
|
-
}
|
|
1609
|
+
};
|
|
1608
1610
|
|
|
1609
1611
|
/* Utility functions */
|
|
1610
1612
|
|
|
@@ -1612,32 +1614,32 @@ const hljs = (function () {
|
|
|
1612
1614
|
* Tests a language name to see if highlighting should be skipped
|
|
1613
1615
|
* @param {string} languageName
|
|
1614
1616
|
*/
|
|
1615
|
-
function shouldNotHighlight
|
|
1616
|
-
return options.noHighlightRe.test(languageName)
|
|
1617
|
+
function shouldNotHighlight(languageName) {
|
|
1618
|
+
return options.noHighlightRe.test(languageName);
|
|
1617
1619
|
}
|
|
1618
1620
|
|
|
1619
1621
|
/**
|
|
1620
1622
|
* @param {HighlightedHTMLElement} block - the HTML element to determine language for
|
|
1621
1623
|
*/
|
|
1622
|
-
function blockLanguage
|
|
1623
|
-
let classes = block.className + ' '
|
|
1624
|
+
function blockLanguage(block) {
|
|
1625
|
+
let classes = block.className + ' ';
|
|
1624
1626
|
|
|
1625
|
-
classes += block.parentNode ? block.parentNode.className : ''
|
|
1627
|
+
classes += block.parentNode ? block.parentNode.className : '';
|
|
1626
1628
|
|
|
1627
1629
|
// language-* takes precedence over non-prefixed class names.
|
|
1628
|
-
const match = options.languageDetectRe.exec(classes)
|
|
1630
|
+
const match = options.languageDetectRe.exec(classes);
|
|
1629
1631
|
if (match) {
|
|
1630
|
-
const language = getLanguage(match[1])
|
|
1632
|
+
const language = getLanguage(match[1]);
|
|
1631
1633
|
if (!language) {
|
|
1632
|
-
warn(LANGUAGE_NOT_FOUND.replace(
|
|
1633
|
-
warn(
|
|
1634
|
+
warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
|
|
1635
|
+
warn("Falling back to no-highlight mode for this block.", block);
|
|
1634
1636
|
}
|
|
1635
|
-
return language ? match[1] : 'no-highlight'
|
|
1637
|
+
return language ? match[1] : 'no-highlight';
|
|
1636
1638
|
}
|
|
1637
1639
|
|
|
1638
1640
|
return classes
|
|
1639
1641
|
.split(/\s+/)
|
|
1640
|
-
.find((_class) => shouldNotHighlight(_class) || getLanguage(_class))
|
|
1642
|
+
.find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
|
|
1641
1643
|
}
|
|
1642
1644
|
|
|
1643
1645
|
/**
|
|
@@ -1662,48 +1664,48 @@ const hljs = (function () {
|
|
|
1662
1664
|
* @property {CompiledMode} top - top of the current mode stack
|
|
1663
1665
|
* @property {boolean} illegal - indicates whether any illegal matches were found
|
|
1664
1666
|
*/
|
|
1665
|
-
function highlight
|
|
1666
|
-
let code =
|
|
1667
|
-
let languageName =
|
|
1668
|
-
if (typeof optionsOrCode ===
|
|
1669
|
-
code = codeOrLanguageName
|
|
1670
|
-
ignoreIllegals = optionsOrCode.ignoreIllegals
|
|
1671
|
-
languageName = optionsOrCode.language
|
|
1667
|
+
function highlight(codeOrLanguageName, optionsOrCode, ignoreIllegals, continuation) {
|
|
1668
|
+
let code = "";
|
|
1669
|
+
let languageName = "";
|
|
1670
|
+
if (typeof optionsOrCode === "object") {
|
|
1671
|
+
code = codeOrLanguageName;
|
|
1672
|
+
ignoreIllegals = optionsOrCode.ignoreIllegals;
|
|
1673
|
+
languageName = optionsOrCode.language;
|
|
1672
1674
|
// continuation not supported at all via the new API
|
|
1673
1675
|
// eslint-disable-next-line no-undefined
|
|
1674
|
-
continuation = undefined
|
|
1676
|
+
continuation = undefined;
|
|
1675
1677
|
} else {
|
|
1676
1678
|
// old API
|
|
1677
|
-
deprecated(
|
|
1678
|
-
deprecated(
|
|
1679
|
-
languageName = codeOrLanguageName
|
|
1680
|
-
code = optionsOrCode
|
|
1679
|
+
deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
|
|
1680
|
+
deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
|
|
1681
|
+
languageName = codeOrLanguageName;
|
|
1682
|
+
code = optionsOrCode;
|
|
1681
1683
|
}
|
|
1682
1684
|
|
|
1683
1685
|
// https://github.com/highlightjs/highlight.js/issues/3149
|
|
1684
1686
|
// eslint-disable-next-line no-undefined
|
|
1685
|
-
if (ignoreIllegals === undefined) { ignoreIllegals = true }
|
|
1687
|
+
if (ignoreIllegals === undefined) { ignoreIllegals = true; }
|
|
1686
1688
|
|
|
1687
1689
|
/** @type {BeforeHighlightContext} */
|
|
1688
1690
|
const context = {
|
|
1689
1691
|
code,
|
|
1690
1692
|
language: languageName
|
|
1691
|
-
}
|
|
1693
|
+
};
|
|
1692
1694
|
// the plugin can change the desired language or the code to be highlighted
|
|
1693
1695
|
// just be changing the object it was passed
|
|
1694
|
-
fire(
|
|
1696
|
+
fire("before:highlight", context);
|
|
1695
1697
|
|
|
1696
1698
|
// a before plugin can usurp the result completely by providing it's own
|
|
1697
1699
|
// in which case we don't even need to call highlight
|
|
1698
1700
|
const result = context.result
|
|
1699
1701
|
? context.result
|
|
1700
|
-
: _highlight(context.language, context.code, ignoreIllegals, continuation)
|
|
1702
|
+
: _highlight(context.language, context.code, ignoreIllegals, continuation);
|
|
1701
1703
|
|
|
1702
|
-
result.code = context.code
|
|
1704
|
+
result.code = context.code;
|
|
1703
1705
|
// the plugin can change anything in result to suite it
|
|
1704
|
-
fire(
|
|
1706
|
+
fire("after:highlight", result);
|
|
1705
1707
|
|
|
1706
|
-
return result
|
|
1708
|
+
return result;
|
|
1707
1709
|
}
|
|
1708
1710
|
|
|
1709
1711
|
/**
|
|
@@ -1715,8 +1717,8 @@ const hljs = (function () {
|
|
|
1715
1717
|
* @param {CompiledMode?} [continuation] - current continuation mode, if any
|
|
1716
1718
|
* @returns {HighlightResult} - result of the highlight operation
|
|
1717
1719
|
*/
|
|
1718
|
-
function _highlight
|
|
1719
|
-
const keywordHits = Object.create(null)
|
|
1720
|
+
function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
|
|
1721
|
+
const keywordHits = Object.create(null);
|
|
1720
1722
|
|
|
1721
1723
|
/**
|
|
1722
1724
|
* Return keyword data if a match is a keyword
|
|
@@ -1724,64 +1726,64 @@ const hljs = (function () {
|
|
|
1724
1726
|
* @param {string} matchText - the textual match
|
|
1725
1727
|
* @returns {KeywordData | false}
|
|
1726
1728
|
*/
|
|
1727
|
-
function keywordData
|
|
1728
|
-
return mode.keywords[matchText]
|
|
1729
|
+
function keywordData(mode, matchText) {
|
|
1730
|
+
return mode.keywords[matchText];
|
|
1729
1731
|
}
|
|
1730
1732
|
|
|
1731
|
-
function processKeywords
|
|
1733
|
+
function processKeywords() {
|
|
1732
1734
|
if (!top.keywords) {
|
|
1733
|
-
emitter.addText(modeBuffer)
|
|
1734
|
-
return
|
|
1735
|
+
emitter.addText(modeBuffer);
|
|
1736
|
+
return;
|
|
1735
1737
|
}
|
|
1736
1738
|
|
|
1737
|
-
let lastIndex = 0
|
|
1738
|
-
top.keywordPatternRe.lastIndex = 0
|
|
1739
|
-
let match = top.keywordPatternRe.exec(modeBuffer)
|
|
1740
|
-
let buf =
|
|
1739
|
+
let lastIndex = 0;
|
|
1740
|
+
top.keywordPatternRe.lastIndex = 0;
|
|
1741
|
+
let match = top.keywordPatternRe.exec(modeBuffer);
|
|
1742
|
+
let buf = "";
|
|
1741
1743
|
|
|
1742
1744
|
while (match) {
|
|
1743
|
-
buf += modeBuffer.substring(lastIndex, match.index)
|
|
1744
|
-
const word = language.case_insensitive ? match[0].toLowerCase() : match[0]
|
|
1745
|
-
const data = keywordData(top, word)
|
|
1745
|
+
buf += modeBuffer.substring(lastIndex, match.index);
|
|
1746
|
+
const word = language.case_insensitive ? match[0].toLowerCase() : match[0];
|
|
1747
|
+
const data = keywordData(top, word);
|
|
1746
1748
|
if (data) {
|
|
1747
|
-
const [kind, keywordRelevance] = data
|
|
1748
|
-
emitter.addText(buf)
|
|
1749
|
-
buf =
|
|
1749
|
+
const [kind, keywordRelevance] = data;
|
|
1750
|
+
emitter.addText(buf);
|
|
1751
|
+
buf = "";
|
|
1750
1752
|
|
|
1751
|
-
keywordHits[word] = (keywordHits[word] || 0) + 1
|
|
1752
|
-
if (keywordHits[word] <= MAX_KEYWORD_HITS) relevance += keywordRelevance
|
|
1753
|
-
if (kind.startsWith(
|
|
1753
|
+
keywordHits[word] = (keywordHits[word] || 0) + 1;
|
|
1754
|
+
if (keywordHits[word] <= MAX_KEYWORD_HITS) relevance += keywordRelevance;
|
|
1755
|
+
if (kind.startsWith("_")) {
|
|
1754
1756
|
// _ implied for relevance only, do not highlight
|
|
1755
1757
|
// by applying a class name
|
|
1756
|
-
buf += match[0]
|
|
1758
|
+
buf += match[0];
|
|
1757
1759
|
} else {
|
|
1758
|
-
const cssClass = language.classNameAliases[kind] || kind
|
|
1759
|
-
emitter.addKeyword(match[0], cssClass)
|
|
1760
|
+
const cssClass = language.classNameAliases[kind] || kind;
|
|
1761
|
+
emitter.addKeyword(match[0], cssClass);
|
|
1760
1762
|
}
|
|
1761
1763
|
} else {
|
|
1762
|
-
buf += match[0]
|
|
1764
|
+
buf += match[0];
|
|
1763
1765
|
}
|
|
1764
|
-
lastIndex = top.keywordPatternRe.lastIndex
|
|
1765
|
-
match = top.keywordPatternRe.exec(modeBuffer)
|
|
1766
|
+
lastIndex = top.keywordPatternRe.lastIndex;
|
|
1767
|
+
match = top.keywordPatternRe.exec(modeBuffer);
|
|
1766
1768
|
}
|
|
1767
|
-
buf += modeBuffer.substr(lastIndex)
|
|
1768
|
-
emitter.addText(buf)
|
|
1769
|
+
buf += modeBuffer.substr(lastIndex);
|
|
1770
|
+
emitter.addText(buf);
|
|
1769
1771
|
}
|
|
1770
1772
|
|
|
1771
|
-
function processSubLanguage
|
|
1772
|
-
if (modeBuffer ===
|
|
1773
|
+
function processSubLanguage() {
|
|
1774
|
+
if (modeBuffer === "") return;
|
|
1773
1775
|
/** @type HighlightResult */
|
|
1774
|
-
let result = null
|
|
1776
|
+
let result = null;
|
|
1775
1777
|
|
|
1776
1778
|
if (typeof top.subLanguage === 'string') {
|
|
1777
1779
|
if (!languages[top.subLanguage]) {
|
|
1778
|
-
emitter.addText(modeBuffer)
|
|
1779
|
-
return
|
|
1780
|
+
emitter.addText(modeBuffer);
|
|
1781
|
+
return;
|
|
1780
1782
|
}
|
|
1781
|
-
result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage])
|
|
1782
|
-
continuations[top.subLanguage] = /** @type {CompiledMode} */ (result._top)
|
|
1783
|
+
result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
|
|
1784
|
+
continuations[top.subLanguage] = /** @type {CompiledMode} */ (result._top);
|
|
1783
1785
|
} else {
|
|
1784
|
-
result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null)
|
|
1786
|
+
result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
|
|
1785
1787
|
}
|
|
1786
1788
|
|
|
1787
1789
|
// Counting embedded language score towards the host language may be disabled
|
|
@@ -1789,39 +1791,39 @@ const hljs = (function () {
|
|
|
1789
1791
|
// allows XML everywhere and makes every XML snippet to have a much larger Markdown
|
|
1790
1792
|
// score.
|
|
1791
1793
|
if (top.relevance > 0) {
|
|
1792
|
-
relevance += result.relevance
|
|
1794
|
+
relevance += result.relevance;
|
|
1793
1795
|
}
|
|
1794
|
-
emitter.addSublanguage(result._emitter, result.language)
|
|
1796
|
+
emitter.addSublanguage(result._emitter, result.language);
|
|
1795
1797
|
}
|
|
1796
1798
|
|
|
1797
|
-
function processBuffer
|
|
1799
|
+
function processBuffer() {
|
|
1798
1800
|
if (top.subLanguage != null) {
|
|
1799
|
-
processSubLanguage()
|
|
1801
|
+
processSubLanguage();
|
|
1800
1802
|
} else {
|
|
1801
|
-
processKeywords()
|
|
1803
|
+
processKeywords();
|
|
1802
1804
|
}
|
|
1803
|
-
modeBuffer = ''
|
|
1805
|
+
modeBuffer = '';
|
|
1804
1806
|
}
|
|
1805
1807
|
|
|
1806
1808
|
/**
|
|
1807
1809
|
* @param {CompiledMode} mode
|
|
1808
1810
|
* @param {RegExpMatchArray} match
|
|
1809
1811
|
*/
|
|
1810
|
-
function emitMultiClass
|
|
1811
|
-
let i = 1
|
|
1812
|
+
function emitMultiClass(scope, match) {
|
|
1813
|
+
let i = 1;
|
|
1812
1814
|
// eslint-disable-next-line no-undefined
|
|
1813
1815
|
while (match[i] !== undefined) {
|
|
1814
|
-
if (!scope._emit[i]) { i++; continue }
|
|
1815
|
-
const klass = language.classNameAliases[scope[i]] || scope[i]
|
|
1816
|
-
const text = match[i]
|
|
1816
|
+
if (!scope._emit[i]) { i++; continue; }
|
|
1817
|
+
const klass = language.classNameAliases[scope[i]] || scope[i];
|
|
1818
|
+
const text = match[i];
|
|
1817
1819
|
if (klass) {
|
|
1818
|
-
emitter.addKeyword(text, klass)
|
|
1820
|
+
emitter.addKeyword(text, klass);
|
|
1819
1821
|
} else {
|
|
1820
|
-
modeBuffer = text
|
|
1821
|
-
processKeywords()
|
|
1822
|
-
modeBuffer =
|
|
1822
|
+
modeBuffer = text;
|
|
1823
|
+
processKeywords();
|
|
1824
|
+
modeBuffer = "";
|
|
1823
1825
|
}
|
|
1824
|
-
i
|
|
1826
|
+
i++;
|
|
1825
1827
|
}
|
|
1826
1828
|
}
|
|
1827
1829
|
|
|
@@ -1829,24 +1831,24 @@ const hljs = (function () {
|
|
|
1829
1831
|
* @param {CompiledMode} mode - new mode to start
|
|
1830
1832
|
* @param {RegExpMatchArray} match
|
|
1831
1833
|
*/
|
|
1832
|
-
function startNewMode
|
|
1833
|
-
if (mode.scope && typeof mode.scope ===
|
|
1834
|
-
emitter.openNode(language.classNameAliases[mode.scope] || mode.scope)
|
|
1834
|
+
function startNewMode(mode, match) {
|
|
1835
|
+
if (mode.scope && typeof mode.scope === "string") {
|
|
1836
|
+
emitter.openNode(language.classNameAliases[mode.scope] || mode.scope);
|
|
1835
1837
|
}
|
|
1836
1838
|
if (mode.beginScope) {
|
|
1837
1839
|
// beginScope just wraps the begin match itself in a scope
|
|
1838
1840
|
if (mode.beginScope._wrap) {
|
|
1839
|
-
emitter.addKeyword(modeBuffer, language.classNameAliases[mode.beginScope._wrap] || mode.beginScope._wrap)
|
|
1840
|
-
modeBuffer =
|
|
1841
|
+
emitter.addKeyword(modeBuffer, language.classNameAliases[mode.beginScope._wrap] || mode.beginScope._wrap);
|
|
1842
|
+
modeBuffer = "";
|
|
1841
1843
|
} else if (mode.beginScope._multi) {
|
|
1842
1844
|
// at this point modeBuffer should just be the match
|
|
1843
|
-
emitMultiClass(mode.beginScope, match)
|
|
1844
|
-
modeBuffer =
|
|
1845
|
+
emitMultiClass(mode.beginScope, match);
|
|
1846
|
+
modeBuffer = "";
|
|
1845
1847
|
}
|
|
1846
1848
|
}
|
|
1847
1849
|
|
|
1848
|
-
top = Object.create(mode, { parent: { value: top } })
|
|
1849
|
-
return top
|
|
1850
|
+
top = Object.create(mode, { parent: { value: top } });
|
|
1851
|
+
return top;
|
|
1850
1852
|
}
|
|
1851
1853
|
|
|
1852
1854
|
/**
|
|
@@ -1855,27 +1857,27 @@ const hljs = (function () {
|
|
|
1855
1857
|
* @param {string} matchPlusRemainder - match plus remainder of content
|
|
1856
1858
|
* @returns {CompiledMode | void} - the next mode, or if void continue on in current mode
|
|
1857
1859
|
*/
|
|
1858
|
-
function endOfMode
|
|
1859
|
-
let matched = startsWith(mode.endRe, matchPlusRemainder)
|
|
1860
|
+
function endOfMode(mode, match, matchPlusRemainder) {
|
|
1861
|
+
let matched = startsWith(mode.endRe, matchPlusRemainder);
|
|
1860
1862
|
|
|
1861
1863
|
if (matched) {
|
|
1862
|
-
if (mode[
|
|
1863
|
-
const resp = new Response(mode)
|
|
1864
|
-
mode[
|
|
1865
|
-
if (resp.isMatchIgnored) matched = false
|
|
1864
|
+
if (mode["on:end"]) {
|
|
1865
|
+
const resp = new Response(mode);
|
|
1866
|
+
mode["on:end"](match, resp);
|
|
1867
|
+
if (resp.isMatchIgnored) matched = false;
|
|
1866
1868
|
}
|
|
1867
1869
|
|
|
1868
1870
|
if (matched) {
|
|
1869
1871
|
while (mode.endsParent && mode.parent) {
|
|
1870
|
-
mode = mode.parent
|
|
1872
|
+
mode = mode.parent;
|
|
1871
1873
|
}
|
|
1872
|
-
return mode
|
|
1874
|
+
return mode;
|
|
1873
1875
|
}
|
|
1874
1876
|
}
|
|
1875
1877
|
// even if on:end fires an `ignore` it's still possible
|
|
1876
1878
|
// that we might trigger the end node because of a parent mode
|
|
1877
1879
|
if (mode.endsWithParent) {
|
|
1878
|
-
return endOfMode(mode.parent, match, matchPlusRemainder)
|
|
1880
|
+
return endOfMode(mode.parent, match, matchPlusRemainder);
|
|
1879
1881
|
}
|
|
1880
1882
|
}
|
|
1881
1883
|
|
|
@@ -1884,17 +1886,17 @@ const hljs = (function () {
|
|
|
1884
1886
|
*
|
|
1885
1887
|
* @param {string} lexeme - string containing full match text
|
|
1886
1888
|
*/
|
|
1887
|
-
function doIgnore
|
|
1889
|
+
function doIgnore(lexeme) {
|
|
1888
1890
|
if (top.matcher.regexIndex === 0) {
|
|
1889
1891
|
// no more regexes to potentially match here, so we move the cursor forward one
|
|
1890
1892
|
// space
|
|
1891
|
-
modeBuffer += lexeme[0]
|
|
1892
|
-
return 1
|
|
1893
|
+
modeBuffer += lexeme[0];
|
|
1894
|
+
return 1;
|
|
1893
1895
|
} else {
|
|
1894
1896
|
// no need to move the cursor, we still have additional regexes to try and
|
|
1895
1897
|
// match at this very spot
|
|
1896
|
-
resumeScanAtSamePosition = true
|
|
1897
|
-
return 0
|
|
1898
|
+
resumeScanAtSamePosition = true;
|
|
1899
|
+
return 0;
|
|
1898
1900
|
}
|
|
1899
1901
|
}
|
|
1900
1902
|
|
|
@@ -1904,32 +1906,32 @@ const hljs = (function () {
|
|
|
1904
1906
|
* @param {EnhancedMatch} match - the current match
|
|
1905
1907
|
* @returns {number} how far to advance the parse cursor
|
|
1906
1908
|
*/
|
|
1907
|
-
function doBeginMatch
|
|
1908
|
-
const lexeme = match[0]
|
|
1909
|
-
const newMode = match.rule
|
|
1909
|
+
function doBeginMatch(match) {
|
|
1910
|
+
const lexeme = match[0];
|
|
1911
|
+
const newMode = match.rule;
|
|
1910
1912
|
|
|
1911
|
-
const resp = new Response(newMode)
|
|
1913
|
+
const resp = new Response(newMode);
|
|
1912
1914
|
// first internal before callbacks, then the public ones
|
|
1913
|
-
const beforeCallbacks = [newMode.__beforeBegin, newMode[
|
|
1915
|
+
const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
|
|
1914
1916
|
for (const cb of beforeCallbacks) {
|
|
1915
|
-
if (!cb) continue
|
|
1916
|
-
cb(match, resp)
|
|
1917
|
-
if (resp.isMatchIgnored) return doIgnore(lexeme)
|
|
1917
|
+
if (!cb) continue;
|
|
1918
|
+
cb(match, resp);
|
|
1919
|
+
if (resp.isMatchIgnored) return doIgnore(lexeme);
|
|
1918
1920
|
}
|
|
1919
1921
|
|
|
1920
1922
|
if (newMode.skip) {
|
|
1921
|
-
modeBuffer += lexeme
|
|
1923
|
+
modeBuffer += lexeme;
|
|
1922
1924
|
} else {
|
|
1923
1925
|
if (newMode.excludeBegin) {
|
|
1924
|
-
modeBuffer += lexeme
|
|
1926
|
+
modeBuffer += lexeme;
|
|
1925
1927
|
}
|
|
1926
|
-
processBuffer()
|
|
1928
|
+
processBuffer();
|
|
1927
1929
|
if (!newMode.returnBegin && !newMode.excludeBegin) {
|
|
1928
|
-
modeBuffer = lexeme
|
|
1930
|
+
modeBuffer = lexeme;
|
|
1929
1931
|
}
|
|
1930
1932
|
}
|
|
1931
|
-
startNewMode(newMode, match)
|
|
1932
|
-
return newMode.returnBegin ? 0 : lexeme.length
|
|
1933
|
+
startNewMode(newMode, match);
|
|
1934
|
+
return newMode.returnBegin ? 0 : lexeme.length;
|
|
1933
1935
|
}
|
|
1934
1936
|
|
|
1935
1937
|
/**
|
|
@@ -1937,58 +1939,58 @@ const hljs = (function () {
|
|
|
1937
1939
|
*
|
|
1938
1940
|
* @param {RegExpMatchArray} match - the current match
|
|
1939
1941
|
*/
|
|
1940
|
-
function doEndMatch
|
|
1941
|
-
const lexeme = match[0]
|
|
1942
|
-
const matchPlusRemainder = codeToHighlight.substr(match.index)
|
|
1942
|
+
function doEndMatch(match) {
|
|
1943
|
+
const lexeme = match[0];
|
|
1944
|
+
const matchPlusRemainder = codeToHighlight.substr(match.index);
|
|
1943
1945
|
|
|
1944
|
-
const endMode = endOfMode(top, match, matchPlusRemainder)
|
|
1945
|
-
if (!endMode) { return NO_MATCH }
|
|
1946
|
+
const endMode = endOfMode(top, match, matchPlusRemainder);
|
|
1947
|
+
if (!endMode) { return NO_MATCH; }
|
|
1946
1948
|
|
|
1947
|
-
const origin = top
|
|
1949
|
+
const origin = top;
|
|
1948
1950
|
if (top.endScope && top.endScope._wrap) {
|
|
1949
|
-
processBuffer()
|
|
1950
|
-
emitter.addKeyword(lexeme, top.endScope._wrap)
|
|
1951
|
+
processBuffer();
|
|
1952
|
+
emitter.addKeyword(lexeme, top.endScope._wrap);
|
|
1951
1953
|
} else if (top.endScope && top.endScope._multi) {
|
|
1952
|
-
processBuffer()
|
|
1953
|
-
emitMultiClass(top.endScope, match)
|
|
1954
|
+
processBuffer();
|
|
1955
|
+
emitMultiClass(top.endScope, match);
|
|
1954
1956
|
} else if (origin.skip) {
|
|
1955
|
-
modeBuffer += lexeme
|
|
1957
|
+
modeBuffer += lexeme;
|
|
1956
1958
|
} else {
|
|
1957
1959
|
if (!(origin.returnEnd || origin.excludeEnd)) {
|
|
1958
|
-
modeBuffer += lexeme
|
|
1960
|
+
modeBuffer += lexeme;
|
|
1959
1961
|
}
|
|
1960
|
-
processBuffer()
|
|
1962
|
+
processBuffer();
|
|
1961
1963
|
if (origin.excludeEnd) {
|
|
1962
|
-
modeBuffer = lexeme
|
|
1964
|
+
modeBuffer = lexeme;
|
|
1963
1965
|
}
|
|
1964
1966
|
}
|
|
1965
1967
|
do {
|
|
1966
1968
|
if (top.scope && !top.isMultiClass) {
|
|
1967
|
-
emitter.closeNode()
|
|
1969
|
+
emitter.closeNode();
|
|
1968
1970
|
}
|
|
1969
1971
|
if (!top.skip && !top.subLanguage) {
|
|
1970
|
-
relevance += top.relevance
|
|
1972
|
+
relevance += top.relevance;
|
|
1971
1973
|
}
|
|
1972
|
-
top = top.parent
|
|
1973
|
-
} while (top !== endMode.parent)
|
|
1974
|
+
top = top.parent;
|
|
1975
|
+
} while (top !== endMode.parent);
|
|
1974
1976
|
if (endMode.starts) {
|
|
1975
|
-
startNewMode(endMode.starts, match)
|
|
1977
|
+
startNewMode(endMode.starts, match);
|
|
1976
1978
|
}
|
|
1977
|
-
return origin.returnEnd ? 0 : lexeme.length
|
|
1979
|
+
return origin.returnEnd ? 0 : lexeme.length;
|
|
1978
1980
|
}
|
|
1979
1981
|
|
|
1980
|
-
function processContinuations
|
|
1981
|
-
const list = []
|
|
1982
|
+
function processContinuations() {
|
|
1983
|
+
const list = [];
|
|
1982
1984
|
for (let current = top; current !== language; current = current.parent) {
|
|
1983
1985
|
if (current.scope) {
|
|
1984
|
-
list.unshift(current.scope)
|
|
1986
|
+
list.unshift(current.scope);
|
|
1985
1987
|
}
|
|
1986
1988
|
}
|
|
1987
|
-
list.forEach(item => emitter.openNode(item))
|
|
1989
|
+
list.forEach(item => emitter.openNode(item));
|
|
1988
1990
|
}
|
|
1989
1991
|
|
|
1990
1992
|
/** @type {{type?: MatchType, index?: number, rule?: Mode}}} */
|
|
1991
|
-
let lastMatch = {}
|
|
1993
|
+
let lastMatch = {};
|
|
1992
1994
|
|
|
1993
1995
|
/**
|
|
1994
1996
|
* Process an individual match
|
|
@@ -1996,56 +1998,56 @@ const hljs = (function () {
|
|
|
1996
1998
|
* @param {string} textBeforeMatch - text preceding the match (since the last match)
|
|
1997
1999
|
* @param {EnhancedMatch} [match] - the match itself
|
|
1998
2000
|
*/
|
|
1999
|
-
function processLexeme
|
|
2000
|
-
const lexeme = match && match[0]
|
|
2001
|
+
function processLexeme(textBeforeMatch, match) {
|
|
2002
|
+
const lexeme = match && match[0];
|
|
2001
2003
|
|
|
2002
2004
|
// add non-matched text to the current mode buffer
|
|
2003
|
-
modeBuffer += textBeforeMatch
|
|
2005
|
+
modeBuffer += textBeforeMatch;
|
|
2004
2006
|
|
|
2005
2007
|
if (lexeme == null) {
|
|
2006
|
-
processBuffer()
|
|
2007
|
-
return 0
|
|
2008
|
+
processBuffer();
|
|
2009
|
+
return 0;
|
|
2008
2010
|
}
|
|
2009
2011
|
|
|
2010
2012
|
// we've found a 0 width match and we're stuck, so we need to advance
|
|
2011
2013
|
// this happens when we have badly behaved rules that have optional matchers to the degree that
|
|
2012
2014
|
// sometimes they can end up matching nothing at all
|
|
2013
2015
|
// Ref: https://github.com/highlightjs/highlight.js/issues/2140
|
|
2014
|
-
if (lastMatch.type ===
|
|
2016
|
+
if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
|
|
2015
2017
|
// spit the "skipped" character that our regex choked on back into the output sequence
|
|
2016
|
-
modeBuffer += codeToHighlight.slice(match.index, match.index + 1)
|
|
2018
|
+
modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
|
|
2017
2019
|
if (!SAFE_MODE) {
|
|
2018
2020
|
/** @type {AnnotatedError} */
|
|
2019
|
-
const err = new Error(`0 width match regex (${languageName})`)
|
|
2020
|
-
err.languageName = languageName
|
|
2021
|
-
err.badRule = lastMatch.rule
|
|
2022
|
-
throw err
|
|
2021
|
+
const err = new Error(`0 width match regex (${languageName})`);
|
|
2022
|
+
err.languageName = languageName;
|
|
2023
|
+
err.badRule = lastMatch.rule;
|
|
2024
|
+
throw err;
|
|
2023
2025
|
}
|
|
2024
|
-
return 1
|
|
2026
|
+
return 1;
|
|
2025
2027
|
}
|
|
2026
|
-
lastMatch = match
|
|
2028
|
+
lastMatch = match;
|
|
2027
2029
|
|
|
2028
|
-
if (match.type ===
|
|
2029
|
-
return doBeginMatch(match)
|
|
2030
|
-
} else if (match.type ===
|
|
2030
|
+
if (match.type === "begin") {
|
|
2031
|
+
return doBeginMatch(match);
|
|
2032
|
+
} else if (match.type === "illegal" && !ignoreIllegals) {
|
|
2031
2033
|
// illegal match, we do not continue processing
|
|
2032
2034
|
/** @type {AnnotatedError} */
|
|
2033
|
-
const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.scope || '<unnamed>') + '"')
|
|
2034
|
-
err.mode = top
|
|
2035
|
-
throw err
|
|
2036
|
-
} else if (match.type ===
|
|
2037
|
-
const processed = doEndMatch(match)
|
|
2035
|
+
const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.scope || '<unnamed>') + '"');
|
|
2036
|
+
err.mode = top;
|
|
2037
|
+
throw err;
|
|
2038
|
+
} else if (match.type === "end") {
|
|
2039
|
+
const processed = doEndMatch(match);
|
|
2038
2040
|
if (processed !== NO_MATCH) {
|
|
2039
|
-
return processed
|
|
2041
|
+
return processed;
|
|
2040
2042
|
}
|
|
2041
2043
|
}
|
|
2042
2044
|
|
|
2043
2045
|
// edge case for when illegal matches $ (end of line) which is technically
|
|
2044
2046
|
// a 0 width match but not a begin/end match so it's not caught by the
|
|
2045
2047
|
// first handler (when ignoreIllegals is true)
|
|
2046
|
-
if (match.type ===
|
|
2048
|
+
if (match.type === "illegal" && lexeme === "") {
|
|
2047
2049
|
// advance so we aren't stuck in an infinite loop
|
|
2048
|
-
return 1
|
|
2050
|
+
return 1;
|
|
2049
2051
|
}
|
|
2050
2052
|
|
|
2051
2053
|
// infinite loops are BAD, this is a last ditch catch all. if we have a
|
|
@@ -2053,8 +2055,8 @@ const hljs = (function () {
|
|
|
2053
2055
|
// parsing) still 3x behind our index then something is very wrong
|
|
2054
2056
|
// so we bail
|
|
2055
2057
|
if (iterations > 100000 && iterations > match.index * 3) {
|
|
2056
|
-
const err = new Error('potential infinite loop, way more iterations than matches')
|
|
2057
|
-
throw err
|
|
2058
|
+
const err = new Error('potential infinite loop, way more iterations than matches');
|
|
2059
|
+
throw err;
|
|
2058
2060
|
}
|
|
2059
2061
|
|
|
2060
2062
|
/*
|
|
@@ -2065,66 +2067,66 @@ const hljs = (function () {
|
|
|
2065
2067
|
This causes no real harm other than stopping a few times too many.
|
|
2066
2068
|
*/
|
|
2067
2069
|
|
|
2068
|
-
modeBuffer += lexeme
|
|
2069
|
-
return lexeme.length
|
|
2070
|
+
modeBuffer += lexeme;
|
|
2071
|
+
return lexeme.length;
|
|
2070
2072
|
}
|
|
2071
2073
|
|
|
2072
|
-
const language = getLanguage(languageName)
|
|
2074
|
+
const language = getLanguage(languageName);
|
|
2073
2075
|
if (!language) {
|
|
2074
|
-
error(LANGUAGE_NOT_FOUND.replace(
|
|
2075
|
-
throw new Error('Unknown language: "' + languageName + '"')
|
|
2076
|
+
error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
|
|
2077
|
+
throw new Error('Unknown language: "' + languageName + '"');
|
|
2076
2078
|
}
|
|
2077
2079
|
|
|
2078
|
-
const md = compileLanguage(language)
|
|
2079
|
-
let result = ''
|
|
2080
|
+
const md = compileLanguage(language);
|
|
2081
|
+
let result = '';
|
|
2080
2082
|
/** @type {CompiledMode} */
|
|
2081
|
-
let top = continuation || md
|
|
2083
|
+
let top = continuation || md;
|
|
2082
2084
|
/** @type Record<string,CompiledMode> */
|
|
2083
|
-
const continuations = {} // keep continuations for sub-languages
|
|
2084
|
-
const emitter = new options.__emitter(options)
|
|
2085
|
-
processContinuations()
|
|
2086
|
-
let modeBuffer = ''
|
|
2087
|
-
let relevance = 0
|
|
2088
|
-
let index = 0
|
|
2089
|
-
let iterations = 0
|
|
2090
|
-
let resumeScanAtSamePosition = false
|
|
2085
|
+
const continuations = {}; // keep continuations for sub-languages
|
|
2086
|
+
const emitter = new options.__emitter(options);
|
|
2087
|
+
processContinuations();
|
|
2088
|
+
let modeBuffer = '';
|
|
2089
|
+
let relevance = 0;
|
|
2090
|
+
let index = 0;
|
|
2091
|
+
let iterations = 0;
|
|
2092
|
+
let resumeScanAtSamePosition = false;
|
|
2091
2093
|
|
|
2092
2094
|
try {
|
|
2093
|
-
top.matcher.considerAll()
|
|
2095
|
+
top.matcher.considerAll();
|
|
2094
2096
|
|
|
2095
2097
|
for (; ;) {
|
|
2096
|
-
iterations
|
|
2098
|
+
iterations++;
|
|
2097
2099
|
if (resumeScanAtSamePosition) {
|
|
2098
2100
|
// only regexes not matched previously will now be
|
|
2099
2101
|
// considered for a potential match
|
|
2100
|
-
resumeScanAtSamePosition = false
|
|
2102
|
+
resumeScanAtSamePosition = false;
|
|
2101
2103
|
} else {
|
|
2102
|
-
top.matcher.considerAll()
|
|
2104
|
+
top.matcher.considerAll();
|
|
2103
2105
|
}
|
|
2104
|
-
top.matcher.lastIndex = index
|
|
2106
|
+
top.matcher.lastIndex = index;
|
|
2105
2107
|
|
|
2106
|
-
const match = top.matcher.exec(codeToHighlight)
|
|
2108
|
+
const match = top.matcher.exec(codeToHighlight);
|
|
2107
2109
|
// console.log("match", match[0], match.rule && match.rule.begin)
|
|
2108
2110
|
|
|
2109
|
-
if (!match) break
|
|
2111
|
+
if (!match) break;
|
|
2110
2112
|
|
|
2111
|
-
const beforeMatch = codeToHighlight.substring(index, match.index)
|
|
2112
|
-
const processedCount = processLexeme(beforeMatch, match)
|
|
2113
|
-
index = match.index + processedCount
|
|
2113
|
+
const beforeMatch = codeToHighlight.substring(index, match.index);
|
|
2114
|
+
const processedCount = processLexeme(beforeMatch, match);
|
|
2115
|
+
index = match.index + processedCount;
|
|
2114
2116
|
}
|
|
2115
|
-
processLexeme(codeToHighlight.substr(index))
|
|
2116
|
-
emitter.closeAllNodes()
|
|
2117
|
-
emitter.finalize()
|
|
2118
|
-
result = emitter.toHTML()
|
|
2117
|
+
processLexeme(codeToHighlight.substr(index));
|
|
2118
|
+
emitter.closeAllNodes();
|
|
2119
|
+
emitter.finalize();
|
|
2120
|
+
result = emitter.toHTML();
|
|
2119
2121
|
|
|
2120
2122
|
return {
|
|
2121
2123
|
language: languageName,
|
|
2122
2124
|
value: result,
|
|
2123
|
-
relevance,
|
|
2125
|
+
relevance: relevance,
|
|
2124
2126
|
illegal: false,
|
|
2125
2127
|
_emitter: emitter,
|
|
2126
2128
|
_top: top
|
|
2127
|
-
}
|
|
2129
|
+
};
|
|
2128
2130
|
} catch (err) {
|
|
2129
2131
|
if (err.message && err.message.includes('Illegal')) {
|
|
2130
2132
|
return {
|
|
@@ -2134,13 +2136,13 @@ const hljs = (function () {
|
|
|
2134
2136
|
relevance: 0,
|
|
2135
2137
|
_illegalBy: {
|
|
2136
2138
|
message: err.message,
|
|
2137
|
-
index,
|
|
2139
|
+
index: index,
|
|
2138
2140
|
context: codeToHighlight.slice(index - 100, index + 100),
|
|
2139
2141
|
mode: err.mode,
|
|
2140
2142
|
resultSoFar: result
|
|
2141
2143
|
},
|
|
2142
2144
|
_emitter: emitter
|
|
2143
|
-
}
|
|
2145
|
+
};
|
|
2144
2146
|
} else if (SAFE_MODE) {
|
|
2145
2147
|
return {
|
|
2146
2148
|
language: languageName,
|
|
@@ -2150,9 +2152,9 @@ const hljs = (function () {
|
|
|
2150
2152
|
errorRaised: err,
|
|
2151
2153
|
_emitter: emitter,
|
|
2152
2154
|
_top: top
|
|
2153
|
-
}
|
|
2155
|
+
};
|
|
2154
2156
|
} else {
|
|
2155
|
-
throw err
|
|
2157
|
+
throw err;
|
|
2156
2158
|
}
|
|
2157
2159
|
}
|
|
2158
2160
|
}
|
|
@@ -2164,16 +2166,16 @@ const hljs = (function () {
|
|
|
2164
2166
|
* @param {string} code
|
|
2165
2167
|
* @returns {HighlightResult}
|
|
2166
2168
|
*/
|
|
2167
|
-
function justTextHighlightResult
|
|
2169
|
+
function justTextHighlightResult(code) {
|
|
2168
2170
|
const result = {
|
|
2169
2171
|
value: escape(code),
|
|
2170
2172
|
illegal: false,
|
|
2171
2173
|
relevance: 0,
|
|
2172
2174
|
_top: PLAINTEXT_LANGUAGE,
|
|
2173
2175
|
_emitter: new options.__emitter(options)
|
|
2174
|
-
}
|
|
2175
|
-
result._emitter.addText(code)
|
|
2176
|
-
return result
|
|
2176
|
+
};
|
|
2177
|
+
result._emitter.addText(code);
|
|
2178
|
+
return result;
|
|
2177
2179
|
}
|
|
2178
2180
|
|
|
2179
2181
|
/**
|
|
@@ -2190,26 +2192,26 @@ const hljs = (function () {
|
|
|
2190
2192
|
@param {Array<string>} [languageSubset]
|
|
2191
2193
|
@returns {AutoHighlightResult}
|
|
2192
2194
|
*/
|
|
2193
|
-
function highlightAuto
|
|
2194
|
-
languageSubset = languageSubset || options.languages || Object.keys(languages)
|
|
2195
|
-
const plaintext = justTextHighlightResult(code)
|
|
2195
|
+
function highlightAuto(code, languageSubset) {
|
|
2196
|
+
languageSubset = languageSubset || options.languages || Object.keys(languages);
|
|
2197
|
+
const plaintext = justTextHighlightResult(code);
|
|
2196
2198
|
|
|
2197
2199
|
const results = languageSubset.filter(getLanguage).filter(autoDetection).map(name =>
|
|
2198
2200
|
_highlight(name, code, false)
|
|
2199
|
-
)
|
|
2200
|
-
results.unshift(plaintext) // plaintext is always an option
|
|
2201
|
+
);
|
|
2202
|
+
results.unshift(plaintext); // plaintext is always an option
|
|
2201
2203
|
|
|
2202
2204
|
const sorted = results.sort((a, b) => {
|
|
2203
2205
|
// sort base on relevance
|
|
2204
|
-
if (a.relevance !== b.relevance) return b.relevance - a.relevance
|
|
2206
|
+
if (a.relevance !== b.relevance) return b.relevance - a.relevance;
|
|
2205
2207
|
|
|
2206
2208
|
// always award the tie to the base language
|
|
2207
2209
|
// ie if C++ and Arduino are tied, it's more likely to be C++
|
|
2208
2210
|
if (a.language && b.language) {
|
|
2209
2211
|
if (getLanguage(a.language).supersetOf === b.language) {
|
|
2210
|
-
return 1
|
|
2212
|
+
return 1;
|
|
2211
2213
|
} else if (getLanguage(b.language).supersetOf === a.language) {
|
|
2212
|
-
return -1
|
|
2214
|
+
return -1;
|
|
2213
2215
|
}
|
|
2214
2216
|
}
|
|
2215
2217
|
|
|
@@ -2217,16 +2219,16 @@ const hljs = (function () {
|
|
|
2217
2219
|
// relevance while preserving the original ordering - which is how ties
|
|
2218
2220
|
// have historically been settled, ie the language that comes first always
|
|
2219
2221
|
// wins in the case of a tie
|
|
2220
|
-
return 0
|
|
2221
|
-
})
|
|
2222
|
+
return 0;
|
|
2223
|
+
});
|
|
2222
2224
|
|
|
2223
|
-
const [best, secondBest] = sorted
|
|
2225
|
+
const [best, secondBest] = sorted;
|
|
2224
2226
|
|
|
2225
2227
|
/** @type {AutoHighlightResult} */
|
|
2226
|
-
const result = best
|
|
2227
|
-
result.secondBest = secondBest
|
|
2228
|
+
const result = best;
|
|
2229
|
+
result.secondBest = secondBest;
|
|
2228
2230
|
|
|
2229
|
-
return result
|
|
2231
|
+
return result;
|
|
2230
2232
|
}
|
|
2231
2233
|
|
|
2232
2234
|
/**
|
|
@@ -2236,11 +2238,11 @@ const hljs = (function () {
|
|
|
2236
2238
|
* @param {string} [currentLang]
|
|
2237
2239
|
* @param {string} [resultLang]
|
|
2238
2240
|
*/
|
|
2239
|
-
function updateClassName
|
|
2240
|
-
const language = (currentLang && aliases[currentLang]) || resultLang
|
|
2241
|
+
function updateClassName(element, currentLang, resultLang) {
|
|
2242
|
+
const language = (currentLang && aliases[currentLang]) || resultLang;
|
|
2241
2243
|
|
|
2242
|
-
element.classList.add(
|
|
2243
|
-
element.classList.add(`language-${language}`)
|
|
2244
|
+
element.classList.add("hljs");
|
|
2245
|
+
element.classList.add(`language-${language}`);
|
|
2244
2246
|
}
|
|
2245
2247
|
|
|
2246
2248
|
/**
|
|
@@ -2248,42 +2250,42 @@ const hljs = (function () {
|
|
|
2248
2250
|
*
|
|
2249
2251
|
* @param {HighlightedHTMLElement} element - the HTML element to highlight
|
|
2250
2252
|
*/
|
|
2251
|
-
function highlightElement
|
|
2253
|
+
function highlightElement(element) {
|
|
2252
2254
|
/** @type HTMLElement */
|
|
2253
|
-
let node = null
|
|
2254
|
-
const language = blockLanguage(element)
|
|
2255
|
+
let node = null;
|
|
2256
|
+
const language = blockLanguage(element);
|
|
2255
2257
|
|
|
2256
|
-
if (shouldNotHighlight(language)) return
|
|
2258
|
+
if (shouldNotHighlight(language)) return;
|
|
2257
2259
|
|
|
2258
|
-
fire(
|
|
2259
|
-
{ el: element, language })
|
|
2260
|
+
fire("before:highlightElement",
|
|
2261
|
+
{ el: element, language: language });
|
|
2260
2262
|
|
|
2261
2263
|
// we should be all text, no child nodes
|
|
2262
2264
|
if (!options.ignoreUnescapedHTML && element.children.length > 0) {
|
|
2263
|
-
console.warn(
|
|
2264
|
-
console.warn(
|
|
2265
|
-
console.warn(element)
|
|
2265
|
+
console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk.");
|
|
2266
|
+
console.warn("https://github.com/highlightjs/highlight.js/issues/2886");
|
|
2267
|
+
console.warn(element);
|
|
2266
2268
|
}
|
|
2267
2269
|
|
|
2268
|
-
node = element
|
|
2269
|
-
const text = node.textContent
|
|
2270
|
-
const result = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text)
|
|
2270
|
+
node = element;
|
|
2271
|
+
const text = node.textContent;
|
|
2272
|
+
const result = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text);
|
|
2271
2273
|
|
|
2272
|
-
fire(
|
|
2274
|
+
fire("after:highlightElement", { el: element, result, text });
|
|
2273
2275
|
|
|
2274
|
-
element.innerHTML = result.value
|
|
2275
|
-
updateClassName(element, language, result.language)
|
|
2276
|
+
element.innerHTML = result.value;
|
|
2277
|
+
updateClassName(element, language, result.language);
|
|
2276
2278
|
element.result = {
|
|
2277
2279
|
language: result.language,
|
|
2278
2280
|
// TODO: remove with version 11.0
|
|
2279
2281
|
re: result.relevance,
|
|
2280
2282
|
relevance: result.relevance
|
|
2281
|
-
}
|
|
2283
|
+
};
|
|
2282
2284
|
if (result.secondBest) {
|
|
2283
2285
|
element.secondBest = {
|
|
2284
2286
|
language: result.secondBest.language,
|
|
2285
2287
|
relevance: result.secondBest.relevance
|
|
2286
|
-
}
|
|
2288
|
+
};
|
|
2287
2289
|
}
|
|
2288
2290
|
}
|
|
2289
2291
|
|
|
@@ -2292,46 +2294,46 @@ const hljs = (function () {
|
|
|
2292
2294
|
*
|
|
2293
2295
|
* @param {Partial<HLJSOptions>} userOptions
|
|
2294
2296
|
*/
|
|
2295
|
-
function configure
|
|
2296
|
-
options = inherit(options, userOptions)
|
|
2297
|
+
function configure(userOptions) {
|
|
2298
|
+
options = inherit(options, userOptions);
|
|
2297
2299
|
}
|
|
2298
2300
|
|
|
2299
2301
|
// TODO: remove v12, deprecated
|
|
2300
2302
|
const initHighlighting = () => {
|
|
2301
|
-
highlightAll()
|
|
2302
|
-
deprecated(
|
|
2303
|
-
}
|
|
2303
|
+
highlightAll();
|
|
2304
|
+
deprecated("10.6.0", "initHighlighting() deprecated. Use highlightAll() now.");
|
|
2305
|
+
};
|
|
2304
2306
|
|
|
2305
2307
|
// TODO: remove v12, deprecated
|
|
2306
|
-
function initHighlightingOnLoad
|
|
2307
|
-
highlightAll()
|
|
2308
|
-
deprecated(
|
|
2308
|
+
function initHighlightingOnLoad() {
|
|
2309
|
+
highlightAll();
|
|
2310
|
+
deprecated("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now.");
|
|
2309
2311
|
}
|
|
2310
2312
|
|
|
2311
|
-
let wantsHighlight = false
|
|
2313
|
+
let wantsHighlight = false;
|
|
2312
2314
|
|
|
2313
2315
|
/**
|
|
2314
2316
|
* auto-highlights all pre>code elements on the page
|
|
2315
2317
|
*/
|
|
2316
|
-
function highlightAll
|
|
2318
|
+
function highlightAll() {
|
|
2317
2319
|
// if we are called too early in the loading process
|
|
2318
|
-
if (document.readyState ===
|
|
2319
|
-
wantsHighlight = true
|
|
2320
|
-
return
|
|
2320
|
+
if (document.readyState === "loading") {
|
|
2321
|
+
wantsHighlight = true;
|
|
2322
|
+
return;
|
|
2321
2323
|
}
|
|
2322
2324
|
|
|
2323
|
-
const blocks = document.querySelectorAll(options.cssSelector)
|
|
2324
|
-
blocks.forEach(highlightElement)
|
|
2325
|
+
const blocks = document.querySelectorAll(options.cssSelector);
|
|
2326
|
+
blocks.forEach(highlightElement);
|
|
2325
2327
|
}
|
|
2326
2328
|
|
|
2327
|
-
function boot
|
|
2329
|
+
function boot() {
|
|
2328
2330
|
// if a highlight was requested before DOM was loaded, do now
|
|
2329
|
-
if (wantsHighlight) highlightAll()
|
|
2331
|
+
if (wantsHighlight) highlightAll();
|
|
2330
2332
|
}
|
|
2331
2333
|
|
|
2332
2334
|
// make sure we are in the browser environment
|
|
2333
2335
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
2334
|
-
window.addEventListener('DOMContentLoaded', boot, false)
|
|
2336
|
+
window.addEventListener('DOMContentLoaded', boot, false);
|
|
2335
2337
|
}
|
|
2336
2338
|
|
|
2337
2339
|
/**
|
|
@@ -2340,27 +2342,27 @@ const hljs = (function () {
|
|
|
2340
2342
|
* @param {string} languageName
|
|
2341
2343
|
* @param {LanguageFn} languageDefinition
|
|
2342
2344
|
*/
|
|
2343
|
-
function registerLanguage
|
|
2344
|
-
let lang = null
|
|
2345
|
+
function registerLanguage(languageName, languageDefinition) {
|
|
2346
|
+
let lang = null;
|
|
2345
2347
|
try {
|
|
2346
|
-
lang = languageDefinition(hljs)
|
|
2348
|
+
lang = languageDefinition(hljs);
|
|
2347
2349
|
} catch (error$1) {
|
|
2348
|
-
error("Language definition for '{}' could not be registered.".replace(
|
|
2350
|
+
error("Language definition for '{}' could not be registered.".replace("{}", languageName));
|
|
2349
2351
|
// hard or soft error
|
|
2350
|
-
if (!SAFE_MODE) { throw error$1 } else { error(error$1) }
|
|
2352
|
+
if (!SAFE_MODE) { throw error$1; } else { error(error$1); }
|
|
2351
2353
|
// languages that have serious errors are replaced with essentially a
|
|
2352
2354
|
// "plaintext" stand-in so that the code blocks will still get normal
|
|
2353
2355
|
// css classes applied to them - and one bad language won't break the
|
|
2354
2356
|
// entire highlighter
|
|
2355
|
-
lang = PLAINTEXT_LANGUAGE
|
|
2357
|
+
lang = PLAINTEXT_LANGUAGE;
|
|
2356
2358
|
}
|
|
2357
2359
|
// give it a temporary name if it doesn't have one in the meta-data
|
|
2358
|
-
if (!lang.name) lang.name = languageName
|
|
2359
|
-
languages[languageName] = lang
|
|
2360
|
-
lang.rawDefinition = languageDefinition.bind(null, hljs)
|
|
2360
|
+
if (!lang.name) lang.name = languageName;
|
|
2361
|
+
languages[languageName] = lang;
|
|
2362
|
+
lang.rawDefinition = languageDefinition.bind(null, hljs);
|
|
2361
2363
|
|
|
2362
2364
|
if (lang.aliases) {
|
|
2363
|
-
registerAliases(lang.aliases, { languageName })
|
|
2365
|
+
registerAliases(lang.aliases, { languageName });
|
|
2364
2366
|
}
|
|
2365
2367
|
}
|
|
2366
2368
|
|
|
@@ -2369,11 +2371,11 @@ const hljs = (function () {
|
|
|
2369
2371
|
*
|
|
2370
2372
|
* @param {string} languageName
|
|
2371
2373
|
*/
|
|
2372
|
-
function unregisterLanguage
|
|
2373
|
-
delete languages[languageName]
|
|
2374
|
+
function unregisterLanguage(languageName) {
|
|
2375
|
+
delete languages[languageName];
|
|
2374
2376
|
for (const alias of Object.keys(aliases)) {
|
|
2375
2377
|
if (aliases[alias] === languageName) {
|
|
2376
|
-
delete aliases[alias]
|
|
2378
|
+
delete aliases[alias];
|
|
2377
2379
|
}
|
|
2378
2380
|
}
|
|
2379
2381
|
}
|
|
@@ -2381,17 +2383,17 @@ const hljs = (function () {
|
|
|
2381
2383
|
/**
|
|
2382
2384
|
* @returns {string[]} List of language internal names
|
|
2383
2385
|
*/
|
|
2384
|
-
function listLanguages
|
|
2385
|
-
return Object.keys(languages)
|
|
2386
|
+
function listLanguages() {
|
|
2387
|
+
return Object.keys(languages);
|
|
2386
2388
|
}
|
|
2387
2389
|
|
|
2388
2390
|
/**
|
|
2389
2391
|
* @param {string} name - name of the language to retrieve
|
|
2390
2392
|
* @returns {Language | undefined}
|
|
2391
2393
|
*/
|
|
2392
|
-
function getLanguage
|
|
2393
|
-
name = (name || '').toLowerCase()
|
|
2394
|
-
return languages[name] || languages[aliases[name]]
|
|
2394
|
+
function getLanguage(name) {
|
|
2395
|
+
name = (name || '').toLowerCase();
|
|
2396
|
+
return languages[name] || languages[aliases[name]];
|
|
2395
2397
|
}
|
|
2396
2398
|
|
|
2397
2399
|
/**
|
|
@@ -2399,20 +2401,20 @@ const hljs = (function () {
|
|
|
2399
2401
|
* @param {string|string[]} aliasList - single alias or list of aliases
|
|
2400
2402
|
* @param {{languageName: string}} opts
|
|
2401
2403
|
*/
|
|
2402
|
-
function registerAliases
|
|
2404
|
+
function registerAliases(aliasList, { languageName }) {
|
|
2403
2405
|
if (typeof aliasList === 'string') {
|
|
2404
|
-
aliasList = [aliasList]
|
|
2406
|
+
aliasList = [aliasList];
|
|
2405
2407
|
}
|
|
2406
|
-
aliasList.forEach(alias => { aliases[alias.toLowerCase()] = languageName })
|
|
2408
|
+
aliasList.forEach(alias => { aliases[alias.toLowerCase()] = languageName; });
|
|
2407
2409
|
}
|
|
2408
2410
|
|
|
2409
2411
|
/**
|
|
2410
2412
|
* Determines if a given language has auto-detection enabled
|
|
2411
2413
|
* @param {string} name - name of the language
|
|
2412
2414
|
*/
|
|
2413
|
-
function autoDetection
|
|
2414
|
-
const lang = getLanguage(name)
|
|
2415
|
-
return lang && !lang.disableAutodetect
|
|
2415
|
+
function autoDetection(name) {
|
|
2416
|
+
const lang = getLanguage(name);
|
|
2417
|
+
return lang && !lang.disableAutodetect;
|
|
2416
2418
|
}
|
|
2417
2419
|
|
|
2418
2420
|
/**
|
|
@@ -2420,30 +2422,30 @@ const hljs = (function () {
|
|
|
2420
2422
|
* highlightElement API
|
|
2421
2423
|
* @param {HLJSPlugin} plugin
|
|
2422
2424
|
*/
|
|
2423
|
-
function upgradePluginAPI
|
|
2425
|
+
function upgradePluginAPI(plugin) {
|
|
2424
2426
|
// TODO: remove with v12
|
|
2425
|
-
if (plugin[
|
|
2426
|
-
plugin[
|
|
2427
|
-
plugin[
|
|
2427
|
+
if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
|
|
2428
|
+
plugin["before:highlightElement"] = (data) => {
|
|
2429
|
+
plugin["before:highlightBlock"](
|
|
2428
2430
|
Object.assign({ block: data.el }, data)
|
|
2429
|
-
)
|
|
2430
|
-
}
|
|
2431
|
+
);
|
|
2432
|
+
};
|
|
2431
2433
|
}
|
|
2432
|
-
if (plugin[
|
|
2433
|
-
plugin[
|
|
2434
|
-
plugin[
|
|
2434
|
+
if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
|
|
2435
|
+
plugin["after:highlightElement"] = (data) => {
|
|
2436
|
+
plugin["after:highlightBlock"](
|
|
2435
2437
|
Object.assign({ block: data.el }, data)
|
|
2436
|
-
)
|
|
2437
|
-
}
|
|
2438
|
+
);
|
|
2439
|
+
};
|
|
2438
2440
|
}
|
|
2439
2441
|
}
|
|
2440
2442
|
|
|
2441
2443
|
/**
|
|
2442
2444
|
* @param {HLJSPlugin} plugin
|
|
2443
2445
|
*/
|
|
2444
|
-
function addPlugin
|
|
2445
|
-
upgradePluginAPI(plugin)
|
|
2446
|
-
plugins.push(plugin)
|
|
2446
|
+
function addPlugin(plugin) {
|
|
2447
|
+
upgradePluginAPI(plugin);
|
|
2448
|
+
plugins.push(plugin);
|
|
2447
2449
|
}
|
|
2448
2450
|
|
|
2449
2451
|
/**
|
|
@@ -2451,24 +2453,24 @@ const hljs = (function () {
|
|
|
2451
2453
|
* @param {PluginEvent} event
|
|
2452
2454
|
* @param {any} args
|
|
2453
2455
|
*/
|
|
2454
|
-
function fire
|
|
2455
|
-
const cb = event
|
|
2456
|
+
function fire(event, args) {
|
|
2457
|
+
const cb = event;
|
|
2456
2458
|
plugins.forEach(function (plugin) {
|
|
2457
2459
|
if (plugin[cb]) {
|
|
2458
|
-
plugin[cb](args)
|
|
2460
|
+
plugin[cb](args);
|
|
2459
2461
|
}
|
|
2460
|
-
})
|
|
2462
|
+
});
|
|
2461
2463
|
}
|
|
2462
2464
|
|
|
2463
2465
|
/**
|
|
2464
2466
|
*
|
|
2465
2467
|
* @param {HighlightedHTMLElement} el
|
|
2466
2468
|
*/
|
|
2467
|
-
function deprecateHighlightBlock
|
|
2468
|
-
deprecated(
|
|
2469
|
-
deprecated(
|
|
2469
|
+
function deprecateHighlightBlock(el) {
|
|
2470
|
+
deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
|
|
2471
|
+
deprecated("10.7.0", "Please use highlightElement now.");
|
|
2470
2472
|
|
|
2471
|
-
return highlightElement(el)
|
|
2473
|
+
return highlightElement(el);
|
|
2472
2474
|
}
|
|
2473
2475
|
|
|
2474
2476
|
/* Interface definition */
|
|
@@ -2490,28 +2492,28 @@ const hljs = (function () {
|
|
|
2490
2492
|
autoDetection,
|
|
2491
2493
|
inherit,
|
|
2492
2494
|
addPlugin
|
|
2493
|
-
})
|
|
2495
|
+
});
|
|
2494
2496
|
|
|
2495
|
-
hljs.debugMode = function () { SAFE_MODE = false }
|
|
2496
|
-
hljs.safeMode = function () { SAFE_MODE = true }
|
|
2497
|
-
hljs.versionString = version
|
|
2497
|
+
hljs.debugMode = function () { SAFE_MODE = false; };
|
|
2498
|
+
hljs.safeMode = function () { SAFE_MODE = true; };
|
|
2499
|
+
hljs.versionString = version;
|
|
2498
2500
|
|
|
2499
2501
|
for (const key in MODES$1) {
|
|
2500
2502
|
// @ts-ignore
|
|
2501
|
-
if (typeof MODES$1[key] ===
|
|
2503
|
+
if (typeof MODES$1[key] === "object") {
|
|
2502
2504
|
// @ts-ignore
|
|
2503
|
-
deepFreeze$1(MODES$1[key])
|
|
2505
|
+
deepFreeze$1(MODES$1[key]);
|
|
2504
2506
|
}
|
|
2505
2507
|
}
|
|
2506
2508
|
|
|
2507
2509
|
// merge all the modes/regexes into our main object
|
|
2508
|
-
Object.assign(hljs, MODES$1)
|
|
2510
|
+
Object.assign(hljs, MODES$1);
|
|
2509
2511
|
|
|
2510
|
-
return hljs
|
|
2511
|
-
}
|
|
2512
|
+
return hljs;
|
|
2513
|
+
};
|
|
2512
2514
|
|
|
2513
2515
|
// export an "instance" of the highlighter
|
|
2514
|
-
|
|
2516
|
+
var HighlightJS = HLJS({});
|
|
2515
2517
|
|
|
2516
2518
|
/*
|
|
2517
2519
|
Language: Bash
|
|
@@ -2522,19 +2524,19 @@ const hljs = (function () {
|
|
|
2522
2524
|
*/
|
|
2523
2525
|
|
|
2524
2526
|
/** @type LanguageFn */
|
|
2525
|
-
function bash
|
|
2526
|
-
const VAR = {}
|
|
2527
|
+
function bash(hljs) {
|
|
2528
|
+
const VAR = {};
|
|
2527
2529
|
const BRACED_VAR = {
|
|
2528
2530
|
begin: /\$\{/,
|
|
2529
2531
|
end: /\}/,
|
|
2530
2532
|
contains: [
|
|
2531
|
-
|
|
2533
|
+
"self",
|
|
2532
2534
|
{
|
|
2533
2535
|
begin: /:-/,
|
|
2534
2536
|
contains: [VAR]
|
|
2535
2537
|
} // default values
|
|
2536
2538
|
]
|
|
2537
|
-
}
|
|
2539
|
+
};
|
|
2538
2540
|
Object.assign(VAR, {
|
|
2539
2541
|
className: 'variable',
|
|
2540
2542
|
variants: [
|
|
@@ -2542,18 +2544,17 @@ const hljs = (function () {
|
|
|
2542
2544
|
begin: concat(/\$[\w\d#@][\w\d_]*/,
|
|
2543
2545
|
// negative look-ahead tries to avoid matching patterns that are not
|
|
2544
2546
|
// Perl at all like $ident$, @ident@, etc.
|
|
2545
|
-
|
|
2547
|
+
`(?![\\w\\d])(?![$])`)
|
|
2546
2548
|
},
|
|
2547
2549
|
BRACED_VAR
|
|
2548
2550
|
]
|
|
2549
|
-
})
|
|
2551
|
+
});
|
|
2550
2552
|
|
|
2551
2553
|
const SUBST = {
|
|
2552
2554
|
className: 'subst',
|
|
2553
|
-
begin: /\$\(/,
|
|
2554
|
-
end: /\)/,
|
|
2555
|
+
begin: /\$\(/, end: /\)/,
|
|
2555
2556
|
contains: [hljs.BACKSLASH_ESCAPE]
|
|
2556
|
-
}
|
|
2557
|
+
};
|
|
2557
2558
|
const HERE_DOC = {
|
|
2558
2559
|
begin: /<<-?\s*(?=\w+)/,
|
|
2559
2560
|
starts: {
|
|
@@ -2565,80 +2566,78 @@ const hljs = (function () {
|
|
|
2565
2566
|
})
|
|
2566
2567
|
]
|
|
2567
2568
|
}
|
|
2568
|
-
}
|
|
2569
|
+
};
|
|
2569
2570
|
const QUOTE_STRING = {
|
|
2570
2571
|
className: 'string',
|
|
2571
|
-
begin: /"/,
|
|
2572
|
-
end: /"/,
|
|
2572
|
+
begin: /"/, end: /"/,
|
|
2573
2573
|
contains: [
|
|
2574
2574
|
hljs.BACKSLASH_ESCAPE,
|
|
2575
2575
|
VAR,
|
|
2576
2576
|
SUBST
|
|
2577
2577
|
]
|
|
2578
|
-
}
|
|
2579
|
-
SUBST.contains.push(QUOTE_STRING)
|
|
2578
|
+
};
|
|
2579
|
+
SUBST.contains.push(QUOTE_STRING);
|
|
2580
2580
|
const ESCAPED_QUOTE = {
|
|
2581
2581
|
className: '',
|
|
2582
2582
|
begin: /\\"/
|
|
2583
2583
|
|
|
2584
|
-
}
|
|
2584
|
+
};
|
|
2585
2585
|
const APOS_STRING = {
|
|
2586
2586
|
className: 'string',
|
|
2587
|
-
begin: /'/,
|
|
2588
|
-
|
|
2589
|
-
}
|
|
2587
|
+
begin: /'/, end: /'/
|
|
2588
|
+
};
|
|
2590
2589
|
const ARITHMETIC = {
|
|
2591
2590
|
begin: /\$\(\(/,
|
|
2592
2591
|
end: /\)\)/,
|
|
2593
2592
|
contains: [
|
|
2594
|
-
{ begin: /\d+#[0-9a-f]+/, className:
|
|
2593
|
+
{ begin: /\d+#[0-9a-f]+/, className: "number" },
|
|
2595
2594
|
hljs.NUMBER_MODE,
|
|
2596
2595
|
VAR
|
|
2597
2596
|
]
|
|
2598
|
-
}
|
|
2597
|
+
};
|
|
2599
2598
|
const SH_LIKE_SHELLS = [
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
]
|
|
2599
|
+
"fish",
|
|
2600
|
+
"bash",
|
|
2601
|
+
"zsh",
|
|
2602
|
+
"sh",
|
|
2603
|
+
"csh",
|
|
2604
|
+
"ksh",
|
|
2605
|
+
"tcsh",
|
|
2606
|
+
"dash",
|
|
2607
|
+
"scsh",
|
|
2608
|
+
];
|
|
2610
2609
|
const KNOWN_SHEBANG = hljs.SHEBANG({
|
|
2611
|
-
binary: `(${SH_LIKE_SHELLS.join(
|
|
2610
|
+
binary: `(${SH_LIKE_SHELLS.join("|")})`,
|
|
2612
2611
|
relevance: 10
|
|
2613
|
-
})
|
|
2612
|
+
});
|
|
2614
2613
|
const FUNCTION = {
|
|
2615
2614
|
className: 'function',
|
|
2616
2615
|
begin: /\w[\w\d_]*\s*\(\s*\)\s*\{/,
|
|
2617
2616
|
returnBegin: true,
|
|
2618
2617
|
contains: [hljs.inherit(hljs.TITLE_MODE, { begin: /\w[\w\d_]*/ })],
|
|
2619
2618
|
relevance: 0
|
|
2620
|
-
}
|
|
2619
|
+
};
|
|
2621
2620
|
|
|
2622
2621
|
const KEYWORDS = [
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
]
|
|
2622
|
+
"if",
|
|
2623
|
+
"then",
|
|
2624
|
+
"else",
|
|
2625
|
+
"elif",
|
|
2626
|
+
"fi",
|
|
2627
|
+
"for",
|
|
2628
|
+
"while",
|
|
2629
|
+
"in",
|
|
2630
|
+
"do",
|
|
2631
|
+
"done",
|
|
2632
|
+
"case",
|
|
2633
|
+
"esac",
|
|
2634
|
+
"function"
|
|
2635
|
+
];
|
|
2637
2636
|
|
|
2638
2637
|
const LITERALS = [
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
]
|
|
2638
|
+
"true",
|
|
2639
|
+
"false"
|
|
2640
|
+
];
|
|
2642
2641
|
|
|
2643
2642
|
return {
|
|
2644
2643
|
name: 'Bash',
|
|
@@ -2677,9 +2676,10 @@ const hljs = (function () {
|
|
|
2677
2676
|
APOS_STRING,
|
|
2678
2677
|
VAR
|
|
2679
2678
|
]
|
|
2680
|
-
}
|
|
2679
|
+
};
|
|
2681
2680
|
}
|
|
2682
2681
|
|
|
2682
|
+
|
|
2683
2683
|
const MODES = (hljs) => {
|
|
2684
2684
|
return {
|
|
2685
2685
|
IMPORTANT: {
|
|
@@ -2713,8 +2713,8 @@ const hljs = (function () {
|
|
|
2713
2713
|
')?',
|
|
2714
2714
|
relevance: 0
|
|
2715
2715
|
}
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2716
|
+
};
|
|
2717
|
+
};
|
|
2718
2718
|
|
|
2719
2719
|
const TAGS = [
|
|
2720
2720
|
'a',
|
|
@@ -2789,7 +2789,7 @@ const hljs = (function () {
|
|
|
2789
2789
|
'ul',
|
|
2790
2790
|
'var',
|
|
2791
2791
|
'video'
|
|
2792
|
-
]
|
|
2792
|
+
];
|
|
2793
2793
|
|
|
2794
2794
|
const MEDIA_FEATURES = [
|
|
2795
2795
|
'any-hover',
|
|
@@ -2826,7 +2826,7 @@ const hljs = (function () {
|
|
|
2826
2826
|
'max-width',
|
|
2827
2827
|
'min-height',
|
|
2828
2828
|
'max-height'
|
|
2829
|
-
]
|
|
2829
|
+
];
|
|
2830
2830
|
|
|
2831
2831
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
|
|
2832
2832
|
const PSEUDO_CLASSES = [
|
|
@@ -2869,8 +2869,8 @@ const hljs = (function () {
|
|
|
2869
2869
|
'nth-col', // nth-col()
|
|
2870
2870
|
'nth-last-child', // nth-last-child()
|
|
2871
2871
|
'nth-last-col', // nth-last-col()
|
|
2872
|
-
'nth-last-of-type', //
|
|
2873
|
-
'nth-of-type', //
|
|
2872
|
+
'nth-last-of-type', //nth-last-of-type()
|
|
2873
|
+
'nth-of-type', //nth-of-type()
|
|
2874
2874
|
'only-child',
|
|
2875
2875
|
'only-of-type',
|
|
2876
2876
|
'optional',
|
|
@@ -2889,7 +2889,7 @@ const hljs = (function () {
|
|
|
2889
2889
|
'valid',
|
|
2890
2890
|
'visited',
|
|
2891
2891
|
'where' // where()
|
|
2892
|
-
]
|
|
2892
|
+
];
|
|
2893
2893
|
|
|
2894
2894
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
|
|
2895
2895
|
const PSEUDO_ELEMENTS = [
|
|
@@ -2907,7 +2907,7 @@ const hljs = (function () {
|
|
|
2907
2907
|
'selection',
|
|
2908
2908
|
'slotted',
|
|
2909
2909
|
'spelling-error'
|
|
2910
|
-
]
|
|
2910
|
+
];
|
|
2911
2911
|
|
|
2912
2912
|
const ATTRIBUTES = [
|
|
2913
2913
|
'align-content',
|
|
@@ -3119,16 +3119,17 @@ const hljs = (function () {
|
|
|
3119
3119
|
'z-index'
|
|
3120
3120
|
// reverse makes sure longer attributes `font-weight` are matched fully
|
|
3121
3121
|
// instead of getting false positives on say `font`
|
|
3122
|
-
].reverse()
|
|
3122
|
+
].reverse();
|
|
3123
3123
|
|
|
3124
3124
|
// some grammars use them all as a single group
|
|
3125
|
-
const PSEUDO_SELECTORS = PSEUDO_CLASSES.concat(PSEUDO_ELEMENTS)
|
|
3125
|
+
const PSEUDO_SELECTORS = PSEUDO_CLASSES.concat(PSEUDO_ELEMENTS);
|
|
3126
|
+
|
|
3126
3127
|
|
|
3127
3128
|
// https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.10
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3129
|
+
var decimalDigits = '[0-9](_*[0-9])*';
|
|
3130
|
+
var frac = `\\.(${decimalDigits})`;
|
|
3131
|
+
var hexDigits = '[0-9a-fA-F](_*[0-9a-fA-F])*';
|
|
3132
|
+
var NUMERIC = {
|
|
3132
3133
|
className: 'number',
|
|
3133
3134
|
variants: [
|
|
3134
3135
|
// DecimalFloatingPointLiteral
|
|
@@ -3158,10 +3159,11 @@ const hljs = (function () {
|
|
|
3158
3159
|
{ begin: '\\b0(_*[0-7])*[lL]?\\b' },
|
|
3159
3160
|
|
|
3160
3161
|
// BinaryIntegerLiteral
|
|
3161
|
-
{ begin: '\\b0[bB][01](_*[01])*[lL]?\\b' }
|
|
3162
|
+
{ begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },
|
|
3162
3163
|
],
|
|
3163
3164
|
relevance: 0
|
|
3164
|
-
}
|
|
3165
|
+
};
|
|
3166
|
+
|
|
3165
3167
|
|
|
3166
3168
|
/**
|
|
3167
3169
|
* Allows recursive regex expressions to a given depth
|
|
@@ -3174,153 +3176,153 @@ const hljs = (function () {
|
|
|
3174
3176
|
* @param {number} depth
|
|
3175
3177
|
* @returns {string}``
|
|
3176
3178
|
*/
|
|
3177
|
-
function recurRegex
|
|
3178
|
-
if (depth === -1) return
|
|
3179
|
+
function recurRegex(re, substitution, depth) {
|
|
3180
|
+
if (depth === -1) return "";
|
|
3179
3181
|
|
|
3180
3182
|
return re.replace(substitution, _ => {
|
|
3181
|
-
return recurRegex(re, substitution, depth - 1)
|
|
3182
|
-
})
|
|
3183
|
+
return recurRegex(re, substitution, depth - 1);
|
|
3184
|
+
});
|
|
3183
3185
|
}
|
|
3184
3186
|
|
|
3185
|
-
const IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*'
|
|
3187
|
+
const IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
|
|
3186
3188
|
const KEYWORDS = [
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3189
|
+
"as", // for exports
|
|
3190
|
+
"in",
|
|
3191
|
+
"of",
|
|
3192
|
+
"if",
|
|
3193
|
+
"for",
|
|
3194
|
+
"while",
|
|
3195
|
+
"finally",
|
|
3196
|
+
"var",
|
|
3197
|
+
"new",
|
|
3198
|
+
"function",
|
|
3199
|
+
"do",
|
|
3200
|
+
"return",
|
|
3201
|
+
"void",
|
|
3202
|
+
"else",
|
|
3203
|
+
"break",
|
|
3204
|
+
"catch",
|
|
3205
|
+
"instanceof",
|
|
3206
|
+
"with",
|
|
3207
|
+
"throw",
|
|
3208
|
+
"case",
|
|
3209
|
+
"default",
|
|
3210
|
+
"try",
|
|
3211
|
+
"switch",
|
|
3212
|
+
"continue",
|
|
3213
|
+
"typeof",
|
|
3214
|
+
"delete",
|
|
3215
|
+
"let",
|
|
3216
|
+
"yield",
|
|
3217
|
+
"const",
|
|
3218
|
+
"class",
|
|
3217
3219
|
// JS handles these with a special rule
|
|
3218
3220
|
// "get",
|
|
3219
3221
|
// "set",
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
]
|
|
3222
|
+
"debugger",
|
|
3223
|
+
"async",
|
|
3224
|
+
"await",
|
|
3225
|
+
"static",
|
|
3226
|
+
"import",
|
|
3227
|
+
"from",
|
|
3228
|
+
"export",
|
|
3229
|
+
"extends"
|
|
3230
|
+
];
|
|
3229
3231
|
const LITERALS = [
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
]
|
|
3232
|
+
"true",
|
|
3233
|
+
"false",
|
|
3234
|
+
"null",
|
|
3235
|
+
"undefined",
|
|
3236
|
+
"NaN",
|
|
3237
|
+
"Infinity"
|
|
3238
|
+
];
|
|
3237
3239
|
|
|
3238
3240
|
const TYPES = [
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
]
|
|
3241
|
+
"Intl",
|
|
3242
|
+
"DataView",
|
|
3243
|
+
"Number",
|
|
3244
|
+
"Math",
|
|
3245
|
+
"Date",
|
|
3246
|
+
"String",
|
|
3247
|
+
"RegExp",
|
|
3248
|
+
"Object",
|
|
3249
|
+
"Function",
|
|
3250
|
+
"Boolean",
|
|
3251
|
+
"Error",
|
|
3252
|
+
"Symbol",
|
|
3253
|
+
"Set",
|
|
3254
|
+
"Map",
|
|
3255
|
+
"WeakSet",
|
|
3256
|
+
"WeakMap",
|
|
3257
|
+
"Proxy",
|
|
3258
|
+
"Reflect",
|
|
3259
|
+
"JSON",
|
|
3260
|
+
"Promise",
|
|
3261
|
+
"Float64Array",
|
|
3262
|
+
"Int16Array",
|
|
3263
|
+
"Int32Array",
|
|
3264
|
+
"Int8Array",
|
|
3265
|
+
"Uint16Array",
|
|
3266
|
+
"Uint32Array",
|
|
3267
|
+
"Float32Array",
|
|
3268
|
+
"Array",
|
|
3269
|
+
"Uint8Array",
|
|
3270
|
+
"Uint8ClampedArray",
|
|
3271
|
+
"ArrayBuffer",
|
|
3272
|
+
"BigInt64Array",
|
|
3273
|
+
"BigUint64Array",
|
|
3274
|
+
"BigInt"
|
|
3275
|
+
];
|
|
3274
3276
|
|
|
3275
3277
|
const ERROR_TYPES = [
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
]
|
|
3278
|
+
"EvalError",
|
|
3279
|
+
"InternalError",
|
|
3280
|
+
"RangeError",
|
|
3281
|
+
"ReferenceError",
|
|
3282
|
+
"SyntaxError",
|
|
3283
|
+
"TypeError",
|
|
3284
|
+
"URIError"
|
|
3285
|
+
];
|
|
3284
3286
|
|
|
3285
3287
|
const BUILT_IN_GLOBALS = [
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
]
|
|
3288
|
+
"setInterval",
|
|
3289
|
+
"setTimeout",
|
|
3290
|
+
"clearInterval",
|
|
3291
|
+
"clearTimeout",
|
|
3292
|
+
|
|
3293
|
+
"require",
|
|
3294
|
+
"exports",
|
|
3295
|
+
|
|
3296
|
+
"eval",
|
|
3297
|
+
"isFinite",
|
|
3298
|
+
"isNaN",
|
|
3299
|
+
"parseFloat",
|
|
3300
|
+
"parseInt",
|
|
3301
|
+
"decodeURI",
|
|
3302
|
+
"decodeURIComponent",
|
|
3303
|
+
"encodeURI",
|
|
3304
|
+
"encodeURIComponent",
|
|
3305
|
+
"escape",
|
|
3306
|
+
"unescape"
|
|
3307
|
+
];
|
|
3306
3308
|
|
|
3307
3309
|
const BUILT_IN_VARIABLES = [
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
]
|
|
3310
|
+
"arguments",
|
|
3311
|
+
"this",
|
|
3312
|
+
"super",
|
|
3313
|
+
"console",
|
|
3314
|
+
"window",
|
|
3315
|
+
"document",
|
|
3316
|
+
"localStorage",
|
|
3317
|
+
"module",
|
|
3318
|
+
"global" // Node.js
|
|
3319
|
+
];
|
|
3318
3320
|
|
|
3319
3321
|
const BUILT_INS = [].concat(
|
|
3320
3322
|
BUILT_IN_GLOBALS,
|
|
3321
3323
|
TYPES,
|
|
3322
3324
|
ERROR_TYPES
|
|
3323
|
-
)
|
|
3325
|
+
);
|
|
3324
3326
|
|
|
3325
3327
|
/*
|
|
3326
3328
|
Language: JavaScript
|
|
@@ -3330,7 +3332,7 @@ const hljs = (function () {
|
|
|
3330
3332
|
*/
|
|
3331
3333
|
|
|
3332
3334
|
/** @type LanguageFn */
|
|
3333
|
-
function javascript
|
|
3335
|
+
function javascript(hljs) {
|
|
3334
3336
|
/**
|
|
3335
3337
|
* Takes a string like "<Booger" and checks to see
|
|
3336
3338
|
* if we can find a matching "</Booger" later in the
|
|
@@ -3339,16 +3341,16 @@ const hljs = (function () {
|
|
|
3339
3341
|
* @param {{after:number}} param1
|
|
3340
3342
|
*/
|
|
3341
3343
|
const hasClosingTag = (match, { after }) => {
|
|
3342
|
-
const tag =
|
|
3343
|
-
const pos = match.input.indexOf(tag, after)
|
|
3344
|
-
return pos !== -1
|
|
3345
|
-
}
|
|
3344
|
+
const tag = "</" + match[0].slice(1);
|
|
3345
|
+
const pos = match.input.indexOf(tag, after);
|
|
3346
|
+
return pos !== -1;
|
|
3347
|
+
};
|
|
3346
3348
|
|
|
3347
|
-
const IDENT_RE$1 = IDENT_RE
|
|
3349
|
+
const IDENT_RE$1 = IDENT_RE;
|
|
3348
3350
|
const FRAGMENT = {
|
|
3349
3351
|
begin: '<>',
|
|
3350
3352
|
end: '</>'
|
|
3351
|
-
}
|
|
3353
|
+
};
|
|
3352
3354
|
const XML_TAG = {
|
|
3353
3355
|
begin: /<[A-Za-z0-9\\._:-]+/,
|
|
3354
3356
|
end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
|
|
@@ -3357,40 +3359,40 @@ const hljs = (function () {
|
|
|
3357
3359
|
* @param {CallbackResponse} response
|
|
3358
3360
|
*/
|
|
3359
3361
|
isTrulyOpeningTag: (match, response) => {
|
|
3360
|
-
const afterMatchIndex = match[0].length + match.index
|
|
3361
|
-
const nextChar = match.input[afterMatchIndex]
|
|
3362
|
+
const afterMatchIndex = match[0].length + match.index;
|
|
3363
|
+
const nextChar = match.input[afterMatchIndex];
|
|
3362
3364
|
// nested type?
|
|
3363
3365
|
// HTML should not include another raw `<` inside a tag
|
|
3364
3366
|
// But a type might: `<Array<Array<number>>`, etc.
|
|
3365
|
-
if (nextChar ===
|
|
3366
|
-
response.ignoreMatch()
|
|
3367
|
-
return
|
|
3367
|
+
if (nextChar === "<") {
|
|
3368
|
+
response.ignoreMatch();
|
|
3369
|
+
return;
|
|
3368
3370
|
}
|
|
3369
3371
|
// <something>
|
|
3370
3372
|
// This is now either a tag or a type.
|
|
3371
|
-
if (nextChar ===
|
|
3373
|
+
if (nextChar === ">") {
|
|
3372
3374
|
// if we cannot find a matching closing tag, then we
|
|
3373
3375
|
// will ignore it
|
|
3374
3376
|
if (!hasClosingTag(match, { after: afterMatchIndex })) {
|
|
3375
|
-
response.ignoreMatch()
|
|
3377
|
+
response.ignoreMatch();
|
|
3376
3378
|
}
|
|
3377
3379
|
}
|
|
3378
3380
|
}
|
|
3379
|
-
}
|
|
3381
|
+
};
|
|
3380
3382
|
const KEYWORDS$1 = {
|
|
3381
3383
|
$pattern: IDENT_RE,
|
|
3382
3384
|
keyword: KEYWORDS,
|
|
3383
3385
|
literal: LITERALS,
|
|
3384
3386
|
built_in: BUILT_INS,
|
|
3385
|
-
|
|
3386
|
-
}
|
|
3387
|
+
"variable.language": BUILT_IN_VARIABLES
|
|
3388
|
+
};
|
|
3387
3389
|
|
|
3388
3390
|
// https://tc39.es/ecma262/#sec-literals-numeric-literals
|
|
3389
|
-
const decimalDigits = '[0-9](_?[0-9])*'
|
|
3390
|
-
const frac = `\\.(${decimalDigits})
|
|
3391
|
+
const decimalDigits = '[0-9](_?[0-9])*';
|
|
3392
|
+
const frac = `\\.(${decimalDigits})`;
|
|
3391
3393
|
// DecimalIntegerLiteral, including Annex B NonOctalDecimalIntegerLiteral
|
|
3392
3394
|
// https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
|
|
3393
|
-
const decimalInteger =
|
|
3395
|
+
const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;
|
|
3394
3396
|
const NUMBER = {
|
|
3395
3397
|
className: 'number',
|
|
3396
3398
|
variants: [
|
|
@@ -3402,19 +3404,19 @@ const hljs = (function () {
|
|
|
3402
3404
|
{ begin: `\\b(${decimalInteger})\\b((${frac})\\b|\\.)?|(${frac})\\b` },
|
|
3403
3405
|
|
|
3404
3406
|
// DecimalBigIntegerLiteral
|
|
3405
|
-
{ begin:
|
|
3407
|
+
{ begin: `\\b(0|[1-9](_?[0-9])*)n\\b` },
|
|
3406
3408
|
|
|
3407
3409
|
// NonDecimalIntegerLiteral
|
|
3408
|
-
{ begin:
|
|
3409
|
-
{ begin:
|
|
3410
|
-
{ begin:
|
|
3410
|
+
{ begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
|
|
3411
|
+
{ begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
|
|
3412
|
+
{ begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
|
|
3411
3413
|
|
|
3412
3414
|
// LegacyOctalIntegerLiteral (does not include underscore separators)
|
|
3413
3415
|
// https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
|
|
3414
|
-
{ begin:
|
|
3416
|
+
{ begin: "\\b0[0-7]+n?\\b" },
|
|
3415
3417
|
],
|
|
3416
3418
|
relevance: 0
|
|
3417
|
-
}
|
|
3419
|
+
};
|
|
3418
3420
|
|
|
3419
3421
|
const SUBST = {
|
|
3420
3422
|
className: 'subst',
|
|
@@ -3422,7 +3424,7 @@ const hljs = (function () {
|
|
|
3422
3424
|
end: '\\}',
|
|
3423
3425
|
keywords: KEYWORDS$1,
|
|
3424
3426
|
contains: [] // defined later
|
|
3425
|
-
}
|
|
3427
|
+
};
|
|
3426
3428
|
const HTML_TEMPLATE = {
|
|
3427
3429
|
begin: 'html`',
|
|
3428
3430
|
end: '',
|
|
@@ -3435,7 +3437,7 @@ const hljs = (function () {
|
|
|
3435
3437
|
],
|
|
3436
3438
|
subLanguage: 'xml'
|
|
3437
3439
|
}
|
|
3438
|
-
}
|
|
3440
|
+
};
|
|
3439
3441
|
const CSS_TEMPLATE = {
|
|
3440
3442
|
begin: 'css`',
|
|
3441
3443
|
end: '',
|
|
@@ -3448,7 +3450,7 @@ const hljs = (function () {
|
|
|
3448
3450
|
],
|
|
3449
3451
|
subLanguage: 'css'
|
|
3450
3452
|
}
|
|
3451
|
-
}
|
|
3453
|
+
};
|
|
3452
3454
|
const TEMPLATE_STRING = {
|
|
3453
3455
|
className: 'string',
|
|
3454
3456
|
begin: '`',
|
|
@@ -3457,7 +3459,7 @@ const hljs = (function () {
|
|
|
3457
3459
|
hljs.BACKSLASH_ESCAPE,
|
|
3458
3460
|
SUBST
|
|
3459
3461
|
]
|
|
3460
|
-
}
|
|
3462
|
+
};
|
|
3461
3463
|
const JSDOC_COMMENT = hljs.COMMENT(
|
|
3462
3464
|
/\/\*\*(?!\/)/,
|
|
3463
3465
|
'\\*/',
|
|
@@ -3496,15 +3498,15 @@ const hljs = (function () {
|
|
|
3496
3498
|
}
|
|
3497
3499
|
]
|
|
3498
3500
|
}
|
|
3499
|
-
)
|
|
3501
|
+
);
|
|
3500
3502
|
const COMMENT = {
|
|
3501
|
-
className:
|
|
3503
|
+
className: "comment",
|
|
3502
3504
|
variants: [
|
|
3503
3505
|
JSDOC_COMMENT,
|
|
3504
3506
|
hljs.C_BLOCK_COMMENT_MODE,
|
|
3505
3507
|
hljs.C_LINE_COMMENT_MODE
|
|
3506
3508
|
]
|
|
3507
|
-
}
|
|
3509
|
+
};
|
|
3508
3510
|
const SUBST_INTERNALS = [
|
|
3509
3511
|
hljs.APOS_STRING_MODE,
|
|
3510
3512
|
hljs.QUOTE_STRING_MODE,
|
|
@@ -3513,7 +3515,7 @@ const hljs = (function () {
|
|
|
3513
3515
|
TEMPLATE_STRING,
|
|
3514
3516
|
NUMBER,
|
|
3515
3517
|
hljs.REGEXP_MODE
|
|
3516
|
-
]
|
|
3518
|
+
];
|
|
3517
3519
|
SUBST.contains = SUBST_INTERNALS
|
|
3518
3520
|
.concat({
|
|
3519
3521
|
// we need to pair up {} inside our subst to prevent
|
|
@@ -3522,19 +3524,19 @@ const hljs = (function () {
|
|
|
3522
3524
|
end: /\}/,
|
|
3523
3525
|
keywords: KEYWORDS$1,
|
|
3524
3526
|
contains: [
|
|
3525
|
-
|
|
3527
|
+
"self"
|
|
3526
3528
|
].concat(SUBST_INTERNALS)
|
|
3527
|
-
})
|
|
3528
|
-
const SUBST_AND_COMMENTS = [].concat(COMMENT, SUBST.contains)
|
|
3529
|
+
});
|
|
3530
|
+
const SUBST_AND_COMMENTS = [].concat(COMMENT, SUBST.contains);
|
|
3529
3531
|
const PARAMS_CONTAINS = SUBST_AND_COMMENTS.concat([
|
|
3530
3532
|
// eat recursive parens in sub expressions
|
|
3531
3533
|
{
|
|
3532
3534
|
begin: /\(/,
|
|
3533
3535
|
end: /\)/,
|
|
3534
3536
|
keywords: KEYWORDS$1,
|
|
3535
|
-
contains: [
|
|
3537
|
+
contains: ["self"].concat(SUBST_AND_COMMENTS)
|
|
3536
3538
|
}
|
|
3537
|
-
])
|
|
3539
|
+
]);
|
|
3538
3540
|
const PARAMS = {
|
|
3539
3541
|
className: 'params',
|
|
3540
3542
|
begin: /\(/,
|
|
@@ -3543,7 +3545,7 @@ const hljs = (function () {
|
|
|
3543
3545
|
excludeEnd: true,
|
|
3544
3546
|
keywords: KEYWORDS$1,
|
|
3545
3547
|
contains: PARAMS_CONTAINS
|
|
3546
|
-
}
|
|
3548
|
+
};
|
|
3547
3549
|
|
|
3548
3550
|
// ES6 classes
|
|
3549
3551
|
const CLASS_OR_EXTENDS = {
|
|
@@ -3555,28 +3557,28 @@ const hljs = (function () {
|
|
|
3555
3557
|
IDENT_RE$1
|
|
3556
3558
|
],
|
|
3557
3559
|
scope: {
|
|
3558
|
-
1:
|
|
3559
|
-
3:
|
|
3560
|
+
1: "keyword",
|
|
3561
|
+
3: "title.class"
|
|
3560
3562
|
}
|
|
3561
3563
|
},
|
|
3562
3564
|
{
|
|
3563
3565
|
match: [
|
|
3564
3566
|
/extends/,
|
|
3565
3567
|
/\s+/,
|
|
3566
|
-
concat(IDENT_RE$1,
|
|
3568
|
+
concat(IDENT_RE$1, "(", concat(/\./, IDENT_RE$1), ")*")
|
|
3567
3569
|
],
|
|
3568
3570
|
scope: {
|
|
3569
|
-
1:
|
|
3570
|
-
3:
|
|
3571
|
+
1: "keyword",
|
|
3572
|
+
3: "title.class.inherited"
|
|
3571
3573
|
}
|
|
3572
3574
|
}
|
|
3573
3575
|
]
|
|
3574
|
-
}
|
|
3576
|
+
};
|
|
3575
3577
|
|
|
3576
3578
|
const CLASS_REFERENCE = {
|
|
3577
3579
|
relevance: 0,
|
|
3578
3580
|
match: /\b[A-Z][a-z]+([A-Z][a-z]+)*/,
|
|
3579
|
-
className:
|
|
3581
|
+
className: "title.class",
|
|
3580
3582
|
keywords: {
|
|
3581
3583
|
_: [
|
|
3582
3584
|
// se we still get relevance credit for JS library classes
|
|
@@ -3584,14 +3586,14 @@ const hljs = (function () {
|
|
|
3584
3586
|
...ERROR_TYPES
|
|
3585
3587
|
]
|
|
3586
3588
|
}
|
|
3587
|
-
}
|
|
3589
|
+
};
|
|
3588
3590
|
|
|
3589
3591
|
const USE_STRICT = {
|
|
3590
|
-
label:
|
|
3592
|
+
label: "use_strict",
|
|
3591
3593
|
className: 'meta',
|
|
3592
3594
|
relevance: 10,
|
|
3593
3595
|
begin: /^\s*['"]use (strict|asm)['"]/
|
|
3594
|
-
}
|
|
3596
|
+
};
|
|
3595
3597
|
|
|
3596
3598
|
const FUNCTION_DEFINITION = {
|
|
3597
3599
|
variants: [
|
|
@@ -3612,22 +3614,22 @@ const hljs = (function () {
|
|
|
3612
3614
|
}
|
|
3613
3615
|
],
|
|
3614
3616
|
className: {
|
|
3615
|
-
1:
|
|
3616
|
-
3:
|
|
3617
|
+
1: "keyword",
|
|
3618
|
+
3: "title.function"
|
|
3617
3619
|
},
|
|
3618
|
-
label:
|
|
3620
|
+
label: "func.def",
|
|
3619
3621
|
contains: [PARAMS],
|
|
3620
3622
|
illegal: /%/
|
|
3621
|
-
}
|
|
3623
|
+
};
|
|
3622
3624
|
|
|
3623
3625
|
const UPPER_CASE_CONSTANT = {
|
|
3624
3626
|
relevance: 0,
|
|
3625
3627
|
match: /\b[A-Z][A-Z_]+\b/,
|
|
3626
|
-
className:
|
|
3627
|
-
}
|
|
3628
|
+
className: "variable.constant"
|
|
3629
|
+
};
|
|
3628
3630
|
|
|
3629
|
-
function noneOf
|
|
3630
|
-
return concat(
|
|
3631
|
+
function noneOf(list) {
|
|
3632
|
+
return concat("(?!", list.join("|"), ")");
|
|
3631
3633
|
}
|
|
3632
3634
|
|
|
3633
3635
|
const FUNCTION_CALL = {
|
|
@@ -3635,12 +3637,12 @@ const hljs = (function () {
|
|
|
3635
3637
|
/\b/,
|
|
3636
3638
|
noneOf([
|
|
3637
3639
|
...BUILT_IN_GLOBALS,
|
|
3638
|
-
|
|
3640
|
+
"super"
|
|
3639
3641
|
]),
|
|
3640
3642
|
IDENT_RE$1, lookahead(/\(/)),
|
|
3641
|
-
className:
|
|
3643
|
+
className: "title.function",
|
|
3642
3644
|
relevance: 0
|
|
3643
|
-
}
|
|
3645
|
+
};
|
|
3644
3646
|
|
|
3645
3647
|
const PROPERTY_ACCESS = {
|
|
3646
3648
|
begin: concat(/\./, lookahead(
|
|
@@ -3648,10 +3650,10 @@ const hljs = (function () {
|
|
|
3648
3650
|
)),
|
|
3649
3651
|
end: IDENT_RE$1,
|
|
3650
3652
|
excludeBegin: true,
|
|
3651
|
-
keywords:
|
|
3652
|
-
className:
|
|
3653
|
+
keywords: "prototype",
|
|
3654
|
+
className: "property",
|
|
3653
3655
|
relevance: 0
|
|
3654
|
-
}
|
|
3656
|
+
};
|
|
3655
3657
|
|
|
3656
3658
|
const GETTER_OR_SETTER = {
|
|
3657
3659
|
match: [
|
|
@@ -3661,8 +3663,8 @@ const hljs = (function () {
|
|
|
3661
3663
|
/(?=\()/
|
|
3662
3664
|
],
|
|
3663
3665
|
className: {
|
|
3664
|
-
1:
|
|
3665
|
-
3:
|
|
3666
|
+
1: "keyword",
|
|
3667
|
+
3: "title.function"
|
|
3666
3668
|
},
|
|
3667
3669
|
contains: [
|
|
3668
3670
|
{ // eat to avoid empty params
|
|
@@ -3670,7 +3672,7 @@ const hljs = (function () {
|
|
|
3670
3672
|
},
|
|
3671
3673
|
PARAMS
|
|
3672
3674
|
]
|
|
3673
|
-
}
|
|
3675
|
+
};
|
|
3674
3676
|
|
|
3675
3677
|
const FUNC_LEAD_IN_RE = '(\\(' +
|
|
3676
3678
|
'[^()]*(\\(' +
|
|
@@ -3678,7 +3680,7 @@ const hljs = (function () {
|
|
|
3678
3680
|
'[^()]*' +
|
|
3679
3681
|
'\\)[^()]*)*' +
|
|
3680
3682
|
'\\)[^()]*)*' +
|
|
3681
|
-
'\\)|' + hljs.UNDERSCORE_IDENT_RE + ')\\s*=>'
|
|
3683
|
+
'\\)|' + hljs.UNDERSCORE_IDENT_RE + ')\\s*=>';
|
|
3682
3684
|
|
|
3683
3685
|
const FUNCTION_VARIABLE = {
|
|
3684
3686
|
match: [
|
|
@@ -3688,13 +3690,13 @@ const hljs = (function () {
|
|
|
3688
3690
|
lookahead(FUNC_LEAD_IN_RE)
|
|
3689
3691
|
],
|
|
3690
3692
|
className: {
|
|
3691
|
-
1:
|
|
3692
|
-
3:
|
|
3693
|
+
1: "keyword",
|
|
3694
|
+
3: "title.function"
|
|
3693
3695
|
},
|
|
3694
3696
|
contains: [
|
|
3695
3697
|
PARAMS
|
|
3696
3698
|
]
|
|
3697
|
-
}
|
|
3699
|
+
};
|
|
3698
3700
|
|
|
3699
3701
|
return {
|
|
3700
3702
|
name: 'Javascript',
|
|
@@ -3705,8 +3707,8 @@ const hljs = (function () {
|
|
|
3705
3707
|
illegal: /#(?![$_A-z])/,
|
|
3706
3708
|
contains: [
|
|
3707
3709
|
hljs.SHEBANG({
|
|
3708
|
-
label:
|
|
3709
|
-
binary:
|
|
3710
|
+
label: "shebang",
|
|
3711
|
+
binary: "node",
|
|
3710
3712
|
relevance: 5
|
|
3711
3713
|
}),
|
|
3712
3714
|
USE_STRICT,
|
|
@@ -3793,13 +3795,13 @@ const hljs = (function () {
|
|
|
3793
3795
|
}
|
|
3794
3796
|
]
|
|
3795
3797
|
}
|
|
3796
|
-
]
|
|
3798
|
+
],
|
|
3797
3799
|
},
|
|
3798
3800
|
FUNCTION_DEFINITION,
|
|
3799
3801
|
{
|
|
3800
3802
|
// prevent this from getting swallowed up by function
|
|
3801
3803
|
// since they appear "function like"
|
|
3802
|
-
beginKeywords:
|
|
3804
|
+
beginKeywords: "while if switch catch for"
|
|
3803
3805
|
},
|
|
3804
3806
|
{
|
|
3805
3807
|
// we have to count the parens to make sure we actually have the correct
|
|
@@ -3814,10 +3816,10 @@ const hljs = (function () {
|
|
|
3814
3816
|
'\\)[^()]*)*' +
|
|
3815
3817
|
'\\)\\s*\\{', // end parens
|
|
3816
3818
|
returnBegin: true,
|
|
3817
|
-
label:
|
|
3819
|
+
label: "func.def",
|
|
3818
3820
|
contains: [
|
|
3819
3821
|
PARAMS,
|
|
3820
|
-
hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1, className:
|
|
3822
|
+
hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1, className: "title.function" })
|
|
3821
3823
|
]
|
|
3822
3824
|
},
|
|
3823
3825
|
// catch ... so it won't trigger the property rule below
|
|
@@ -3835,7 +3837,7 @@ const hljs = (function () {
|
|
|
3835
3837
|
},
|
|
3836
3838
|
{
|
|
3837
3839
|
match: [/\bconstructor(?=\s*\()/],
|
|
3838
|
-
className: { 1:
|
|
3840
|
+
className: { 1: "title.function" },
|
|
3839
3841
|
contains: [PARAMS]
|
|
3840
3842
|
},
|
|
3841
3843
|
FUNCTION_CALL,
|
|
@@ -3846,7 +3848,7 @@ const hljs = (function () {
|
|
|
3846
3848
|
match: /\$[(.]/ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
|
|
3847
3849
|
}
|
|
3848
3850
|
]
|
|
3849
|
-
}
|
|
3851
|
+
};
|
|
3850
3852
|
}
|
|
3851
3853
|
|
|
3852
3854
|
/*
|
|
@@ -3857,17 +3859,17 @@ const hljs = (function () {
|
|
|
3857
3859
|
Category: common, protocols, web
|
|
3858
3860
|
*/
|
|
3859
3861
|
|
|
3860
|
-
function json
|
|
3862
|
+
function json(hljs) {
|
|
3861
3863
|
const ATTRIBUTE = {
|
|
3862
3864
|
className: 'attr',
|
|
3863
3865
|
begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/,
|
|
3864
3866
|
relevance: 1.01
|
|
3865
|
-
}
|
|
3867
|
+
};
|
|
3866
3868
|
const PUNCTUATION = {
|
|
3867
3869
|
match: /[{}[\],:]/,
|
|
3868
|
-
className:
|
|
3870
|
+
className: "punctuation",
|
|
3869
3871
|
relevance: 0
|
|
3870
|
-
}
|
|
3872
|
+
};
|
|
3871
3873
|
// normally we would rely on `keywords` for this but using a mode here allows us
|
|
3872
3874
|
// to use the very tight `illegal: \S` rule later to flag any other character
|
|
3873
3875
|
// as illegal indicating that despite looking like JSON we do not truly have
|
|
@@ -3875,11 +3877,11 @@ const hljs = (function () {
|
|
|
3875
3877
|
// all sorts of JSON looking stuff
|
|
3876
3878
|
const LITERALS = {
|
|
3877
3879
|
beginKeywords: [
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
].join(
|
|
3882
|
-
}
|
|
3880
|
+
"true",
|
|
3881
|
+
"false",
|
|
3882
|
+
"null"
|
|
3883
|
+
].join(" ")
|
|
3884
|
+
};
|
|
3883
3885
|
|
|
3884
3886
|
return {
|
|
3885
3887
|
name: 'JSON',
|
|
@@ -3893,18 +3895,19 @@ const hljs = (function () {
|
|
|
3893
3895
|
hljs.C_BLOCK_COMMENT_MODE
|
|
3894
3896
|
],
|
|
3895
3897
|
illegal: '\\S'
|
|
3896
|
-
}
|
|
3898
|
+
};
|
|
3897
3899
|
}
|
|
3898
3900
|
|
|
3901
|
+
|
|
3899
3902
|
/** @type LanguageFn */
|
|
3900
|
-
function xml
|
|
3903
|
+
function xml(hljs) {
|
|
3901
3904
|
// Element names can contain letters, digits, hyphens, underscores, and periods
|
|
3902
|
-
const TAG_NAME_RE = concat(/[A-Z_]/, optional(/[A-Z0-9_.-]*:/), /[A-Z0-9_.-]*/)
|
|
3903
|
-
const XML_IDENT_RE = /[A-Za-z0-9._:-]
|
|
3905
|
+
const TAG_NAME_RE = concat(/[A-Z_]/, optional(/[A-Z0-9_.-]*:/), /[A-Z0-9_.-]*/);
|
|
3906
|
+
const XML_IDENT_RE = /[A-Za-z0-9._:-]+/;
|
|
3904
3907
|
const XML_ENTITIES = {
|
|
3905
3908
|
className: 'symbol',
|
|
3906
3909
|
begin: /&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;/
|
|
3907
|
-
}
|
|
3910
|
+
};
|
|
3908
3911
|
const XML_META_KEYWORDS = {
|
|
3909
3912
|
begin: /\s/,
|
|
3910
3913
|
contains: [
|
|
@@ -3914,17 +3917,17 @@ const hljs = (function () {
|
|
|
3914
3917
|
illegal: /\n/
|
|
3915
3918
|
}
|
|
3916
3919
|
]
|
|
3917
|
-
}
|
|
3920
|
+
};
|
|
3918
3921
|
const XML_META_PAR_KEYWORDS = hljs.inherit(XML_META_KEYWORDS, {
|
|
3919
3922
|
begin: /\(/,
|
|
3920
3923
|
end: /\)/
|
|
3921
|
-
})
|
|
3924
|
+
});
|
|
3922
3925
|
const APOS_META_STRING_MODE = hljs.inherit(hljs.APOS_STRING_MODE, {
|
|
3923
3926
|
className: 'string'
|
|
3924
|
-
})
|
|
3927
|
+
});
|
|
3925
3928
|
const QUOTE_META_STRING_MODE = hljs.inherit(hljs.QUOTE_STRING_MODE, {
|
|
3926
3929
|
className: 'string'
|
|
3927
|
-
})
|
|
3930
|
+
});
|
|
3928
3931
|
const TAG_INTERNALS = {
|
|
3929
3932
|
endsWithParent: true,
|
|
3930
3933
|
illegal: /</,
|
|
@@ -3961,7 +3964,7 @@ const hljs = (function () {
|
|
|
3961
3964
|
]
|
|
3962
3965
|
}
|
|
3963
3966
|
]
|
|
3964
|
-
}
|
|
3967
|
+
};
|
|
3965
3968
|
return {
|
|
3966
3969
|
name: 'HTML, XML',
|
|
3967
3970
|
aliases: [
|
|
@@ -4118,7 +4121,7 @@ const hljs = (function () {
|
|
|
4118
4121
|
]
|
|
4119
4122
|
}
|
|
4120
4123
|
]
|
|
4121
|
-
}
|
|
4124
|
+
};
|
|
4122
4125
|
}
|
|
4123
4126
|
|
|
4124
4127
|
/*
|
|
@@ -4129,17 +4132,17 @@ const hljs = (function () {
|
|
|
4129
4132
|
Category: common, markup
|
|
4130
4133
|
*/
|
|
4131
4134
|
|
|
4132
|
-
function markdown
|
|
4135
|
+
function markdown(hljs) {
|
|
4133
4136
|
const INLINE_HTML = {
|
|
4134
4137
|
begin: /<\/?[A-Za-z_]/,
|
|
4135
4138
|
end: '>',
|
|
4136
4139
|
subLanguage: 'xml',
|
|
4137
4140
|
relevance: 0
|
|
4138
|
-
}
|
|
4141
|
+
};
|
|
4139
4142
|
const HORIZONTAL_RULE = {
|
|
4140
4143
|
begin: '^[-\\*]{3,}',
|
|
4141
4144
|
end: '$'
|
|
4142
|
-
}
|
|
4145
|
+
};
|
|
4143
4146
|
const CODE = {
|
|
4144
4147
|
className: 'code',
|
|
4145
4148
|
variants: [
|
|
@@ -4175,13 +4178,13 @@ const hljs = (function () {
|
|
|
4175
4178
|
relevance: 0
|
|
4176
4179
|
}
|
|
4177
4180
|
]
|
|
4178
|
-
}
|
|
4181
|
+
};
|
|
4179
4182
|
const LIST = {
|
|
4180
4183
|
className: 'bullet',
|
|
4181
4184
|
begin: '^[ \t]*([*+-]|(\\d+\\.))(?=\\s+)',
|
|
4182
4185
|
end: '\\s+',
|
|
4183
4186
|
excludeEnd: true
|
|
4184
|
-
}
|
|
4187
|
+
};
|
|
4185
4188
|
const LINK_REFERENCE = {
|
|
4186
4189
|
begin: /^\[[^\n]+\]:/,
|
|
4187
4190
|
returnBegin: true,
|
|
@@ -4200,8 +4203,8 @@ const hljs = (function () {
|
|
|
4200
4203
|
excludeBegin: true
|
|
4201
4204
|
}
|
|
4202
4205
|
]
|
|
4203
|
-
}
|
|
4204
|
-
const URL_SCHEME = /[A-Za-z][A-Za-z0-9+.-]
|
|
4206
|
+
};
|
|
4207
|
+
const URL_SCHEME = /[A-Za-z][A-Za-z0-9+.-]*/;
|
|
4205
4208
|
const LINK = {
|
|
4206
4209
|
variants: [
|
|
4207
4210
|
// too much like nested array access in so many languages
|
|
@@ -4257,7 +4260,7 @@ const hljs = (function () {
|
|
|
4257
4260
|
excludeEnd: true
|
|
4258
4261
|
}
|
|
4259
4262
|
]
|
|
4260
|
-
}
|
|
4263
|
+
};
|
|
4261
4264
|
const BOLD = {
|
|
4262
4265
|
className: 'strong',
|
|
4263
4266
|
contains: [], // defined later
|
|
@@ -4271,7 +4274,7 @@ const hljs = (function () {
|
|
|
4271
4274
|
end: /\*{2}/
|
|
4272
4275
|
}
|
|
4273
4276
|
]
|
|
4274
|
-
}
|
|
4277
|
+
};
|
|
4275
4278
|
const ITALIC = {
|
|
4276
4279
|
className: 'emphasis',
|
|
4277
4280
|
contains: [], // defined later
|
|
@@ -4286,19 +4289,19 @@ const hljs = (function () {
|
|
|
4286
4289
|
relevance: 0
|
|
4287
4290
|
}
|
|
4288
4291
|
]
|
|
4289
|
-
}
|
|
4290
|
-
BOLD.contains.push(ITALIC)
|
|
4291
|
-
ITALIC.contains.push(BOLD)
|
|
4292
|
+
};
|
|
4293
|
+
BOLD.contains.push(ITALIC);
|
|
4294
|
+
ITALIC.contains.push(BOLD);
|
|
4292
4295
|
|
|
4293
4296
|
let CONTAINABLE = [
|
|
4294
4297
|
INLINE_HTML,
|
|
4295
4298
|
LINK
|
|
4296
|
-
]
|
|
4299
|
+
];
|
|
4297
4300
|
|
|
4298
|
-
BOLD.contains = BOLD.contains.concat(CONTAINABLE)
|
|
4299
|
-
ITALIC.contains = ITALIC.contains.concat(CONTAINABLE)
|
|
4301
|
+
BOLD.contains = BOLD.contains.concat(CONTAINABLE);
|
|
4302
|
+
ITALIC.contains = ITALIC.contains.concat(CONTAINABLE);
|
|
4300
4303
|
|
|
4301
|
-
CONTAINABLE = CONTAINABLE.concat(BOLD, ITALIC)
|
|
4304
|
+
CONTAINABLE = CONTAINABLE.concat(BOLD, ITALIC);
|
|
4302
4305
|
|
|
4303
4306
|
const HEADER = {
|
|
4304
4307
|
className: 'section',
|
|
@@ -4316,20 +4319,20 @@ const hljs = (function () {
|
|
|
4316
4319
|
},
|
|
4317
4320
|
{
|
|
4318
4321
|
begin: '^',
|
|
4319
|
-
end:
|
|
4322
|
+
end: "\\n",
|
|
4320
4323
|
contains: CONTAINABLE
|
|
4321
4324
|
}
|
|
4322
4325
|
]
|
|
4323
4326
|
}
|
|
4324
4327
|
]
|
|
4325
|
-
}
|
|
4328
|
+
};
|
|
4326
4329
|
|
|
4327
4330
|
const BLOCKQUOTE = {
|
|
4328
4331
|
className: 'quote',
|
|
4329
4332
|
begin: '^>\\s+',
|
|
4330
4333
|
contains: CONTAINABLE,
|
|
4331
4334
|
end: '$'
|
|
4332
|
-
}
|
|
4335
|
+
};
|
|
4333
4336
|
|
|
4334
4337
|
return {
|
|
4335
4338
|
name: 'Markdown',
|
|
@@ -4350,9 +4353,10 @@ const hljs = (function () {
|
|
|
4350
4353
|
LINK,
|
|
4351
4354
|
LINK_REFERENCE
|
|
4352
4355
|
]
|
|
4353
|
-
}
|
|
4356
|
+
};
|
|
4354
4357
|
}
|
|
4355
4358
|
|
|
4359
|
+
|
|
4356
4360
|
/*
|
|
4357
4361
|
Language: Plain text
|
|
4358
4362
|
Author: Egor Rogov (e.rogov@postgrespro.ru)
|
|
@@ -4360,7 +4364,7 @@ const hljs = (function () {
|
|
|
4360
4364
|
Category: common
|
|
4361
4365
|
*/
|
|
4362
4366
|
|
|
4363
|
-
function plaintext
|
|
4367
|
+
function plaintext(hljs) {
|
|
4364
4368
|
return {
|
|
4365
4369
|
name: 'Plain text',
|
|
4366
4370
|
aliases: [
|
|
@@ -4368,9 +4372,10 @@ const hljs = (function () {
|
|
|
4368
4372
|
'txt'
|
|
4369
4373
|
],
|
|
4370
4374
|
disableAutodetect: true
|
|
4371
|
-
}
|
|
4375
|
+
};
|
|
4372
4376
|
}
|
|
4373
4377
|
|
|
4378
|
+
|
|
4374
4379
|
/*
|
|
4375
4380
|
Language: SCSS
|
|
4376
4381
|
Description: Scss is an extension of the syntax of CSS.
|
|
@@ -4380,18 +4385,18 @@ const hljs = (function () {
|
|
|
4380
4385
|
*/
|
|
4381
4386
|
|
|
4382
4387
|
/** @type LanguageFn */
|
|
4383
|
-
function scss
|
|
4384
|
-
const modes = MODES(hljs)
|
|
4385
|
-
const PSEUDO_ELEMENTS$1 = PSEUDO_ELEMENTS
|
|
4386
|
-
const PSEUDO_CLASSES$1 = PSEUDO_CLASSES
|
|
4387
|
-
|
|
4388
|
-
const AT_IDENTIFIER = '@[a-z-]+' // @font-face
|
|
4389
|
-
const AT_MODIFIERS =
|
|
4390
|
-
const IDENT_RE = '[a-zA-Z-][a-zA-Z0-9_-]*'
|
|
4388
|
+
function scss(hljs) {
|
|
4389
|
+
const modes = MODES(hljs);
|
|
4390
|
+
const PSEUDO_ELEMENTS$1 = PSEUDO_ELEMENTS;
|
|
4391
|
+
const PSEUDO_CLASSES$1 = PSEUDO_CLASSES;
|
|
4392
|
+
|
|
4393
|
+
const AT_IDENTIFIER = '@[a-z-]+'; // @font-face
|
|
4394
|
+
const AT_MODIFIERS = "and or not only";
|
|
4395
|
+
const IDENT_RE = '[a-zA-Z-][a-zA-Z0-9_-]*';
|
|
4391
4396
|
const VARIABLE = {
|
|
4392
4397
|
className: 'variable',
|
|
4393
4398
|
begin: '(\\$' + IDENT_RE + ')\\b'
|
|
4394
|
-
}
|
|
4399
|
+
};
|
|
4395
4400
|
|
|
4396
4401
|
return {
|
|
4397
4402
|
name: 'SCSS',
|
|
@@ -4467,16 +4472,16 @@ const hljs = (function () {
|
|
|
4467
4472
|
keywords: {
|
|
4468
4473
|
$pattern: /[a-z-]+/,
|
|
4469
4474
|
keyword: AT_MODIFIERS,
|
|
4470
|
-
attribute: MEDIA_FEATURES.join(
|
|
4475
|
+
attribute: MEDIA_FEATURES.join(" ")
|
|
4471
4476
|
},
|
|
4472
4477
|
contains: [
|
|
4473
4478
|
{
|
|
4474
4479
|
begin: AT_IDENTIFIER,
|
|
4475
|
-
className:
|
|
4480
|
+
className: "keyword"
|
|
4476
4481
|
},
|
|
4477
4482
|
{
|
|
4478
4483
|
begin: /[a-z-]+(?=:)/,
|
|
4479
|
-
className:
|
|
4484
|
+
className: "attribute"
|
|
4480
4485
|
},
|
|
4481
4486
|
VARIABLE,
|
|
4482
4487
|
hljs.QUOTE_STRING_MODE,
|
|
@@ -4486,7 +4491,7 @@ const hljs = (function () {
|
|
|
4486
4491
|
]
|
|
4487
4492
|
}
|
|
4488
4493
|
]
|
|
4489
|
-
}
|
|
4494
|
+
};
|
|
4490
4495
|
}
|
|
4491
4496
|
|
|
4492
4497
|
/*
|
|
@@ -4498,7 +4503,7 @@ const hljs = (function () {
|
|
|
4498
4503
|
*/
|
|
4499
4504
|
|
|
4500
4505
|
/** @type LanguageFn */
|
|
4501
|
-
function shell
|
|
4506
|
+
function shell(hljs) {
|
|
4502
4507
|
return {
|
|
4503
4508
|
name: 'Shell Session',
|
|
4504
4509
|
aliases: ['console', 'shellsession'],
|
|
@@ -4515,32 +4520,33 @@ const hljs = (function () {
|
|
|
4515
4520
|
}
|
|
4516
4521
|
}
|
|
4517
4522
|
]
|
|
4518
|
-
}
|
|
4523
|
+
};
|
|
4519
4524
|
}
|
|
4520
4525
|
|
|
4526
|
+
|
|
4521
4527
|
const keywordWrapper = keyword => concat(
|
|
4522
4528
|
/\b/,
|
|
4523
4529
|
keyword,
|
|
4524
4530
|
/\w$/.test(keyword) ? /\b/ : /\B/
|
|
4525
|
-
)
|
|
4531
|
+
);
|
|
4526
4532
|
|
|
4527
4533
|
// Keywords that require a leading dot.
|
|
4528
4534
|
const dotKeywords = [
|
|
4529
4535
|
'Protocol', // contextual
|
|
4530
4536
|
'Type' // contextual
|
|
4531
|
-
].map(keywordWrapper)
|
|
4537
|
+
].map(keywordWrapper);
|
|
4532
4538
|
|
|
4533
4539
|
// Keywords that may have a leading dot.
|
|
4534
4540
|
const optionalDotKeywords = [
|
|
4535
4541
|
'init',
|
|
4536
4542
|
'self'
|
|
4537
|
-
].map(keywordWrapper)
|
|
4543
|
+
].map(keywordWrapper);
|
|
4538
4544
|
|
|
4539
4545
|
// should register as keyword, not type
|
|
4540
4546
|
const keywordTypes = [
|
|
4541
4547
|
'Any',
|
|
4542
4548
|
'Self'
|
|
4543
|
-
]
|
|
4549
|
+
];
|
|
4544
4550
|
|
|
4545
4551
|
// Regular keywords and literals.
|
|
4546
4552
|
const keywords = [
|
|
@@ -4630,7 +4636,7 @@ const hljs = (function () {
|
|
|
4630
4636
|
'where',
|
|
4631
4637
|
'while',
|
|
4632
4638
|
'willSet' // contextual
|
|
4633
|
-
]
|
|
4639
|
+
];
|
|
4634
4640
|
|
|
4635
4641
|
// NOTE: Contextual keywords are reserved only in specific contexts.
|
|
4636
4642
|
// Ideally, these should be matched using modes to avoid false positives.
|
|
@@ -4640,7 +4646,7 @@ const hljs = (function () {
|
|
|
4640
4646
|
'false',
|
|
4641
4647
|
'nil',
|
|
4642
4648
|
'true'
|
|
4643
|
-
]
|
|
4649
|
+
];
|
|
4644
4650
|
|
|
4645
4651
|
// Keywords used in precedence groups.
|
|
4646
4652
|
const precedencegroupKeywords = [
|
|
@@ -4651,7 +4657,7 @@ const hljs = (function () {
|
|
|
4651
4657
|
'lowerThan',
|
|
4652
4658
|
'none',
|
|
4653
4659
|
'right'
|
|
4654
|
-
]
|
|
4660
|
+
];
|
|
4655
4661
|
|
|
4656
4662
|
// Keywords that start with a number sign (#).
|
|
4657
4663
|
// #available is handled separately.
|
|
@@ -4676,7 +4682,7 @@ const hljs = (function () {
|
|
|
4676
4682
|
'#sourceLocation',
|
|
4677
4683
|
'#warn_unqualified_access',
|
|
4678
4684
|
'#warning'
|
|
4679
|
-
]
|
|
4685
|
+
];
|
|
4680
4686
|
|
|
4681
4687
|
// Global functions in the Standard Library.
|
|
4682
4688
|
const builtIns$1 = [
|
|
@@ -4714,7 +4720,7 @@ const hljs = (function () {
|
|
|
4714
4720
|
'withVaList',
|
|
4715
4721
|
'withoutActuallyEscaping',
|
|
4716
4722
|
'zip'
|
|
4717
|
-
]
|
|
4723
|
+
];
|
|
4718
4724
|
|
|
4719
4725
|
// Valid first characters for operators.
|
|
4720
4726
|
const operatorHead = either(
|
|
@@ -4736,7 +4742,7 @@ const hljs = (function () {
|
|
|
4736
4742
|
/[\u3001-\u3003]/,
|
|
4737
4743
|
/[\u3008-\u3020]/,
|
|
4738
4744
|
/[\u3030]/
|
|
4739
|
-
)
|
|
4745
|
+
);
|
|
4740
4746
|
|
|
4741
4747
|
// Valid characters for operators.
|
|
4742
4748
|
const operatorCharacter = either(
|
|
@@ -4748,10 +4754,10 @@ const hljs = (function () {
|
|
|
4748
4754
|
/[\uFE20-\uFE2F]/
|
|
4749
4755
|
// TODO: The following characters are also allowed, but the regex isn't supported yet.
|
|
4750
4756
|
// /[\u{E0100}-\u{E01EF}]/u
|
|
4751
|
-
)
|
|
4757
|
+
);
|
|
4752
4758
|
|
|
4753
4759
|
// Valid operator.
|
|
4754
|
-
const operator = concat(operatorHead, operatorCharacter, '*')
|
|
4760
|
+
const operator = concat(operatorHead, operatorCharacter, '*');
|
|
4755
4761
|
|
|
4756
4762
|
// Valid first characters for identifiers.
|
|
4757
4763
|
const identifierHead = either(
|
|
@@ -4771,20 +4777,20 @@ const hljs = (function () {
|
|
|
4771
4777
|
// /[\u{50000}-\u{5FFFD}\u{60000-\u{6FFFD}\u{70000}-\u{7FFFD}\u{80000}-\u{8FFFD}]/u,
|
|
4772
4778
|
// /[\u{90000}-\u{9FFFD}\u{A0000-\u{AFFFD}\u{B0000}-\u{BFFFD}\u{C0000}-\u{CFFFD}]/u,
|
|
4773
4779
|
// /[\u{D0000}-\u{DFFFD}\u{E0000-\u{EFFFD}]/u
|
|
4774
|
-
)
|
|
4780
|
+
);
|
|
4775
4781
|
|
|
4776
4782
|
// Valid characters for identifiers.
|
|
4777
4783
|
const identifierCharacter = either(
|
|
4778
4784
|
identifierHead,
|
|
4779
4785
|
/\d/,
|
|
4780
4786
|
/[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/
|
|
4781
|
-
)
|
|
4787
|
+
);
|
|
4782
4788
|
|
|
4783
4789
|
// Valid identifier.
|
|
4784
|
-
const identifier = concat(identifierHead, identifierCharacter, '*')
|
|
4790
|
+
const identifier = concat(identifierHead, identifierCharacter, '*');
|
|
4785
4791
|
|
|
4786
4792
|
// Valid type identifier.
|
|
4787
|
-
const typeIdentifier = concat(/[A-Z]/, identifierCharacter, '*')
|
|
4793
|
+
const typeIdentifier = concat(/[A-Z]/, identifierCharacter, '*');
|
|
4788
4794
|
|
|
4789
4795
|
// Built-in attributes, which are highlighted as keywords.
|
|
4790
4796
|
// @available is handled separately.
|
|
@@ -4818,7 +4824,7 @@ const hljs = (function () {
|
|
|
4818
4824
|
'UIApplicationMain',
|
|
4819
4825
|
'unknown',
|
|
4820
4826
|
'usableFromInline'
|
|
4821
|
-
]
|
|
4827
|
+
];
|
|
4822
4828
|
|
|
4823
4829
|
// Contextual keywords used in @available and #available.
|
|
4824
4830
|
const availabilityKeywords = [
|
|
@@ -4833,7 +4839,8 @@ const hljs = (function () {
|
|
|
4833
4839
|
'tvOS',
|
|
4834
4840
|
'tvOSApplicationExtension',
|
|
4835
4841
|
'swift'
|
|
4836
|
-
]
|
|
4842
|
+
];
|
|
4843
|
+
|
|
4837
4844
|
|
|
4838
4845
|
/*
|
|
4839
4846
|
Language: TypeScript
|
|
@@ -4845,92 +4852,91 @@ const hljs = (function () {
|
|
|
4845
4852
|
*/
|
|
4846
4853
|
|
|
4847
4854
|
/** @type LanguageFn */
|
|
4848
|
-
function typescript
|
|
4849
|
-
const IDENT_RE$1 = IDENT_RE
|
|
4855
|
+
function typescript(hljs) {
|
|
4856
|
+
const IDENT_RE$1 = IDENT_RE;
|
|
4850
4857
|
const NAMESPACE = {
|
|
4851
4858
|
beginKeywords: 'namespace', end: /\{/, excludeEnd: true
|
|
4852
|
-
}
|
|
4859
|
+
};
|
|
4853
4860
|
const INTERFACE = {
|
|
4854
|
-
beginKeywords: 'interface',
|
|
4855
|
-
end: /\{/,
|
|
4856
|
-
excludeEnd: true,
|
|
4861
|
+
beginKeywords: 'interface', end: /\{/, excludeEnd: true,
|
|
4857
4862
|
keywords: 'interface extends'
|
|
4858
|
-
}
|
|
4863
|
+
};
|
|
4859
4864
|
const USE_STRICT = {
|
|
4860
4865
|
className: 'meta',
|
|
4861
4866
|
relevance: 10,
|
|
4862
4867
|
begin: /^\s*['"]use strict['"]/
|
|
4863
|
-
}
|
|
4868
|
+
};
|
|
4864
4869
|
const TYPES = [
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
]
|
|
4870
|
+
"any",
|
|
4871
|
+
"void",
|
|
4872
|
+
"number",
|
|
4873
|
+
"boolean",
|
|
4874
|
+
"string",
|
|
4875
|
+
"object",
|
|
4876
|
+
"never",
|
|
4877
|
+
"enum"
|
|
4878
|
+
];
|
|
4874
4879
|
const TS_SPECIFIC_KEYWORDS = [
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
]
|
|
4880
|
+
"type",
|
|
4881
|
+
"namespace",
|
|
4882
|
+
"typedef",
|
|
4883
|
+
"interface",
|
|
4884
|
+
"public",
|
|
4885
|
+
"private",
|
|
4886
|
+
"protected",
|
|
4887
|
+
"implements",
|
|
4888
|
+
"declare",
|
|
4889
|
+
"abstract",
|
|
4890
|
+
"readonly"
|
|
4891
|
+
];
|
|
4887
4892
|
const KEYWORDS$1 = {
|
|
4888
4893
|
$pattern: IDENT_RE,
|
|
4889
4894
|
keyword: KEYWORDS.concat(TS_SPECIFIC_KEYWORDS),
|
|
4890
4895
|
literal: LITERALS,
|
|
4891
4896
|
built_in: BUILT_INS.concat(TYPES),
|
|
4892
|
-
|
|
4893
|
-
}
|
|
4897
|
+
"variable.language": BUILT_IN_VARIABLES
|
|
4898
|
+
};
|
|
4894
4899
|
const DECORATOR = {
|
|
4895
4900
|
className: 'meta',
|
|
4896
|
-
begin: '@' + IDENT_RE$1
|
|
4897
|
-
}
|
|
4901
|
+
begin: '@' + IDENT_RE$1,
|
|
4902
|
+
};
|
|
4898
4903
|
|
|
4899
4904
|
const swapMode = (mode, label, replacement) => {
|
|
4900
|
-
const indx = mode.contains.findIndex(m => m.label === label)
|
|
4901
|
-
if (indx === -1) { throw new Error(
|
|
4902
|
-
mode.contains.splice(indx, 1, replacement)
|
|
4903
|
-
}
|
|
4905
|
+
const indx = mode.contains.findIndex(m => m.label === label);
|
|
4906
|
+
if (indx === -1) { throw new Error("can not find mode to replace"); }
|
|
4907
|
+
mode.contains.splice(indx, 1, replacement);
|
|
4908
|
+
};
|
|
4904
4909
|
|
|
4905
|
-
const tsLanguage = javascript(hljs)
|
|
4910
|
+
const tsLanguage = javascript(hljs);
|
|
4906
4911
|
|
|
4907
4912
|
// this should update anywhere keywords is used since
|
|
4908
4913
|
// it will be the same actual JS object
|
|
4909
|
-
Object.assign(tsLanguage.keywords, KEYWORDS$1)
|
|
4914
|
+
Object.assign(tsLanguage.keywords, KEYWORDS$1);
|
|
4910
4915
|
|
|
4911
|
-
tsLanguage.exports.PARAMS_CONTAINS.push(DECORATOR)
|
|
4916
|
+
tsLanguage.exports.PARAMS_CONTAINS.push(DECORATOR);
|
|
4912
4917
|
tsLanguage.contains = tsLanguage.contains.concat([
|
|
4913
4918
|
DECORATOR,
|
|
4914
4919
|
NAMESPACE,
|
|
4915
|
-
INTERFACE
|
|
4916
|
-
])
|
|
4920
|
+
INTERFACE,
|
|
4921
|
+
]);
|
|
4917
4922
|
|
|
4918
4923
|
// TS gets a simpler shebang rule than JS
|
|
4919
|
-
swapMode(tsLanguage,
|
|
4924
|
+
swapMode(tsLanguage, "shebang", hljs.SHEBANG());
|
|
4920
4925
|
// JS use strict rule purposely excludes `asm` which makes no sense
|
|
4921
|
-
swapMode(tsLanguage,
|
|
4926
|
+
swapMode(tsLanguage, "use_strict", USE_STRICT);
|
|
4922
4927
|
|
|
4923
|
-
const functionDeclaration = tsLanguage.contains.find(m => m.label ===
|
|
4924
|
-
functionDeclaration.relevance = 0 // () => {} is more typical in TypeScript
|
|
4928
|
+
const functionDeclaration = tsLanguage.contains.find(m => m.label === "func.def");
|
|
4929
|
+
functionDeclaration.relevance = 0; // () => {} is more typical in TypeScript
|
|
4925
4930
|
|
|
4926
4931
|
Object.assign(tsLanguage, {
|
|
4927
4932
|
name: 'TypeScript',
|
|
4928
4933
|
aliases: ['ts', 'tsx']
|
|
4929
|
-
})
|
|
4934
|
+
});
|
|
4930
4935
|
|
|
4931
|
-
return tsLanguage
|
|
4936
|
+
return tsLanguage;
|
|
4932
4937
|
}
|
|
4933
4938
|
|
|
4939
|
+
|
|
4934
4940
|
/*
|
|
4935
4941
|
Language: YAML
|
|
4936
4942
|
Description: Yet Another Markdown Language
|
|
@@ -4940,11 +4946,11 @@ const hljs = (function () {
|
|
|
4940
4946
|
Website: https://yaml.org
|
|
4941
4947
|
Category: common, config
|
|
4942
4948
|
*/
|
|
4943
|
-
function yaml
|
|
4944
|
-
const LITERALS = 'true false yes no null'
|
|
4949
|
+
function yaml(hljs) {
|
|
4950
|
+
const LITERALS = 'true false yes no null';
|
|
4945
4951
|
|
|
4946
4952
|
// YAML spec allows non-reserved URI characters in tags.
|
|
4947
|
-
const URI_CHARACTERS = '[\\w#;/?:@&=+$,.~*\'()[\\]]+'
|
|
4953
|
+
const URI_CHARACTERS = '[\\w#;/?:@&=+$,.~*\'()[\\]]+';
|
|
4948
4954
|
|
|
4949
4955
|
// Define keys as starting with a word character
|
|
4950
4956
|
// ...containing word chars, spaces, colons, forward-slashes, hyphens and periods
|
|
@@ -4963,7 +4969,7 @@ const hljs = (function () {
|
|
|
4963
4969
|
begin: '\'\\w[\\w :\\/.-]*\':(?=[ \t]|$)'
|
|
4964
4970
|
}
|
|
4965
4971
|
]
|
|
4966
|
-
}
|
|
4972
|
+
};
|
|
4967
4973
|
|
|
4968
4974
|
const TEMPLATE_VARIABLES = {
|
|
4969
4975
|
className: 'template-variable',
|
|
@@ -4977,7 +4983,7 @@ const hljs = (function () {
|
|
|
4977
4983
|
end: /\}/
|
|
4978
4984
|
}
|
|
4979
4985
|
]
|
|
4980
|
-
}
|
|
4986
|
+
};
|
|
4981
4987
|
const STRING = {
|
|
4982
4988
|
className: 'string',
|
|
4983
4989
|
relevance: 0,
|
|
@@ -4998,7 +5004,7 @@ const hljs = (function () {
|
|
|
4998
5004
|
hljs.BACKSLASH_ESCAPE,
|
|
4999
5005
|
TEMPLATE_VARIABLES
|
|
5000
5006
|
]
|
|
5001
|
-
}
|
|
5007
|
+
};
|
|
5002
5008
|
|
|
5003
5009
|
// Strings inside of value containers (objects) can't contain braces,
|
|
5004
5010
|
// brackets, or commas
|
|
@@ -5016,16 +5022,16 @@ const hljs = (function () {
|
|
|
5016
5022
|
begin: /[^\s,{}[\]]+/
|
|
5017
5023
|
}
|
|
5018
5024
|
]
|
|
5019
|
-
})
|
|
5025
|
+
});
|
|
5020
5026
|
|
|
5021
|
-
const DATE_RE = '[0-9]{4}(-[0-9][0-9]){0,2}'
|
|
5022
|
-
const TIME_RE = '([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?'
|
|
5023
|
-
const FRACTION_RE = '(\\.[0-9]*)?'
|
|
5024
|
-
const ZONE_RE = '([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?'
|
|
5027
|
+
const DATE_RE = '[0-9]{4}(-[0-9][0-9]){0,2}';
|
|
5028
|
+
const TIME_RE = '([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?';
|
|
5029
|
+
const FRACTION_RE = '(\\.[0-9]*)?';
|
|
5030
|
+
const ZONE_RE = '([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?';
|
|
5025
5031
|
const TIMESTAMP = {
|
|
5026
5032
|
className: 'number',
|
|
5027
5033
|
begin: '\\b' + DATE_RE + TIME_RE + FRACTION_RE + ZONE_RE + '\\b'
|
|
5028
|
-
}
|
|
5034
|
+
};
|
|
5029
5035
|
|
|
5030
5036
|
const VALUE_CONTAINER = {
|
|
5031
5037
|
end: ',',
|
|
@@ -5033,21 +5039,21 @@ const hljs = (function () {
|
|
|
5033
5039
|
excludeEnd: true,
|
|
5034
5040
|
keywords: LITERALS,
|
|
5035
5041
|
relevance: 0
|
|
5036
|
-
}
|
|
5042
|
+
};
|
|
5037
5043
|
const OBJECT = {
|
|
5038
5044
|
begin: /\{/,
|
|
5039
5045
|
end: /\}/,
|
|
5040
5046
|
contains: [VALUE_CONTAINER],
|
|
5041
5047
|
illegal: '\\n',
|
|
5042
5048
|
relevance: 0
|
|
5043
|
-
}
|
|
5049
|
+
};
|
|
5044
5050
|
const ARRAY = {
|
|
5045
5051
|
begin: '\\[',
|
|
5046
5052
|
end: '\\]',
|
|
5047
5053
|
contains: [VALUE_CONTAINER],
|
|
5048
5054
|
illegal: '\\n',
|
|
5049
5055
|
relevance: 0
|
|
5050
|
-
}
|
|
5056
|
+
};
|
|
5051
5057
|
|
|
5052
5058
|
const MODES = [
|
|
5053
5059
|
KEY,
|
|
@@ -5079,7 +5085,7 @@ const hljs = (function () {
|
|
|
5079
5085
|
// https://yaml.org/spec/1.2/spec.html#id2784064
|
|
5080
5086
|
{ // verbatim tags
|
|
5081
5087
|
className: 'type',
|
|
5082
|
-
begin: '!<' + URI_CHARACTERS +
|
|
5088
|
+
begin: '!<' + URI_CHARACTERS + ">"
|
|
5083
5089
|
},
|
|
5084
5090
|
{ // primary tags
|
|
5085
5091
|
className: 'type',
|
|
@@ -5121,22 +5127,22 @@ const hljs = (function () {
|
|
|
5121
5127
|
OBJECT,
|
|
5122
5128
|
ARRAY,
|
|
5123
5129
|
STRING
|
|
5124
|
-
]
|
|
5130
|
+
];
|
|
5125
5131
|
|
|
5126
|
-
const VALUE_MODES = [...MODES]
|
|
5127
|
-
VALUE_MODES.pop()
|
|
5128
|
-
VALUE_MODES.push(CONTAINER_STRING)
|
|
5129
|
-
VALUE_CONTAINER.contains = VALUE_MODES
|
|
5132
|
+
const VALUE_MODES = [...MODES];
|
|
5133
|
+
VALUE_MODES.pop();
|
|
5134
|
+
VALUE_MODES.push(CONTAINER_STRING);
|
|
5135
|
+
VALUE_CONTAINER.contains = VALUE_MODES;
|
|
5130
5136
|
|
|
5131
5137
|
return {
|
|
5132
5138
|
name: 'YAML',
|
|
5133
5139
|
case_insensitive: true,
|
|
5134
5140
|
aliases: ['yml'],
|
|
5135
5141
|
contains: MODES
|
|
5136
|
-
}
|
|
5142
|
+
};
|
|
5137
5143
|
}
|
|
5138
5144
|
|
|
5139
|
-
|
|
5145
|
+
var builtIns = /*#__PURE__*/Object.freeze({
|
|
5140
5146
|
__proto__: null,
|
|
5141
5147
|
grmr_bash: bash,
|
|
5142
5148
|
grmr_scss: scss,
|
|
@@ -5150,15 +5156,16 @@ const hljs = (function () {
|
|
|
5150
5156
|
grmr_shell: shell,
|
|
5151
5157
|
grmr_typescript: typescript,
|
|
5152
5158
|
grmr_yaml: yaml
|
|
5153
|
-
})
|
|
5159
|
+
});
|
|
5154
5160
|
|
|
5155
|
-
const hljs = HighlightJS
|
|
5161
|
+
const hljs = HighlightJS;
|
|
5156
5162
|
|
|
5157
5163
|
for (const key of Object.keys(builtIns)) {
|
|
5158
|
-
const languageName = key.replace(
|
|
5159
|
-
hljs.registerLanguage(languageName, builtIns[key])
|
|
5164
|
+
const languageName = key.replace("grmr_", "");
|
|
5165
|
+
hljs.registerLanguage(languageName, builtIns[key]);
|
|
5160
5166
|
}
|
|
5161
5167
|
|
|
5162
|
-
return hljs
|
|
5163
|
-
|
|
5164
|
-
|
|
5168
|
+
return hljs;
|
|
5169
|
+
|
|
5170
|
+
}());
|
|
5171
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') { module.exports = hljs; }
|