@wangeditor-next/code-highlight 1.0.3 → 1.2.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.
@@ -0,0 +1,4834 @@
1
+ import { i18nAddResources, DomEditor, t } from '@wangeditor-next/core';
2
+ import $, { attr } from 'dom7';
3
+ import { Element as Element$1, Transforms, Text } from 'slate';
4
+
5
+ /**
6
+ * @description i18n en
7
+ * @author wangfupeng
8
+ */
9
+ var enResources = {
10
+ highLightModule: {
11
+ selectLang: 'Language',
12
+ },
13
+ };
14
+
15
+ /**
16
+ * @description i18n zh-CN
17
+ * @author wangfupeng
18
+ */
19
+ var zhResources = {
20
+ highLightModule: {
21
+ selectLang: '选择语言',
22
+ },
23
+ };
24
+
25
+ /**
26
+ * @description i18n entry
27
+ * @author wangfupeng
28
+ */
29
+ i18nAddResources('en', enResources);
30
+ i18nAddResources('zh-CN', zhResources);
31
+
32
+ /**
33
+ * @description vdom utils fn
34
+ * @author wangfupeng
35
+ */
36
+ /**
37
+ * 给 vnode 添加 className
38
+ * @param vnode vnode
39
+ * @param className css class
40
+ */
41
+ function addVnodeClassName(vnode, className) {
42
+ if (vnode.data == null)
43
+ vnode.data = {};
44
+ var data = vnode.data;
45
+ if (data.props == null)
46
+ data.props = {};
47
+ Object.assign(data.props, { className: className });
48
+ }
49
+
50
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
51
+
52
+ function createCommonjsModule(fn) {
53
+ var module = { exports: {} };
54
+ return fn(module, module.exports), module.exports;
55
+ }
56
+
57
+ var prism = createCommonjsModule(function (module) {
58
+ /* **********************************************
59
+ Begin prism-core.js
60
+ ********************************************** */
61
+
62
+ /// <reference lib="WebWorker"/>
63
+
64
+ var _self = (typeof window !== 'undefined')
65
+ ? window // if in browser
66
+ : (
67
+ (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
68
+ ? self // if in worker
69
+ : {} // if in node js
70
+ );
71
+
72
+ /**
73
+ * Prism: Lightweight, robust, elegant syntax highlighting
74
+ *
75
+ * @license MIT <https://opensource.org/licenses/MIT>
76
+ * @author Lea Verou <https://lea.verou.me>
77
+ * @namespace
78
+ * @public
79
+ */
80
+ var Prism = (function (_self) {
81
+
82
+ // Private helper vars
83
+ var lang = /\blang(?:uage)?-([\w-]+)\b/i;
84
+ var uniqueId = 0;
85
+
86
+ // The grammar object for plaintext
87
+ var plainTextGrammar = {};
88
+
89
+
90
+ var _ = {
91
+ /**
92
+ * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
93
+ * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
94
+ * additional languages or plugins yourself.
95
+ *
96
+ * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
97
+ *
98
+ * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
99
+ * empty Prism object into the global scope before loading the Prism script like this:
100
+ *
101
+ * ```js
102
+ * window.Prism = window.Prism || {};
103
+ * Prism.manual = true;
104
+ * // add a new <script> to load Prism's script
105
+ * ```
106
+ *
107
+ * @default false
108
+ * @type {boolean}
109
+ * @memberof Prism
110
+ * @public
111
+ */
112
+ manual: _self.Prism && _self.Prism.manual,
113
+ disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
114
+
115
+ /**
116
+ * A namespace for utility methods.
117
+ *
118
+ * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
119
+ * change or disappear at any time.
120
+ *
121
+ * @namespace
122
+ * @memberof Prism
123
+ */
124
+ util: {
125
+ encode: function encode(tokens) {
126
+ if (tokens instanceof Token) {
127
+ return new Token(tokens.type, encode(tokens.content), tokens.alias);
128
+ } else if (Array.isArray(tokens)) {
129
+ return tokens.map(encode);
130
+ } else {
131
+ return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
132
+ }
133
+ },
134
+
135
+ /**
136
+ * Returns the name of the type of the given value.
137
+ *
138
+ * @param {any} o
139
+ * @returns {string}
140
+ * @example
141
+ * type(null) === 'Null'
142
+ * type(undefined) === 'Undefined'
143
+ * type(123) === 'Number'
144
+ * type('foo') === 'String'
145
+ * type(true) === 'Boolean'
146
+ * type([1, 2]) === 'Array'
147
+ * type({}) === 'Object'
148
+ * type(String) === 'Function'
149
+ * type(/abc+/) === 'RegExp'
150
+ */
151
+ type: function (o) {
152
+ return Object.prototype.toString.call(o).slice(8, -1);
153
+ },
154
+
155
+ /**
156
+ * Returns a unique number for the given object. Later calls will still return the same number.
157
+ *
158
+ * @param {Object} obj
159
+ * @returns {number}
160
+ */
161
+ objId: function (obj) {
162
+ if (!obj['__id']) {
163
+ Object.defineProperty(obj, '__id', { value: ++uniqueId });
164
+ }
165
+ return obj['__id'];
166
+ },
167
+
168
+ /**
169
+ * Creates a deep clone of the given object.
170
+ *
171
+ * The main intended use of this function is to clone language definitions.
172
+ *
173
+ * @param {T} o
174
+ * @param {Record<number, any>} [visited]
175
+ * @returns {T}
176
+ * @template T
177
+ */
178
+ clone: function deepClone(o, visited) {
179
+ visited = visited || {};
180
+
181
+ var clone; var id;
182
+ switch (_.util.type(o)) {
183
+ case 'Object':
184
+ id = _.util.objId(o);
185
+ if (visited[id]) {
186
+ return visited[id];
187
+ }
188
+ clone = /** @type {Record<string, any>} */ ({});
189
+ visited[id] = clone;
190
+
191
+ for (var key in o) {
192
+ if (o.hasOwnProperty(key)) {
193
+ clone[key] = deepClone(o[key], visited);
194
+ }
195
+ }
196
+
197
+ return /** @type {any} */ (clone);
198
+
199
+ case 'Array':
200
+ id = _.util.objId(o);
201
+ if (visited[id]) {
202
+ return visited[id];
203
+ }
204
+ clone = [];
205
+ visited[id] = clone;
206
+
207
+ (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
208
+ clone[i] = deepClone(v, visited);
209
+ });
210
+
211
+ return /** @type {any} */ (clone);
212
+
213
+ default:
214
+ return o;
215
+ }
216
+ },
217
+
218
+ /**
219
+ * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
220
+ *
221
+ * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
222
+ *
223
+ * @param {Element} element
224
+ * @returns {string}
225
+ */
226
+ getLanguage: function (element) {
227
+ while (element && !lang.test(element.className)) {
228
+ element = element.parentElement;
229
+ }
230
+ if (element) {
231
+ return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
232
+ }
233
+ return 'none';
234
+ },
235
+
236
+ /**
237
+ * Returns the script element that is currently executing.
238
+ *
239
+ * This does __not__ work for line script element.
240
+ *
241
+ * @returns {HTMLScriptElement | null}
242
+ */
243
+ currentScript: function () {
244
+ if (typeof document === 'undefined') {
245
+ return null;
246
+ }
247
+ if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
248
+ return /** @type {any} */ (document.currentScript);
249
+ }
250
+
251
+ // IE11 workaround
252
+ // we'll get the src of the current script by parsing IE11's error stack trace
253
+ // this will not work for inline scripts
254
+
255
+ try {
256
+ throw new Error();
257
+ } catch (err) {
258
+ // Get file src url from stack. Specifically works with the format of stack traces in IE.
259
+ // A stack will look like this:
260
+ //
261
+ // Error
262
+ // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
263
+ // at Global code (http://localhost/components/prism-core.js:606:1)
264
+
265
+ var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
266
+ if (src) {
267
+ var scripts = document.getElementsByTagName('script');
268
+ for (var i in scripts) {
269
+ if (scripts[i].src == src) {
270
+ return scripts[i];
271
+ }
272
+ }
273
+ }
274
+ return null;
275
+ }
276
+ },
277
+
278
+ /**
279
+ * Returns whether a given class is active for `element`.
280
+ *
281
+ * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
282
+ * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
283
+ * given class is just the given class with a `no-` prefix.
284
+ *
285
+ * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
286
+ * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
287
+ * ancestors have the given class or the negated version of it, then the default activation will be returned.
288
+ *
289
+ * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
290
+ * version of it, the class is considered active.
291
+ *
292
+ * @param {Element} element
293
+ * @param {string} className
294
+ * @param {boolean} [defaultActivation=false]
295
+ * @returns {boolean}
296
+ */
297
+ isActive: function (element, className, defaultActivation) {
298
+ var no = 'no-' + className;
299
+
300
+ while (element) {
301
+ var classList = element.classList;
302
+ if (classList.contains(className)) {
303
+ return true;
304
+ }
305
+ if (classList.contains(no)) {
306
+ return false;
307
+ }
308
+ element = element.parentElement;
309
+ }
310
+ return !!defaultActivation;
311
+ }
312
+ },
313
+
314
+ /**
315
+ * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
316
+ *
317
+ * @namespace
318
+ * @memberof Prism
319
+ * @public
320
+ */
321
+ languages: {
322
+ /**
323
+ * The grammar for plain, unformatted text.
324
+ */
325
+ plain: plainTextGrammar,
326
+ plaintext: plainTextGrammar,
327
+ text: plainTextGrammar,
328
+ txt: plainTextGrammar,
329
+
330
+ /**
331
+ * Creates a deep copy of the language with the given id and appends the given tokens.
332
+ *
333
+ * If a token in `redef` also appears in the copied language, then the existing token in the copied language
334
+ * will be overwritten at its original position.
335
+ *
336
+ * ## Best practices
337
+ *
338
+ * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
339
+ * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
340
+ * understand the language definition because, normally, the order of tokens matters in Prism grammars.
341
+ *
342
+ * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
343
+ * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
344
+ *
345
+ * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
346
+ * @param {Grammar} redef The new tokens to append.
347
+ * @returns {Grammar} The new language created.
348
+ * @public
349
+ * @example
350
+ * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
351
+ * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
352
+ * // at its original position
353
+ * 'comment': { ... },
354
+ * // CSS doesn't have a 'color' token, so this token will be appended
355
+ * 'color': /\b(?:red|green|blue)\b/
356
+ * });
357
+ */
358
+ extend: function (id, redef) {
359
+ var lang = _.util.clone(_.languages[id]);
360
+
361
+ for (var key in redef) {
362
+ lang[key] = redef[key];
363
+ }
364
+
365
+ return lang;
366
+ },
367
+
368
+ /**
369
+ * Inserts tokens _before_ another token in a language definition or any other grammar.
370
+ *
371
+ * ## Usage
372
+ *
373
+ * This helper method makes it easy to modify existing languages. For example, the CSS language definition
374
+ * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
375
+ * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
376
+ * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
377
+ * this:
378
+ *
379
+ * ```js
380
+ * Prism.languages.markup.style = {
381
+ * // token
382
+ * };
383
+ * ```
384
+ *
385
+ * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
386
+ * before existing tokens. For the CSS example above, you would use it like this:
387
+ *
388
+ * ```js
389
+ * Prism.languages.insertBefore('markup', 'cdata', {
390
+ * 'style': {
391
+ * // token
392
+ * }
393
+ * });
394
+ * ```
395
+ *
396
+ * ## Special cases
397
+ *
398
+ * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
399
+ * will be ignored.
400
+ *
401
+ * This behavior can be used to insert tokens after `before`:
402
+ *
403
+ * ```js
404
+ * Prism.languages.insertBefore('markup', 'comment', {
405
+ * 'comment': Prism.languages.markup.comment,
406
+ * // tokens after 'comment'
407
+ * });
408
+ * ```
409
+ *
410
+ * ## Limitations
411
+ *
412
+ * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
413
+ * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
414
+ * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
415
+ * deleting properties which is necessary to insert at arbitrary positions.
416
+ *
417
+ * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
418
+ * Instead, it will create a new object and replace all references to the target object with the new one. This
419
+ * can be done without temporarily deleting properties, so the iteration order is well-defined.
420
+ *
421
+ * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
422
+ * you hold the target object in a variable, then the value of the variable will not change.
423
+ *
424
+ * ```js
425
+ * var oldMarkup = Prism.languages.markup;
426
+ * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
427
+ *
428
+ * assert(oldMarkup !== Prism.languages.markup);
429
+ * assert(newMarkup === Prism.languages.markup);
430
+ * ```
431
+ *
432
+ * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
433
+ * object to be modified.
434
+ * @param {string} before The key to insert before.
435
+ * @param {Grammar} insert An object containing the key-value pairs to be inserted.
436
+ * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
437
+ * object to be modified.
438
+ *
439
+ * Defaults to `Prism.languages`.
440
+ * @returns {Grammar} The new grammar object.
441
+ * @public
442
+ */
443
+ insertBefore: function (inside, before, insert, root) {
444
+ root = root || /** @type {any} */ (_.languages);
445
+ var grammar = root[inside];
446
+ /** @type {Grammar} */
447
+ var ret = {};
448
+
449
+ for (var token in grammar) {
450
+ if (grammar.hasOwnProperty(token)) {
451
+
452
+ if (token == before) {
453
+ for (var newToken in insert) {
454
+ if (insert.hasOwnProperty(newToken)) {
455
+ ret[newToken] = insert[newToken];
456
+ }
457
+ }
458
+ }
459
+
460
+ // Do not insert token which also occur in insert. See #1525
461
+ if (!insert.hasOwnProperty(token)) {
462
+ ret[token] = grammar[token];
463
+ }
464
+ }
465
+ }
466
+
467
+ var old = root[inside];
468
+ root[inside] = ret;
469
+
470
+ // Update references in other language definitions
471
+ _.languages.DFS(_.languages, function (key, value) {
472
+ if (value === old && key != inside) {
473
+ this[key] = ret;
474
+ }
475
+ });
476
+
477
+ return ret;
478
+ },
479
+
480
+ // Traverse a language definition with Depth First Search
481
+ DFS: function DFS(o, callback, type, visited) {
482
+ visited = visited || {};
483
+
484
+ var objId = _.util.objId;
485
+
486
+ for (var i in o) {
487
+ if (o.hasOwnProperty(i)) {
488
+ callback.call(o, i, o[i], type || i);
489
+
490
+ var property = o[i];
491
+ var propertyType = _.util.type(property);
492
+
493
+ if (propertyType === 'Object' && !visited[objId(property)]) {
494
+ visited[objId(property)] = true;
495
+ DFS(property, callback, null, visited);
496
+ } else if (propertyType === 'Array' && !visited[objId(property)]) {
497
+ visited[objId(property)] = true;
498
+ DFS(property, callback, i, visited);
499
+ }
500
+ }
501
+ }
502
+ }
503
+ },
504
+
505
+ plugins: {},
506
+
507
+ /**
508
+ * This is the most high-level function in Prism’s API.
509
+ * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
510
+ * each one of them.
511
+ *
512
+ * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
513
+ *
514
+ * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
515
+ * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
516
+ * @memberof Prism
517
+ * @public
518
+ */
519
+ highlightAll: function (async, callback) {
520
+ _.highlightAllUnder(document, async, callback);
521
+ },
522
+
523
+ /**
524
+ * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
525
+ * {@link Prism.highlightElement} on each one of them.
526
+ *
527
+ * The following hooks will be run:
528
+ * 1. `before-highlightall`
529
+ * 2. `before-all-elements-highlight`
530
+ * 3. All hooks of {@link Prism.highlightElement} for each element.
531
+ *
532
+ * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
533
+ * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
534
+ * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
535
+ * @memberof Prism
536
+ * @public
537
+ */
538
+ highlightAllUnder: function (container, async, callback) {
539
+ var env = {
540
+ callback: callback,
541
+ container: container,
542
+ selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
543
+ };
544
+
545
+ _.hooks.run('before-highlightall', env);
546
+
547
+ env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
548
+
549
+ _.hooks.run('before-all-elements-highlight', env);
550
+
551
+ for (var i = 0, element; (element = env.elements[i++]);) {
552
+ _.highlightElement(element, async === true, env.callback);
553
+ }
554
+ },
555
+
556
+ /**
557
+ * Highlights the code inside a single element.
558
+ *
559
+ * The following hooks will be run:
560
+ * 1. `before-sanity-check`
561
+ * 2. `before-highlight`
562
+ * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
563
+ * 4. `before-insert`
564
+ * 5. `after-highlight`
565
+ * 6. `complete`
566
+ *
567
+ * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
568
+ * the element's language.
569
+ *
570
+ * @param {Element} element The element containing the code.
571
+ * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
572
+ * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
573
+ * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
574
+ * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
575
+ *
576
+ * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
577
+ * asynchronous highlighting to work. You can build your own bundle on the
578
+ * [Download page](https://prismjs.com/download.html).
579
+ * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
580
+ * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
581
+ * @memberof Prism
582
+ * @public
583
+ */
584
+ highlightElement: function (element, async, callback) {
585
+ // Find language
586
+ var language = _.util.getLanguage(element);
587
+ var grammar = _.languages[language];
588
+
589
+ // Set language on the element, if not present
590
+ element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
591
+
592
+ // Set language on the parent, for styling
593
+ var parent = element.parentElement;
594
+ if (parent && parent.nodeName.toLowerCase() === 'pre') {
595
+ parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
596
+ }
597
+
598
+ var code = element.textContent;
599
+
600
+ var env = {
601
+ element: element,
602
+ language: language,
603
+ grammar: grammar,
604
+ code: code
605
+ };
606
+
607
+ function insertHighlightedCode(highlightedCode) {
608
+ env.highlightedCode = highlightedCode;
609
+
610
+ _.hooks.run('before-insert', env);
611
+
612
+ env.element.innerHTML = env.highlightedCode;
613
+
614
+ _.hooks.run('after-highlight', env);
615
+ _.hooks.run('complete', env);
616
+ callback && callback.call(env.element);
617
+ }
618
+
619
+ _.hooks.run('before-sanity-check', env);
620
+
621
+ // plugins may change/add the parent/element
622
+ parent = env.element.parentElement;
623
+ if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
624
+ parent.setAttribute('tabindex', '0');
625
+ }
626
+
627
+ if (!env.code) {
628
+ _.hooks.run('complete', env);
629
+ callback && callback.call(env.element);
630
+ return;
631
+ }
632
+
633
+ _.hooks.run('before-highlight', env);
634
+
635
+ if (!env.grammar) {
636
+ insertHighlightedCode(_.util.encode(env.code));
637
+ return;
638
+ }
639
+
640
+ if (async && _self.Worker) {
641
+ var worker = new Worker(_.filename);
642
+
643
+ worker.onmessage = function (evt) {
644
+ insertHighlightedCode(evt.data);
645
+ };
646
+
647
+ worker.postMessage(JSON.stringify({
648
+ language: env.language,
649
+ code: env.code,
650
+ immediateClose: true
651
+ }));
652
+ } else {
653
+ insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
654
+ }
655
+ },
656
+
657
+ /**
658
+ * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
659
+ * and the language definitions to use, and returns a string with the HTML produced.
660
+ *
661
+ * The following hooks will be run:
662
+ * 1. `before-tokenize`
663
+ * 2. `after-tokenize`
664
+ * 3. `wrap`: On each {@link Token}.
665
+ *
666
+ * @param {string} text A string with the code to be highlighted.
667
+ * @param {Grammar} grammar An object containing the tokens to use.
668
+ *
669
+ * Usually a language definition like `Prism.languages.markup`.
670
+ * @param {string} language The name of the language definition passed to `grammar`.
671
+ * @returns {string} The highlighted HTML.
672
+ * @memberof Prism
673
+ * @public
674
+ * @example
675
+ * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
676
+ */
677
+ highlight: function (text, grammar, language) {
678
+ var env = {
679
+ code: text,
680
+ grammar: grammar,
681
+ language: language
682
+ };
683
+ _.hooks.run('before-tokenize', env);
684
+ env.tokens = _.tokenize(env.code, env.grammar);
685
+ _.hooks.run('after-tokenize', env);
686
+ return Token.stringify(_.util.encode(env.tokens), env.language);
687
+ },
688
+
689
+ /**
690
+ * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
691
+ * and the language definitions to use, and returns an array with the tokenized code.
692
+ *
693
+ * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
694
+ *
695
+ * This method could be useful in other contexts as well, as a very crude parser.
696
+ *
697
+ * @param {string} text A string with the code to be highlighted.
698
+ * @param {Grammar} grammar An object containing the tokens to use.
699
+ *
700
+ * Usually a language definition like `Prism.languages.markup`.
701
+ * @returns {TokenStream} An array of strings and tokens, a token stream.
702
+ * @memberof Prism
703
+ * @public
704
+ * @example
705
+ * let code = `var foo = 0;`;
706
+ * let tokens = Prism.tokenize(code, Prism.languages.javascript);
707
+ * tokens.forEach(token => {
708
+ * if (token instanceof Prism.Token && token.type === 'number') {
709
+ * console.log(`Found numeric literal: ${token.content}`);
710
+ * }
711
+ * });
712
+ */
713
+ tokenize: function (text, grammar) {
714
+ var rest = grammar.rest;
715
+ if (rest) {
716
+ for (var token in rest) {
717
+ grammar[token] = rest[token];
718
+ }
719
+
720
+ delete grammar.rest;
721
+ }
722
+
723
+ var tokenList = new LinkedList();
724
+ addAfter(tokenList, tokenList.head, text);
725
+
726
+ matchGrammar(text, tokenList, grammar, tokenList.head, 0);
727
+
728
+ return toArray(tokenList);
729
+ },
730
+
731
+ /**
732
+ * @namespace
733
+ * @memberof Prism
734
+ * @public
735
+ */
736
+ hooks: {
737
+ all: {},
738
+
739
+ /**
740
+ * Adds the given callback to the list of callbacks for the given hook.
741
+ *
742
+ * The callback will be invoked when the hook it is registered for is run.
743
+ * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
744
+ *
745
+ * One callback function can be registered to multiple hooks and the same hook multiple times.
746
+ *
747
+ * @param {string} name The name of the hook.
748
+ * @param {HookCallback} callback The callback function which is given environment variables.
749
+ * @public
750
+ */
751
+ add: function (name, callback) {
752
+ var hooks = _.hooks.all;
753
+
754
+ hooks[name] = hooks[name] || [];
755
+
756
+ hooks[name].push(callback);
757
+ },
758
+
759
+ /**
760
+ * Runs a hook invoking all registered callbacks with the given environment variables.
761
+ *
762
+ * Callbacks will be invoked synchronously and in the order in which they were registered.
763
+ *
764
+ * @param {string} name The name of the hook.
765
+ * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
766
+ * @public
767
+ */
768
+ run: function (name, env) {
769
+ var callbacks = _.hooks.all[name];
770
+
771
+ if (!callbacks || !callbacks.length) {
772
+ return;
773
+ }
774
+
775
+ for (var i = 0, callback; (callback = callbacks[i++]);) {
776
+ callback(env);
777
+ }
778
+ }
779
+ },
780
+
781
+ Token: Token
782
+ };
783
+ _self.Prism = _;
784
+
785
+
786
+ // Typescript note:
787
+ // The following can be used to import the Token type in JSDoc:
788
+ //
789
+ // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
790
+
791
+ /**
792
+ * Creates a new token.
793
+ *
794
+ * @param {string} type See {@link Token#type type}
795
+ * @param {string | TokenStream} content See {@link Token#content content}
796
+ * @param {string|string[]} [alias] The alias(es) of the token.
797
+ * @param {string} [matchedStr=""] A copy of the full string this token was created from.
798
+ * @class
799
+ * @global
800
+ * @public
801
+ */
802
+ function Token(type, content, alias, matchedStr) {
803
+ /**
804
+ * The type of the token.
805
+ *
806
+ * This is usually the key of a pattern in a {@link Grammar}.
807
+ *
808
+ * @type {string}
809
+ * @see GrammarToken
810
+ * @public
811
+ */
812
+ this.type = type;
813
+ /**
814
+ * The strings or tokens contained by this token.
815
+ *
816
+ * This will be a token stream if the pattern matched also defined an `inside` grammar.
817
+ *
818
+ * @type {string | TokenStream}
819
+ * @public
820
+ */
821
+ this.content = content;
822
+ /**
823
+ * The alias(es) of the token.
824
+ *
825
+ * @type {string|string[]}
826
+ * @see GrammarToken
827
+ * @public
828
+ */
829
+ this.alias = alias;
830
+ // Copy of the full string this token was created from
831
+ this.length = (matchedStr || '').length | 0;
832
+ }
833
+
834
+ /**
835
+ * A token stream is an array of strings and {@link Token Token} objects.
836
+ *
837
+ * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
838
+ * them.
839
+ *
840
+ * 1. No adjacent strings.
841
+ * 2. No empty strings.
842
+ *
843
+ * The only exception here is the token stream that only contains the empty string and nothing else.
844
+ *
845
+ * @typedef {Array<string | Token>} TokenStream
846
+ * @global
847
+ * @public
848
+ */
849
+
850
+ /**
851
+ * Converts the given token or token stream to an HTML representation.
852
+ *
853
+ * The following hooks will be run:
854
+ * 1. `wrap`: On each {@link Token}.
855
+ *
856
+ * @param {string | Token | TokenStream} o The token or token stream to be converted.
857
+ * @param {string} language The name of current language.
858
+ * @returns {string} The HTML representation of the token or token stream.
859
+ * @memberof Token
860
+ * @static
861
+ */
862
+ Token.stringify = function stringify(o, language) {
863
+ if (typeof o == 'string') {
864
+ return o;
865
+ }
866
+ if (Array.isArray(o)) {
867
+ var s = '';
868
+ o.forEach(function (e) {
869
+ s += stringify(e, language);
870
+ });
871
+ return s;
872
+ }
873
+
874
+ var env = {
875
+ type: o.type,
876
+ content: stringify(o.content, language),
877
+ tag: 'span',
878
+ classes: ['token', o.type],
879
+ attributes: {},
880
+ language: language
881
+ };
882
+
883
+ var aliases = o.alias;
884
+ if (aliases) {
885
+ if (Array.isArray(aliases)) {
886
+ Array.prototype.push.apply(env.classes, aliases);
887
+ } else {
888
+ env.classes.push(aliases);
889
+ }
890
+ }
891
+
892
+ _.hooks.run('wrap', env);
893
+
894
+ var attributes = '';
895
+ for (var name in env.attributes) {
896
+ attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
897
+ }
898
+
899
+ return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
900
+ };
901
+
902
+ /**
903
+ * @param {RegExp} pattern
904
+ * @param {number} pos
905
+ * @param {string} text
906
+ * @param {boolean} lookbehind
907
+ * @returns {RegExpExecArray | null}
908
+ */
909
+ function matchPattern(pattern, pos, text, lookbehind) {
910
+ pattern.lastIndex = pos;
911
+ var match = pattern.exec(text);
912
+ if (match && lookbehind && match[1]) {
913
+ // change the match to remove the text matched by the Prism lookbehind group
914
+ var lookbehindLength = match[1].length;
915
+ match.index += lookbehindLength;
916
+ match[0] = match[0].slice(lookbehindLength);
917
+ }
918
+ return match;
919
+ }
920
+
921
+ /**
922
+ * @param {string} text
923
+ * @param {LinkedList<string | Token>} tokenList
924
+ * @param {any} grammar
925
+ * @param {LinkedListNode<string | Token>} startNode
926
+ * @param {number} startPos
927
+ * @param {RematchOptions} [rematch]
928
+ * @returns {void}
929
+ * @private
930
+ *
931
+ * @typedef RematchOptions
932
+ * @property {string} cause
933
+ * @property {number} reach
934
+ */
935
+ function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
936
+ for (var token in grammar) {
937
+ if (!grammar.hasOwnProperty(token) || !grammar[token]) {
938
+ continue;
939
+ }
940
+
941
+ var patterns = grammar[token];
942
+ patterns = Array.isArray(patterns) ? patterns : [patterns];
943
+
944
+ for (var j = 0; j < patterns.length; ++j) {
945
+ if (rematch && rematch.cause == token + ',' + j) {
946
+ return;
947
+ }
948
+
949
+ var patternObj = patterns[j];
950
+ var inside = patternObj.inside;
951
+ var lookbehind = !!patternObj.lookbehind;
952
+ var greedy = !!patternObj.greedy;
953
+ var alias = patternObj.alias;
954
+
955
+ if (greedy && !patternObj.pattern.global) {
956
+ // Without the global flag, lastIndex won't work
957
+ var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
958
+ patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
959
+ }
960
+
961
+ /** @type {RegExp} */
962
+ var pattern = patternObj.pattern || patternObj;
963
+
964
+ for ( // iterate the token list and keep track of the current token/string position
965
+ var currentNode = startNode.next, pos = startPos;
966
+ currentNode !== tokenList.tail;
967
+ pos += currentNode.value.length, currentNode = currentNode.next
968
+ ) {
969
+
970
+ if (rematch && pos >= rematch.reach) {
971
+ break;
972
+ }
973
+
974
+ var str = currentNode.value;
975
+
976
+ if (tokenList.length > text.length) {
977
+ // Something went terribly wrong, ABORT, ABORT!
978
+ return;
979
+ }
980
+
981
+ if (str instanceof Token) {
982
+ continue;
983
+ }
984
+
985
+ var removeCount = 1; // this is the to parameter of removeBetween
986
+ var match;
987
+
988
+ if (greedy) {
989
+ match = matchPattern(pattern, pos, text, lookbehind);
990
+ if (!match) {
991
+ break;
992
+ }
993
+
994
+ var from = match.index;
995
+ var to = match.index + match[0].length;
996
+ var p = pos;
997
+
998
+ // find the node that contains the match
999
+ p += currentNode.value.length;
1000
+ while (from >= p) {
1001
+ currentNode = currentNode.next;
1002
+ p += currentNode.value.length;
1003
+ }
1004
+ // adjust pos (and p)
1005
+ p -= currentNode.value.length;
1006
+ pos = p;
1007
+
1008
+ // the current node is a Token, then the match starts inside another Token, which is invalid
1009
+ if (currentNode.value instanceof Token) {
1010
+ continue;
1011
+ }
1012
+
1013
+ // find the last node which is affected by this match
1014
+ for (
1015
+ var k = currentNode;
1016
+ k !== tokenList.tail && (p < to || typeof k.value === 'string');
1017
+ k = k.next
1018
+ ) {
1019
+ removeCount++;
1020
+ p += k.value.length;
1021
+ }
1022
+ removeCount--;
1023
+
1024
+ // replace with the new match
1025
+ str = text.slice(pos, p);
1026
+ match.index -= pos;
1027
+ } else {
1028
+ match = matchPattern(pattern, 0, str, lookbehind);
1029
+ if (!match) {
1030
+ continue;
1031
+ }
1032
+ }
1033
+
1034
+ // eslint-disable-next-line no-redeclare
1035
+ var from = match.index;
1036
+ var matchStr = match[0];
1037
+ var before = str.slice(0, from);
1038
+ var after = str.slice(from + matchStr.length);
1039
+
1040
+ var reach = pos + str.length;
1041
+ if (rematch && reach > rematch.reach) {
1042
+ rematch.reach = reach;
1043
+ }
1044
+
1045
+ var removeFrom = currentNode.prev;
1046
+
1047
+ if (before) {
1048
+ removeFrom = addAfter(tokenList, removeFrom, before);
1049
+ pos += before.length;
1050
+ }
1051
+
1052
+ removeRange(tokenList, removeFrom, removeCount);
1053
+
1054
+ var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
1055
+ currentNode = addAfter(tokenList, removeFrom, wrapped);
1056
+
1057
+ if (after) {
1058
+ addAfter(tokenList, currentNode, after);
1059
+ }
1060
+
1061
+ if (removeCount > 1) {
1062
+ // at least one Token object was removed, so we have to do some rematching
1063
+ // this can only happen if the current pattern is greedy
1064
+
1065
+ /** @type {RematchOptions} */
1066
+ var nestedRematch = {
1067
+ cause: token + ',' + j,
1068
+ reach: reach
1069
+ };
1070
+ matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
1071
+
1072
+ // the reach might have been extended because of the rematching
1073
+ if (rematch && nestedRematch.reach > rematch.reach) {
1074
+ rematch.reach = nestedRematch.reach;
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
+ }
1080
+ }
1081
+
1082
+ /**
1083
+ * @typedef LinkedListNode
1084
+ * @property {T} value
1085
+ * @property {LinkedListNode<T> | null} prev The previous node.
1086
+ * @property {LinkedListNode<T> | null} next The next node.
1087
+ * @template T
1088
+ * @private
1089
+ */
1090
+
1091
+ /**
1092
+ * @template T
1093
+ * @private
1094
+ */
1095
+ function LinkedList() {
1096
+ /** @type {LinkedListNode<T>} */
1097
+ var head = { value: null, prev: null, next: null };
1098
+ /** @type {LinkedListNode<T>} */
1099
+ var tail = { value: null, prev: head, next: null };
1100
+ head.next = tail;
1101
+
1102
+ /** @type {LinkedListNode<T>} */
1103
+ this.head = head;
1104
+ /** @type {LinkedListNode<T>} */
1105
+ this.tail = tail;
1106
+ this.length = 0;
1107
+ }
1108
+
1109
+ /**
1110
+ * Adds a new node with the given value to the list.
1111
+ *
1112
+ * @param {LinkedList<T>} list
1113
+ * @param {LinkedListNode<T>} node
1114
+ * @param {T} value
1115
+ * @returns {LinkedListNode<T>} The added node.
1116
+ * @template T
1117
+ */
1118
+ function addAfter(list, node, value) {
1119
+ // assumes that node != list.tail && values.length >= 0
1120
+ var next = node.next;
1121
+
1122
+ var newNode = { value: value, prev: node, next: next };
1123
+ node.next = newNode;
1124
+ next.prev = newNode;
1125
+ list.length++;
1126
+
1127
+ return newNode;
1128
+ }
1129
+ /**
1130
+ * Removes `count` nodes after the given node. The given node will not be removed.
1131
+ *
1132
+ * @param {LinkedList<T>} list
1133
+ * @param {LinkedListNode<T>} node
1134
+ * @param {number} count
1135
+ * @template T
1136
+ */
1137
+ function removeRange(list, node, count) {
1138
+ var next = node.next;
1139
+ for (var i = 0; i < count && next !== list.tail; i++) {
1140
+ next = next.next;
1141
+ }
1142
+ node.next = next;
1143
+ next.prev = node;
1144
+ list.length -= i;
1145
+ }
1146
+ /**
1147
+ * @param {LinkedList<T>} list
1148
+ * @returns {T[]}
1149
+ * @template T
1150
+ */
1151
+ function toArray(list) {
1152
+ var array = [];
1153
+ var node = list.head.next;
1154
+ while (node !== list.tail) {
1155
+ array.push(node.value);
1156
+ node = node.next;
1157
+ }
1158
+ return array;
1159
+ }
1160
+
1161
+
1162
+ if (!_self.document) {
1163
+ if (!_self.addEventListener) {
1164
+ // in Node.js
1165
+ return _;
1166
+ }
1167
+
1168
+ if (!_.disableWorkerMessageHandler) {
1169
+ // In worker
1170
+ _self.addEventListener('message', function (evt) {
1171
+ var message = JSON.parse(evt.data);
1172
+ var lang = message.language;
1173
+ var code = message.code;
1174
+ var immediateClose = message.immediateClose;
1175
+
1176
+ _self.postMessage(_.highlight(code, _.languages[lang], lang));
1177
+ if (immediateClose) {
1178
+ _self.close();
1179
+ }
1180
+ }, false);
1181
+ }
1182
+
1183
+ return _;
1184
+ }
1185
+
1186
+ // Get current script and highlight
1187
+ var script = _.util.currentScript();
1188
+
1189
+ if (script) {
1190
+ _.filename = script.src;
1191
+
1192
+ if (script.hasAttribute('data-manual')) {
1193
+ _.manual = true;
1194
+ }
1195
+ }
1196
+
1197
+ function highlightAutomaticallyCallback() {
1198
+ if (!_.manual) {
1199
+ _.highlightAll();
1200
+ }
1201
+ }
1202
+
1203
+ if (!_.manual) {
1204
+ // If the document state is "loading", then we'll use DOMContentLoaded.
1205
+ // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
1206
+ // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
1207
+ // might take longer one animation frame to execute which can create a race condition where only some plugins have
1208
+ // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
1209
+ // See https://github.com/PrismJS/prism/issues/2102
1210
+ var readyState = document.readyState;
1211
+ if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
1212
+ document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
1213
+ } else {
1214
+ if (window.requestAnimationFrame) {
1215
+ window.requestAnimationFrame(highlightAutomaticallyCallback);
1216
+ } else {
1217
+ window.setTimeout(highlightAutomaticallyCallback, 16);
1218
+ }
1219
+ }
1220
+ }
1221
+
1222
+ return _;
1223
+
1224
+ }(_self));
1225
+
1226
+ if (module.exports) {
1227
+ module.exports = Prism;
1228
+ }
1229
+
1230
+ // hack for components to work correctly in node.js
1231
+ if (typeof commonjsGlobal !== 'undefined') {
1232
+ commonjsGlobal.Prism = Prism;
1233
+ }
1234
+
1235
+ // some additional documentation/types
1236
+
1237
+ /**
1238
+ * The expansion of a simple `RegExp` literal to support additional properties.
1239
+ *
1240
+ * @typedef GrammarToken
1241
+ * @property {RegExp} pattern The regular expression of the token.
1242
+ * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
1243
+ * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
1244
+ * @property {boolean} [greedy=false] Whether the token is greedy.
1245
+ * @property {string|string[]} [alias] An optional alias or list of aliases.
1246
+ * @property {Grammar} [inside] The nested grammar of this token.
1247
+ *
1248
+ * The `inside` grammar will be used to tokenize the text value of each token of this kind.
1249
+ *
1250
+ * This can be used to make nested and even recursive language definitions.
1251
+ *
1252
+ * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
1253
+ * each another.
1254
+ * @global
1255
+ * @public
1256
+ */
1257
+
1258
+ /**
1259
+ * @typedef Grammar
1260
+ * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
1261
+ * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
1262
+ * @global
1263
+ * @public
1264
+ */
1265
+
1266
+ /**
1267
+ * A function which will invoked after an element was successfully highlighted.
1268
+ *
1269
+ * @callback HighlightCallback
1270
+ * @param {Element} element The element successfully highlighted.
1271
+ * @returns {void}
1272
+ * @global
1273
+ * @public
1274
+ */
1275
+
1276
+ /**
1277
+ * @callback HookCallback
1278
+ * @param {Object<string, any>} env The environment variables of the hook.
1279
+ * @returns {void}
1280
+ * @global
1281
+ * @public
1282
+ */
1283
+
1284
+
1285
+ /* **********************************************
1286
+ Begin prism-markup.js
1287
+ ********************************************** */
1288
+
1289
+ Prism.languages.markup = {
1290
+ 'comment': {
1291
+ pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
1292
+ greedy: true
1293
+ },
1294
+ 'prolog': {
1295
+ pattern: /<\?[\s\S]+?\?>/,
1296
+ greedy: true
1297
+ },
1298
+ 'doctype': {
1299
+ // https://www.w3.org/TR/xml/#NT-doctypedecl
1300
+ pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
1301
+ greedy: true,
1302
+ inside: {
1303
+ 'internal-subset': {
1304
+ pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
1305
+ lookbehind: true,
1306
+ greedy: true,
1307
+ inside: null // see below
1308
+ },
1309
+ 'string': {
1310
+ pattern: /"[^"]*"|'[^']*'/,
1311
+ greedy: true
1312
+ },
1313
+ 'punctuation': /^<!|>$|[[\]]/,
1314
+ 'doctype-tag': /^DOCTYPE/i,
1315
+ 'name': /[^\s<>'"]+/
1316
+ }
1317
+ },
1318
+ 'cdata': {
1319
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1320
+ greedy: true
1321
+ },
1322
+ 'tag': {
1323
+ pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
1324
+ greedy: true,
1325
+ inside: {
1326
+ 'tag': {
1327
+ pattern: /^<\/?[^\s>\/]+/,
1328
+ inside: {
1329
+ 'punctuation': /^<\/?/,
1330
+ 'namespace': /^[^\s>\/:]+:/
1331
+ }
1332
+ },
1333
+ 'special-attr': [],
1334
+ 'attr-value': {
1335
+ pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
1336
+ inside: {
1337
+ 'punctuation': [
1338
+ {
1339
+ pattern: /^=/,
1340
+ alias: 'attr-equals'
1341
+ },
1342
+ /"|'/
1343
+ ]
1344
+ }
1345
+ },
1346
+ 'punctuation': /\/?>/,
1347
+ 'attr-name': {
1348
+ pattern: /[^\s>\/]+/,
1349
+ inside: {
1350
+ 'namespace': /^[^\s>\/:]+:/
1351
+ }
1352
+ }
1353
+
1354
+ }
1355
+ },
1356
+ 'entity': [
1357
+ {
1358
+ pattern: /&[\da-z]{1,8};/i,
1359
+ alias: 'named-entity'
1360
+ },
1361
+ /&#x?[\da-f]{1,8};/i
1362
+ ]
1363
+ };
1364
+
1365
+ Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
1366
+ Prism.languages.markup['entity'];
1367
+ Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
1368
+
1369
+ // Plugin to make entity title show the real entity, idea by Roman Komarov
1370
+ Prism.hooks.add('wrap', function (env) {
1371
+
1372
+ if (env.type === 'entity') {
1373
+ env.attributes['title'] = env.content.replace(/&amp;/, '&');
1374
+ }
1375
+ });
1376
+
1377
+ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
1378
+ /**
1379
+ * Adds an inlined language to markup.
1380
+ *
1381
+ * An example of an inlined language is CSS with `<style>` tags.
1382
+ *
1383
+ * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
1384
+ * case insensitive.
1385
+ * @param {string} lang The language key.
1386
+ * @example
1387
+ * addInlined('style', 'css');
1388
+ */
1389
+ value: function addInlined(tagName, lang) {
1390
+ var includedCdataInside = {};
1391
+ includedCdataInside['language-' + lang] = {
1392
+ pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
1393
+ lookbehind: true,
1394
+ inside: Prism.languages[lang]
1395
+ };
1396
+ includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
1397
+
1398
+ var inside = {
1399
+ 'included-cdata': {
1400
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1401
+ inside: includedCdataInside
1402
+ }
1403
+ };
1404
+ inside['language-' + lang] = {
1405
+ pattern: /[\s\S]+/,
1406
+ inside: Prism.languages[lang]
1407
+ };
1408
+
1409
+ var def = {};
1410
+ def[tagName] = {
1411
+ pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
1412
+ lookbehind: true,
1413
+ greedy: true,
1414
+ inside: inside
1415
+ };
1416
+
1417
+ Prism.languages.insertBefore('markup', 'cdata', def);
1418
+ }
1419
+ });
1420
+ Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
1421
+ /**
1422
+ * Adds an pattern to highlight languages embedded in HTML attributes.
1423
+ *
1424
+ * An example of an inlined language is CSS with `style` attributes.
1425
+ *
1426
+ * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
1427
+ * case insensitive.
1428
+ * @param {string} lang The language key.
1429
+ * @example
1430
+ * addAttribute('style', 'css');
1431
+ */
1432
+ value: function (attrName, lang) {
1433
+ Prism.languages.markup.tag.inside['special-attr'].push({
1434
+ pattern: RegExp(
1435
+ /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
1436
+ 'i'
1437
+ ),
1438
+ lookbehind: true,
1439
+ inside: {
1440
+ 'attr-name': /^[^\s=]+/,
1441
+ 'attr-value': {
1442
+ pattern: /=[\s\S]+/,
1443
+ inside: {
1444
+ 'value': {
1445
+ pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
1446
+ lookbehind: true,
1447
+ alias: [lang, 'language-' + lang],
1448
+ inside: Prism.languages[lang]
1449
+ },
1450
+ 'punctuation': [
1451
+ {
1452
+ pattern: /^=/,
1453
+ alias: 'attr-equals'
1454
+ },
1455
+ /"|'/
1456
+ ]
1457
+ }
1458
+ }
1459
+ }
1460
+ });
1461
+ }
1462
+ });
1463
+
1464
+ Prism.languages.html = Prism.languages.markup;
1465
+ Prism.languages.mathml = Prism.languages.markup;
1466
+ Prism.languages.svg = Prism.languages.markup;
1467
+
1468
+ Prism.languages.xml = Prism.languages.extend('markup', {});
1469
+ Prism.languages.ssml = Prism.languages.xml;
1470
+ Prism.languages.atom = Prism.languages.xml;
1471
+ Prism.languages.rss = Prism.languages.xml;
1472
+
1473
+
1474
+ /* **********************************************
1475
+ Begin prism-css.js
1476
+ ********************************************** */
1477
+
1478
+ (function (Prism) {
1479
+
1480
+ var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
1481
+
1482
+ Prism.languages.css = {
1483
+ 'comment': /\/\*[\s\S]*?\*\//,
1484
+ 'atrule': {
1485
+ pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
1486
+ inside: {
1487
+ 'rule': /^@[\w-]+/,
1488
+ 'selector-function-argument': {
1489
+ pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
1490
+ lookbehind: true,
1491
+ alias: 'selector'
1492
+ },
1493
+ 'keyword': {
1494
+ pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
1495
+ lookbehind: true
1496
+ }
1497
+ // See rest below
1498
+ }
1499
+ },
1500
+ 'url': {
1501
+ // https://drafts.csswg.org/css-values-3/#urls
1502
+ pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
1503
+ greedy: true,
1504
+ inside: {
1505
+ 'function': /^url/i,
1506
+ 'punctuation': /^\(|\)$/,
1507
+ 'string': {
1508
+ pattern: RegExp('^' + string.source + '$'),
1509
+ alias: 'url'
1510
+ }
1511
+ }
1512
+ },
1513
+ 'selector': {
1514
+ pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
1515
+ lookbehind: true
1516
+ },
1517
+ 'string': {
1518
+ pattern: string,
1519
+ greedy: true
1520
+ },
1521
+ 'property': {
1522
+ pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
1523
+ lookbehind: true
1524
+ },
1525
+ 'important': /!important\b/i,
1526
+ 'function': {
1527
+ pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
1528
+ lookbehind: true
1529
+ },
1530
+ 'punctuation': /[(){};:,]/
1531
+ };
1532
+
1533
+ Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
1534
+
1535
+ var markup = Prism.languages.markup;
1536
+ if (markup) {
1537
+ markup.tag.addInlined('style', 'css');
1538
+ markup.tag.addAttribute('style', 'css');
1539
+ }
1540
+
1541
+ }(Prism));
1542
+
1543
+
1544
+ /* **********************************************
1545
+ Begin prism-clike.js
1546
+ ********************************************** */
1547
+
1548
+ Prism.languages.clike = {
1549
+ 'comment': [
1550
+ {
1551
+ pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
1552
+ lookbehind: true,
1553
+ greedy: true
1554
+ },
1555
+ {
1556
+ pattern: /(^|[^\\:])\/\/.*/,
1557
+ lookbehind: true,
1558
+ greedy: true
1559
+ }
1560
+ ],
1561
+ 'string': {
1562
+ pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
1563
+ greedy: true
1564
+ },
1565
+ 'class-name': {
1566
+ pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
1567
+ lookbehind: true,
1568
+ inside: {
1569
+ 'punctuation': /[.\\]/
1570
+ }
1571
+ },
1572
+ 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
1573
+ 'boolean': /\b(?:true|false)\b/,
1574
+ 'function': /\b\w+(?=\()/,
1575
+ 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
1576
+ 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
1577
+ 'punctuation': /[{}[\];(),.:]/
1578
+ };
1579
+
1580
+
1581
+ /* **********************************************
1582
+ Begin prism-javascript.js
1583
+ ********************************************** */
1584
+
1585
+ Prism.languages.javascript = Prism.languages.extend('clike', {
1586
+ 'class-name': [
1587
+ Prism.languages.clike['class-name'],
1588
+ {
1589
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:prototype|constructor))/,
1590
+ lookbehind: true
1591
+ }
1592
+ ],
1593
+ 'keyword': [
1594
+ {
1595
+ pattern: /((?:^|\})\s*)catch\b/,
1596
+ lookbehind: true
1597
+ },
1598
+ {
1599
+ pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
1600
+ lookbehind: true
1601
+ },
1602
+ ],
1603
+ // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
1604
+ 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
1605
+ 'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
1606
+ 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
1607
+ });
1608
+
1609
+ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
1610
+
1611
+ Prism.languages.insertBefore('javascript', 'keyword', {
1612
+ 'regex': {
1613
+ // eslint-disable-next-line regexp/no-dupe-characters-character-class
1614
+ pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
1615
+ lookbehind: true,
1616
+ greedy: true,
1617
+ inside: {
1618
+ 'regex-source': {
1619
+ pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
1620
+ lookbehind: true,
1621
+ alias: 'language-regex',
1622
+ inside: Prism.languages.regex
1623
+ },
1624
+ 'regex-delimiter': /^\/|\/$/,
1625
+ 'regex-flags': /^[a-z]+$/,
1626
+ }
1627
+ },
1628
+ // This must be declared before keyword because we use "function" inside the look-forward
1629
+ 'function-variable': {
1630
+ pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
1631
+ alias: 'function'
1632
+ },
1633
+ 'parameter': [
1634
+ {
1635
+ pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
1636
+ lookbehind: true,
1637
+ inside: Prism.languages.javascript
1638
+ },
1639
+ {
1640
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
1641
+ lookbehind: true,
1642
+ inside: Prism.languages.javascript
1643
+ },
1644
+ {
1645
+ pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
1646
+ lookbehind: true,
1647
+ inside: Prism.languages.javascript
1648
+ },
1649
+ {
1650
+ pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
1651
+ lookbehind: true,
1652
+ inside: Prism.languages.javascript
1653
+ }
1654
+ ],
1655
+ 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
1656
+ });
1657
+
1658
+ Prism.languages.insertBefore('javascript', 'string', {
1659
+ 'hashbang': {
1660
+ pattern: /^#!.*/,
1661
+ greedy: true,
1662
+ alias: 'comment'
1663
+ },
1664
+ 'template-string': {
1665
+ pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
1666
+ greedy: true,
1667
+ inside: {
1668
+ 'template-punctuation': {
1669
+ pattern: /^`|`$/,
1670
+ alias: 'string'
1671
+ },
1672
+ 'interpolation': {
1673
+ pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
1674
+ lookbehind: true,
1675
+ inside: {
1676
+ 'interpolation-punctuation': {
1677
+ pattern: /^\$\{|\}$/,
1678
+ alias: 'punctuation'
1679
+ },
1680
+ rest: Prism.languages.javascript
1681
+ }
1682
+ },
1683
+ 'string': /[\s\S]+/
1684
+ }
1685
+ }
1686
+ });
1687
+
1688
+ if (Prism.languages.markup) {
1689
+ Prism.languages.markup.tag.addInlined('script', 'javascript');
1690
+
1691
+ // add attribute support for all DOM events.
1692
+ // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
1693
+ Prism.languages.markup.tag.addAttribute(
1694
+ /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
1695
+ 'javascript'
1696
+ );
1697
+ }
1698
+
1699
+ Prism.languages.js = Prism.languages.javascript;
1700
+
1701
+
1702
+ /* **********************************************
1703
+ Begin prism-file-highlight.js
1704
+ ********************************************** */
1705
+
1706
+ (function () {
1707
+
1708
+ if (typeof Prism === 'undefined' || typeof document === 'undefined') {
1709
+ return;
1710
+ }
1711
+
1712
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
1713
+ if (!Element.prototype.matches) {
1714
+ Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
1715
+ }
1716
+
1717
+ var LOADING_MESSAGE = 'Loading…';
1718
+ var FAILURE_MESSAGE = function (status, message) {
1719
+ return '✖ Error ' + status + ' while fetching file: ' + message;
1720
+ };
1721
+ var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
1722
+
1723
+ var EXTENSIONS = {
1724
+ 'js': 'javascript',
1725
+ 'py': 'python',
1726
+ 'rb': 'ruby',
1727
+ 'ps1': 'powershell',
1728
+ 'psm1': 'powershell',
1729
+ 'sh': 'bash',
1730
+ 'bat': 'batch',
1731
+ 'h': 'c',
1732
+ 'tex': 'latex'
1733
+ };
1734
+
1735
+ var STATUS_ATTR = 'data-src-status';
1736
+ var STATUS_LOADING = 'loading';
1737
+ var STATUS_LOADED = 'loaded';
1738
+ var STATUS_FAILED = 'failed';
1739
+
1740
+ var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
1741
+ + ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
1742
+
1743
+ var lang = /\blang(?:uage)?-([\w-]+)\b/i;
1744
+
1745
+ /**
1746
+ * Sets the Prism `language-xxxx` or `lang-xxxx` class to the given language.
1747
+ *
1748
+ * @param {HTMLElement} element
1749
+ * @param {string} language
1750
+ * @returns {void}
1751
+ */
1752
+ function setLanguageClass(element, language) {
1753
+ var className = element.className;
1754
+ className = className.replace(lang, ' ') + ' language-' + language;
1755
+ element.className = className.replace(/\s+/g, ' ').trim();
1756
+ }
1757
+
1758
+
1759
+ Prism.hooks.add('before-highlightall', function (env) {
1760
+ env.selector += ', ' + SELECTOR;
1761
+ });
1762
+
1763
+ Prism.hooks.add('before-sanity-check', function (env) {
1764
+ var pre = /** @type {HTMLPreElement} */ (env.element);
1765
+ if (pre.matches(SELECTOR)) {
1766
+ env.code = ''; // fast-path the whole thing and go to complete
1767
+
1768
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADING); // mark as loading
1769
+
1770
+ // add code element with loading message
1771
+ var code = pre.appendChild(document.createElement('CODE'));
1772
+ code.textContent = LOADING_MESSAGE;
1773
+
1774
+ var src = pre.getAttribute('data-src');
1775
+
1776
+ var language = env.language;
1777
+ if (language === 'none') {
1778
+ // the language might be 'none' because there is no language set;
1779
+ // in this case, we want to use the extension as the language
1780
+ var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
1781
+ language = EXTENSIONS[extension] || extension;
1782
+ }
1783
+
1784
+ // set language classes
1785
+ setLanguageClass(code, language);
1786
+ setLanguageClass(pre, language);
1787
+
1788
+ // preload the language
1789
+ var autoloader = Prism.plugins.autoloader;
1790
+ if (autoloader) {
1791
+ autoloader.loadLanguages(language);
1792
+ }
1793
+
1794
+ // load file
1795
+ var xhr = new XMLHttpRequest();
1796
+ xhr.open('GET', src, true);
1797
+ xhr.onreadystatechange = function () {
1798
+ if (xhr.readyState == 4) {
1799
+ if (xhr.status < 400 && xhr.responseText) {
1800
+ // mark as loaded
1801
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
1802
+
1803
+ // highlight code
1804
+ code.textContent = xhr.responseText;
1805
+ Prism.highlightElement(code);
1806
+
1807
+ } else {
1808
+ // mark as failed
1809
+ pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
1810
+
1811
+ if (xhr.status >= 400) {
1812
+ code.textContent = FAILURE_MESSAGE(xhr.status, xhr.statusText);
1813
+ } else {
1814
+ code.textContent = FAILURE_EMPTY_MESSAGE;
1815
+ }
1816
+ }
1817
+ }
1818
+ };
1819
+ xhr.send(null);
1820
+ }
1821
+ });
1822
+
1823
+ Prism.plugins.fileHighlight = {
1824
+ /**
1825
+ * Executes the File Highlight plugin for all matching `pre` elements under the given container.
1826
+ *
1827
+ * Note: Elements which are already loaded or currently loading will not be touched by this method.
1828
+ *
1829
+ * @param {ParentNode} [container=document]
1830
+ */
1831
+ highlight: function highlight(container) {
1832
+ var elements = (container || document).querySelectorAll(SELECTOR);
1833
+
1834
+ for (var i = 0, element; (element = elements[i++]);) {
1835
+ Prism.highlightElement(element);
1836
+ }
1837
+ }
1838
+ };
1839
+
1840
+ var logged = false;
1841
+ /** @deprecated Use `Prism.plugins.fileHighlight.highlight` instead. */
1842
+ Prism.fileHighlight = function () {
1843
+ if (!logged) {
1844
+ console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
1845
+ logged = true;
1846
+ }
1847
+ Prism.plugins.fileHighlight.highlight.apply(this, arguments);
1848
+ };
1849
+
1850
+ }());
1851
+ });
1852
+
1853
+ (function (Prism) {
1854
+
1855
+ var javascript = Prism.util.clone(Prism.languages.javascript);
1856
+
1857
+ var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
1858
+ var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
1859
+ var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
1860
+
1861
+ /**
1862
+ * @param {string} source
1863
+ * @param {string} [flags]
1864
+ */
1865
+ function re(source, flags) {
1866
+ source = source
1867
+ .replace(/<S>/g, function () { return space; })
1868
+ .replace(/<BRACES>/g, function () { return braces; })
1869
+ .replace(/<SPREAD>/g, function () { return spread; });
1870
+ return RegExp(source, flags);
1871
+ }
1872
+
1873
+ spread = re(spread).source;
1874
+
1875
+
1876
+ Prism.languages.jsx = Prism.languages.extend('markup', javascript);
1877
+ Prism.languages.jsx.tag.pattern = re(
1878
+ /<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
1879
+ );
1880
+
1881
+ Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/i;
1882
+ Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/i;
1883
+ Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
1884
+ Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
1885
+
1886
+ Prism.languages.insertBefore('inside', 'attr-name', {
1887
+ 'spread': {
1888
+ pattern: re(/<SPREAD>/.source),
1889
+ inside: Prism.languages.jsx
1890
+ }
1891
+ }, Prism.languages.jsx.tag);
1892
+
1893
+ Prism.languages.insertBefore('inside', 'special-attr', {
1894
+ 'script': {
1895
+ // Allow for two levels of nesting
1896
+ pattern: re(/=<BRACES>/.source),
1897
+ inside: {
1898
+ 'script-punctuation': {
1899
+ pattern: /^=(?=\{)/,
1900
+ alias: 'punctuation'
1901
+ },
1902
+ rest: Prism.languages.jsx
1903
+ },
1904
+ 'alias': 'language-javascript'
1905
+ }
1906
+ }, Prism.languages.jsx.tag);
1907
+
1908
+ // The following will handle plain text inside tags
1909
+ var stringifyToken = function (token) {
1910
+ if (!token) {
1911
+ return '';
1912
+ }
1913
+ if (typeof token === 'string') {
1914
+ return token;
1915
+ }
1916
+ if (typeof token.content === 'string') {
1917
+ return token.content;
1918
+ }
1919
+ return token.content.map(stringifyToken).join('');
1920
+ };
1921
+
1922
+ var walkTokens = function (tokens) {
1923
+ var openedTags = [];
1924
+ for (var i = 0; i < tokens.length; i++) {
1925
+ var token = tokens[i];
1926
+ var notTagNorBrace = false;
1927
+
1928
+ if (typeof token !== 'string') {
1929
+ if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
1930
+ // We found a tag, now find its kind
1931
+
1932
+ if (token.content[0].content[0].content === '</') {
1933
+ // Closing tag
1934
+ if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
1935
+ // Pop matching opening tag
1936
+ openedTags.pop();
1937
+ }
1938
+ } else {
1939
+ if (token.content[token.content.length - 1].content === '/>') ; else {
1940
+ // Opening tag
1941
+ openedTags.push({
1942
+ tagName: stringifyToken(token.content[0].content[1]),
1943
+ openedBraces: 0
1944
+ });
1945
+ }
1946
+ }
1947
+ } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
1948
+
1949
+ // Here we might have entered a JSX context inside a tag
1950
+ openedTags[openedTags.length - 1].openedBraces++;
1951
+
1952
+ } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
1953
+
1954
+ // Here we might have left a JSX context inside a tag
1955
+ openedTags[openedTags.length - 1].openedBraces--;
1956
+
1957
+ } else {
1958
+ notTagNorBrace = true;
1959
+ }
1960
+ }
1961
+ if (notTagNorBrace || typeof token === 'string') {
1962
+ if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
1963
+ // Here we are inside a tag, and not inside a JSX context.
1964
+ // That's plain text: drop any tokens matched.
1965
+ var plainText = stringifyToken(token);
1966
+
1967
+ // And merge text with adjacent text
1968
+ if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
1969
+ plainText += stringifyToken(tokens[i + 1]);
1970
+ tokens.splice(i + 1, 1);
1971
+ }
1972
+ if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
1973
+ plainText = stringifyToken(tokens[i - 1]) + plainText;
1974
+ tokens.splice(i - 1, 1);
1975
+ i--;
1976
+ }
1977
+
1978
+ tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
1979
+ }
1980
+ }
1981
+
1982
+ if (token.content && typeof token.content !== 'string') {
1983
+ walkTokens(token.content);
1984
+ }
1985
+ }
1986
+ };
1987
+
1988
+ Prism.hooks.add('after-tokenize', function (env) {
1989
+ if (env.language !== 'jsx' && env.language !== 'tsx') {
1990
+ return;
1991
+ }
1992
+ walkTokens(env.tokens);
1993
+ });
1994
+
1995
+ }(Prism));
1996
+
1997
+ (function (Prism) {
1998
+
1999
+ Prism.languages.typescript = Prism.languages.extend('javascript', {
2000
+ 'class-name': {
2001
+ pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
2002
+ lookbehind: true,
2003
+ greedy: true,
2004
+ inside: null // see below
2005
+ },
2006
+ 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
2007
+ });
2008
+
2009
+ // The keywords TypeScript adds to JavaScript
2010
+ Prism.languages.typescript.keyword.push(
2011
+ /\b(?:abstract|as|declare|implements|is|keyof|readonly|require)\b/,
2012
+ // keywords that have to be followed by an identifier
2013
+ /\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
2014
+ // This is for `import type *, {}`
2015
+ /\btype\b(?=\s*(?:[\{*]|$))/
2016
+ );
2017
+
2018
+ // doesn't work with TS because TS is too complex
2019
+ delete Prism.languages.typescript['parameter'];
2020
+
2021
+ // a version of typescript specifically for highlighting types
2022
+ var typeInside = Prism.languages.extend('typescript', {});
2023
+ delete typeInside['class-name'];
2024
+
2025
+ Prism.languages.typescript['class-name'].inside = typeInside;
2026
+
2027
+ Prism.languages.insertBefore('typescript', 'function', {
2028
+ 'decorator': {
2029
+ pattern: /@[$\w\xA0-\uFFFF]+/,
2030
+ inside: {
2031
+ 'at': {
2032
+ pattern: /^@/,
2033
+ alias: 'operator'
2034
+ },
2035
+ 'function': /^[\s\S]+/
2036
+ }
2037
+ },
2038
+ 'generic-function': {
2039
+ // e.g. foo<T extends "bar" | "baz">( ...
2040
+ pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
2041
+ greedy: true,
2042
+ inside: {
2043
+ 'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
2044
+ 'generic': {
2045
+ pattern: /<[\s\S]+/, // everything after the first <
2046
+ alias: 'class-name',
2047
+ inside: typeInside
2048
+ }
2049
+ }
2050
+ }
2051
+ });
2052
+
2053
+ Prism.languages.ts = Prism.languages.typescript;
2054
+
2055
+ }(Prism));
2056
+
2057
+ Prism.languages.markup = {
2058
+ 'comment': {
2059
+ pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
2060
+ greedy: true
2061
+ },
2062
+ 'prolog': {
2063
+ pattern: /<\?[\s\S]+?\?>/,
2064
+ greedy: true
2065
+ },
2066
+ 'doctype': {
2067
+ // https://www.w3.org/TR/xml/#NT-doctypedecl
2068
+ pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
2069
+ greedy: true,
2070
+ inside: {
2071
+ 'internal-subset': {
2072
+ pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
2073
+ lookbehind: true,
2074
+ greedy: true,
2075
+ inside: null // see below
2076
+ },
2077
+ 'string': {
2078
+ pattern: /"[^"]*"|'[^']*'/,
2079
+ greedy: true
2080
+ },
2081
+ 'punctuation': /^<!|>$|[[\]]/,
2082
+ 'doctype-tag': /^DOCTYPE/i,
2083
+ 'name': /[^\s<>'"]+/
2084
+ }
2085
+ },
2086
+ 'cdata': {
2087
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
2088
+ greedy: true
2089
+ },
2090
+ 'tag': {
2091
+ pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
2092
+ greedy: true,
2093
+ inside: {
2094
+ 'tag': {
2095
+ pattern: /^<\/?[^\s>\/]+/,
2096
+ inside: {
2097
+ 'punctuation': /^<\/?/,
2098
+ 'namespace': /^[^\s>\/:]+:/
2099
+ }
2100
+ },
2101
+ 'special-attr': [],
2102
+ 'attr-value': {
2103
+ pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
2104
+ inside: {
2105
+ 'punctuation': [
2106
+ {
2107
+ pattern: /^=/,
2108
+ alias: 'attr-equals'
2109
+ },
2110
+ /"|'/
2111
+ ]
2112
+ }
2113
+ },
2114
+ 'punctuation': /\/?>/,
2115
+ 'attr-name': {
2116
+ pattern: /[^\s>\/]+/,
2117
+ inside: {
2118
+ 'namespace': /^[^\s>\/:]+:/
2119
+ }
2120
+ }
2121
+
2122
+ }
2123
+ },
2124
+ 'entity': [
2125
+ {
2126
+ pattern: /&[\da-z]{1,8};/i,
2127
+ alias: 'named-entity'
2128
+ },
2129
+ /&#x?[\da-f]{1,8};/i
2130
+ ]
2131
+ };
2132
+
2133
+ Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
2134
+ Prism.languages.markup['entity'];
2135
+ Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
2136
+
2137
+ // Plugin to make entity title show the real entity, idea by Roman Komarov
2138
+ Prism.hooks.add('wrap', function (env) {
2139
+
2140
+ if (env.type === 'entity') {
2141
+ env.attributes['title'] = env.content.replace(/&amp;/, '&');
2142
+ }
2143
+ });
2144
+
2145
+ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
2146
+ /**
2147
+ * Adds an inlined language to markup.
2148
+ *
2149
+ * An example of an inlined language is CSS with `<style>` tags.
2150
+ *
2151
+ * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
2152
+ * case insensitive.
2153
+ * @param {string} lang The language key.
2154
+ * @example
2155
+ * addInlined('style', 'css');
2156
+ */
2157
+ value: function addInlined(tagName, lang) {
2158
+ var includedCdataInside = {};
2159
+ includedCdataInside['language-' + lang] = {
2160
+ pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
2161
+ lookbehind: true,
2162
+ inside: Prism.languages[lang]
2163
+ };
2164
+ includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
2165
+
2166
+ var inside = {
2167
+ 'included-cdata': {
2168
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
2169
+ inside: includedCdataInside
2170
+ }
2171
+ };
2172
+ inside['language-' + lang] = {
2173
+ pattern: /[\s\S]+/,
2174
+ inside: Prism.languages[lang]
2175
+ };
2176
+
2177
+ var def = {};
2178
+ def[tagName] = {
2179
+ pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
2180
+ lookbehind: true,
2181
+ greedy: true,
2182
+ inside: inside
2183
+ };
2184
+
2185
+ Prism.languages.insertBefore('markup', 'cdata', def);
2186
+ }
2187
+ });
2188
+ Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
2189
+ /**
2190
+ * Adds an pattern to highlight languages embedded in HTML attributes.
2191
+ *
2192
+ * An example of an inlined language is CSS with `style` attributes.
2193
+ *
2194
+ * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
2195
+ * case insensitive.
2196
+ * @param {string} lang The language key.
2197
+ * @example
2198
+ * addAttribute('style', 'css');
2199
+ */
2200
+ value: function (attrName, lang) {
2201
+ Prism.languages.markup.tag.inside['special-attr'].push({
2202
+ pattern: RegExp(
2203
+ /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
2204
+ 'i'
2205
+ ),
2206
+ lookbehind: true,
2207
+ inside: {
2208
+ 'attr-name': /^[^\s=]+/,
2209
+ 'attr-value': {
2210
+ pattern: /=[\s\S]+/,
2211
+ inside: {
2212
+ 'value': {
2213
+ pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
2214
+ lookbehind: true,
2215
+ alias: [lang, 'language-' + lang],
2216
+ inside: Prism.languages[lang]
2217
+ },
2218
+ 'punctuation': [
2219
+ {
2220
+ pattern: /^=/,
2221
+ alias: 'attr-equals'
2222
+ },
2223
+ /"|'/
2224
+ ]
2225
+ }
2226
+ }
2227
+ }
2228
+ });
2229
+ }
2230
+ });
2231
+
2232
+ Prism.languages.html = Prism.languages.markup;
2233
+ Prism.languages.mathml = Prism.languages.markup;
2234
+ Prism.languages.svg = Prism.languages.markup;
2235
+
2236
+ Prism.languages.xml = Prism.languages.extend('markup', {});
2237
+ Prism.languages.ssml = Prism.languages.xml;
2238
+ Prism.languages.atom = Prism.languages.xml;
2239
+ Prism.languages.rss = Prism.languages.xml;
2240
+
2241
+ Prism.languages.go = Prism.languages.extend('clike', {
2242
+ 'string': {
2243
+ pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
2244
+ greedy: true
2245
+ },
2246
+ 'keyword': /\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
2247
+ 'boolean': /\b(?:_|iota|nil|true|false)\b/,
2248
+ 'number': /(?:\b0x[a-f\d]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[-+]?\d+)?)i?/i,
2249
+ 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
2250
+ 'builtin': /\b(?:bool|byte|complex(?:64|128)|error|float(?:32|64)|rune|string|u?int(?:8|16|32|64)?|uintptr|append|cap|close|complex|copy|delete|imag|len|make|new|panic|print(?:ln)?|real|recover)\b/
2251
+ });
2252
+ delete Prism.languages.go['class-name'];
2253
+
2254
+ /**
2255
+ * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
2256
+ * Modified by Miles Johnson: http://milesj.me
2257
+ * Rewritten by Tom Pavelec
2258
+ *
2259
+ * Supports PHP 5.3 - 8.0
2260
+ */
2261
+ (function (Prism) {
2262
+ var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
2263
+ var constant = [
2264
+ {
2265
+ pattern: /\b(?:false|true)\b/i,
2266
+ alias: 'boolean'
2267
+ },
2268
+ {
2269
+ pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
2270
+ greedy: true,
2271
+ lookbehind: true,
2272
+ },
2273
+ {
2274
+ pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
2275
+ greedy: true,
2276
+ lookbehind: true,
2277
+ },
2278
+ /\b(?:null)\b/i,
2279
+ /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
2280
+ ];
2281
+ var number = /\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i;
2282
+ var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
2283
+ var punctuation = /[{}\[\](),:;]/;
2284
+
2285
+ Prism.languages.php = {
2286
+ 'delimiter': {
2287
+ pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
2288
+ alias: 'important'
2289
+ },
2290
+ 'comment': comment,
2291
+ 'variable': /\$+(?:\w+\b|(?=\{))/i,
2292
+ 'package': {
2293
+ pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
2294
+ lookbehind: true,
2295
+ inside: {
2296
+ 'punctuation': /\\/
2297
+ }
2298
+ },
2299
+ 'class-name-definition': {
2300
+ pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
2301
+ lookbehind: true,
2302
+ alias: 'class-name'
2303
+ },
2304
+ 'function-definition': {
2305
+ pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
2306
+ lookbehind: true,
2307
+ alias: 'function'
2308
+ },
2309
+ 'keyword': [
2310
+ {
2311
+ pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,
2312
+ alias: 'type-casting',
2313
+ greedy: true,
2314
+ lookbehind: true
2315
+ },
2316
+ {
2317
+ pattern: /([(,?]\s*)\b(?:bool|int|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b(?=\s*\$)/i,
2318
+ alias: 'type-hint',
2319
+ greedy: true,
2320
+ lookbehind: true
2321
+ },
2322
+ {
2323
+ pattern: /([(,?]\s*[\w|]\|\s*)(?:null|false)\b(?=\s*\$)/i,
2324
+ alias: 'type-hint',
2325
+ greedy: true,
2326
+ lookbehind: true
2327
+ },
2328
+ {
2329
+ pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b/i,
2330
+ alias: 'return-type',
2331
+ greedy: true,
2332
+ lookbehind: true
2333
+ },
2334
+ {
2335
+ pattern: /(\)\s*:\s*(?:\?\s*)?[\w|]\|\s*)(?:null|false)\b/i,
2336
+ alias: 'return-type',
2337
+ greedy: true,
2338
+ lookbehind: true
2339
+ },
2340
+ {
2341
+ pattern: /\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|iterable|(?:null|false)(?=\s*\|))\b/i,
2342
+ alias: 'type-declaration',
2343
+ greedy: true
2344
+ },
2345
+ {
2346
+ pattern: /(\|\s*)(?:null|false)\b/i,
2347
+ alias: 'type-declaration',
2348
+ greedy: true,
2349
+ lookbehind: true
2350
+ },
2351
+ {
2352
+ pattern: /\b(?:parent|self|static)(?=\s*::)/i,
2353
+ alias: 'static-context',
2354
+ greedy: true
2355
+ },
2356
+ {
2357
+ // yield from
2358
+ pattern: /(\byield\s+)from\b/i,
2359
+ lookbehind: true
2360
+ },
2361
+ // `class` is always a keyword unlike other keywords
2362
+ /\bclass\b/i,
2363
+ {
2364
+ // https://www.php.net/manual/en/reserved.keywords.php
2365
+ //
2366
+ // keywords cannot be preceded by "->"
2367
+ // the complex lookbehind means `(?<!(?:->|::)\s*)`
2368
+ pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,
2369
+ lookbehind: true
2370
+ }
2371
+ ],
2372
+ 'argument-name': {
2373
+ pattern: /([(,]\s+)\b[a-z_]\w*(?=\s*:(?!:))/i,
2374
+ lookbehind: true
2375
+ },
2376
+ 'class-name': [
2377
+ {
2378
+ pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
2379
+ greedy: true,
2380
+ lookbehind: true
2381
+ },
2382
+ {
2383
+ pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
2384
+ greedy: true,
2385
+ lookbehind: true
2386
+ },
2387
+ {
2388
+ pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
2389
+ greedy: true
2390
+ },
2391
+ {
2392
+ pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
2393
+ alias: 'class-name-fully-qualified',
2394
+ greedy: true,
2395
+ lookbehind: true,
2396
+ inside: {
2397
+ 'punctuation': /\\/
2398
+ }
2399
+ },
2400
+ {
2401
+ pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
2402
+ alias: 'class-name-fully-qualified',
2403
+ greedy: true,
2404
+ inside: {
2405
+ 'punctuation': /\\/
2406
+ }
2407
+ },
2408
+ {
2409
+ pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
2410
+ alias: 'class-name-fully-qualified',
2411
+ greedy: true,
2412
+ lookbehind: true,
2413
+ inside: {
2414
+ 'punctuation': /\\/
2415
+ }
2416
+ },
2417
+ {
2418
+ pattern: /\b[a-z_]\w*(?=\s*\$)/i,
2419
+ alias: 'type-declaration',
2420
+ greedy: true
2421
+ },
2422
+ {
2423
+ pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
2424
+ alias: ['class-name-fully-qualified', 'type-declaration'],
2425
+ greedy: true,
2426
+ inside: {
2427
+ 'punctuation': /\\/
2428
+ }
2429
+ },
2430
+ {
2431
+ pattern: /\b[a-z_]\w*(?=\s*::)/i,
2432
+ alias: 'static-context',
2433
+ greedy: true
2434
+ },
2435
+ {
2436
+ pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
2437
+ alias: ['class-name-fully-qualified', 'static-context'],
2438
+ greedy: true,
2439
+ inside: {
2440
+ 'punctuation': /\\/
2441
+ }
2442
+ },
2443
+ {
2444
+ pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
2445
+ alias: 'type-hint',
2446
+ greedy: true,
2447
+ lookbehind: true
2448
+ },
2449
+ {
2450
+ pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
2451
+ alias: ['class-name-fully-qualified', 'type-hint'],
2452
+ greedy: true,
2453
+ lookbehind: true,
2454
+ inside: {
2455
+ 'punctuation': /\\/
2456
+ }
2457
+ },
2458
+ {
2459
+ pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
2460
+ alias: 'return-type',
2461
+ greedy: true,
2462
+ lookbehind: true
2463
+ },
2464
+ {
2465
+ pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
2466
+ alias: ['class-name-fully-qualified', 'return-type'],
2467
+ greedy: true,
2468
+ lookbehind: true,
2469
+ inside: {
2470
+ 'punctuation': /\\/
2471
+ }
2472
+ }
2473
+ ],
2474
+ 'constant': constant,
2475
+ 'function': {
2476
+ pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
2477
+ lookbehind: true,
2478
+ inside: {
2479
+ 'punctuation': /\\/
2480
+ }
2481
+ },
2482
+ 'property': {
2483
+ pattern: /(->\s*)\w+/,
2484
+ lookbehind: true
2485
+ },
2486
+ 'number': number,
2487
+ 'operator': operator,
2488
+ 'punctuation': punctuation
2489
+ };
2490
+
2491
+ var string_interpolation = {
2492
+ pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
2493
+ lookbehind: true,
2494
+ inside: Prism.languages.php
2495
+ };
2496
+
2497
+ var string = [
2498
+ {
2499
+ pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
2500
+ alias: 'nowdoc-string',
2501
+ greedy: true,
2502
+ inside: {
2503
+ 'delimiter': {
2504
+ pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
2505
+ alias: 'symbol',
2506
+ inside: {
2507
+ 'punctuation': /^<<<'?|[';]$/
2508
+ }
2509
+ }
2510
+ }
2511
+ },
2512
+ {
2513
+ pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
2514
+ alias: 'heredoc-string',
2515
+ greedy: true,
2516
+ inside: {
2517
+ 'delimiter': {
2518
+ pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
2519
+ alias: 'symbol',
2520
+ inside: {
2521
+ 'punctuation': /^<<<"?|[";]$/
2522
+ }
2523
+ },
2524
+ 'interpolation': string_interpolation
2525
+ }
2526
+ },
2527
+ {
2528
+ pattern: /`(?:\\[\s\S]|[^\\`])*`/,
2529
+ alias: 'backtick-quoted-string',
2530
+ greedy: true
2531
+ },
2532
+ {
2533
+ pattern: /'(?:\\[\s\S]|[^\\'])*'/,
2534
+ alias: 'single-quoted-string',
2535
+ greedy: true
2536
+ },
2537
+ {
2538
+ pattern: /"(?:\\[\s\S]|[^\\"])*"/,
2539
+ alias: 'double-quoted-string',
2540
+ greedy: true,
2541
+ inside: {
2542
+ 'interpolation': string_interpolation
2543
+ }
2544
+ }
2545
+ ];
2546
+
2547
+ Prism.languages.insertBefore('php', 'variable', {
2548
+ 'string': string,
2549
+ 'attribute': {
2550
+ pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,
2551
+ greedy: true,
2552
+ inside: {
2553
+ 'attribute-content': {
2554
+ pattern: /^(#\[)[\s\S]+(?=\]$)/,
2555
+ lookbehind: true,
2556
+ // inside can appear subset of php
2557
+ inside: {
2558
+ 'comment': comment,
2559
+ 'string': string,
2560
+ 'attribute-class-name': [
2561
+ {
2562
+ pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
2563
+ alias: 'class-name',
2564
+ greedy: true,
2565
+ lookbehind: true
2566
+ },
2567
+ {
2568
+ pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
2569
+ alias: [
2570
+ 'class-name',
2571
+ 'class-name-fully-qualified'
2572
+ ],
2573
+ greedy: true,
2574
+ lookbehind: true,
2575
+ inside: {
2576
+ 'punctuation': /\\/
2577
+ }
2578
+ }
2579
+ ],
2580
+ 'constant': constant,
2581
+ 'number': number,
2582
+ 'operator': operator,
2583
+ 'punctuation': punctuation
2584
+ }
2585
+ },
2586
+ 'delimiter': {
2587
+ pattern: /^#\[|\]$/,
2588
+ alias: 'punctuation'
2589
+ }
2590
+ }
2591
+ },
2592
+ });
2593
+
2594
+ Prism.hooks.add('before-tokenize', function (env) {
2595
+ if (!/<\?/.test(env.code)) {
2596
+ return;
2597
+ }
2598
+
2599
+ var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/gi;
2600
+ Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
2601
+ });
2602
+
2603
+ Prism.hooks.add('after-tokenize', function (env) {
2604
+ Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
2605
+ });
2606
+
2607
+ }(Prism));
2608
+
2609
+ Prism.languages.c = Prism.languages.extend('clike', {
2610
+ 'comment': {
2611
+ pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
2612
+ greedy: true
2613
+ },
2614
+ 'class-name': {
2615
+ pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
2616
+ lookbehind: true
2617
+ },
2618
+ 'keyword': /\b(?:__attribute__|_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
2619
+ 'function': /\b[a-z_]\w*(?=\s*\()/i,
2620
+ 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
2621
+ 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
2622
+ });
2623
+
2624
+ Prism.languages.insertBefore('c', 'string', {
2625
+ 'macro': {
2626
+ // allow for multiline macro definitions
2627
+ // spaces after the # character compile fine with gcc
2628
+ pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
2629
+ lookbehind: true,
2630
+ greedy: true,
2631
+ alias: 'property',
2632
+ inside: {
2633
+ 'string': [
2634
+ {
2635
+ // highlight the path of the include statement as a string
2636
+ pattern: /^(#\s*include\s*)<[^>]+>/,
2637
+ lookbehind: true
2638
+ },
2639
+ Prism.languages.c['string']
2640
+ ],
2641
+ 'comment': Prism.languages.c['comment'],
2642
+ 'macro-name': [
2643
+ {
2644
+ pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
2645
+ lookbehind: true
2646
+ },
2647
+ {
2648
+ pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
2649
+ lookbehind: true,
2650
+ alias: 'function'
2651
+ }
2652
+ ],
2653
+ // highlight macro directives as keywords
2654
+ 'directive': {
2655
+ pattern: /^(#\s*)[a-z]+/,
2656
+ lookbehind: true,
2657
+ alias: 'keyword'
2658
+ },
2659
+ 'directive-hash': /^#/,
2660
+ 'punctuation': /##|\\(?=[\r\n])/,
2661
+ 'expression': {
2662
+ pattern: /\S[\s\S]*/,
2663
+ inside: Prism.languages.c
2664
+ }
2665
+ }
2666
+ },
2667
+ // highlight predefined macros as constants
2668
+ 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
2669
+ });
2670
+
2671
+ delete Prism.languages.c['boolean'];
2672
+
2673
+ Prism.languages.python = {
2674
+ 'comment': {
2675
+ pattern: /(^|[^\\])#.*/,
2676
+ lookbehind: true
2677
+ },
2678
+ 'string-interpolation': {
2679
+ pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
2680
+ greedy: true,
2681
+ inside: {
2682
+ 'interpolation': {
2683
+ // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
2684
+ pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
2685
+ lookbehind: true,
2686
+ inside: {
2687
+ 'format-spec': {
2688
+ pattern: /(:)[^:(){}]+(?=\}$)/,
2689
+ lookbehind: true
2690
+ },
2691
+ 'conversion-option': {
2692
+ pattern: /![sra](?=[:}]$)/,
2693
+ alias: 'punctuation'
2694
+ },
2695
+ rest: null
2696
+ }
2697
+ },
2698
+ 'string': /[\s\S]+/
2699
+ }
2700
+ },
2701
+ 'triple-quoted-string': {
2702
+ pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,
2703
+ greedy: true,
2704
+ alias: 'string'
2705
+ },
2706
+ 'string': {
2707
+ pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
2708
+ greedy: true
2709
+ },
2710
+ 'function': {
2711
+ pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
2712
+ lookbehind: true
2713
+ },
2714
+ 'class-name': {
2715
+ pattern: /(\bclass\s+)\w+/i,
2716
+ lookbehind: true
2717
+ },
2718
+ 'decorator': {
2719
+ pattern: /(^[\t ]*)@\w+(?:\.\w+)*/im,
2720
+ lookbehind: true,
2721
+ alias: ['annotation', 'punctuation'],
2722
+ inside: {
2723
+ 'punctuation': /\./
2724
+ }
2725
+ },
2726
+ 'keyword': /\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
2727
+ 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
2728
+ 'boolean': /\b(?:True|False|None)\b/,
2729
+ 'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?\b/i,
2730
+ 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
2731
+ 'punctuation': /[{}[\];(),.:]/
2732
+ };
2733
+
2734
+ Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
2735
+
2736
+ Prism.languages.py = Prism.languages.python;
2737
+
2738
+ (function (Prism) {
2739
+
2740
+ var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
2741
+
2742
+ // full package (optional) + parent classes (optional)
2743
+ var classNamePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
2744
+
2745
+ // based on the java naming conventions
2746
+ var className = {
2747
+ pattern: RegExp(classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
2748
+ lookbehind: true,
2749
+ inside: {
2750
+ 'namespace': {
2751
+ pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
2752
+ inside: {
2753
+ 'punctuation': /\./
2754
+ }
2755
+ },
2756
+ 'punctuation': /\./
2757
+ }
2758
+ };
2759
+
2760
+ Prism.languages.java = Prism.languages.extend('clike', {
2761
+ 'class-name': [
2762
+ className,
2763
+ {
2764
+ // variables and parameters
2765
+ // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
2766
+ pattern: RegExp(classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source),
2767
+ lookbehind: true,
2768
+ inside: className.inside
2769
+ }
2770
+ ],
2771
+ 'keyword': keywords,
2772
+ 'function': [
2773
+ Prism.languages.clike.function,
2774
+ {
2775
+ pattern: /(::\s*)[a-z_]\w*/,
2776
+ lookbehind: true
2777
+ }
2778
+ ],
2779
+ 'number': /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
2780
+ 'operator': {
2781
+ pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
2782
+ lookbehind: true
2783
+ }
2784
+ });
2785
+
2786
+ Prism.languages.insertBefore('java', 'string', {
2787
+ 'triple-quoted-string': {
2788
+ // http://openjdk.java.net/jeps/355#Description
2789
+ pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
2790
+ greedy: true,
2791
+ alias: 'string'
2792
+ }
2793
+ });
2794
+
2795
+ Prism.languages.insertBefore('java', 'class-name', {
2796
+ 'annotation': {
2797
+ pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
2798
+ lookbehind: true,
2799
+ alias: 'punctuation'
2800
+ },
2801
+ 'generics': {
2802
+ pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
2803
+ inside: {
2804
+ 'class-name': className,
2805
+ 'keyword': keywords,
2806
+ 'punctuation': /[<>(),.:]/,
2807
+ 'operator': /[?&|]/
2808
+ }
2809
+ },
2810
+ 'namespace': {
2811
+ pattern: RegExp(
2812
+ /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
2813
+ .source.replace(/<keyword>/g, function () { return keywords.source; })),
2814
+ lookbehind: true,
2815
+ inside: {
2816
+ 'punctuation': /\./,
2817
+ }
2818
+ }
2819
+ });
2820
+ }(Prism));
2821
+
2822
+ (function (Prism) {
2823
+
2824
+ var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
2825
+ var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; });
2826
+
2827
+ Prism.languages.cpp = Prism.languages.extend('c', {
2828
+ 'class-name': [
2829
+ {
2830
+ pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
2831
+ .replace(/<keyword>/g, function () { return keyword.source; })),
2832
+ lookbehind: true
2833
+ },
2834
+ // This is intended to capture the class name of method implementations like:
2835
+ // void foo::bar() const {}
2836
+ // However! The `foo` in the above example could also be a namespace, so we only capture the class name if
2837
+ // it starts with an uppercase letter. This approximation should give decent results.
2838
+ /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
2839
+ // This will capture the class name before destructors like:
2840
+ // Foo::~Foo() {}
2841
+ /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
2842
+ // This also intends to capture the class name of method implementations but here the class has template
2843
+ // parameters, so it can't be a namespace (until C++ adds generic namespaces).
2844
+ /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
2845
+ ],
2846
+ 'keyword': keyword,
2847
+ 'number': {
2848
+ pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
2849
+ greedy: true
2850
+ },
2851
+ 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
2852
+ 'boolean': /\b(?:true|false)\b/
2853
+ });
2854
+
2855
+ Prism.languages.insertBefore('cpp', 'string', {
2856
+ 'module': {
2857
+ // https://en.cppreference.com/w/cpp/language/modules
2858
+ pattern: RegExp(
2859
+ /(\b(?:module|import)\s+)/.source +
2860
+ '(?:' +
2861
+ // header-name
2862
+ /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
2863
+ '|' +
2864
+ // module name or partition or both
2865
+ /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) +
2866
+ ')'
2867
+ ),
2868
+ lookbehind: true,
2869
+ greedy: true,
2870
+ inside: {
2871
+ 'string': /^[<"][\s\S]+/,
2872
+ 'operator': /:/,
2873
+ 'punctuation': /\./
2874
+ }
2875
+ },
2876
+ 'raw-string': {
2877
+ pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
2878
+ alias: 'string',
2879
+ greedy: true
2880
+ }
2881
+ });
2882
+
2883
+ Prism.languages.insertBefore('cpp', 'keyword', {
2884
+ 'generic-function': {
2885
+ pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
2886
+ inside: {
2887
+ 'function': /^\w+/,
2888
+ 'generic': {
2889
+ pattern: /<[\s\S]+/,
2890
+ alias: 'class-name',
2891
+ inside: Prism.languages.cpp
2892
+ }
2893
+ }
2894
+ }
2895
+ });
2896
+
2897
+ Prism.languages.insertBefore('cpp', 'operator', {
2898
+ 'double-colon': {
2899
+ pattern: /::/,
2900
+ alias: 'punctuation'
2901
+ }
2902
+ });
2903
+
2904
+ Prism.languages.insertBefore('cpp', 'class-name', {
2905
+ // the base clause is an optional list of parent classes
2906
+ // https://en.cppreference.com/w/cpp/language/class
2907
+ 'base-clause': {
2908
+ pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
2909
+ lookbehind: true,
2910
+ greedy: true,
2911
+ inside: Prism.languages.extend('cpp', {})
2912
+ }
2913
+ });
2914
+
2915
+ Prism.languages.insertBefore('inside', 'double-colon', {
2916
+ // All untokenized words that are not namespaces should be class names
2917
+ 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i
2918
+ }, Prism.languages.cpp['base-clause']);
2919
+
2920
+ }(Prism));
2921
+
2922
+ (function (Prism) {
2923
+
2924
+ /**
2925
+ * Replaces all placeholders "<<n>>" of given pattern with the n-th replacement (zero based).
2926
+ *
2927
+ * Note: This is a simple text based replacement. Be careful when using backreferences!
2928
+ *
2929
+ * @param {string} pattern the given pattern.
2930
+ * @param {string[]} replacements a list of replacement which can be inserted into the given pattern.
2931
+ * @returns {string} the pattern with all placeholders replaced with their corresponding replacements.
2932
+ * @example replace(/a<<0>>a/.source, [/b+/.source]) === /a(?:b+)a/.source
2933
+ */
2934
+ function replace(pattern, replacements) {
2935
+ return pattern.replace(/<<(\d+)>>/g, function (m, index) {
2936
+ return '(?:' + replacements[+index] + ')';
2937
+ });
2938
+ }
2939
+ /**
2940
+ * @param {string} pattern
2941
+ * @param {string[]} replacements
2942
+ * @param {string} [flags]
2943
+ * @returns {RegExp}
2944
+ */
2945
+ function re(pattern, replacements, flags) {
2946
+ return RegExp(replace(pattern, replacements), flags || '');
2947
+ }
2948
+
2949
+ /**
2950
+ * Creates a nested pattern where all occurrences of the string `<<self>>` are replaced with the pattern itself.
2951
+ *
2952
+ * @param {string} pattern
2953
+ * @param {number} depthLog2
2954
+ * @returns {string}
2955
+ */
2956
+ function nested(pattern, depthLog2) {
2957
+ for (var i = 0; i < depthLog2; i++) {
2958
+ pattern = pattern.replace(/<<self>>/g, function () { return '(?:' + pattern + ')'; });
2959
+ }
2960
+ return pattern.replace(/<<self>>/g, '[^\\s\\S]');
2961
+ }
2962
+
2963
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
2964
+ var keywordKinds = {
2965
+ // keywords which represent a return or variable type
2966
+ type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void',
2967
+ // keywords which are used to declare a type
2968
+ typeDeclaration: 'class enum interface record struct',
2969
+ // contextual keywords
2970
+ // ("var" and "dynamic" are missing because they are used like types)
2971
+ contextual: 'add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where with(?=\\s*{)',
2972
+ // all other keywords
2973
+ other: 'abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield'
2974
+ };
2975
+
2976
+ // keywords
2977
+ function keywordsToPattern(words) {
2978
+ return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b';
2979
+ }
2980
+ var typeDeclarationKeywords = keywordsToPattern(keywordKinds.typeDeclaration);
2981
+ var keywords = RegExp(keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other));
2982
+ var nonTypeKeywords = keywordsToPattern(keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other);
2983
+ var nonContextualKeywords = keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.other);
2984
+
2985
+ // types
2986
+ var generic = nested(/<(?:[^<>;=+\-*/%&|^]|<<self>>)*>/.source, 2); // the idea behind the other forbidden characters is to prevent false positives. Same for tupleElement.
2987
+ var nestedRound = nested(/\((?:[^()]|<<self>>)*\)/.source, 2);
2988
+ var name = /@?\b[A-Za-z_]\w*\b/.source;
2989
+ var genericName = replace(/<<0>>(?:\s*<<1>>)?/.source, [name, generic]);
2990
+ var identifier = replace(/(?!<<0>>)<<1>>(?:\s*\.\s*<<1>>)*/.source, [nonTypeKeywords, genericName]);
2991
+ var array = /\[\s*(?:,\s*)*\]/.source;
2992
+ var typeExpressionWithoutTuple = replace(/<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, [identifier, array]);
2993
+ var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [generic, nestedRound, array]);
2994
+ var tuple = replace(/\(<<0>>+(?:,<<0>>+)+\)/.source, [tupleElement]);
2995
+ var typeExpression = replace(/(?:<<0>>|<<1>>)(?:\s*(?:\?\s*)?<<2>>)*(?:\s*\?)?/.source, [tuple, identifier, array]);
2996
+
2997
+ var typeInside = {
2998
+ 'keyword': keywords,
2999
+ 'punctuation': /[<>()?,.:[\]]/
3000
+ };
3001
+
3002
+ // strings & characters
3003
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#character-literals
3004
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#string-literals
3005
+ var character = /'(?:[^\r\n'\\]|\\.|\\[Uux][\da-fA-F]{1,8})'/.source; // simplified pattern
3006
+ var regularString = /"(?:\\.|[^\\"\r\n])*"/.source;
3007
+ var verbatimString = /@"(?:""|\\[\s\S]|[^\\"])*"(?!")/.source;
3008
+
3009
+
3010
+ Prism.languages.csharp = Prism.languages.extend('clike', {
3011
+ 'string': [
3012
+ {
3013
+ pattern: re(/(^|[^$\\])<<0>>/.source, [verbatimString]),
3014
+ lookbehind: true,
3015
+ greedy: true
3016
+ },
3017
+ {
3018
+ pattern: re(/(^|[^@$\\])<<0>>/.source, [regularString]),
3019
+ lookbehind: true,
3020
+ greedy: true
3021
+ },
3022
+ {
3023
+ pattern: RegExp(character),
3024
+ greedy: true,
3025
+ alias: 'character'
3026
+ }
3027
+ ],
3028
+ 'class-name': [
3029
+ {
3030
+ // Using static
3031
+ // using static System.Math;
3032
+ pattern: re(/(\busing\s+static\s+)<<0>>(?=\s*;)/.source, [identifier]),
3033
+ lookbehind: true,
3034
+ inside: typeInside
3035
+ },
3036
+ {
3037
+ // Using alias (type)
3038
+ // using Project = PC.MyCompany.Project;
3039
+ pattern: re(/(\busing\s+<<0>>\s*=\s*)<<1>>(?=\s*;)/.source, [name, typeExpression]),
3040
+ lookbehind: true,
3041
+ inside: typeInside
3042
+ },
3043
+ {
3044
+ // Using alias (alias)
3045
+ // using Project = PC.MyCompany.Project;
3046
+ pattern: re(/(\busing\s+)<<0>>(?=\s*=)/.source, [name]),
3047
+ lookbehind: true
3048
+ },
3049
+ {
3050
+ // Type declarations
3051
+ // class Foo<A, B>
3052
+ // interface Foo<out A, B>
3053
+ pattern: re(/(\b<<0>>\s+)<<1>>/.source, [typeDeclarationKeywords, genericName]),
3054
+ lookbehind: true,
3055
+ inside: typeInside
3056
+ },
3057
+ {
3058
+ // Single catch exception declaration
3059
+ // catch(Foo)
3060
+ // (things like catch(Foo e) is covered by variable declaration)
3061
+ pattern: re(/(\bcatch\s*\(\s*)<<0>>/.source, [identifier]),
3062
+ lookbehind: true,
3063
+ inside: typeInside
3064
+ },
3065
+ {
3066
+ // Name of the type parameter of generic constraints
3067
+ // where Foo : class
3068
+ pattern: re(/(\bwhere\s+)<<0>>/.source, [name]),
3069
+ lookbehind: true
3070
+ },
3071
+ {
3072
+ // Casts and checks via as and is.
3073
+ // as Foo<A>, is Bar<B>
3074
+ // (things like if(a is Foo b) is covered by variable declaration)
3075
+ pattern: re(/(\b(?:is(?:\s+not)?|as)\s+)<<0>>/.source, [typeExpressionWithoutTuple]),
3076
+ lookbehind: true,
3077
+ inside: typeInside
3078
+ },
3079
+ {
3080
+ // Variable, field and parameter declaration
3081
+ // (Foo bar, Bar baz, Foo[,,] bay, Foo<Bar, FooBar<Bar>> bax)
3082
+ pattern: re(/\b<<0>>(?=\s+(?!<<1>>|with\s*\{)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [typeExpression, nonContextualKeywords, name]),
3083
+ inside: typeInside
3084
+ }
3085
+ ],
3086
+ 'keyword': keywords,
3087
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#literals
3088
+ 'number': /(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:ul|lu|[dflmu])?\b/i,
3089
+ 'operator': />>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,
3090
+ 'punctuation': /\?\.?|::|[{}[\];(),.:]/
3091
+ });
3092
+
3093
+ Prism.languages.insertBefore('csharp', 'number', {
3094
+ 'range': {
3095
+ pattern: /\.\./,
3096
+ alias: 'operator'
3097
+ }
3098
+ });
3099
+
3100
+ Prism.languages.insertBefore('csharp', 'punctuation', {
3101
+ 'named-parameter': {
3102
+ pattern: re(/([(,]\s*)<<0>>(?=\s*:)/.source, [name]),
3103
+ lookbehind: true,
3104
+ alias: 'punctuation'
3105
+ }
3106
+ });
3107
+
3108
+ Prism.languages.insertBefore('csharp', 'class-name', {
3109
+ 'namespace': {
3110
+ // namespace Foo.Bar {}
3111
+ // using Foo.Bar;
3112
+ pattern: re(/(\b(?:namespace|using)\s+)<<0>>(?:\s*\.\s*<<0>>)*(?=\s*[;{])/.source, [name]),
3113
+ lookbehind: true,
3114
+ inside: {
3115
+ 'punctuation': /\./
3116
+ }
3117
+ },
3118
+ 'type-expression': {
3119
+ // default(Foo), typeof(Foo<Bar>), sizeof(int)
3120
+ pattern: re(/(\b(?:default|typeof|sizeof)\s*\(\s*(?!\s))(?:[^()\s]|\s(?!\s)|<<0>>)*(?=\s*\))/.source, [nestedRound]),
3121
+ lookbehind: true,
3122
+ alias: 'class-name',
3123
+ inside: typeInside
3124
+ },
3125
+ 'return-type': {
3126
+ // Foo<Bar> ForBar(); Foo IFoo.Bar() => 0
3127
+ // int this[int index] => 0; T IReadOnlyList<T>.this[int index] => this[index];
3128
+ // int Foo => 0; int Foo { get; set } = 0;
3129
+ pattern: re(/<<0>>(?=\s+(?:<<1>>\s*(?:=>|[({]|\.\s*this\s*\[)|this\s*\[))/.source, [typeExpression, identifier]),
3130
+ inside: typeInside,
3131
+ alias: 'class-name'
3132
+ },
3133
+ 'constructor-invocation': {
3134
+ // new List<Foo<Bar[]>> { }
3135
+ pattern: re(/(\bnew\s+)<<0>>(?=\s*[[({])/.source, [typeExpression]),
3136
+ lookbehind: true,
3137
+ inside: typeInside,
3138
+ alias: 'class-name'
3139
+ },
3140
+ /*'explicit-implementation': {
3141
+ // int IFoo<Foo>.Bar => 0; void IFoo<Foo<Foo>>.Foo<T>();
3142
+ pattern: replace(/\b<<0>>(?=\.<<1>>)/, className, methodOrPropertyDeclaration),
3143
+ inside: classNameInside,
3144
+ alias: 'class-name'
3145
+ },*/
3146
+ 'generic-method': {
3147
+ // foo<Bar>()
3148
+ pattern: re(/<<0>>\s*<<1>>(?=\s*\()/.source, [name, generic]),
3149
+ inside: {
3150
+ 'function': re(/^<<0>>/.source, [name]),
3151
+ 'generic': {
3152
+ pattern: RegExp(generic),
3153
+ alias: 'class-name',
3154
+ inside: typeInside
3155
+ }
3156
+ }
3157
+ },
3158
+ 'type-list': {
3159
+ // The list of types inherited or of generic constraints
3160
+ // class Foo<F> : Bar, IList<FooBar>
3161
+ // where F : Bar, IList<int>
3162
+ pattern: re(
3163
+ /\b((?:<<0>>\s+<<1>>|record\s+<<1>>\s*<<5>>|where\s+<<2>>)\s*:\s*)(?:<<3>>|<<4>>|<<1>>\s*<<5>>|<<6>>)(?:\s*,\s*(?:<<3>>|<<4>>|<<6>>))*(?=\s*(?:where|[{;]|=>|$))/.source,
3164
+ [typeDeclarationKeywords, genericName, name, typeExpression, keywords.source, nestedRound, /\bnew\s*\(\s*\)/.source]
3165
+ ),
3166
+ lookbehind: true,
3167
+ inside: {
3168
+ 'record-arguments': {
3169
+ pattern: re(/(^(?!new\s*\()<<0>>\s*)<<1>>/.source, [genericName, nestedRound]),
3170
+ lookbehind: true,
3171
+ greedy: true,
3172
+ inside: Prism.languages.csharp
3173
+ },
3174
+ 'keyword': keywords,
3175
+ 'class-name': {
3176
+ pattern: RegExp(typeExpression),
3177
+ greedy: true,
3178
+ inside: typeInside
3179
+ },
3180
+ 'punctuation': /[,()]/
3181
+ }
3182
+ },
3183
+ 'preprocessor': {
3184
+ pattern: /(^[\t ]*)#.*/m,
3185
+ lookbehind: true,
3186
+ alias: 'property',
3187
+ inside: {
3188
+ // highlight preprocessor directives as keywords
3189
+ 'directive': {
3190
+ pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,
3191
+ lookbehind: true,
3192
+ alias: 'keyword'
3193
+ }
3194
+ }
3195
+ }
3196
+ });
3197
+
3198
+ // attributes
3199
+ var regularStringOrCharacter = regularString + '|' + character;
3200
+ var regularStringCharacterOrComment = replace(/\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>/.source, [regularStringOrCharacter]);
3201
+ var roundExpression = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
3202
+
3203
+ // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/#attribute-targets
3204
+ var attrTarget = /\b(?:assembly|event|field|method|module|param|property|return|type)\b/.source;
3205
+ var attr = replace(/<<0>>(?:\s*\(<<1>>*\))?/.source, [identifier, roundExpression]);
3206
+
3207
+ Prism.languages.insertBefore('csharp', 'class-name', {
3208
+ 'attribute': {
3209
+ // Attributes
3210
+ // [Foo], [Foo(1), Bar(2, Prop = "foo")], [return: Foo(1), Bar(2)], [assembly: Foo(Bar)]
3211
+ pattern: re(/((?:^|[^\s\w>)?])\s*\[\s*)(?:<<0>>\s*:\s*)?<<1>>(?:\s*,\s*<<1>>)*(?=\s*\])/.source, [attrTarget, attr]),
3212
+ lookbehind: true,
3213
+ greedy: true,
3214
+ inside: {
3215
+ 'target': {
3216
+ pattern: re(/^<<0>>(?=\s*:)/.source, [attrTarget]),
3217
+ alias: 'keyword'
3218
+ },
3219
+ 'attribute-arguments': {
3220
+ pattern: re(/\(<<0>>*\)/.source, [roundExpression]),
3221
+ inside: Prism.languages.csharp
3222
+ },
3223
+ 'class-name': {
3224
+ pattern: RegExp(identifier),
3225
+ inside: {
3226
+ 'punctuation': /\./
3227
+ }
3228
+ },
3229
+ 'punctuation': /[:,]/
3230
+ }
3231
+ }
3232
+ });
3233
+
3234
+
3235
+ // string interpolation
3236
+ var formatString = /:[^}\r\n]+/.source;
3237
+ // multi line
3238
+ var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
3239
+ var mInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [mInterpolationRound, formatString]);
3240
+ // single line
3241
+ var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<<self>>*\)/.source, [regularStringOrCharacter]), 2);
3242
+ var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [sInterpolationRound, formatString]);
3243
+
3244
+ function createInterpolationInside(interpolation, interpolationRound) {
3245
+ return {
3246
+ 'interpolation': {
3247
+ pattern: re(/((?:^|[^{])(?:\{\{)*)<<0>>/.source, [interpolation]),
3248
+ lookbehind: true,
3249
+ inside: {
3250
+ 'format-string': {
3251
+ pattern: re(/(^\{(?:(?![}:])<<0>>)*)<<1>>(?=\}$)/.source, [interpolationRound, formatString]),
3252
+ lookbehind: true,
3253
+ inside: {
3254
+ 'punctuation': /^:/
3255
+ }
3256
+ },
3257
+ 'punctuation': /^\{|\}$/,
3258
+ 'expression': {
3259
+ pattern: /[\s\S]+/,
3260
+ alias: 'language-csharp',
3261
+ inside: Prism.languages.csharp
3262
+ }
3263
+ }
3264
+ },
3265
+ 'string': /[\s\S]+/
3266
+ };
3267
+ }
3268
+
3269
+ Prism.languages.insertBefore('csharp', 'string', {
3270
+ 'interpolation-string': [
3271
+ {
3272
+ pattern: re(/(^|[^\\])(?:\$@|@\$)"(?:""|\\[\s\S]|\{\{|<<0>>|[^\\{"])*"/.source, [mInterpolation]),
3273
+ lookbehind: true,
3274
+ greedy: true,
3275
+ inside: createInterpolationInside(mInterpolation, mInterpolationRound),
3276
+ },
3277
+ {
3278
+ pattern: re(/(^|[^@\\])\$"(?:\\.|\{\{|<<0>>|[^\\"{])*"/.source, [sInterpolation]),
3279
+ lookbehind: true,
3280
+ greedy: true,
3281
+ inside: createInterpolationInside(sInterpolation, sInterpolationRound),
3282
+ }
3283
+ ]
3284
+ });
3285
+
3286
+ }(Prism));
3287
+
3288
+ Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp;
3289
+
3290
+ Prism.languages['visual-basic'] = {
3291
+ 'comment': {
3292
+ pattern: /(?:['‘’]|REM\b)(?:[^\r\n_]|_(?:\r\n?|\n)?)*/i,
3293
+ inside: {
3294
+ 'keyword': /^REM/i
3295
+ }
3296
+ },
3297
+ 'directive': {
3298
+ pattern: /#(?:Const|Else|ElseIf|End|ExternalChecksum|ExternalSource|If|Region)(?:[^\S\r\n]_[^\S\r\n]*(?:\r\n?|\n)|.)+/i,
3299
+ alias: 'comment',
3300
+ greedy: true
3301
+ },
3302
+ 'string': {
3303
+ pattern: /\$?["“”](?:["“”]{2}|[^"“”])*["“”]C?/i,
3304
+ greedy: true
3305
+ },
3306
+ 'date': {
3307
+ pattern: /#[^\S\r\n]*(?:\d+([/-])\d+\1\d+(?:[^\S\r\n]+(?:\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?))?|\d+[^\S\r\n]*(?:AM|PM)|\d+:\d+(?::\d+)?(?:[^\S\r\n]*(?:AM|PM))?)[^\S\r\n]*#/i,
3308
+ alias: 'builtin'
3309
+ },
3310
+ 'number': /(?:(?:\b\d+(?:\.\d+)?|\.\d+)(?:E[+-]?\d+)?|&[HO][\dA-F]+)(?:U?[ILS]|[FRD])?/i,
3311
+ 'boolean': /\b(?:True|False|Nothing)\b/i,
3312
+ 'keyword': /\b(?:AddHandler|AddressOf|Alias|And(?:Also)?|As|Boolean|ByRef|Byte|ByVal|Call|Case|Catch|C(?:Bool|Byte|Char|Date|Dbl|Dec|Int|Lng|Obj|SByte|Short|Sng|Str|Type|UInt|ULng|UShort)|Char|Class|Const|Continue|Currency|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|Each|Else(?:If)?|End(?:If)?|Enum|Erase|Error|Event|Exit|Finally|For|Friend|Function|Get(?:Type|XMLNamespace)?|Global|GoSub|GoTo|Handles|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|Let|Lib|Like|Long|Loop|Me|Mod|Module|Must(?:Inherit|Override)|My(?:Base|Class)|Namespace|Narrowing|New|Next|Not(?:Inheritable|Overridable)?|Object|Of|On|Operator|Option(?:al)?|Or(?:Else)?|Out|Overloads|Overridable|Overrides|ParamArray|Partial|Private|Property|Protected|Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|Return|SByte|Select|Set|Shadows|Shared|short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|Then|Throw|To|Try|TryCast|Type|TypeOf|U(?:Integer|Long|Short)|Using|Variant|Wend|When|While|Widening|With(?:Events)?|WriteOnly|Until|Xor)\b/i,
3313
+ 'operator': [
3314
+ /[+\-*/\\^<=>&#@$%!]/,
3315
+ {
3316
+ pattern: /([^\S\r\n])_(?=[^\S\r\n]*[\r\n])/,
3317
+ lookbehind: true
3318
+ }
3319
+ ],
3320
+ 'punctuation': /[{}().,:?]/
3321
+ };
3322
+
3323
+ Prism.languages.vb = Prism.languages['visual-basic'];
3324
+ Prism.languages.vba = Prism.languages['visual-basic'];
3325
+
3326
+ Prism.languages.sql = {
3327
+ 'comment': {
3328
+ pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
3329
+ lookbehind: true
3330
+ },
3331
+ 'variable': [
3332
+ {
3333
+ pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
3334
+ greedy: true
3335
+ },
3336
+ /@[\w.$]+/
3337
+ ],
3338
+ 'string': {
3339
+ pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
3340
+ greedy: true,
3341
+ lookbehind: true
3342
+ },
3343
+ 'function': /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i, // Should we highlight user defined functions too?
3344
+ 'keyword': /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:S|ING)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
3345
+ 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
3346
+ 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
3347
+ 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|IN|ILIKE|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
3348
+ 'punctuation': /[;[\]()`,.]/
3349
+ };
3350
+
3351
+ /**
3352
+ * Original by Samuel Flores
3353
+ *
3354
+ * Adds the following new token classes:
3355
+ * constant, builtin, variable, symbol, regex
3356
+ */
3357
+ (function (Prism) {
3358
+ Prism.languages.ruby = Prism.languages.extend('clike', {
3359
+ 'comment': [
3360
+ /#.*/,
3361
+ {
3362
+ pattern: /^=begin\s[\s\S]*?^=end/m,
3363
+ greedy: true
3364
+ }
3365
+ ],
3366
+ 'class-name': {
3367
+ pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
3368
+ lookbehind: true,
3369
+ inside: {
3370
+ 'punctuation': /[.\\]/
3371
+ }
3372
+ },
3373
+ 'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/
3374
+ });
3375
+
3376
+ var interpolation = {
3377
+ pattern: /#\{[^}]+\}/,
3378
+ inside: {
3379
+ 'delimiter': {
3380
+ pattern: /^#\{|\}$/,
3381
+ alias: 'tag'
3382
+ },
3383
+ rest: Prism.languages.ruby
3384
+ }
3385
+ };
3386
+
3387
+ delete Prism.languages.ruby.function;
3388
+
3389
+ Prism.languages.insertBefore('ruby', 'keyword', {
3390
+ 'regex': [
3391
+ {
3392
+ pattern: RegExp(/%r/.source + '(?:' + [
3393
+ /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
3394
+ /\((?:[^()\\]|\\[\s\S])*\)/.source,
3395
+ // Here we need to specifically allow interpolation
3396
+ /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
3397
+ /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
3398
+ /<(?:[^<>\\]|\\[\s\S])*>/.source
3399
+ ].join('|') + ')' + /[egimnosux]{0,6}/.source),
3400
+ greedy: true,
3401
+ inside: {
3402
+ 'interpolation': interpolation
3403
+ }
3404
+ },
3405
+ {
3406
+ pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
3407
+ lookbehind: true,
3408
+ greedy: true,
3409
+ inside: {
3410
+ 'interpolation': interpolation
3411
+ }
3412
+ }
3413
+ ],
3414
+ 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
3415
+ 'symbol': {
3416
+ pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
3417
+ lookbehind: true
3418
+ },
3419
+ 'method-definition': {
3420
+ pattern: /(\bdef\s+)[\w.]+/,
3421
+ lookbehind: true,
3422
+ inside: {
3423
+ 'function': /\w+$/,
3424
+ rest: Prism.languages.ruby
3425
+ }
3426
+ }
3427
+ });
3428
+
3429
+ Prism.languages.insertBefore('ruby', 'number', {
3430
+ 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
3431
+ 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
3432
+ });
3433
+
3434
+ Prism.languages.ruby.string = [
3435
+ {
3436
+ pattern: RegExp(/%[qQiIwWxs]?/.source + '(?:' + [
3437
+ /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
3438
+ /\((?:[^()\\]|\\[\s\S])*\)/.source,
3439
+ // Here we need to specifically allow interpolation
3440
+ /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
3441
+ /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
3442
+ /<(?:[^<>\\]|\\[\s\S])*>/.source
3443
+ ].join('|') + ')'),
3444
+ greedy: true,
3445
+ inside: {
3446
+ 'interpolation': interpolation
3447
+ }
3448
+ },
3449
+ {
3450
+ pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
3451
+ greedy: true,
3452
+ inside: {
3453
+ 'interpolation': interpolation
3454
+ }
3455
+ },
3456
+ {
3457
+ pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
3458
+ alias: 'heredoc-string',
3459
+ greedy: true,
3460
+ inside: {
3461
+ 'delimiter': {
3462
+ pattern: /^<<[-~]?[a-z_]\w*|[a-z_]\w*$/i,
3463
+ alias: 'symbol',
3464
+ inside: {
3465
+ 'punctuation': /^<<[-~]?/
3466
+ }
3467
+ },
3468
+ 'interpolation': interpolation
3469
+ }
3470
+ },
3471
+ {
3472
+ pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
3473
+ alias: 'heredoc-string',
3474
+ greedy: true,
3475
+ inside: {
3476
+ 'delimiter': {
3477
+ pattern: /^<<[-~]?'[a-z_]\w*'|[a-z_]\w*$/i,
3478
+ alias: 'symbol',
3479
+ inside: {
3480
+ 'punctuation': /^<<[-~]?'|'$/,
3481
+ }
3482
+ }
3483
+ }
3484
+ }
3485
+ ];
3486
+
3487
+ Prism.languages.rb = Prism.languages.ruby;
3488
+ }(Prism));
3489
+
3490
+ Prism.languages.swift = {
3491
+ 'comment': {
3492
+ // Nested comments are supported up to 2 levels
3493
+ pattern: /(^|[^\\:])(?:\/\/.*|\/\*(?:[^/*]|\/(?!\*)|\*(?!\/)|\/\*(?:[^*]|\*(?!\/))*\*\/)*\*\/)/,
3494
+ lookbehind: true,
3495
+ greedy: true
3496
+ },
3497
+ 'string-literal': [
3498
+ // https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html
3499
+ {
3500
+ pattern: RegExp(
3501
+ /(^|[^"#])/.source
3502
+ + '(?:'
3503
+ // single-line string
3504
+ + /"(?:\\(?:\((?:[^()]|\([^()]*\))*\)|\r\n|[^(])|[^\\\r\n"])*"/.source
3505
+ + '|'
3506
+ // multi-line string
3507
+ + /"""(?:\\(?:\((?:[^()]|\([^()]*\))*\)|[^(])|[^\\"]|"(?!""))*"""/.source
3508
+ + ')'
3509
+ + /(?!["#])/.source
3510
+ ),
3511
+ lookbehind: true,
3512
+ greedy: true,
3513
+ inside: {
3514
+ 'interpolation': {
3515
+ pattern: /(\\\()(?:[^()]|\([^()]*\))*(?=\))/,
3516
+ lookbehind: true,
3517
+ inside: null // see below
3518
+ },
3519
+ 'interpolation-punctuation': {
3520
+ pattern: /^\)|\\\($/,
3521
+ alias: 'punctuation'
3522
+ },
3523
+ 'punctuation': /\\(?=[\r\n])/,
3524
+ 'string': /[\s\S]+/
3525
+ }
3526
+ },
3527
+ {
3528
+ pattern: RegExp(
3529
+ /(^|[^"#])(#+)/.source
3530
+ + '(?:'
3531
+ // single-line string
3532
+ + /"(?:\\(?:#+\((?:[^()]|\([^()]*\))*\)|\r\n|[^#])|[^\\\r\n])*?"/.source
3533
+ + '|'
3534
+ // multi-line string
3535
+ + /"""(?:\\(?:#+\((?:[^()]|\([^()]*\))*\)|[^#])|[^\\])*?"""/.source
3536
+ + ')'
3537
+ + '\\2'
3538
+ ),
3539
+ lookbehind: true,
3540
+ greedy: true,
3541
+ inside: {
3542
+ 'interpolation': {
3543
+ pattern: /(\\#+\()(?:[^()]|\([^()]*\))*(?=\))/,
3544
+ lookbehind: true,
3545
+ inside: null // see below
3546
+ },
3547
+ 'interpolation-punctuation': {
3548
+ pattern: /^\)|\\#+\($/,
3549
+ alias: 'punctuation'
3550
+ },
3551
+ 'string': /[\s\S]+/
3552
+ }
3553
+ },
3554
+ ],
3555
+
3556
+ 'directive': {
3557
+ // directives with conditions
3558
+ pattern: RegExp(
3559
+ /#/.source
3560
+ + '(?:'
3561
+ + (
3562
+ /(?:elseif|if)\b/.source
3563
+ + '(?:[ \t]*'
3564
+ // This regex is a little complex. It's equivalent to this:
3565
+ // (?:![ \t]*)?(?:\b\w+\b(?:[ \t]*<round>)?|<round>)(?:[ \t]*(?:&&|\|\|))?
3566
+ // where <round> is a general parentheses expression.
3567
+ + /(?:![ \t]*)?(?:\b\w+\b(?:[ \t]*\((?:[^()]|\([^()]*\))*\))?|\((?:[^()]|\([^()]*\))*\))(?:[ \t]*(?:&&|\|\|))?/.source
3568
+ + ')+'
3569
+ )
3570
+ + '|'
3571
+ + /(?:else|endif)\b/.source
3572
+ + ')'
3573
+ ),
3574
+ alias: 'property',
3575
+ inside: {
3576
+ 'directive-name': /^#\w+/,
3577
+ 'boolean': /\b(?:true|false)\b/,
3578
+ 'number': /\b\d+(?:\.\d+)*\b/,
3579
+ 'operator': /!|&&|\|\||[<>]=?/,
3580
+ 'punctuation': /[(),]/
3581
+ }
3582
+ },
3583
+ 'literal': {
3584
+ pattern: /#(?:colorLiteral|column|dsohandle|file(?:ID|Literal|Path)?|function|imageLiteral|line)\b/,
3585
+ alias: 'constant'
3586
+ },
3587
+ 'other-directive': {
3588
+ pattern: /#\w+\b/,
3589
+ alias: 'property'
3590
+ },
3591
+
3592
+ 'attribute': {
3593
+ pattern: /@\w+/,
3594
+ alias: 'atrule'
3595
+ },
3596
+
3597
+ 'function-definition': {
3598
+ pattern: /(\bfunc\s+)\w+/,
3599
+ lookbehind: true,
3600
+ alias: 'function'
3601
+ },
3602
+ 'label': {
3603
+ // https://docs.swift.org/swift-book/LanguageGuide/ControlFlow.html#ID141
3604
+ pattern: /\b(break|continue)\s+\w+|\b[a-zA-Z_]\w*(?=\s*:\s*(?:for|repeat|while)\b)/,
3605
+ lookbehind: true,
3606
+ alias: 'important'
3607
+ },
3608
+
3609
+ 'keyword': /\b(?:Any|Protocol|Self|Type|actor|as|assignment|associatedtype|associativity|async|await|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic|else|enum|extension|fallthrough|fileprivate|final|for|func|get|guard|higherThan|if|import|in|indirect|infix|init|inout|internal|is|lazy|left|let|lowerThan|mutating|none|nonisolated|nonmutating|open|operator|optional|override|postfix|precedencegroup|prefix|private|protocol|public|repeat|required|rethrows|return|right|safe|self|set|some|static|struct|subscript|super|switch|throw|throws|try|typealias|unowned|unsafe|var|weak|where|while|willSet)\b/,
3610
+ 'boolean': /\b(?:true|false)\b/,
3611
+ 'nil': {
3612
+ pattern: /\bnil\b/,
3613
+ alias: 'constant'
3614
+ },
3615
+
3616
+ 'short-argument': /\$\d+\b/,
3617
+ 'omit': {
3618
+ pattern: /\b_\b/,
3619
+ alias: 'keyword'
3620
+ },
3621
+ 'number': /\b(?:[\d_]+(?:\.[\de_]+)?|0x[a-f0-9_]+(?:\.[a-f0-9p_]+)?|0b[01_]+|0o[0-7_]+)\b/i,
3622
+
3623
+ // A class name must start with an upper-case letter and be either 1 letter long or contain a lower-case letter.
3624
+ 'class-name': /\b[A-Z](?:[A-Z_\d]*[a-z]\w*)?\b/,
3625
+ 'function': /\b[a-z_]\w*(?=\s*\()/i,
3626
+ 'constant': /\b(?:[A-Z_]{2,}|k[A-Z][A-Za-z_]+)\b/,
3627
+
3628
+ // Operators are generic in Swift. Developers can even create new operators (e.g. +++).
3629
+ // https://docs.swift.org/swift-book/ReferenceManual/zzSummaryOfTheGrammar.html#ID481
3630
+ // This regex only supports ASCII operators.
3631
+ 'operator': /[-+*/%=!<>&|^~?]+|\.[.\-+*/%=!<>&|^~?]+/,
3632
+ 'punctuation': /[{}[\]();,.:\\]/
3633
+ };
3634
+
3635
+ Prism.languages.swift['string-literal'].forEach(function (rule) {
3636
+ rule.inside['interpolation'].inside = Prism.languages.swift;
3637
+ });
3638
+
3639
+ (function (Prism) {
3640
+ // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
3641
+ // + LC_ALL, RANDOM, REPLY, SECONDS.
3642
+ // + make sure PS1..4 are here as they are not always set,
3643
+ // - some useless things.
3644
+ var envVars = '\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b';
3645
+
3646
+ var commandAfterHeredoc = {
3647
+ pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
3648
+ lookbehind: true,
3649
+ alias: 'punctuation', // this looks reasonably well in all themes
3650
+ inside: null // see below
3651
+ };
3652
+
3653
+ var insideString = {
3654
+ 'bash': commandAfterHeredoc,
3655
+ 'environment': {
3656
+ pattern: RegExp('\\$' + envVars),
3657
+ alias: 'constant'
3658
+ },
3659
+ 'variable': [
3660
+ // [0]: Arithmetic Environment
3661
+ {
3662
+ pattern: /\$?\(\([\s\S]+?\)\)/,
3663
+ greedy: true,
3664
+ inside: {
3665
+ // If there is a $ sign at the beginning highlight $(( and )) as variable
3666
+ 'variable': [
3667
+ {
3668
+ pattern: /(^\$\(\([\s\S]+)\)\)/,
3669
+ lookbehind: true
3670
+ },
3671
+ /^\$\(\(/
3672
+ ],
3673
+ 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
3674
+ // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
3675
+ 'operator': /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
3676
+ // If there is no $ sign at the beginning highlight (( and )) as punctuation
3677
+ 'punctuation': /\(\(?|\)\)?|,|;/
3678
+ }
3679
+ },
3680
+ // [1]: Command Substitution
3681
+ {
3682
+ pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
3683
+ greedy: true,
3684
+ inside: {
3685
+ 'variable': /^\$\(|^`|\)$|`$/
3686
+ }
3687
+ },
3688
+ // [2]: Brace expansion
3689
+ {
3690
+ pattern: /\$\{[^}]+\}/,
3691
+ greedy: true,
3692
+ inside: {
3693
+ 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
3694
+ 'punctuation': /[\[\]]/,
3695
+ 'environment': {
3696
+ pattern: RegExp('(\\{)' + envVars),
3697
+ lookbehind: true,
3698
+ alias: 'constant'
3699
+ }
3700
+ }
3701
+ },
3702
+ /\$(?:\w+|[#?*!@$])/
3703
+ ],
3704
+ // Escape sequences from echo and printf's manuals, and escaped quotes.
3705
+ 'entity': /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})/
3706
+ };
3707
+
3708
+ Prism.languages.bash = {
3709
+ 'shebang': {
3710
+ pattern: /^#!\s*\/.*/,
3711
+ alias: 'important'
3712
+ },
3713
+ 'comment': {
3714
+ pattern: /(^|[^"{\\$])#.*/,
3715
+ lookbehind: true
3716
+ },
3717
+ 'function-name': [
3718
+ // a) function foo {
3719
+ // b) foo() {
3720
+ // c) function foo() {
3721
+ // but not “foo {”
3722
+ {
3723
+ // a) and c)
3724
+ pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
3725
+ lookbehind: true,
3726
+ alias: 'function'
3727
+ },
3728
+ {
3729
+ // b)
3730
+ pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/,
3731
+ alias: 'function'
3732
+ }
3733
+ ],
3734
+ // Highlight variable names as variables in for and select beginnings.
3735
+ 'for-or-select': {
3736
+ pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
3737
+ alias: 'variable',
3738
+ lookbehind: true
3739
+ },
3740
+ // Highlight variable names as variables in the left-hand part
3741
+ // of assignments (“=” and “+=”).
3742
+ 'assign-left': {
3743
+ pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
3744
+ inside: {
3745
+ 'environment': {
3746
+ pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars),
3747
+ lookbehind: true,
3748
+ alias: 'constant'
3749
+ }
3750
+ },
3751
+ alias: 'variable',
3752
+ lookbehind: true
3753
+ },
3754
+ 'string': [
3755
+ // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
3756
+ {
3757
+ pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,
3758
+ lookbehind: true,
3759
+ greedy: true,
3760
+ inside: insideString
3761
+ },
3762
+ // Here-document with quotes around the tag
3763
+ // → No expansion (so no “inside”).
3764
+ {
3765
+ pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
3766
+ lookbehind: true,
3767
+ greedy: true,
3768
+ inside: {
3769
+ 'bash': commandAfterHeredoc
3770
+ }
3771
+ },
3772
+ // “Normal” string
3773
+ {
3774
+ // https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
3775
+ pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
3776
+ lookbehind: true,
3777
+ greedy: true,
3778
+ inside: insideString
3779
+ },
3780
+ {
3781
+ // https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html
3782
+ pattern: /(^|[^$\\])'[^']*'/,
3783
+ lookbehind: true,
3784
+ greedy: true
3785
+ },
3786
+ {
3787
+ // https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
3788
+ pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
3789
+ greedy: true,
3790
+ inside: {
3791
+ 'entity': insideString.entity
3792
+ }
3793
+ }
3794
+ ],
3795
+ 'environment': {
3796
+ pattern: RegExp('\\$?' + envVars),
3797
+ alias: 'constant'
3798
+ },
3799
+ 'variable': insideString.variable,
3800
+ 'function': {
3801
+ pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|aptitude|apt-cache|apt-get|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,
3802
+ lookbehind: true
3803
+ },
3804
+ 'keyword': {
3805
+ pattern: /(^|[\s;|&]|[<>]\()(?:if|then|else|elif|fi|for|while|in|case|esac|function|select|do|done|until)(?=$|[)\s;|&])/,
3806
+ lookbehind: true
3807
+ },
3808
+ // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
3809
+ 'builtin': {
3810
+ pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|break|cd|continue|eval|exec|exit|export|getopts|hash|pwd|readonly|return|shift|test|times|trap|umask|unset|alias|bind|builtin|caller|command|declare|echo|enable|help|let|local|logout|mapfile|printf|read|readarray|source|type|typeset|ulimit|unalias|set|shopt)(?=$|[)\s;|&])/,
3811
+ lookbehind: true,
3812
+ // Alias added to make those easier to distinguish from strings.
3813
+ alias: 'class-name'
3814
+ },
3815
+ 'boolean': {
3816
+ pattern: /(^|[\s;|&]|[<>]\()(?:true|false)(?=$|[)\s;|&])/,
3817
+ lookbehind: true
3818
+ },
3819
+ 'file-descriptor': {
3820
+ pattern: /\B&\d\b/,
3821
+ alias: 'important'
3822
+ },
3823
+ 'operator': {
3824
+ // Lots of redirections here, but not just that.
3825
+ pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,
3826
+ inside: {
3827
+ 'file-descriptor': {
3828
+ pattern: /^\d/,
3829
+ alias: 'important'
3830
+ }
3831
+ }
3832
+ },
3833
+ 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
3834
+ 'number': {
3835
+ pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
3836
+ lookbehind: true
3837
+ }
3838
+ };
3839
+
3840
+ commandAfterHeredoc.inside = Prism.languages.bash;
3841
+
3842
+ /* Patterns in command substitution. */
3843
+ var toBeCopied = [
3844
+ 'comment',
3845
+ 'function-name',
3846
+ 'for-or-select',
3847
+ 'assign-left',
3848
+ 'string',
3849
+ 'environment',
3850
+ 'function',
3851
+ 'keyword',
3852
+ 'builtin',
3853
+ 'boolean',
3854
+ 'file-descriptor',
3855
+ 'operator',
3856
+ 'punctuation',
3857
+ 'number'
3858
+ ];
3859
+ var inside = insideString.variable[1].inside;
3860
+ for (var i = 0; i < toBeCopied.length; i++) {
3861
+ inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
3862
+ }
3863
+
3864
+ Prism.languages.shell = Prism.languages.bash;
3865
+ }(Prism));
3866
+
3867
+ (function (Prism) {
3868
+
3869
+ // Allow only one line break
3870
+ var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;
3871
+
3872
+ /**
3873
+ * This function is intended for the creation of the bold or italic pattern.
3874
+ *
3875
+ * This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
3876
+ *
3877
+ * _Note:_ Keep in mind that this adds a capturing group.
3878
+ *
3879
+ * @param {string} pattern
3880
+ * @returns {RegExp}
3881
+ */
3882
+ function createInline(pattern) {
3883
+ pattern = pattern.replace(/<inner>/g, function () { return inner; });
3884
+ return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')');
3885
+ }
3886
+
3887
+
3888
+ var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
3889
+ var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g, function () { return tableCell; });
3890
+ var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
3891
+
3892
+
3893
+ Prism.languages.markdown = Prism.languages.extend('markup', {});
3894
+ Prism.languages.insertBefore('markdown', 'prolog', {
3895
+ 'front-matter-block': {
3896
+ pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
3897
+ lookbehind: true,
3898
+ greedy: true,
3899
+ inside: {
3900
+ 'punctuation': /^---|---$/,
3901
+ 'font-matter': {
3902
+ pattern: /\S+(?:\s+\S+)*/,
3903
+ alias: ['yaml', 'language-yaml'],
3904
+ inside: Prism.languages.yaml
3905
+ }
3906
+ }
3907
+ },
3908
+ 'blockquote': {
3909
+ // > ...
3910
+ pattern: /^>(?:[\t ]*>)*/m,
3911
+ alias: 'punctuation'
3912
+ },
3913
+ 'table': {
3914
+ pattern: RegExp('^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm'),
3915
+ inside: {
3916
+ 'table-data-rows': {
3917
+ pattern: RegExp('^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$'),
3918
+ lookbehind: true,
3919
+ inside: {
3920
+ 'table-data': {
3921
+ pattern: RegExp(tableCell),
3922
+ inside: Prism.languages.markdown
3923
+ },
3924
+ 'punctuation': /\|/
3925
+ }
3926
+ },
3927
+ 'table-line': {
3928
+ pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'),
3929
+ lookbehind: true,
3930
+ inside: {
3931
+ 'punctuation': /\||:?-{3,}:?/
3932
+ }
3933
+ },
3934
+ 'table-header-row': {
3935
+ pattern: RegExp('^' + tableRow + '$'),
3936
+ inside: {
3937
+ 'table-header': {
3938
+ pattern: RegExp(tableCell),
3939
+ alias: 'important',
3940
+ inside: Prism.languages.markdown
3941
+ },
3942
+ 'punctuation': /\|/
3943
+ }
3944
+ }
3945
+ }
3946
+ },
3947
+ 'code': [
3948
+ {
3949
+ // Prefixed by 4 spaces or 1 tab and preceded by an empty line
3950
+ pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
3951
+ lookbehind: true,
3952
+ alias: 'keyword'
3953
+ },
3954
+ {
3955
+ // ```optional language
3956
+ // code block
3957
+ // ```
3958
+ pattern: /^```[\s\S]*?^```$/m,
3959
+ greedy: true,
3960
+ inside: {
3961
+ 'code-block': {
3962
+ pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
3963
+ lookbehind: true
3964
+ },
3965
+ 'code-language': {
3966
+ pattern: /^(```).+/,
3967
+ lookbehind: true
3968
+ },
3969
+ 'punctuation': /```/
3970
+ }
3971
+ }
3972
+ ],
3973
+ 'title': [
3974
+ {
3975
+ // title 1
3976
+ // =======
3977
+
3978
+ // title 2
3979
+ // -------
3980
+ pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
3981
+ alias: 'important',
3982
+ inside: {
3983
+ punctuation: /==+$|--+$/
3984
+ }
3985
+ },
3986
+ {
3987
+ // # title 1
3988
+ // ###### title 6
3989
+ pattern: /(^\s*)#.+/m,
3990
+ lookbehind: true,
3991
+ alias: 'important',
3992
+ inside: {
3993
+ punctuation: /^#+|#+$/
3994
+ }
3995
+ }
3996
+ ],
3997
+ 'hr': {
3998
+ // ***
3999
+ // ---
4000
+ // * * *
4001
+ // -----------
4002
+ pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
4003
+ lookbehind: true,
4004
+ alias: 'punctuation'
4005
+ },
4006
+ 'list': {
4007
+ // * item
4008
+ // + item
4009
+ // - item
4010
+ // 1. item
4011
+ pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
4012
+ lookbehind: true,
4013
+ alias: 'punctuation'
4014
+ },
4015
+ 'url-reference': {
4016
+ // [id]: http://example.com "Optional title"
4017
+ // [id]: http://example.com 'Optional title'
4018
+ // [id]: http://example.com (Optional title)
4019
+ // [id]: <http://example.com> "Optional title"
4020
+ pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
4021
+ inside: {
4022
+ 'variable': {
4023
+ pattern: /^(!?\[)[^\]]+/,
4024
+ lookbehind: true
4025
+ },
4026
+ 'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
4027
+ 'punctuation': /^[\[\]!:]|[<>]/
4028
+ },
4029
+ alias: 'url'
4030
+ },
4031
+ 'bold': {
4032
+ // **strong**
4033
+ // __strong__
4034
+
4035
+ // allow one nested instance of italic text using the same delimiter
4036
+ pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
4037
+ lookbehind: true,
4038
+ greedy: true,
4039
+ inside: {
4040
+ 'content': {
4041
+ pattern: /(^..)[\s\S]+(?=..$)/,
4042
+ lookbehind: true,
4043
+ inside: {} // see below
4044
+ },
4045
+ 'punctuation': /\*\*|__/
4046
+ }
4047
+ },
4048
+ 'italic': {
4049
+ // *em*
4050
+ // _em_
4051
+
4052
+ // allow one nested instance of bold text using the same delimiter
4053
+ pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
4054
+ lookbehind: true,
4055
+ greedy: true,
4056
+ inside: {
4057
+ 'content': {
4058
+ pattern: /(^.)[\s\S]+(?=.$)/,
4059
+ lookbehind: true,
4060
+ inside: {} // see below
4061
+ },
4062
+ 'punctuation': /[*_]/
4063
+ }
4064
+ },
4065
+ 'strike': {
4066
+ // ~~strike through~~
4067
+ // ~strike~
4068
+ // eslint-disable-next-line regexp/strict
4069
+ pattern: createInline(/(~~?)(?:(?!~)<inner>)+\2/.source),
4070
+ lookbehind: true,
4071
+ greedy: true,
4072
+ inside: {
4073
+ 'content': {
4074
+ pattern: /(^~~?)[\s\S]+(?=\1$)/,
4075
+ lookbehind: true,
4076
+ inside: {} // see below
4077
+ },
4078
+ 'punctuation': /~~?/
4079
+ }
4080
+ },
4081
+ 'code-snippet': {
4082
+ // `code`
4083
+ // ``code``
4084
+ pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,
4085
+ lookbehind: true,
4086
+ greedy: true,
4087
+ alias: ['code', 'keyword']
4088
+ },
4089
+ 'url': {
4090
+ // [example](http://example.com "Optional title")
4091
+ // [example][id]
4092
+ // [example] [id]
4093
+ pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\])<inner>)+\])/.source),
4094
+ lookbehind: true,
4095
+ greedy: true,
4096
+ inside: {
4097
+ 'operator': /^!/,
4098
+ 'content': {
4099
+ pattern: /(^\[)[^\]]+(?=\])/,
4100
+ lookbehind: true,
4101
+ inside: {} // see below
4102
+ },
4103
+ 'variable': {
4104
+ pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/,
4105
+ lookbehind: true
4106
+ },
4107
+ 'url': {
4108
+ pattern: /(^\]\()[^\s)]+/,
4109
+ lookbehind: true
4110
+ },
4111
+ 'string': {
4112
+ pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,
4113
+ lookbehind: true
4114
+ }
4115
+ }
4116
+ }
4117
+ });
4118
+
4119
+ ['url', 'bold', 'italic', 'strike'].forEach(function (token) {
4120
+ ['url', 'bold', 'italic', 'strike', 'code-snippet'].forEach(function (inside) {
4121
+ if (token !== inside) {
4122
+ Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
4123
+ }
4124
+ });
4125
+ });
4126
+
4127
+ Prism.hooks.add('after-tokenize', function (env) {
4128
+ if (env.language !== 'markdown' && env.language !== 'md') {
4129
+ return;
4130
+ }
4131
+
4132
+ function walkTokens(tokens) {
4133
+ if (!tokens || typeof tokens === 'string') {
4134
+ return;
4135
+ }
4136
+
4137
+ for (var i = 0, l = tokens.length; i < l; i++) {
4138
+ var token = tokens[i];
4139
+
4140
+ if (token.type !== 'code') {
4141
+ walkTokens(token.content);
4142
+ continue;
4143
+ }
4144
+
4145
+ /*
4146
+ * Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
4147
+ * is optional. But the grammar is defined so that there is only one case we have to handle:
4148
+ *
4149
+ * token.content = [
4150
+ * <span class="punctuation">```</span>,
4151
+ * <span class="code-language">xxxx</span>,
4152
+ * '\n', // exactly one new lines (\r or \n or \r\n)
4153
+ * <span class="code-block">...</span>,
4154
+ * '\n', // exactly one new lines again
4155
+ * <span class="punctuation">```</span>
4156
+ * ];
4157
+ */
4158
+
4159
+ var codeLang = token.content[1];
4160
+ var codeBlock = token.content[3];
4161
+
4162
+ if (codeLang && codeBlock &&
4163
+ codeLang.type === 'code-language' && codeBlock.type === 'code-block' &&
4164
+ typeof codeLang.content === 'string') {
4165
+
4166
+ // this might be a language that Prism does not support
4167
+
4168
+ // do some replacements to support C++, C#, and F#
4169
+ var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp');
4170
+ // only use the first word
4171
+ lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase();
4172
+ var alias = 'language-' + lang;
4173
+
4174
+ // add alias
4175
+ if (!codeBlock.alias) {
4176
+ codeBlock.alias = [alias];
4177
+ } else if (typeof codeBlock.alias === 'string') {
4178
+ codeBlock.alias = [codeBlock.alias, alias];
4179
+ } else {
4180
+ codeBlock.alias.push(alias);
4181
+ }
4182
+ }
4183
+ }
4184
+ }
4185
+
4186
+ walkTokens(env.tokens);
4187
+ });
4188
+
4189
+ Prism.hooks.add('wrap', function (env) {
4190
+ if (env.type !== 'code-block') {
4191
+ return;
4192
+ }
4193
+
4194
+ var codeLang = '';
4195
+ for (var i = 0, l = env.classes.length; i < l; i++) {
4196
+ var cls = env.classes[i];
4197
+ var match = /language-(.+)/.exec(cls);
4198
+ if (match) {
4199
+ codeLang = match[1];
4200
+ break;
4201
+ }
4202
+ }
4203
+
4204
+ var grammar = Prism.languages[codeLang];
4205
+
4206
+ if (!grammar) {
4207
+ if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) {
4208
+ var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16);
4209
+ env.attributes['id'] = id;
4210
+
4211
+ Prism.plugins.autoloader.loadLanguages(codeLang, function () {
4212
+ var ele = document.getElementById(id);
4213
+ if (ele) {
4214
+ ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
4215
+ }
4216
+ });
4217
+ }
4218
+ } else {
4219
+ env.content = Prism.highlight(textContent(env.content), grammar, codeLang);
4220
+ }
4221
+ });
4222
+
4223
+ var tagPattern = RegExp(Prism.languages.markup.tag.pattern.source, 'gi');
4224
+
4225
+ /**
4226
+ * A list of known entity names.
4227
+ *
4228
+ * This will always be incomplete to save space. The current list is the one used by lowdash's unescape function.
4229
+ *
4230
+ * @see {@link https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/unescape.js#L2}
4231
+ */
4232
+ var KNOWN_ENTITY_NAMES = {
4233
+ 'amp': '&',
4234
+ 'lt': '<',
4235
+ 'gt': '>',
4236
+ 'quot': '"',
4237
+ };
4238
+
4239
+ // IE 11 doesn't support `String.fromCodePoint`
4240
+ var fromCodePoint = String.fromCodePoint || String.fromCharCode;
4241
+
4242
+ /**
4243
+ * Returns the text content of a given HTML source code string.
4244
+ *
4245
+ * @param {string} html
4246
+ * @returns {string}
4247
+ */
4248
+ function textContent(html) {
4249
+ // remove all tags
4250
+ var text = html.replace(tagPattern, '');
4251
+
4252
+ // decode known entities
4253
+ text = text.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi, function (m, code) {
4254
+ code = code.toLowerCase();
4255
+
4256
+ if (code[0] === '#') {
4257
+ var value;
4258
+ if (code[1] === 'x') {
4259
+ value = parseInt(code.slice(2), 16);
4260
+ } else {
4261
+ value = Number(code.slice(1));
4262
+ }
4263
+
4264
+ return fromCodePoint(value);
4265
+ } else {
4266
+ var known = KNOWN_ENTITY_NAMES[code];
4267
+ if (known) {
4268
+ return known;
4269
+ }
4270
+
4271
+ // unable to decode
4272
+ return m;
4273
+ }
4274
+ });
4275
+
4276
+ return text;
4277
+ }
4278
+
4279
+ Prism.languages.md = Prism.languages.markdown;
4280
+
4281
+ }(Prism));
4282
+
4283
+ Prism.languages.lua = {
4284
+ 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
4285
+ // \z may be used to skip the following space
4286
+ 'string': {
4287
+ pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
4288
+ greedy: true
4289
+ },
4290
+ 'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
4291
+ 'keyword': /\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/,
4292
+ 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
4293
+ 'operator': [
4294
+ /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
4295
+ {
4296
+ // Match ".." but don't break "..."
4297
+ pattern: /(^|[^.])\.\.(?!\.)/,
4298
+ lookbehind: true
4299
+ }
4300
+ ],
4301
+ 'punctuation': /[\[\](){},;]|\.+|:+/
4302
+ };
4303
+
4304
+ Prism.languages.groovy = Prism.languages.extend('clike', {
4305
+ 'string': [
4306
+ {
4307
+ // https://groovy-lang.org/syntax.html#_dollar_slashy_string
4308
+ pattern: /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
4309
+ greedy: true
4310
+ },
4311
+ {
4312
+ // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
4313
+ // simple division (see JS regex), so find a fix maybe?
4314
+ pattern: /(["'/])(?:\\.|(?!\1)[^\\\r\n])*\1/,
4315
+ greedy: true
4316
+ }
4317
+ ],
4318
+ 'keyword': /\b(?:as|def|in|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|trait|transient|try|void|volatile|while)\b/,
4319
+ 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
4320
+ 'operator': {
4321
+ pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
4322
+ lookbehind: true
4323
+ },
4324
+ 'punctuation': /\.+|[{}[\];(),:$]/
4325
+ });
4326
+
4327
+ Prism.languages.insertBefore('groovy', 'string', {
4328
+ 'shebang': {
4329
+ pattern: /#!.+/,
4330
+ alias: 'comment'
4331
+ }
4332
+ });
4333
+
4334
+ Prism.languages.insertBefore('groovy', 'punctuation', {
4335
+ 'spock-block': /\b(?:setup|given|when|then|and|cleanup|expect|where):/
4336
+ });
4337
+
4338
+ Prism.languages.insertBefore('groovy', 'function', {
4339
+ 'annotation': {
4340
+ pattern: /(^|[^.])@\w+/,
4341
+ lookbehind: true,
4342
+ alias: 'punctuation'
4343
+ }
4344
+ });
4345
+
4346
+ // Handle string interpolation
4347
+ Prism.hooks.add('wrap', function (env) {
4348
+ if (env.language === 'groovy' && env.type === 'string') {
4349
+ var delimiter = env.content[0];
4350
+
4351
+ if (delimiter != "'") {
4352
+ var pattern = /([^\\])(?:\$(?:\{.*?\}|[\w.]+))/;
4353
+ if (delimiter === '$') {
4354
+ pattern = /([^\$])(?:\$(?:\{.*?\}|[\w.]+))/;
4355
+ }
4356
+
4357
+ // To prevent double HTML-encoding we have to decode env.content first
4358
+ env.content = env.content.replace(/&lt;/g, '<').replace(/&amp;/g, '&');
4359
+
4360
+ env.content = Prism.highlight(env.content, {
4361
+ 'expression': {
4362
+ pattern: pattern,
4363
+ lookbehind: true,
4364
+ inside: Prism.languages.groovy
4365
+ }
4366
+ });
4367
+
4368
+ env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
4369
+ }
4370
+ }
4371
+ });
4372
+
4373
+ Prism.languages.abap = {
4374
+ 'comment': /^\*.*/m,
4375
+ 'string': /(`|')(?:\\.|(?!\1)[^\\\r\n])*\1/m,
4376
+ 'string-template': {
4377
+ pattern: /([|}])(?:\\.|[^\\|{\r\n])*(?=[|{])/,
4378
+ lookbehind: true,
4379
+ alias: 'string'
4380
+ },
4381
+ /* End Of Line comments should not interfere with strings when the
4382
+ quote character occurs within them. We assume a string being highlighted
4383
+ inside an EOL comment is more acceptable than the opposite.
4384
+ */
4385
+ 'eol-comment': {
4386
+ pattern: /(^|\s)".*/m,
4387
+ lookbehind: true,
4388
+ alias: 'comment'
4389
+ },
4390
+ 'keyword': {
4391
+ pattern: /(\s|\.|^)(?:SCIENTIFIC_WITH_LEADING_ZERO|SCALE_PRESERVING_SCIENTIFIC|RMC_COMMUNICATION_FAILURE|END-ENHANCEMENT-SECTION|MULTIPLY-CORRESPONDING|SUBTRACT-CORRESPONDING|VERIFICATION-MESSAGE|DIVIDE-CORRESPONDING|ENHANCEMENT-SECTION|CURRENCY_CONVERSION|RMC_SYSTEM_FAILURE|START-OF-SELECTION|MOVE-CORRESPONDING|RMC_INVALID_STATUS|CUSTOMER-FUNCTION|END-OF-DEFINITION|ENHANCEMENT-POINT|SYSTEM-EXCEPTIONS|ADD-CORRESPONDING|SCALE_PRESERVING|SELECTION-SCREEN|CURSOR-SELECTION|END-OF-SELECTION|LOAD-OF-PROGRAM|SCROLL-BOUNDARY|SELECTION-TABLE|EXCEPTION-TABLE|IMPLEMENTATIONS|PARAMETER-TABLE|RIGHT-JUSTIFIED|UNIT_CONVERSION|AUTHORITY-CHECK|LIST-PROCESSING|SIGN_AS_POSTFIX|COL_BACKGROUND|IMPLEMENTATION|INTERFACE-POOL|TRANSFORMATION|IDENTIFICATION|ENDENHANCEMENT|LINE-SELECTION|INITIALIZATION|LEFT-JUSTIFIED|SELECT-OPTIONS|SELECTION-SETS|COMMUNICATION|CORRESPONDING|DECIMAL_SHIFT|PRINT-CONTROL|VALUE-REQUEST|CHAIN-REQUEST|FUNCTION-POOL|FIELD-SYMBOLS|FUNCTIONALITY|INVERTED-DATE|SELECTION-SET|CLASS-METHODS|OUTPUT-LENGTH|CLASS-CODING|COL_NEGATIVE|ERRORMESSAGE|FIELD-GROUPS|HELP-REQUEST|NO-EXTENSION|NO-TOPOFPAGE|REDEFINITION|DISPLAY-MODE|ENDINTERFACE|EXIT-COMMAND|FIELD-SYMBOL|NO-SCROLLING|SHORTDUMP-ID|ACCESSPOLICY|CLASS-EVENTS|COL_POSITIVE|DECLARATIONS|ENHANCEMENTS|FILTER-TABLE|SWITCHSTATES|SYNTAX-CHECK|TRANSPORTING|ASYNCHRONOUS|SYNTAX-TRACE|TOKENIZATION|USER-COMMAND|WITH-HEADING|ABAP-SOURCE|BREAK-POINT|CHAIN-INPUT|COMPRESSION|FIXED-POINT|NEW-SECTION|NON-UNICODE|OCCURRENCES|RESPONSIBLE|SYSTEM-CALL|TRACE-TABLE|ABBREVIATED|CHAR-TO-HEX|END-OF-FILE|ENDFUNCTION|ENVIRONMENT|ASSOCIATION|COL_HEADING|EDITOR-CALL|END-OF-PAGE|ENGINEERING|IMPLEMENTED|INTENSIFIED|RADIOBUTTON|SYSTEM-EXIT|TOP-OF-PAGE|TRANSACTION|APPLICATION|CONCATENATE|DESTINATION|ENHANCEMENT|IMMEDIATELY|NO-GROUPING|PRECOMPILED|REPLACEMENT|TITLE-LINES|ACTIVATION|BYTE-ORDER|CLASS-POOL|CONNECTION|CONVERSION|DEFINITION|DEPARTMENT|EXPIRATION|INHERITING|MESSAGE-ID|NO-HEADING|PERFORMING|QUEUE-ONLY|RIGHTSPACE|SCIENTIFIC|STATUSINFO|STRUCTURES|SYNCPOINTS|WITH-TITLE|ATTRIBUTES|BOUNDARIES|CLASS-DATA|COL_NORMAL|DD\/MM\/YYYY|DESCENDING|INTERFACES|LINE-COUNT|MM\/DD\/YYYY|NON-UNIQUE|PRESERVING|SELECTIONS|STATEMENTS|SUBROUTINE|TRUNCATION|TYPE-POOLS|ARITHMETIC|BACKGROUND|ENDPROVIDE|EXCEPTIONS|IDENTIFIER|INDEX-LINE|OBLIGATORY|PARAMETERS|PERCENTAGE|PUSHBUTTON|RESOLUTION|COMPONENTS|DEALLOCATE|DISCONNECT|DUPLICATES|FIRST-LINE|HEAD-LINES|NO-DISPLAY|OCCURRENCE|RESPECTING|RETURNCODE|SUBMATCHES|TRACE-FILE|ASCENDING|BYPASSING|ENDMODULE|EXCEPTION|EXCLUDING|EXPORTING|INCREMENT|MATCHCODE|PARAMETER|PARTIALLY|PREFERRED|REFERENCE|REPLACING|RETURNING|SELECTION|SEPARATED|SPECIFIED|STATEMENT|TIMESTAMP|TYPE-POOL|ACCEPTING|APPENDAGE|ASSIGNING|COL_GROUP|COMPARING|CONSTANTS|DANGEROUS|IMPORTING|INSTANCES|LEFTSPACE|LOG-POINT|QUICKINFO|READ-ONLY|SCROLLING|SQLSCRIPT|STEP-LOOP|TOP-LINES|TRANSLATE|APPENDING|AUTHORITY|CHARACTER|COMPONENT|CONDITION|DIRECTORY|DUPLICATE|MESSAGING|RECEIVING|SUBSCREEN|ACCORDING|COL_TOTAL|END-LINES|ENDMETHOD|ENDSELECT|EXPANDING|EXTENSION|INCLUDING|INFOTYPES|INTERFACE|INTERVALS|LINE-SIZE|PF-STATUS|PROCEDURE|PROTECTED|REQUESTED|RESUMABLE|RIGHTPLUS|SAP-SPOOL|SECONDARY|STRUCTURE|SUBSTRING|TABLEVIEW|NUMOFCHAR|ADJACENT|ANALYSIS|ASSIGNED|BACKWARD|CHANNELS|CHECKBOX|CONTINUE|CRITICAL|DATAINFO|DD\/MM\/YY|DURATION|ENCODING|ENDCLASS|FUNCTION|LEFTPLUS|LINEFEED|MM\/DD\/YY|OVERFLOW|RECEIVED|SKIPPING|SORTABLE|STANDARD|SUBTRACT|SUPPRESS|TABSTRIP|TITLEBAR|TRUNCATE|UNASSIGN|WHENEVER|ANALYZER|COALESCE|COMMENTS|CONDENSE|DECIMALS|DEFERRED|ENDWHILE|EXPLICIT|KEYWORDS|MESSAGES|POSITION|PRIORITY|RECEIVER|RENAMING|TIMEZONE|TRAILING|ALLOCATE|CENTERED|CIRCULAR|CONTROLS|CURRENCY|DELETING|DESCRIBE|DISTANCE|ENDCATCH|EXPONENT|EXTENDED|GENERATE|IGNORING|INCLUDES|INTERNAL|MAJOR-ID|MODIFIER|NEW-LINE|OPTIONAL|PROPERTY|ROLLBACK|STARTING|SUPPLIED|ABSTRACT|CHANGING|CONTEXTS|CREATING|CUSTOMER|DATABASE|DAYLIGHT|DEFINING|DISTINCT|DIVISION|ENABLING|ENDCHAIN|ESCAPING|HARMLESS|IMPLICIT|INACTIVE|LANGUAGE|MINOR-ID|MULTIPLY|NEW-PAGE|NO-TITLE|POS_HIGH|SEPARATE|TEXTPOOL|TRANSFER|SELECTOR|DBMAXLEN|ITERATOR|ARCHIVE|BIT-XOR|BYTE-CO|COLLECT|COMMENT|CURRENT|DEFAULT|DISPLAY|ENDFORM|EXTRACT|LEADING|LISTBOX|LOCATOR|MEMBERS|METHODS|NESTING|POS_LOW|PROCESS|PROVIDE|RAISING|RESERVE|SECONDS|SUMMARY|VISIBLE|BETWEEN|BIT-AND|BYTE-CS|CLEANUP|COMPUTE|CONTROL|CONVERT|DATASET|ENDCASE|FORWARD|HEADERS|HOTSPOT|INCLUDE|INVERSE|KEEPING|NO-ZERO|OBJECTS|OVERLAY|PADDING|PATTERN|PROGRAM|REFRESH|SECTION|SUMMING|TESTING|VERSION|WINDOWS|WITHOUT|BIT-NOT|BYTE-CA|BYTE-NA|CASTING|CONTEXT|COUNTRY|DYNAMIC|ENABLED|ENDLOOP|EXECUTE|FRIENDS|HANDLER|HEADING|INITIAL|\*-INPUT|LOGFILE|MAXIMUM|MINIMUM|NO-GAPS|NO-SIGN|PRAGMAS|PRIMARY|PRIVATE|REDUCED|REPLACE|REQUEST|RESULTS|UNICODE|WARNING|ALIASES|BYTE-CN|BYTE-NS|CALLING|COL_KEY|COLUMNS|CONNECT|ENDEXEC|ENTRIES|EXCLUDE|FILTERS|FURTHER|HELP-ID|LOGICAL|MAPPING|MESSAGE|NAMETAB|OPTIONS|PACKAGE|PERFORM|RECEIVE|STATICS|VARYING|BINDING|CHARLEN|GREATER|XSTRLEN|ACCEPT|APPEND|DETAIL|ELSEIF|ENDING|ENDTRY|FORMAT|FRAMES|GIVING|HASHED|HEADER|IMPORT|INSERT|MARGIN|MODULE|NATIVE|OBJECT|OFFSET|REMOTE|RESUME|SAVING|SIMPLE|SUBMIT|TABBED|TOKENS|UNIQUE|UNPACK|UPDATE|WINDOW|YELLOW|ACTUAL|ASPECT|CENTER|CURSOR|DELETE|DIALOG|DIVIDE|DURING|ERRORS|EVENTS|EXTEND|FILTER|HANDLE|HAVING|IGNORE|LITTLE|MEMORY|NO-GAP|OCCURS|OPTION|PERSON|PLACES|PUBLIC|REDUCE|REPORT|RESULT|SINGLE|SORTED|SWITCH|SYNTAX|TARGET|VALUES|WRITER|ASSERT|BLOCKS|BOUNDS|BUFFER|CHANGE|COLUMN|COMMIT|CONCAT|COPIES|CREATE|DDMMYY|DEFINE|ENDIAN|ESCAPE|EXPAND|KERNEL|LAYOUT|LEGACY|LEVELS|MMDDYY|NUMBER|OUTPUT|RANGES|READER|RETURN|SCREEN|SEARCH|SELECT|SHARED|SOURCE|STABLE|STATIC|SUBKEY|SUFFIX|TABLES|UNWIND|YYMMDD|ASSIGN|BACKUP|BEFORE|BINARY|BIT-OR|BLANKS|CLIENT|CODING|COMMON|DEMAND|DYNPRO|EXCEPT|EXISTS|EXPORT|FIELDS|GLOBAL|GROUPS|LENGTH|LOCALE|MEDIUM|METHOD|MODIFY|NESTED|OTHERS|REJECT|SCROLL|SUPPLY|SYMBOL|ENDFOR|STRLEN|ALIGN|BEGIN|BOUND|ENDAT|ENTRY|EVENT|FINAL|FLUSH|GRANT|INNER|SHORT|USING|WRITE|AFTER|BLACK|BLOCK|CLOCK|COLOR|COUNT|DUMMY|EMPTY|ENDDO|ENDON|GREEN|INDEX|INOUT|LEAVE|LEVEL|LINES|MODIF|ORDER|OUTER|RANGE|RESET|RETRY|RIGHT|SMART|SPLIT|STYLE|TABLE|THROW|UNDER|UNTIL|UPPER|UTF-8|WHERE|ALIAS|BLANK|CLEAR|CLOSE|EXACT|FETCH|FIRST|FOUND|GROUP|LLANG|LOCAL|OTHER|REGEX|SPOOL|TITLE|TYPES|VALID|WHILE|ALPHA|BOXED|CATCH|CHAIN|CHECK|CLASS|COVER|ENDIF|EQUIV|FIELD|FLOOR|FRAME|INPUT|LOWER|MATCH|NODES|PAGES|PRINT|RAISE|ROUND|SHIFT|SPACE|SPOTS|STAMP|STATE|TASKS|TIMES|TRMAC|ULINE|UNION|VALUE|WIDTH|EQUAL|LOG10|TRUNC|BLOB|CASE|CEIL|CLOB|COND|EXIT|FILE|GAPS|HOLD|INCL|INTO|KEEP|KEYS|LAST|LINE|LONG|LPAD|MAIL|MODE|OPEN|PINK|READ|ROWS|TEST|THEN|ZERO|AREA|BACK|BADI|BYTE|CAST|EDIT|EXEC|FAIL|FIND|FKEQ|FONT|FREE|GKEQ|HIDE|INIT|ITNO|LATE|LOOP|MAIN|MARK|MOVE|NEXT|NULL|RISK|ROLE|UNIT|WAIT|ZONE|BASE|CALL|CODE|DATA|DATE|FKGE|GKGE|HIGH|KIND|LEFT|LIST|MASK|MESH|NAME|NODE|PACK|PAGE|POOL|SEND|SIGN|SIZE|SOME|STOP|TASK|TEXT|TIME|USER|VARY|WITH|WORD|BLUE|CONV|COPY|DEEP|ELSE|FORM|FROM|HINT|ICON|JOIN|LIKE|LOAD|ONLY|PART|SCAN|SKIP|SORT|TYPE|UNIX|VIEW|WHEN|WORK|ACOS|ASIN|ATAN|COSH|EACH|FRAC|LESS|RTTI|SINH|SQRT|TANH|AVG|BIT|DIV|ISO|LET|OUT|PAD|SQL|ALL|CI_|CPI|END|LOB|LPI|MAX|MIN|NEW|OLE|RUN|SET|\?TO|YES|ABS|ADD|AND|BIG|FOR|HDB|JOB|LOW|NOT|SAP|TRY|VIA|XML|ANY|GET|IDS|KEY|MOD|OFF|PUT|RAW|RED|REF|SUM|TAB|XSD|CNT|COS|EXP|LOG|SIN|TAN|XOR|AT|CO|CP|DO|GT|ID|IF|NS|OR|BT|CA|CS|GE|NA|NB|EQ|IN|LT|NE|NO|OF|ON|PF|TO|AS|BY|CN|IS|LE|NP|UP|E|I|M|O|Z|C|X)\b/i,
4392
+ lookbehind: true
4393
+ },
4394
+ /* Numbers can be only integers. Decimal or Hex appear only as strings */
4395
+ 'number': /\b\d+\b/,
4396
+ /* Operators must always be surrounded by whitespace, they cannot be put
4397
+ adjacent to operands.
4398
+ */
4399
+ 'operator': {
4400
+ pattern: /(\s)(?:\*\*?|<[=>]?|>=?|\?=|[-+\/=])(?=\s)/,
4401
+ lookbehind: true
4402
+ },
4403
+ 'string-operator': {
4404
+ pattern: /(\s)&&?(?=\s)/,
4405
+ lookbehind: true,
4406
+ /* The official editor highlights */
4407
+ alias: 'keyword'
4408
+ },
4409
+ 'token-operator': [{
4410
+ /* Special operators used to access structure components, class methods/attributes, etc. */
4411
+ pattern: /(\w)(?:->?|=>|[~|{}])(?=\w)/,
4412
+ lookbehind: true,
4413
+ alias: 'punctuation'
4414
+ }, {
4415
+ /* Special tokens used do delimit string templates */
4416
+ pattern: /[|{}]/,
4417
+ alias: 'punctuation'
4418
+ }],
4419
+ 'punctuation': /[,.:()]/
4420
+ };
4421
+
4422
+ /**
4423
+ * @description prismjs
4424
+ * @author wangfupeng
4425
+ */
4426
+ // 语言模块,参考 https://github.com/PrismJS/prism/tree/master/components
4427
+ // prismjs 的 token 类型汇总
4428
+ var prismTokenTypes = [
4429
+ 'comment',
4430
+ 'prolog',
4431
+ 'doctype',
4432
+ 'cdata',
4433
+ 'punctuation',
4434
+ 'namespace',
4435
+ 'property',
4436
+ 'tag',
4437
+ 'boolean',
4438
+ 'number',
4439
+ 'constant',
4440
+ 'symbol',
4441
+ 'deleted',
4442
+ 'selector',
4443
+ 'attr-name',
4444
+ 'string',
4445
+ 'builtin',
4446
+ 'inserted',
4447
+ 'operator',
4448
+ 'entity',
4449
+ 'url',
4450
+ 'string',
4451
+ 'atrule',
4452
+ 'attr-value',
4453
+ 'keyword',
4454
+ 'function',
4455
+ 'class-name',
4456
+ 'regex',
4457
+ 'important',
4458
+ 'variable',
4459
+ 'bold',
4460
+ 'italic',
4461
+ 'entity',
4462
+ 'char',
4463
+ ];
4464
+ /**
4465
+ * 获取 prism token 的字符串长度
4466
+ * @param token prism token
4467
+ */
4468
+ function getPrismTokenLength(token) {
4469
+ if (typeof token === 'string') {
4470
+ return token.length;
4471
+ }
4472
+ else if (typeof token.content === 'string') {
4473
+ return token.content.length;
4474
+ }
4475
+ else {
4476
+ // 累加 length
4477
+ return token.content.reduce(
4478
+ // @ts-ignore
4479
+ function (l, t) { return l + getPrismTokenLength(t); }, 0);
4480
+ }
4481
+ }
4482
+ /**
4483
+ * 获取 prism 解析的 token 列表
4484
+ * @param textNode text node
4485
+ * @param language 代码语言
4486
+ */
4487
+ function getPrismTokens(textNode, language) {
4488
+ if (!language)
4489
+ return [];
4490
+ var langGrammar = prism.languages[language];
4491
+ if (!langGrammar)
4492
+ return [];
4493
+ return prism.tokenize(textNode.text, langGrammar);
4494
+ // tokens 即 Prism 对整个字符串的拆分,有普通文字也有高亮的关键字
4495
+ // 例如 `const a = 100;` 的 tokens 是一个数组 [ token, ' a ', token, ' ', token ] ,有对象有字符串,对象就表示关键字
4496
+ // 如数组第一个 token 是 { type: "keyword", content: "const" } 。关键字类型不同 type 也不同
4497
+ }
4498
+
4499
+ /**
4500
+ * @description render code highlight style
4501
+ * @author wangfupeng
4502
+ */
4503
+ /**
4504
+ * 添加样式
4505
+ * @param node slate text
4506
+ * @param vnode vnode
4507
+ * @returns vnode
4508
+ */
4509
+ function renderStyle(node, vnode) {
4510
+ var leafNode = node;
4511
+ var styleVnode = vnode;
4512
+ var className = '';
4513
+ prismTokenTypes.forEach(function (type) {
4514
+ if (leafNode[type])
4515
+ className = type;
4516
+ });
4517
+ if (className) {
4518
+ className = "token " + className; // 如 'token keyword' - prismjs 渲染的规则
4519
+ addVnodeClassName(styleVnode, className);
4520
+ }
4521
+ return styleVnode;
4522
+ }
4523
+
4524
+ /**
4525
+ * @description DOM 操作
4526
+ * @author wangfupeng
4527
+ */
4528
+ if (attr)
4529
+ $.fn.attr = attr;
4530
+
4531
+ /**
4532
+ * @description parse style html
4533
+ * @author wangfupeng
4534
+ */
4535
+ function parseCodeStyleHtml(elem, node, editor) {
4536
+ var $elem = $(elem);
4537
+ if (!Element$1.isElement(node))
4538
+ return node;
4539
+ if (DomEditor.getNodeType(node) !== 'code')
4540
+ return node; // 只针对 pre/code 元素
4541
+ var elemNode = node;
4542
+ var langAttr = $elem.attr('class') || '';
4543
+ if (langAttr.indexOf('language-') === 0) {
4544
+ // V5 版本,格式如 class="language-javascript"
4545
+ elemNode.language = langAttr.split('-')[1] || ''; // 获取 'javascript'
4546
+ }
4547
+ else {
4548
+ // 兼容 V4 版本,格式如 class="Javascript"
4549
+ elemNode.language = langAttr.toLowerCase();
4550
+ }
4551
+ return elemNode;
4552
+ }
4553
+
4554
+ /**
4555
+ * @description icon svg
4556
+ * @author wangfupeng
4557
+ */
4558
+ /**
4559
+ * 【注意】svg 字符串的长度 ,否则会导致代码体积过大
4560
+ * 尽量选择 https://www.iconfont.cn/collections/detail?spm=a313x.7781069.0.da5a778a4&cid=20293
4561
+ * 找不到再从 iconfont.com 搜索
4562
+ */
4563
+ var JS_SVG = '<svg viewBox="0 0 1024 1024"><path d="M64 64v896h896V64H64z m487.6 698.8c0 87.2-51.2 127-125.8 127-67.4 0-106.4-34.8-126.4-77l68.6-41.4c13.2 23.4 25.2 43.2 54.2 43.2 27.6 0 45.2-10.8 45.2-53V475.4h84.2v287.4z m199.2 127c-78.2 0-128.8-37.2-153.4-86l68.6-39.6c18 29.4 41.6 51.2 83 51.2 34.8 0 57.2-17.4 57.2-41.6 0-28.8-22.8-39-61.4-56l-21-9c-60.8-25.8-101-58.4-101-127 0-63.2 48.2-111.2 123.2-111.2 53.6 0 92 18.6 119.6 67.4L800 580c-14.4-25.8-30-36-54.2-36-24.6 0-40.2 15.6-40.2 36 0 25.2 15.6 35.4 51.8 51.2l21 9c71.6 30.6 111.8 62 111.8 132.4 0 75.6-59.6 117.2-139.4 117.2z"></path></svg>';
4564
+
4565
+ /**
4566
+ * @description code-highlight select lang
4567
+ * @author wangfupeng
4568
+ */
4569
+ var SelectLangMenu = /** @class */ (function () {
4570
+ function SelectLangMenu() {
4571
+ this.title = t('highLightModule.selectLang');
4572
+ this.iconSvg = JS_SVG;
4573
+ this.tag = 'select';
4574
+ this.width = 95;
4575
+ this.selectPanelWidth = 115;
4576
+ }
4577
+ SelectLangMenu.prototype.getOptions = function (editor) {
4578
+ var options = [];
4579
+ // 获取配置,参考 './config.ts'
4580
+ var _a = editor.getMenuConfig('codeSelectLang').codeLangs, codeLangs = _a === void 0 ? [] : _a; // 第二个参数 menu key
4581
+ options.push({
4582
+ text: 'plain text',
4583
+ value: '', // getValue 默认会返回 ''
4584
+ });
4585
+ codeLangs.forEach(function (lang) {
4586
+ var text = lang.text, value = lang.value;
4587
+ options.push({ text: text, value: value });
4588
+ });
4589
+ // 设置 selected
4590
+ var curValue = this.getValue(editor);
4591
+ options.forEach(function (opt) {
4592
+ if (opt.value === curValue) {
4593
+ opt.selected = true;
4594
+ }
4595
+ else {
4596
+ delete opt.selected;
4597
+ }
4598
+ });
4599
+ return options;
4600
+ };
4601
+ SelectLangMenu.prototype.isActive = function (editor) {
4602
+ // select menu 会显示 selected value ,用不到 active
4603
+ return false;
4604
+ };
4605
+ /**
4606
+ * 获取语言类型
4607
+ * @param editor editor
4608
+ */
4609
+ SelectLangMenu.prototype.getValue = function (editor) {
4610
+ var elem = this.getSelectCodeElem(editor);
4611
+ if (elem == null)
4612
+ return '';
4613
+ if (!Element$1.isElement(elem))
4614
+ return '';
4615
+ var lang = elem.language.toString();
4616
+ // 当前 elem.language 是否在已配置的 langs 中?
4617
+ var _a = editor.getMenuConfig('codeSelectLang').codeLangs, codeLangs = _a === void 0 ? [] : _a;
4618
+ var hasLang = codeLangs.some(function (item) { return item.value === lang; });
4619
+ if (hasLang)
4620
+ return lang;
4621
+ return '';
4622
+ };
4623
+ SelectLangMenu.prototype.isDisabled = function (editor) {
4624
+ if (editor.selection == null)
4625
+ return true;
4626
+ var elem = this.getSelectCodeElem(editor);
4627
+ if (elem)
4628
+ return false;
4629
+ return true;
4630
+ };
4631
+ SelectLangMenu.prototype.exec = function (editor, value) {
4632
+ var elem = this.getSelectCodeElem(editor);
4633
+ if (elem == null)
4634
+ return;
4635
+ // 设置语言
4636
+ var props = { language: value.toString() };
4637
+ Transforms.setNodes(editor, props, {
4638
+ match: function (n) { return DomEditor.checkNodeType(n, 'code'); },
4639
+ });
4640
+ };
4641
+ SelectLangMenu.prototype.getSelectCodeElem = function (editor) {
4642
+ var codeNode = DomEditor.getSelectedNodeByType(editor, 'code');
4643
+ if (codeNode == null)
4644
+ return null;
4645
+ var preNode = DomEditor.getParentNode(editor, codeNode);
4646
+ if (!Element$1.isElement(preNode))
4647
+ return null;
4648
+ if (preNode.type !== 'pre')
4649
+ return null;
4650
+ return codeNode;
4651
+ };
4652
+ return SelectLangMenu;
4653
+ }());
4654
+
4655
+ /**
4656
+ * @description menu config
4657
+ * @author wangfupeng
4658
+ */
4659
+ function genCodeLangs() {
4660
+ // 1. text value 对应关系参考 prism 官网 https://prismjs.com/#supported-languages
4661
+ // 2. 要加入一个新语言时,要引入相应的 js 模块(代码在 `vender/prism.ts`),例如 `import 'prismjs/components/prism-php'`
4662
+ return [
4663
+ { text: 'CSS', value: 'css' },
4664
+ { text: 'HTML', value: 'html' },
4665
+ { text: 'XML', value: 'xml' },
4666
+ { text: 'Javascript', value: 'javascript' },
4667
+ { text: 'Typescript', value: 'typescript' },
4668
+ { text: 'JSX', value: 'jsx' },
4669
+ { text: 'Go', value: 'go' },
4670
+ { text: 'PHP', value: 'php' },
4671
+ { text: 'C', value: 'c' },
4672
+ { text: 'Python', value: 'python' },
4673
+ { text: 'Java', value: 'java' },
4674
+ { text: 'C++', value: 'cpp' },
4675
+ { text: 'C#', value: 'csharp' },
4676
+ { text: 'Visual Basic', value: 'visual-basic' },
4677
+ { text: 'SQL', value: 'sql' },
4678
+ { text: 'Ruby', value: 'ruby' },
4679
+ { text: 'Swift', value: 'swift' },
4680
+ { text: 'Bash', value: 'bash' },
4681
+ { text: 'Lua', value: 'lua' },
4682
+ { text: 'Groovy', value: 'groovy' },
4683
+ { text: 'Markdown', value: 'markdown' },
4684
+ { text: 'ABAP', value: 'abap' },
4685
+ ];
4686
+ }
4687
+
4688
+ /**
4689
+ * @description code-highlight menu
4690
+ * @author wangfupeng
4691
+ */
4692
+ var selectLangMenuConf = {
4693
+ key: 'codeSelectLang',
4694
+ factory: function () {
4695
+ return new SelectLangMenu();
4696
+ },
4697
+ config: {
4698
+ codeLangs: genCodeLangs(),
4699
+ },
4700
+ };
4701
+
4702
+ /**
4703
+ * @description to html
4704
+ * @author wangfupeng
4705
+ */
4706
+ function codeToHtml(elem, childrenHtml) {
4707
+ var _a = elem.language, language = _a === void 0 ? '' : _a;
4708
+ var cssClass = language
4709
+ ? "class=\"language-" + language + "\"" // prism.js 根据 language 代码高亮
4710
+ : '';
4711
+ return "<code " + cssClass + ">" + childrenHtml + "</code>";
4712
+ }
4713
+ // 覆盖 basic-module 中的 code to html
4714
+ var codeToHtmlConf = {
4715
+ type: 'code',
4716
+ elemToHtml: codeToHtml,
4717
+ };
4718
+
4719
+ /**
4720
+ * @description code highlight module
4721
+ * @author wangfupeng
4722
+ */
4723
+ var codeHighlightModule = {
4724
+ renderStyle: renderStyle,
4725
+ parseStyleHtml: parseCodeStyleHtml,
4726
+ menus: [selectLangMenuConf],
4727
+ elemsToHtml: [codeToHtmlConf],
4728
+ };
4729
+
4730
+ /*! *****************************************************************************
4731
+ Copyright (c) Microsoft Corporation.
4732
+
4733
+ Permission to use, copy, modify, and/or distribute this software for any
4734
+ purpose with or without fee is hereby granted.
4735
+
4736
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4737
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4738
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4739
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4740
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4741
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4742
+ PERFORMANCE OF THIS SOFTWARE.
4743
+ ***************************************************************************** */
4744
+
4745
+ function __values(o) {
4746
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4747
+ if (m) return m.call(o);
4748
+ if (o && typeof o.length === "number") return {
4749
+ next: function () {
4750
+ if (o && i >= o.length) o = void 0;
4751
+ return { value: o && o[i++], done: !o };
4752
+ }
4753
+ };
4754
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
4755
+ }
4756
+
4757
+ function __read(o, n) {
4758
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4759
+ if (!m) return o;
4760
+ var i = m.call(o), r, ar = [], e;
4761
+ try {
4762
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
4763
+ }
4764
+ catch (error) { e = { error: error }; }
4765
+ finally {
4766
+ try {
4767
+ if (r && !r.done && (m = i["return"])) m.call(i);
4768
+ }
4769
+ finally { if (e) throw e.error; }
4770
+ }
4771
+ return ar;
4772
+ }
4773
+
4774
+ /**
4775
+ * @description code-highlight decorate
4776
+ * @author wangfupeng
4777
+ */
4778
+ /**
4779
+ * 获取 code elem
4780
+ * @param node text node
4781
+ */
4782
+ function getCodeElem(textNode) {
4783
+ if (!Text.isText(textNode))
4784
+ return null; // 非文本 node
4785
+ var codeNode = DomEditor.getParentNode(null, textNode);
4786
+ if (codeNode && DomEditor.getNodeType(codeNode) === 'code') {
4787
+ var preNode = DomEditor.getParentNode(null, codeNode);
4788
+ if (preNode && DomEditor.getNodeType(preNode) === 'pre') {
4789
+ return codeNode;
4790
+ }
4791
+ }
4792
+ return null;
4793
+ }
4794
+ var codeHighLightDecorate = function (nodeEntry) {
4795
+ var e_1, _a, _b;
4796
+ var _c = __read(nodeEntry, 2), n = _c[0], path = _c[1];
4797
+ var ranges = [];
4798
+ // 节点不合法,则不处理
4799
+ var codeElem = getCodeElem(n);
4800
+ if (codeElem == null)
4801
+ return ranges;
4802
+ var _d = codeElem.language, language = _d === void 0 ? '' : _d;
4803
+ if (!language)
4804
+ return ranges;
4805
+ var textNode = n;
4806
+ var tokens = getPrismTokens(textNode, language);
4807
+ var start = 0;
4808
+ try {
4809
+ for (var tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
4810
+ var token = tokens_1_1.value;
4811
+ var length_1 = getPrismTokenLength(token);
4812
+ var end = start + length_1;
4813
+ if (typeof token !== 'string') {
4814
+ // 遇到关键字,则拆分多个 range —— decorate 规则
4815
+ ranges.push((_b = {},
4816
+ _b[token.type] = true,
4817
+ _b.anchor = { path: path, offset: start },
4818
+ _b.focus = { path: path, offset: end },
4819
+ _b));
4820
+ }
4821
+ start = end;
4822
+ }
4823
+ }
4824
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
4825
+ finally {
4826
+ try {
4827
+ if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
4828
+ }
4829
+ finally { if (e_1) throw e_1.error; }
4830
+ }
4831
+ return ranges;
4832
+ };
4833
+
4834
+ export { codeHighLightDecorate as wangEditorCodeHighLightDecorate, codeHighlightModule as wangEditorCodeHighlightModule };