@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.
package/dist/index.js ADDED
@@ -0,0 +1,4845 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@wangeditor-next/core'), require('dom7'), require('slate')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@wangeditor-next/core', 'dom7', 'slate'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WangEditorCodeHighLight = {}, global.core, global.$, global.slate));
5
+ })(this, (function (exports, core, $, slate) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var $__default = /*#__PURE__*/_interopDefaultLegacy($);
10
+
11
+ /**
12
+ * @description i18n en
13
+ * @author wangfupeng
14
+ */
15
+ var enResources = {
16
+ highLightModule: {
17
+ selectLang: 'Language',
18
+ },
19
+ };
20
+
21
+ /**
22
+ * @description i18n zh-CN
23
+ * @author wangfupeng
24
+ */
25
+ var zhResources = {
26
+ highLightModule: {
27
+ selectLang: '选择语言',
28
+ },
29
+ };
30
+
31
+ /**
32
+ * @description i18n entry
33
+ * @author wangfupeng
34
+ */
35
+ core.i18nAddResources('en', enResources);
36
+ core.i18nAddResources('zh-CN', zhResources);
37
+
38
+ /**
39
+ * @description vdom utils fn
40
+ * @author wangfupeng
41
+ */
42
+ /**
43
+ * 给 vnode 添加 className
44
+ * @param vnode vnode
45
+ * @param className css class
46
+ */
47
+ function addVnodeClassName(vnode, className) {
48
+ if (vnode.data == null)
49
+ vnode.data = {};
50
+ var data = vnode.data;
51
+ if (data.props == null)
52
+ data.props = {};
53
+ Object.assign(data.props, { className: className });
54
+ }
55
+
56
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
57
+
58
+ function createCommonjsModule(fn) {
59
+ var module = { exports: {} };
60
+ return fn(module, module.exports), module.exports;
61
+ }
62
+
63
+ var prism = createCommonjsModule(function (module) {
64
+ /* **********************************************
65
+ Begin prism-core.js
66
+ ********************************************** */
67
+
68
+ /// <reference lib="WebWorker"/>
69
+
70
+ var _self = (typeof window !== 'undefined')
71
+ ? window // if in browser
72
+ : (
73
+ (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
74
+ ? self // if in worker
75
+ : {} // if in node js
76
+ );
77
+
78
+ /**
79
+ * Prism: Lightweight, robust, elegant syntax highlighting
80
+ *
81
+ * @license MIT <https://opensource.org/licenses/MIT>
82
+ * @author Lea Verou <https://lea.verou.me>
83
+ * @namespace
84
+ * @public
85
+ */
86
+ var Prism = (function (_self) {
87
+
88
+ // Private helper vars
89
+ var lang = /\blang(?:uage)?-([\w-]+)\b/i;
90
+ var uniqueId = 0;
91
+
92
+ // The grammar object for plaintext
93
+ var plainTextGrammar = {};
94
+
95
+
96
+ var _ = {
97
+ /**
98
+ * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
99
+ * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
100
+ * additional languages or plugins yourself.
101
+ *
102
+ * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
103
+ *
104
+ * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
105
+ * empty Prism object into the global scope before loading the Prism script like this:
106
+ *
107
+ * ```js
108
+ * window.Prism = window.Prism || {};
109
+ * Prism.manual = true;
110
+ * // add a new <script> to load Prism's script
111
+ * ```
112
+ *
113
+ * @default false
114
+ * @type {boolean}
115
+ * @memberof Prism
116
+ * @public
117
+ */
118
+ manual: _self.Prism && _self.Prism.manual,
119
+ disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
120
+
121
+ /**
122
+ * A namespace for utility methods.
123
+ *
124
+ * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
125
+ * change or disappear at any time.
126
+ *
127
+ * @namespace
128
+ * @memberof Prism
129
+ */
130
+ util: {
131
+ encode: function encode(tokens) {
132
+ if (tokens instanceof Token) {
133
+ return new Token(tokens.type, encode(tokens.content), tokens.alias);
134
+ } else if (Array.isArray(tokens)) {
135
+ return tokens.map(encode);
136
+ } else {
137
+ return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
138
+ }
139
+ },
140
+
141
+ /**
142
+ * Returns the name of the type of the given value.
143
+ *
144
+ * @param {any} o
145
+ * @returns {string}
146
+ * @example
147
+ * type(null) === 'Null'
148
+ * type(undefined) === 'Undefined'
149
+ * type(123) === 'Number'
150
+ * type('foo') === 'String'
151
+ * type(true) === 'Boolean'
152
+ * type([1, 2]) === 'Array'
153
+ * type({}) === 'Object'
154
+ * type(String) === 'Function'
155
+ * type(/abc+/) === 'RegExp'
156
+ */
157
+ type: function (o) {
158
+ return Object.prototype.toString.call(o).slice(8, -1);
159
+ },
160
+
161
+ /**
162
+ * Returns a unique number for the given object. Later calls will still return the same number.
163
+ *
164
+ * @param {Object} obj
165
+ * @returns {number}
166
+ */
167
+ objId: function (obj) {
168
+ if (!obj['__id']) {
169
+ Object.defineProperty(obj, '__id', { value: ++uniqueId });
170
+ }
171
+ return obj['__id'];
172
+ },
173
+
174
+ /**
175
+ * Creates a deep clone of the given object.
176
+ *
177
+ * The main intended use of this function is to clone language definitions.
178
+ *
179
+ * @param {T} o
180
+ * @param {Record<number, any>} [visited]
181
+ * @returns {T}
182
+ * @template T
183
+ */
184
+ clone: function deepClone(o, visited) {
185
+ visited = visited || {};
186
+
187
+ var clone; var id;
188
+ switch (_.util.type(o)) {
189
+ case 'Object':
190
+ id = _.util.objId(o);
191
+ if (visited[id]) {
192
+ return visited[id];
193
+ }
194
+ clone = /** @type {Record<string, any>} */ ({});
195
+ visited[id] = clone;
196
+
197
+ for (var key in o) {
198
+ if (o.hasOwnProperty(key)) {
199
+ clone[key] = deepClone(o[key], visited);
200
+ }
201
+ }
202
+
203
+ return /** @type {any} */ (clone);
204
+
205
+ case 'Array':
206
+ id = _.util.objId(o);
207
+ if (visited[id]) {
208
+ return visited[id];
209
+ }
210
+ clone = [];
211
+ visited[id] = clone;
212
+
213
+ (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
214
+ clone[i] = deepClone(v, visited);
215
+ });
216
+
217
+ return /** @type {any} */ (clone);
218
+
219
+ default:
220
+ return o;
221
+ }
222
+ },
223
+
224
+ /**
225
+ * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
226
+ *
227
+ * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
228
+ *
229
+ * @param {Element} element
230
+ * @returns {string}
231
+ */
232
+ getLanguage: function (element) {
233
+ while (element && !lang.test(element.className)) {
234
+ element = element.parentElement;
235
+ }
236
+ if (element) {
237
+ return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
238
+ }
239
+ return 'none';
240
+ },
241
+
242
+ /**
243
+ * Returns the script element that is currently executing.
244
+ *
245
+ * This does __not__ work for line script element.
246
+ *
247
+ * @returns {HTMLScriptElement | null}
248
+ */
249
+ currentScript: function () {
250
+ if (typeof document === 'undefined') {
251
+ return null;
252
+ }
253
+ if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
254
+ return /** @type {any} */ (document.currentScript);
255
+ }
256
+
257
+ // IE11 workaround
258
+ // we'll get the src of the current script by parsing IE11's error stack trace
259
+ // this will not work for inline scripts
260
+
261
+ try {
262
+ throw new Error();
263
+ } catch (err) {
264
+ // Get file src url from stack. Specifically works with the format of stack traces in IE.
265
+ // A stack will look like this:
266
+ //
267
+ // Error
268
+ // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
269
+ // at Global code (http://localhost/components/prism-core.js:606:1)
270
+
271
+ var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
272
+ if (src) {
273
+ var scripts = document.getElementsByTagName('script');
274
+ for (var i in scripts) {
275
+ if (scripts[i].src == src) {
276
+ return scripts[i];
277
+ }
278
+ }
279
+ }
280
+ return null;
281
+ }
282
+ },
283
+
284
+ /**
285
+ * Returns whether a given class is active for `element`.
286
+ *
287
+ * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
288
+ * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
289
+ * given class is just the given class with a `no-` prefix.
290
+ *
291
+ * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
292
+ * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
293
+ * ancestors have the given class or the negated version of it, then the default activation will be returned.
294
+ *
295
+ * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
296
+ * version of it, the class is considered active.
297
+ *
298
+ * @param {Element} element
299
+ * @param {string} className
300
+ * @param {boolean} [defaultActivation=false]
301
+ * @returns {boolean}
302
+ */
303
+ isActive: function (element, className, defaultActivation) {
304
+ var no = 'no-' + className;
305
+
306
+ while (element) {
307
+ var classList = element.classList;
308
+ if (classList.contains(className)) {
309
+ return true;
310
+ }
311
+ if (classList.contains(no)) {
312
+ return false;
313
+ }
314
+ element = element.parentElement;
315
+ }
316
+ return !!defaultActivation;
317
+ }
318
+ },
319
+
320
+ /**
321
+ * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
322
+ *
323
+ * @namespace
324
+ * @memberof Prism
325
+ * @public
326
+ */
327
+ languages: {
328
+ /**
329
+ * The grammar for plain, unformatted text.
330
+ */
331
+ plain: plainTextGrammar,
332
+ plaintext: plainTextGrammar,
333
+ text: plainTextGrammar,
334
+ txt: plainTextGrammar,
335
+
336
+ /**
337
+ * Creates a deep copy of the language with the given id and appends the given tokens.
338
+ *
339
+ * If a token in `redef` also appears in the copied language, then the existing token in the copied language
340
+ * will be overwritten at its original position.
341
+ *
342
+ * ## Best practices
343
+ *
344
+ * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
345
+ * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
346
+ * understand the language definition because, normally, the order of tokens matters in Prism grammars.
347
+ *
348
+ * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
349
+ * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
350
+ *
351
+ * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
352
+ * @param {Grammar} redef The new tokens to append.
353
+ * @returns {Grammar} The new language created.
354
+ * @public
355
+ * @example
356
+ * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
357
+ * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
358
+ * // at its original position
359
+ * 'comment': { ... },
360
+ * // CSS doesn't have a 'color' token, so this token will be appended
361
+ * 'color': /\b(?:red|green|blue)\b/
362
+ * });
363
+ */
364
+ extend: function (id, redef) {
365
+ var lang = _.util.clone(_.languages[id]);
366
+
367
+ for (var key in redef) {
368
+ lang[key] = redef[key];
369
+ }
370
+
371
+ return lang;
372
+ },
373
+
374
+ /**
375
+ * Inserts tokens _before_ another token in a language definition or any other grammar.
376
+ *
377
+ * ## Usage
378
+ *
379
+ * This helper method makes it easy to modify existing languages. For example, the CSS language definition
380
+ * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
381
+ * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
382
+ * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
383
+ * this:
384
+ *
385
+ * ```js
386
+ * Prism.languages.markup.style = {
387
+ * // token
388
+ * };
389
+ * ```
390
+ *
391
+ * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
392
+ * before existing tokens. For the CSS example above, you would use it like this:
393
+ *
394
+ * ```js
395
+ * Prism.languages.insertBefore('markup', 'cdata', {
396
+ * 'style': {
397
+ * // token
398
+ * }
399
+ * });
400
+ * ```
401
+ *
402
+ * ## Special cases
403
+ *
404
+ * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
405
+ * will be ignored.
406
+ *
407
+ * This behavior can be used to insert tokens after `before`:
408
+ *
409
+ * ```js
410
+ * Prism.languages.insertBefore('markup', 'comment', {
411
+ * 'comment': Prism.languages.markup.comment,
412
+ * // tokens after 'comment'
413
+ * });
414
+ * ```
415
+ *
416
+ * ## Limitations
417
+ *
418
+ * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
419
+ * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
420
+ * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
421
+ * deleting properties which is necessary to insert at arbitrary positions.
422
+ *
423
+ * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
424
+ * Instead, it will create a new object and replace all references to the target object with the new one. This
425
+ * can be done without temporarily deleting properties, so the iteration order is well-defined.
426
+ *
427
+ * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
428
+ * you hold the target object in a variable, then the value of the variable will not change.
429
+ *
430
+ * ```js
431
+ * var oldMarkup = Prism.languages.markup;
432
+ * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
433
+ *
434
+ * assert(oldMarkup !== Prism.languages.markup);
435
+ * assert(newMarkup === Prism.languages.markup);
436
+ * ```
437
+ *
438
+ * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
439
+ * object to be modified.
440
+ * @param {string} before The key to insert before.
441
+ * @param {Grammar} insert An object containing the key-value pairs to be inserted.
442
+ * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
443
+ * object to be modified.
444
+ *
445
+ * Defaults to `Prism.languages`.
446
+ * @returns {Grammar} The new grammar object.
447
+ * @public
448
+ */
449
+ insertBefore: function (inside, before, insert, root) {
450
+ root = root || /** @type {any} */ (_.languages);
451
+ var grammar = root[inside];
452
+ /** @type {Grammar} */
453
+ var ret = {};
454
+
455
+ for (var token in grammar) {
456
+ if (grammar.hasOwnProperty(token)) {
457
+
458
+ if (token == before) {
459
+ for (var newToken in insert) {
460
+ if (insert.hasOwnProperty(newToken)) {
461
+ ret[newToken] = insert[newToken];
462
+ }
463
+ }
464
+ }
465
+
466
+ // Do not insert token which also occur in insert. See #1525
467
+ if (!insert.hasOwnProperty(token)) {
468
+ ret[token] = grammar[token];
469
+ }
470
+ }
471
+ }
472
+
473
+ var old = root[inside];
474
+ root[inside] = ret;
475
+
476
+ // Update references in other language definitions
477
+ _.languages.DFS(_.languages, function (key, value) {
478
+ if (value === old && key != inside) {
479
+ this[key] = ret;
480
+ }
481
+ });
482
+
483
+ return ret;
484
+ },
485
+
486
+ // Traverse a language definition with Depth First Search
487
+ DFS: function DFS(o, callback, type, visited) {
488
+ visited = visited || {};
489
+
490
+ var objId = _.util.objId;
491
+
492
+ for (var i in o) {
493
+ if (o.hasOwnProperty(i)) {
494
+ callback.call(o, i, o[i], type || i);
495
+
496
+ var property = o[i];
497
+ var propertyType = _.util.type(property);
498
+
499
+ if (propertyType === 'Object' && !visited[objId(property)]) {
500
+ visited[objId(property)] = true;
501
+ DFS(property, callback, null, visited);
502
+ } else if (propertyType === 'Array' && !visited[objId(property)]) {
503
+ visited[objId(property)] = true;
504
+ DFS(property, callback, i, visited);
505
+ }
506
+ }
507
+ }
508
+ }
509
+ },
510
+
511
+ plugins: {},
512
+
513
+ /**
514
+ * This is the most high-level function in Prism’s API.
515
+ * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
516
+ * each one of them.
517
+ *
518
+ * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
519
+ *
520
+ * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
521
+ * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
522
+ * @memberof Prism
523
+ * @public
524
+ */
525
+ highlightAll: function (async, callback) {
526
+ _.highlightAllUnder(document, async, callback);
527
+ },
528
+
529
+ /**
530
+ * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
531
+ * {@link Prism.highlightElement} on each one of them.
532
+ *
533
+ * The following hooks will be run:
534
+ * 1. `before-highlightall`
535
+ * 2. `before-all-elements-highlight`
536
+ * 3. All hooks of {@link Prism.highlightElement} for each element.
537
+ *
538
+ * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
539
+ * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
540
+ * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
541
+ * @memberof Prism
542
+ * @public
543
+ */
544
+ highlightAllUnder: function (container, async, callback) {
545
+ var env = {
546
+ callback: callback,
547
+ container: container,
548
+ selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
549
+ };
550
+
551
+ _.hooks.run('before-highlightall', env);
552
+
553
+ env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
554
+
555
+ _.hooks.run('before-all-elements-highlight', env);
556
+
557
+ for (var i = 0, element; (element = env.elements[i++]);) {
558
+ _.highlightElement(element, async === true, env.callback);
559
+ }
560
+ },
561
+
562
+ /**
563
+ * Highlights the code inside a single element.
564
+ *
565
+ * The following hooks will be run:
566
+ * 1. `before-sanity-check`
567
+ * 2. `before-highlight`
568
+ * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
569
+ * 4. `before-insert`
570
+ * 5. `after-highlight`
571
+ * 6. `complete`
572
+ *
573
+ * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
574
+ * the element's language.
575
+ *
576
+ * @param {Element} element The element containing the code.
577
+ * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
578
+ * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
579
+ * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
580
+ * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
581
+ *
582
+ * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
583
+ * asynchronous highlighting to work. You can build your own bundle on the
584
+ * [Download page](https://prismjs.com/download.html).
585
+ * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
586
+ * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
587
+ * @memberof Prism
588
+ * @public
589
+ */
590
+ highlightElement: function (element, async, callback) {
591
+ // Find language
592
+ var language = _.util.getLanguage(element);
593
+ var grammar = _.languages[language];
594
+
595
+ // Set language on the element, if not present
596
+ element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
597
+
598
+ // Set language on the parent, for styling
599
+ var parent = element.parentElement;
600
+ if (parent && parent.nodeName.toLowerCase() === 'pre') {
601
+ parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
602
+ }
603
+
604
+ var code = element.textContent;
605
+
606
+ var env = {
607
+ element: element,
608
+ language: language,
609
+ grammar: grammar,
610
+ code: code
611
+ };
612
+
613
+ function insertHighlightedCode(highlightedCode) {
614
+ env.highlightedCode = highlightedCode;
615
+
616
+ _.hooks.run('before-insert', env);
617
+
618
+ env.element.innerHTML = env.highlightedCode;
619
+
620
+ _.hooks.run('after-highlight', env);
621
+ _.hooks.run('complete', env);
622
+ callback && callback.call(env.element);
623
+ }
624
+
625
+ _.hooks.run('before-sanity-check', env);
626
+
627
+ // plugins may change/add the parent/element
628
+ parent = env.element.parentElement;
629
+ if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
630
+ parent.setAttribute('tabindex', '0');
631
+ }
632
+
633
+ if (!env.code) {
634
+ _.hooks.run('complete', env);
635
+ callback && callback.call(env.element);
636
+ return;
637
+ }
638
+
639
+ _.hooks.run('before-highlight', env);
640
+
641
+ if (!env.grammar) {
642
+ insertHighlightedCode(_.util.encode(env.code));
643
+ return;
644
+ }
645
+
646
+ if (async && _self.Worker) {
647
+ var worker = new Worker(_.filename);
648
+
649
+ worker.onmessage = function (evt) {
650
+ insertHighlightedCode(evt.data);
651
+ };
652
+
653
+ worker.postMessage(JSON.stringify({
654
+ language: env.language,
655
+ code: env.code,
656
+ immediateClose: true
657
+ }));
658
+ } else {
659
+ insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
660
+ }
661
+ },
662
+
663
+ /**
664
+ * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
665
+ * and the language definitions to use, and returns a string with the HTML produced.
666
+ *
667
+ * The following hooks will be run:
668
+ * 1. `before-tokenize`
669
+ * 2. `after-tokenize`
670
+ * 3. `wrap`: On each {@link Token}.
671
+ *
672
+ * @param {string} text A string with the code to be highlighted.
673
+ * @param {Grammar} grammar An object containing the tokens to use.
674
+ *
675
+ * Usually a language definition like `Prism.languages.markup`.
676
+ * @param {string} language The name of the language definition passed to `grammar`.
677
+ * @returns {string} The highlighted HTML.
678
+ * @memberof Prism
679
+ * @public
680
+ * @example
681
+ * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
682
+ */
683
+ highlight: function (text, grammar, language) {
684
+ var env = {
685
+ code: text,
686
+ grammar: grammar,
687
+ language: language
688
+ };
689
+ _.hooks.run('before-tokenize', env);
690
+ env.tokens = _.tokenize(env.code, env.grammar);
691
+ _.hooks.run('after-tokenize', env);
692
+ return Token.stringify(_.util.encode(env.tokens), env.language);
693
+ },
694
+
695
+ /**
696
+ * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
697
+ * and the language definitions to use, and returns an array with the tokenized code.
698
+ *
699
+ * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
700
+ *
701
+ * This method could be useful in other contexts as well, as a very crude parser.
702
+ *
703
+ * @param {string} text A string with the code to be highlighted.
704
+ * @param {Grammar} grammar An object containing the tokens to use.
705
+ *
706
+ * Usually a language definition like `Prism.languages.markup`.
707
+ * @returns {TokenStream} An array of strings and tokens, a token stream.
708
+ * @memberof Prism
709
+ * @public
710
+ * @example
711
+ * let code = `var foo = 0;`;
712
+ * let tokens = Prism.tokenize(code, Prism.languages.javascript);
713
+ * tokens.forEach(token => {
714
+ * if (token instanceof Prism.Token && token.type === 'number') {
715
+ * console.log(`Found numeric literal: ${token.content}`);
716
+ * }
717
+ * });
718
+ */
719
+ tokenize: function (text, grammar) {
720
+ var rest = grammar.rest;
721
+ if (rest) {
722
+ for (var token in rest) {
723
+ grammar[token] = rest[token];
724
+ }
725
+
726
+ delete grammar.rest;
727
+ }
728
+
729
+ var tokenList = new LinkedList();
730
+ addAfter(tokenList, tokenList.head, text);
731
+
732
+ matchGrammar(text, tokenList, grammar, tokenList.head, 0);
733
+
734
+ return toArray(tokenList);
735
+ },
736
+
737
+ /**
738
+ * @namespace
739
+ * @memberof Prism
740
+ * @public
741
+ */
742
+ hooks: {
743
+ all: {},
744
+
745
+ /**
746
+ * Adds the given callback to the list of callbacks for the given hook.
747
+ *
748
+ * The callback will be invoked when the hook it is registered for is run.
749
+ * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
750
+ *
751
+ * One callback function can be registered to multiple hooks and the same hook multiple times.
752
+ *
753
+ * @param {string} name The name of the hook.
754
+ * @param {HookCallback} callback The callback function which is given environment variables.
755
+ * @public
756
+ */
757
+ add: function (name, callback) {
758
+ var hooks = _.hooks.all;
759
+
760
+ hooks[name] = hooks[name] || [];
761
+
762
+ hooks[name].push(callback);
763
+ },
764
+
765
+ /**
766
+ * Runs a hook invoking all registered callbacks with the given environment variables.
767
+ *
768
+ * Callbacks will be invoked synchronously and in the order in which they were registered.
769
+ *
770
+ * @param {string} name The name of the hook.
771
+ * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
772
+ * @public
773
+ */
774
+ run: function (name, env) {
775
+ var callbacks = _.hooks.all[name];
776
+
777
+ if (!callbacks || !callbacks.length) {
778
+ return;
779
+ }
780
+
781
+ for (var i = 0, callback; (callback = callbacks[i++]);) {
782
+ callback(env);
783
+ }
784
+ }
785
+ },
786
+
787
+ Token: Token
788
+ };
789
+ _self.Prism = _;
790
+
791
+
792
+ // Typescript note:
793
+ // The following can be used to import the Token type in JSDoc:
794
+ //
795
+ // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
796
+
797
+ /**
798
+ * Creates a new token.
799
+ *
800
+ * @param {string} type See {@link Token#type type}
801
+ * @param {string | TokenStream} content See {@link Token#content content}
802
+ * @param {string|string[]} [alias] The alias(es) of the token.
803
+ * @param {string} [matchedStr=""] A copy of the full string this token was created from.
804
+ * @class
805
+ * @global
806
+ * @public
807
+ */
808
+ function Token(type, content, alias, matchedStr) {
809
+ /**
810
+ * The type of the token.
811
+ *
812
+ * This is usually the key of a pattern in a {@link Grammar}.
813
+ *
814
+ * @type {string}
815
+ * @see GrammarToken
816
+ * @public
817
+ */
818
+ this.type = type;
819
+ /**
820
+ * The strings or tokens contained by this token.
821
+ *
822
+ * This will be a token stream if the pattern matched also defined an `inside` grammar.
823
+ *
824
+ * @type {string | TokenStream}
825
+ * @public
826
+ */
827
+ this.content = content;
828
+ /**
829
+ * The alias(es) of the token.
830
+ *
831
+ * @type {string|string[]}
832
+ * @see GrammarToken
833
+ * @public
834
+ */
835
+ this.alias = alias;
836
+ // Copy of the full string this token was created from
837
+ this.length = (matchedStr || '').length | 0;
838
+ }
839
+
840
+ /**
841
+ * A token stream is an array of strings and {@link Token Token} objects.
842
+ *
843
+ * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
844
+ * them.
845
+ *
846
+ * 1. No adjacent strings.
847
+ * 2. No empty strings.
848
+ *
849
+ * The only exception here is the token stream that only contains the empty string and nothing else.
850
+ *
851
+ * @typedef {Array<string | Token>} TokenStream
852
+ * @global
853
+ * @public
854
+ */
855
+
856
+ /**
857
+ * Converts the given token or token stream to an HTML representation.
858
+ *
859
+ * The following hooks will be run:
860
+ * 1. `wrap`: On each {@link Token}.
861
+ *
862
+ * @param {string | Token | TokenStream} o The token or token stream to be converted.
863
+ * @param {string} language The name of current language.
864
+ * @returns {string} The HTML representation of the token or token stream.
865
+ * @memberof Token
866
+ * @static
867
+ */
868
+ Token.stringify = function stringify(o, language) {
869
+ if (typeof o == 'string') {
870
+ return o;
871
+ }
872
+ if (Array.isArray(o)) {
873
+ var s = '';
874
+ o.forEach(function (e) {
875
+ s += stringify(e, language);
876
+ });
877
+ return s;
878
+ }
879
+
880
+ var env = {
881
+ type: o.type,
882
+ content: stringify(o.content, language),
883
+ tag: 'span',
884
+ classes: ['token', o.type],
885
+ attributes: {},
886
+ language: language
887
+ };
888
+
889
+ var aliases = o.alias;
890
+ if (aliases) {
891
+ if (Array.isArray(aliases)) {
892
+ Array.prototype.push.apply(env.classes, aliases);
893
+ } else {
894
+ env.classes.push(aliases);
895
+ }
896
+ }
897
+
898
+ _.hooks.run('wrap', env);
899
+
900
+ var attributes = '';
901
+ for (var name in env.attributes) {
902
+ attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
903
+ }
904
+
905
+ return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
906
+ };
907
+
908
+ /**
909
+ * @param {RegExp} pattern
910
+ * @param {number} pos
911
+ * @param {string} text
912
+ * @param {boolean} lookbehind
913
+ * @returns {RegExpExecArray | null}
914
+ */
915
+ function matchPattern(pattern, pos, text, lookbehind) {
916
+ pattern.lastIndex = pos;
917
+ var match = pattern.exec(text);
918
+ if (match && lookbehind && match[1]) {
919
+ // change the match to remove the text matched by the Prism lookbehind group
920
+ var lookbehindLength = match[1].length;
921
+ match.index += lookbehindLength;
922
+ match[0] = match[0].slice(lookbehindLength);
923
+ }
924
+ return match;
925
+ }
926
+
927
+ /**
928
+ * @param {string} text
929
+ * @param {LinkedList<string | Token>} tokenList
930
+ * @param {any} grammar
931
+ * @param {LinkedListNode<string | Token>} startNode
932
+ * @param {number} startPos
933
+ * @param {RematchOptions} [rematch]
934
+ * @returns {void}
935
+ * @private
936
+ *
937
+ * @typedef RematchOptions
938
+ * @property {string} cause
939
+ * @property {number} reach
940
+ */
941
+ function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
942
+ for (var token in grammar) {
943
+ if (!grammar.hasOwnProperty(token) || !grammar[token]) {
944
+ continue;
945
+ }
946
+
947
+ var patterns = grammar[token];
948
+ patterns = Array.isArray(patterns) ? patterns : [patterns];
949
+
950
+ for (var j = 0; j < patterns.length; ++j) {
951
+ if (rematch && rematch.cause == token + ',' + j) {
952
+ return;
953
+ }
954
+
955
+ var patternObj = patterns[j];
956
+ var inside = patternObj.inside;
957
+ var lookbehind = !!patternObj.lookbehind;
958
+ var greedy = !!patternObj.greedy;
959
+ var alias = patternObj.alias;
960
+
961
+ if (greedy && !patternObj.pattern.global) {
962
+ // Without the global flag, lastIndex won't work
963
+ var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
964
+ patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
965
+ }
966
+
967
+ /** @type {RegExp} */
968
+ var pattern = patternObj.pattern || patternObj;
969
+
970
+ for ( // iterate the token list and keep track of the current token/string position
971
+ var currentNode = startNode.next, pos = startPos;
972
+ currentNode !== tokenList.tail;
973
+ pos += currentNode.value.length, currentNode = currentNode.next
974
+ ) {
975
+
976
+ if (rematch && pos >= rematch.reach) {
977
+ break;
978
+ }
979
+
980
+ var str = currentNode.value;
981
+
982
+ if (tokenList.length > text.length) {
983
+ // Something went terribly wrong, ABORT, ABORT!
984
+ return;
985
+ }
986
+
987
+ if (str instanceof Token) {
988
+ continue;
989
+ }
990
+
991
+ var removeCount = 1; // this is the to parameter of removeBetween
992
+ var match;
993
+
994
+ if (greedy) {
995
+ match = matchPattern(pattern, pos, text, lookbehind);
996
+ if (!match) {
997
+ break;
998
+ }
999
+
1000
+ var from = match.index;
1001
+ var to = match.index + match[0].length;
1002
+ var p = pos;
1003
+
1004
+ // find the node that contains the match
1005
+ p += currentNode.value.length;
1006
+ while (from >= p) {
1007
+ currentNode = currentNode.next;
1008
+ p += currentNode.value.length;
1009
+ }
1010
+ // adjust pos (and p)
1011
+ p -= currentNode.value.length;
1012
+ pos = p;
1013
+
1014
+ // the current node is a Token, then the match starts inside another Token, which is invalid
1015
+ if (currentNode.value instanceof Token) {
1016
+ continue;
1017
+ }
1018
+
1019
+ // find the last node which is affected by this match
1020
+ for (
1021
+ var k = currentNode;
1022
+ k !== tokenList.tail && (p < to || typeof k.value === 'string');
1023
+ k = k.next
1024
+ ) {
1025
+ removeCount++;
1026
+ p += k.value.length;
1027
+ }
1028
+ removeCount--;
1029
+
1030
+ // replace with the new match
1031
+ str = text.slice(pos, p);
1032
+ match.index -= pos;
1033
+ } else {
1034
+ match = matchPattern(pattern, 0, str, lookbehind);
1035
+ if (!match) {
1036
+ continue;
1037
+ }
1038
+ }
1039
+
1040
+ // eslint-disable-next-line no-redeclare
1041
+ var from = match.index;
1042
+ var matchStr = match[0];
1043
+ var before = str.slice(0, from);
1044
+ var after = str.slice(from + matchStr.length);
1045
+
1046
+ var reach = pos + str.length;
1047
+ if (rematch && reach > rematch.reach) {
1048
+ rematch.reach = reach;
1049
+ }
1050
+
1051
+ var removeFrom = currentNode.prev;
1052
+
1053
+ if (before) {
1054
+ removeFrom = addAfter(tokenList, removeFrom, before);
1055
+ pos += before.length;
1056
+ }
1057
+
1058
+ removeRange(tokenList, removeFrom, removeCount);
1059
+
1060
+ var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
1061
+ currentNode = addAfter(tokenList, removeFrom, wrapped);
1062
+
1063
+ if (after) {
1064
+ addAfter(tokenList, currentNode, after);
1065
+ }
1066
+
1067
+ if (removeCount > 1) {
1068
+ // at least one Token object was removed, so we have to do some rematching
1069
+ // this can only happen if the current pattern is greedy
1070
+
1071
+ /** @type {RematchOptions} */
1072
+ var nestedRematch = {
1073
+ cause: token + ',' + j,
1074
+ reach: reach
1075
+ };
1076
+ matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
1077
+
1078
+ // the reach might have been extended because of the rematching
1079
+ if (rematch && nestedRematch.reach > rematch.reach) {
1080
+ rematch.reach = nestedRematch.reach;
1081
+ }
1082
+ }
1083
+ }
1084
+ }
1085
+ }
1086
+ }
1087
+
1088
+ /**
1089
+ * @typedef LinkedListNode
1090
+ * @property {T} value
1091
+ * @property {LinkedListNode<T> | null} prev The previous node.
1092
+ * @property {LinkedListNode<T> | null} next The next node.
1093
+ * @template T
1094
+ * @private
1095
+ */
1096
+
1097
+ /**
1098
+ * @template T
1099
+ * @private
1100
+ */
1101
+ function LinkedList() {
1102
+ /** @type {LinkedListNode<T>} */
1103
+ var head = { value: null, prev: null, next: null };
1104
+ /** @type {LinkedListNode<T>} */
1105
+ var tail = { value: null, prev: head, next: null };
1106
+ head.next = tail;
1107
+
1108
+ /** @type {LinkedListNode<T>} */
1109
+ this.head = head;
1110
+ /** @type {LinkedListNode<T>} */
1111
+ this.tail = tail;
1112
+ this.length = 0;
1113
+ }
1114
+
1115
+ /**
1116
+ * Adds a new node with the given value to the list.
1117
+ *
1118
+ * @param {LinkedList<T>} list
1119
+ * @param {LinkedListNode<T>} node
1120
+ * @param {T} value
1121
+ * @returns {LinkedListNode<T>} The added node.
1122
+ * @template T
1123
+ */
1124
+ function addAfter(list, node, value) {
1125
+ // assumes that node != list.tail && values.length >= 0
1126
+ var next = node.next;
1127
+
1128
+ var newNode = { value: value, prev: node, next: next };
1129
+ node.next = newNode;
1130
+ next.prev = newNode;
1131
+ list.length++;
1132
+
1133
+ return newNode;
1134
+ }
1135
+ /**
1136
+ * Removes `count` nodes after the given node. The given node will not be removed.
1137
+ *
1138
+ * @param {LinkedList<T>} list
1139
+ * @param {LinkedListNode<T>} node
1140
+ * @param {number} count
1141
+ * @template T
1142
+ */
1143
+ function removeRange(list, node, count) {
1144
+ var next = node.next;
1145
+ for (var i = 0; i < count && next !== list.tail; i++) {
1146
+ next = next.next;
1147
+ }
1148
+ node.next = next;
1149
+ next.prev = node;
1150
+ list.length -= i;
1151
+ }
1152
+ /**
1153
+ * @param {LinkedList<T>} list
1154
+ * @returns {T[]}
1155
+ * @template T
1156
+ */
1157
+ function toArray(list) {
1158
+ var array = [];
1159
+ var node = list.head.next;
1160
+ while (node !== list.tail) {
1161
+ array.push(node.value);
1162
+ node = node.next;
1163
+ }
1164
+ return array;
1165
+ }
1166
+
1167
+
1168
+ if (!_self.document) {
1169
+ if (!_self.addEventListener) {
1170
+ // in Node.js
1171
+ return _;
1172
+ }
1173
+
1174
+ if (!_.disableWorkerMessageHandler) {
1175
+ // In worker
1176
+ _self.addEventListener('message', function (evt) {
1177
+ var message = JSON.parse(evt.data);
1178
+ var lang = message.language;
1179
+ var code = message.code;
1180
+ var immediateClose = message.immediateClose;
1181
+
1182
+ _self.postMessage(_.highlight(code, _.languages[lang], lang));
1183
+ if (immediateClose) {
1184
+ _self.close();
1185
+ }
1186
+ }, false);
1187
+ }
1188
+
1189
+ return _;
1190
+ }
1191
+
1192
+ // Get current script and highlight
1193
+ var script = _.util.currentScript();
1194
+
1195
+ if (script) {
1196
+ _.filename = script.src;
1197
+
1198
+ if (script.hasAttribute('data-manual')) {
1199
+ _.manual = true;
1200
+ }
1201
+ }
1202
+
1203
+ function highlightAutomaticallyCallback() {
1204
+ if (!_.manual) {
1205
+ _.highlightAll();
1206
+ }
1207
+ }
1208
+
1209
+ if (!_.manual) {
1210
+ // If the document state is "loading", then we'll use DOMContentLoaded.
1211
+ // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
1212
+ // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
1213
+ // might take longer one animation frame to execute which can create a race condition where only some plugins have
1214
+ // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
1215
+ // See https://github.com/PrismJS/prism/issues/2102
1216
+ var readyState = document.readyState;
1217
+ if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
1218
+ document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
1219
+ } else {
1220
+ if (window.requestAnimationFrame) {
1221
+ window.requestAnimationFrame(highlightAutomaticallyCallback);
1222
+ } else {
1223
+ window.setTimeout(highlightAutomaticallyCallback, 16);
1224
+ }
1225
+ }
1226
+ }
1227
+
1228
+ return _;
1229
+
1230
+ }(_self));
1231
+
1232
+ if (module.exports) {
1233
+ module.exports = Prism;
1234
+ }
1235
+
1236
+ // hack for components to work correctly in node.js
1237
+ if (typeof commonjsGlobal !== 'undefined') {
1238
+ commonjsGlobal.Prism = Prism;
1239
+ }
1240
+
1241
+ // some additional documentation/types
1242
+
1243
+ /**
1244
+ * The expansion of a simple `RegExp` literal to support additional properties.
1245
+ *
1246
+ * @typedef GrammarToken
1247
+ * @property {RegExp} pattern The regular expression of the token.
1248
+ * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
1249
+ * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
1250
+ * @property {boolean} [greedy=false] Whether the token is greedy.
1251
+ * @property {string|string[]} [alias] An optional alias or list of aliases.
1252
+ * @property {Grammar} [inside] The nested grammar of this token.
1253
+ *
1254
+ * The `inside` grammar will be used to tokenize the text value of each token of this kind.
1255
+ *
1256
+ * This can be used to make nested and even recursive language definitions.
1257
+ *
1258
+ * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
1259
+ * each another.
1260
+ * @global
1261
+ * @public
1262
+ */
1263
+
1264
+ /**
1265
+ * @typedef Grammar
1266
+ * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
1267
+ * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
1268
+ * @global
1269
+ * @public
1270
+ */
1271
+
1272
+ /**
1273
+ * A function which will invoked after an element was successfully highlighted.
1274
+ *
1275
+ * @callback HighlightCallback
1276
+ * @param {Element} element The element successfully highlighted.
1277
+ * @returns {void}
1278
+ * @global
1279
+ * @public
1280
+ */
1281
+
1282
+ /**
1283
+ * @callback HookCallback
1284
+ * @param {Object<string, any>} env The environment variables of the hook.
1285
+ * @returns {void}
1286
+ * @global
1287
+ * @public
1288
+ */
1289
+
1290
+
1291
+ /* **********************************************
1292
+ Begin prism-markup.js
1293
+ ********************************************** */
1294
+
1295
+ Prism.languages.markup = {
1296
+ 'comment': {
1297
+ pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
1298
+ greedy: true
1299
+ },
1300
+ 'prolog': {
1301
+ pattern: /<\?[\s\S]+?\?>/,
1302
+ greedy: true
1303
+ },
1304
+ 'doctype': {
1305
+ // https://www.w3.org/TR/xml/#NT-doctypedecl
1306
+ pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
1307
+ greedy: true,
1308
+ inside: {
1309
+ 'internal-subset': {
1310
+ pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
1311
+ lookbehind: true,
1312
+ greedy: true,
1313
+ inside: null // see below
1314
+ },
1315
+ 'string': {
1316
+ pattern: /"[^"]*"|'[^']*'/,
1317
+ greedy: true
1318
+ },
1319
+ 'punctuation': /^<!|>$|[[\]]/,
1320
+ 'doctype-tag': /^DOCTYPE/i,
1321
+ 'name': /[^\s<>'"]+/
1322
+ }
1323
+ },
1324
+ 'cdata': {
1325
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1326
+ greedy: true
1327
+ },
1328
+ 'tag': {
1329
+ pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
1330
+ greedy: true,
1331
+ inside: {
1332
+ 'tag': {
1333
+ pattern: /^<\/?[^\s>\/]+/,
1334
+ inside: {
1335
+ 'punctuation': /^<\/?/,
1336
+ 'namespace': /^[^\s>\/:]+:/
1337
+ }
1338
+ },
1339
+ 'special-attr': [],
1340
+ 'attr-value': {
1341
+ pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
1342
+ inside: {
1343
+ 'punctuation': [
1344
+ {
1345
+ pattern: /^=/,
1346
+ alias: 'attr-equals'
1347
+ },
1348
+ /"|'/
1349
+ ]
1350
+ }
1351
+ },
1352
+ 'punctuation': /\/?>/,
1353
+ 'attr-name': {
1354
+ pattern: /[^\s>\/]+/,
1355
+ inside: {
1356
+ 'namespace': /^[^\s>\/:]+:/
1357
+ }
1358
+ }
1359
+
1360
+ }
1361
+ },
1362
+ 'entity': [
1363
+ {
1364
+ pattern: /&[\da-z]{1,8};/i,
1365
+ alias: 'named-entity'
1366
+ },
1367
+ /&#x?[\da-f]{1,8};/i
1368
+ ]
1369
+ };
1370
+
1371
+ Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
1372
+ Prism.languages.markup['entity'];
1373
+ Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
1374
+
1375
+ // Plugin to make entity title show the real entity, idea by Roman Komarov
1376
+ Prism.hooks.add('wrap', function (env) {
1377
+
1378
+ if (env.type === 'entity') {
1379
+ env.attributes['title'] = env.content.replace(/&amp;/, '&');
1380
+ }
1381
+ });
1382
+
1383
+ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
1384
+ /**
1385
+ * Adds an inlined language to markup.
1386
+ *
1387
+ * An example of an inlined language is CSS with `<style>` tags.
1388
+ *
1389
+ * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
1390
+ * case insensitive.
1391
+ * @param {string} lang The language key.
1392
+ * @example
1393
+ * addInlined('style', 'css');
1394
+ */
1395
+ value: function addInlined(tagName, lang) {
1396
+ var includedCdataInside = {};
1397
+ includedCdataInside['language-' + lang] = {
1398
+ pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
1399
+ lookbehind: true,
1400
+ inside: Prism.languages[lang]
1401
+ };
1402
+ includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
1403
+
1404
+ var inside = {
1405
+ 'included-cdata': {
1406
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1407
+ inside: includedCdataInside
1408
+ }
1409
+ };
1410
+ inside['language-' + lang] = {
1411
+ pattern: /[\s\S]+/,
1412
+ inside: Prism.languages[lang]
1413
+ };
1414
+
1415
+ var def = {};
1416
+ def[tagName] = {
1417
+ pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
1418
+ lookbehind: true,
1419
+ greedy: true,
1420
+ inside: inside
1421
+ };
1422
+
1423
+ Prism.languages.insertBefore('markup', 'cdata', def);
1424
+ }
1425
+ });
1426
+ Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
1427
+ /**
1428
+ * Adds an pattern to highlight languages embedded in HTML attributes.
1429
+ *
1430
+ * An example of an inlined language is CSS with `style` attributes.
1431
+ *
1432
+ * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
1433
+ * case insensitive.
1434
+ * @param {string} lang The language key.
1435
+ * @example
1436
+ * addAttribute('style', 'css');
1437
+ */
1438
+ value: function (attrName, lang) {
1439
+ Prism.languages.markup.tag.inside['special-attr'].push({
1440
+ pattern: RegExp(
1441
+ /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
1442
+ 'i'
1443
+ ),
1444
+ lookbehind: true,
1445
+ inside: {
1446
+ 'attr-name': /^[^\s=]+/,
1447
+ 'attr-value': {
1448
+ pattern: /=[\s\S]+/,
1449
+ inside: {
1450
+ 'value': {
1451
+ pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
1452
+ lookbehind: true,
1453
+ alias: [lang, 'language-' + lang],
1454
+ inside: Prism.languages[lang]
1455
+ },
1456
+ 'punctuation': [
1457
+ {
1458
+ pattern: /^=/,
1459
+ alias: 'attr-equals'
1460
+ },
1461
+ /"|'/
1462
+ ]
1463
+ }
1464
+ }
1465
+ }
1466
+ });
1467
+ }
1468
+ });
1469
+
1470
+ Prism.languages.html = Prism.languages.markup;
1471
+ Prism.languages.mathml = Prism.languages.markup;
1472
+ Prism.languages.svg = Prism.languages.markup;
1473
+
1474
+ Prism.languages.xml = Prism.languages.extend('markup', {});
1475
+ Prism.languages.ssml = Prism.languages.xml;
1476
+ Prism.languages.atom = Prism.languages.xml;
1477
+ Prism.languages.rss = Prism.languages.xml;
1478
+
1479
+
1480
+ /* **********************************************
1481
+ Begin prism-css.js
1482
+ ********************************************** */
1483
+
1484
+ (function (Prism) {
1485
+
1486
+ var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
1487
+
1488
+ Prism.languages.css = {
1489
+ 'comment': /\/\*[\s\S]*?\*\//,
1490
+ 'atrule': {
1491
+ pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
1492
+ inside: {
1493
+ 'rule': /^@[\w-]+/,
1494
+ 'selector-function-argument': {
1495
+ pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
1496
+ lookbehind: true,
1497
+ alias: 'selector'
1498
+ },
1499
+ 'keyword': {
1500
+ pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
1501
+ lookbehind: true
1502
+ }
1503
+ // See rest below
1504
+ }
1505
+ },
1506
+ 'url': {
1507
+ // https://drafts.csswg.org/css-values-3/#urls
1508
+ pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
1509
+ greedy: true,
1510
+ inside: {
1511
+ 'function': /^url/i,
1512
+ 'punctuation': /^\(|\)$/,
1513
+ 'string': {
1514
+ pattern: RegExp('^' + string.source + '$'),
1515
+ alias: 'url'
1516
+ }
1517
+ }
1518
+ },
1519
+ 'selector': {
1520
+ pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
1521
+ lookbehind: true
1522
+ },
1523
+ 'string': {
1524
+ pattern: string,
1525
+ greedy: true
1526
+ },
1527
+ 'property': {
1528
+ pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
1529
+ lookbehind: true
1530
+ },
1531
+ 'important': /!important\b/i,
1532
+ 'function': {
1533
+ pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
1534
+ lookbehind: true
1535
+ },
1536
+ 'punctuation': /[(){};:,]/
1537
+ };
1538
+
1539
+ Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
1540
+
1541
+ var markup = Prism.languages.markup;
1542
+ if (markup) {
1543
+ markup.tag.addInlined('style', 'css');
1544
+ markup.tag.addAttribute('style', 'css');
1545
+ }
1546
+
1547
+ }(Prism));
1548
+
1549
+
1550
+ /* **********************************************
1551
+ Begin prism-clike.js
1552
+ ********************************************** */
1553
+
1554
+ Prism.languages.clike = {
1555
+ 'comment': [
1556
+ {
1557
+ pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
1558
+ lookbehind: true,
1559
+ greedy: true
1560
+ },
1561
+ {
1562
+ pattern: /(^|[^\\:])\/\/.*/,
1563
+ lookbehind: true,
1564
+ greedy: true
1565
+ }
1566
+ ],
1567
+ 'string': {
1568
+ pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
1569
+ greedy: true
1570
+ },
1571
+ 'class-name': {
1572
+ pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
1573
+ lookbehind: true,
1574
+ inside: {
1575
+ 'punctuation': /[.\\]/
1576
+ }
1577
+ },
1578
+ 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
1579
+ 'boolean': /\b(?:true|false)\b/,
1580
+ 'function': /\b\w+(?=\()/,
1581
+ 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
1582
+ 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
1583
+ 'punctuation': /[{}[\];(),.:]/
1584
+ };
1585
+
1586
+
1587
+ /* **********************************************
1588
+ Begin prism-javascript.js
1589
+ ********************************************** */
1590
+
1591
+ Prism.languages.javascript = Prism.languages.extend('clike', {
1592
+ 'class-name': [
1593
+ Prism.languages.clike['class-name'],
1594
+ {
1595
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:prototype|constructor))/,
1596
+ lookbehind: true
1597
+ }
1598
+ ],
1599
+ 'keyword': [
1600
+ {
1601
+ pattern: /((?:^|\})\s*)catch\b/,
1602
+ lookbehind: true
1603
+ },
1604
+ {
1605
+ 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/,
1606
+ lookbehind: true
1607
+ },
1608
+ ],
1609
+ // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
1610
+ 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
1611
+ '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)?)+)?/,
1612
+ 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
1613
+ });
1614
+
1615
+ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
1616
+
1617
+ Prism.languages.insertBefore('javascript', 'keyword', {
1618
+ 'regex': {
1619
+ // eslint-disable-next-line regexp/no-dupe-characters-character-class
1620
+ pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
1621
+ lookbehind: true,
1622
+ greedy: true,
1623
+ inside: {
1624
+ 'regex-source': {
1625
+ pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
1626
+ lookbehind: true,
1627
+ alias: 'language-regex',
1628
+ inside: Prism.languages.regex
1629
+ },
1630
+ 'regex-delimiter': /^\/|\/$/,
1631
+ 'regex-flags': /^[a-z]+$/,
1632
+ }
1633
+ },
1634
+ // This must be declared before keyword because we use "function" inside the look-forward
1635
+ 'function-variable': {
1636
+ 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*=>))/,
1637
+ alias: 'function'
1638
+ },
1639
+ 'parameter': [
1640
+ {
1641
+ pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
1642
+ lookbehind: true,
1643
+ inside: Prism.languages.javascript
1644
+ },
1645
+ {
1646
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
1647
+ lookbehind: true,
1648
+ inside: Prism.languages.javascript
1649
+ },
1650
+ {
1651
+ pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
1652
+ lookbehind: true,
1653
+ inside: Prism.languages.javascript
1654
+ },
1655
+ {
1656
+ 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*\{)/,
1657
+ lookbehind: true,
1658
+ inside: Prism.languages.javascript
1659
+ }
1660
+ ],
1661
+ 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
1662
+ });
1663
+
1664
+ Prism.languages.insertBefore('javascript', 'string', {
1665
+ 'hashbang': {
1666
+ pattern: /^#!.*/,
1667
+ greedy: true,
1668
+ alias: 'comment'
1669
+ },
1670
+ 'template-string': {
1671
+ pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
1672
+ greedy: true,
1673
+ inside: {
1674
+ 'template-punctuation': {
1675
+ pattern: /^`|`$/,
1676
+ alias: 'string'
1677
+ },
1678
+ 'interpolation': {
1679
+ pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
1680
+ lookbehind: true,
1681
+ inside: {
1682
+ 'interpolation-punctuation': {
1683
+ pattern: /^\$\{|\}$/,
1684
+ alias: 'punctuation'
1685
+ },
1686
+ rest: Prism.languages.javascript
1687
+ }
1688
+ },
1689
+ 'string': /[\s\S]+/
1690
+ }
1691
+ }
1692
+ });
1693
+
1694
+ if (Prism.languages.markup) {
1695
+ Prism.languages.markup.tag.addInlined('script', 'javascript');
1696
+
1697
+ // add attribute support for all DOM events.
1698
+ // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
1699
+ Prism.languages.markup.tag.addAttribute(
1700
+ /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,
1701
+ 'javascript'
1702
+ );
1703
+ }
1704
+
1705
+ Prism.languages.js = Prism.languages.javascript;
1706
+
1707
+
1708
+ /* **********************************************
1709
+ Begin prism-file-highlight.js
1710
+ ********************************************** */
1711
+
1712
+ (function () {
1713
+
1714
+ if (typeof Prism === 'undefined' || typeof document === 'undefined') {
1715
+ return;
1716
+ }
1717
+
1718
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
1719
+ if (!Element.prototype.matches) {
1720
+ Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
1721
+ }
1722
+
1723
+ var LOADING_MESSAGE = 'Loading…';
1724
+ var FAILURE_MESSAGE = function (status, message) {
1725
+ return '✖ Error ' + status + ' while fetching file: ' + message;
1726
+ };
1727
+ var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
1728
+
1729
+ var EXTENSIONS = {
1730
+ 'js': 'javascript',
1731
+ 'py': 'python',
1732
+ 'rb': 'ruby',
1733
+ 'ps1': 'powershell',
1734
+ 'psm1': 'powershell',
1735
+ 'sh': 'bash',
1736
+ 'bat': 'batch',
1737
+ 'h': 'c',
1738
+ 'tex': 'latex'
1739
+ };
1740
+
1741
+ var STATUS_ATTR = 'data-src-status';
1742
+ var STATUS_LOADING = 'loading';
1743
+ var STATUS_LOADED = 'loaded';
1744
+ var STATUS_FAILED = 'failed';
1745
+
1746
+ var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
1747
+ + ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
1748
+
1749
+ var lang = /\blang(?:uage)?-([\w-]+)\b/i;
1750
+
1751
+ /**
1752
+ * Sets the Prism `language-xxxx` or `lang-xxxx` class to the given language.
1753
+ *
1754
+ * @param {HTMLElement} element
1755
+ * @param {string} language
1756
+ * @returns {void}
1757
+ */
1758
+ function setLanguageClass(element, language) {
1759
+ var className = element.className;
1760
+ className = className.replace(lang, ' ') + ' language-' + language;
1761
+ element.className = className.replace(/\s+/g, ' ').trim();
1762
+ }
1763
+
1764
+
1765
+ Prism.hooks.add('before-highlightall', function (env) {
1766
+ env.selector += ', ' + SELECTOR;
1767
+ });
1768
+
1769
+ Prism.hooks.add('before-sanity-check', function (env) {
1770
+ var pre = /** @type {HTMLPreElement} */ (env.element);
1771
+ if (pre.matches(SELECTOR)) {
1772
+ env.code = ''; // fast-path the whole thing and go to complete
1773
+
1774
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADING); // mark as loading
1775
+
1776
+ // add code element with loading message
1777
+ var code = pre.appendChild(document.createElement('CODE'));
1778
+ code.textContent = LOADING_MESSAGE;
1779
+
1780
+ var src = pre.getAttribute('data-src');
1781
+
1782
+ var language = env.language;
1783
+ if (language === 'none') {
1784
+ // the language might be 'none' because there is no language set;
1785
+ // in this case, we want to use the extension as the language
1786
+ var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
1787
+ language = EXTENSIONS[extension] || extension;
1788
+ }
1789
+
1790
+ // set language classes
1791
+ setLanguageClass(code, language);
1792
+ setLanguageClass(pre, language);
1793
+
1794
+ // preload the language
1795
+ var autoloader = Prism.plugins.autoloader;
1796
+ if (autoloader) {
1797
+ autoloader.loadLanguages(language);
1798
+ }
1799
+
1800
+ // load file
1801
+ var xhr = new XMLHttpRequest();
1802
+ xhr.open('GET', src, true);
1803
+ xhr.onreadystatechange = function () {
1804
+ if (xhr.readyState == 4) {
1805
+ if (xhr.status < 400 && xhr.responseText) {
1806
+ // mark as loaded
1807
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
1808
+
1809
+ // highlight code
1810
+ code.textContent = xhr.responseText;
1811
+ Prism.highlightElement(code);
1812
+
1813
+ } else {
1814
+ // mark as failed
1815
+ pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
1816
+
1817
+ if (xhr.status >= 400) {
1818
+ code.textContent = FAILURE_MESSAGE(xhr.status, xhr.statusText);
1819
+ } else {
1820
+ code.textContent = FAILURE_EMPTY_MESSAGE;
1821
+ }
1822
+ }
1823
+ }
1824
+ };
1825
+ xhr.send(null);
1826
+ }
1827
+ });
1828
+
1829
+ Prism.plugins.fileHighlight = {
1830
+ /**
1831
+ * Executes the File Highlight plugin for all matching `pre` elements under the given container.
1832
+ *
1833
+ * Note: Elements which are already loaded or currently loading will not be touched by this method.
1834
+ *
1835
+ * @param {ParentNode} [container=document]
1836
+ */
1837
+ highlight: function highlight(container) {
1838
+ var elements = (container || document).querySelectorAll(SELECTOR);
1839
+
1840
+ for (var i = 0, element; (element = elements[i++]);) {
1841
+ Prism.highlightElement(element);
1842
+ }
1843
+ }
1844
+ };
1845
+
1846
+ var logged = false;
1847
+ /** @deprecated Use `Prism.plugins.fileHighlight.highlight` instead. */
1848
+ Prism.fileHighlight = function () {
1849
+ if (!logged) {
1850
+ console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
1851
+ logged = true;
1852
+ }
1853
+ Prism.plugins.fileHighlight.highlight.apply(this, arguments);
1854
+ };
1855
+
1856
+ }());
1857
+ });
1858
+
1859
+ (function (Prism) {
1860
+
1861
+ var javascript = Prism.util.clone(Prism.languages.javascript);
1862
+
1863
+ var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
1864
+ var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
1865
+ var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
1866
+
1867
+ /**
1868
+ * @param {string} source
1869
+ * @param {string} [flags]
1870
+ */
1871
+ function re(source, flags) {
1872
+ source = source
1873
+ .replace(/<S>/g, function () { return space; })
1874
+ .replace(/<BRACES>/g, function () { return braces; })
1875
+ .replace(/<SPREAD>/g, function () { return spread; });
1876
+ return RegExp(source, flags);
1877
+ }
1878
+
1879
+ spread = re(spread).source;
1880
+
1881
+
1882
+ Prism.languages.jsx = Prism.languages.extend('markup', javascript);
1883
+ Prism.languages.jsx.tag.pattern = re(
1884
+ /<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
1885
+ );
1886
+
1887
+ Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/i;
1888
+ Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/i;
1889
+ Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
1890
+ Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
1891
+
1892
+ Prism.languages.insertBefore('inside', 'attr-name', {
1893
+ 'spread': {
1894
+ pattern: re(/<SPREAD>/.source),
1895
+ inside: Prism.languages.jsx
1896
+ }
1897
+ }, Prism.languages.jsx.tag);
1898
+
1899
+ Prism.languages.insertBefore('inside', 'special-attr', {
1900
+ 'script': {
1901
+ // Allow for two levels of nesting
1902
+ pattern: re(/=<BRACES>/.source),
1903
+ inside: {
1904
+ 'script-punctuation': {
1905
+ pattern: /^=(?=\{)/,
1906
+ alias: 'punctuation'
1907
+ },
1908
+ rest: Prism.languages.jsx
1909
+ },
1910
+ 'alias': 'language-javascript'
1911
+ }
1912
+ }, Prism.languages.jsx.tag);
1913
+
1914
+ // The following will handle plain text inside tags
1915
+ var stringifyToken = function (token) {
1916
+ if (!token) {
1917
+ return '';
1918
+ }
1919
+ if (typeof token === 'string') {
1920
+ return token;
1921
+ }
1922
+ if (typeof token.content === 'string') {
1923
+ return token.content;
1924
+ }
1925
+ return token.content.map(stringifyToken).join('');
1926
+ };
1927
+
1928
+ var walkTokens = function (tokens) {
1929
+ var openedTags = [];
1930
+ for (var i = 0; i < tokens.length; i++) {
1931
+ var token = tokens[i];
1932
+ var notTagNorBrace = false;
1933
+
1934
+ if (typeof token !== 'string') {
1935
+ if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
1936
+ // We found a tag, now find its kind
1937
+
1938
+ if (token.content[0].content[0].content === '</') {
1939
+ // Closing tag
1940
+ if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
1941
+ // Pop matching opening tag
1942
+ openedTags.pop();
1943
+ }
1944
+ } else {
1945
+ if (token.content[token.content.length - 1].content === '/>') ; else {
1946
+ // Opening tag
1947
+ openedTags.push({
1948
+ tagName: stringifyToken(token.content[0].content[1]),
1949
+ openedBraces: 0
1950
+ });
1951
+ }
1952
+ }
1953
+ } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
1954
+
1955
+ // Here we might have entered a JSX context inside a tag
1956
+ openedTags[openedTags.length - 1].openedBraces++;
1957
+
1958
+ } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
1959
+
1960
+ // Here we might have left a JSX context inside a tag
1961
+ openedTags[openedTags.length - 1].openedBraces--;
1962
+
1963
+ } else {
1964
+ notTagNorBrace = true;
1965
+ }
1966
+ }
1967
+ if (notTagNorBrace || typeof token === 'string') {
1968
+ if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
1969
+ // Here we are inside a tag, and not inside a JSX context.
1970
+ // That's plain text: drop any tokens matched.
1971
+ var plainText = stringifyToken(token);
1972
+
1973
+ // And merge text with adjacent text
1974
+ if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
1975
+ plainText += stringifyToken(tokens[i + 1]);
1976
+ tokens.splice(i + 1, 1);
1977
+ }
1978
+ if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
1979
+ plainText = stringifyToken(tokens[i - 1]) + plainText;
1980
+ tokens.splice(i - 1, 1);
1981
+ i--;
1982
+ }
1983
+
1984
+ tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
1985
+ }
1986
+ }
1987
+
1988
+ if (token.content && typeof token.content !== 'string') {
1989
+ walkTokens(token.content);
1990
+ }
1991
+ }
1992
+ };
1993
+
1994
+ Prism.hooks.add('after-tokenize', function (env) {
1995
+ if (env.language !== 'jsx' && env.language !== 'tsx') {
1996
+ return;
1997
+ }
1998
+ walkTokens(env.tokens);
1999
+ });
2000
+
2001
+ }(Prism));
2002
+
2003
+ (function (Prism) {
2004
+
2005
+ Prism.languages.typescript = Prism.languages.extend('javascript', {
2006
+ 'class-name': {
2007
+ pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
2008
+ lookbehind: true,
2009
+ greedy: true,
2010
+ inside: null // see below
2011
+ },
2012
+ 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
2013
+ });
2014
+
2015
+ // The keywords TypeScript adds to JavaScript
2016
+ Prism.languages.typescript.keyword.push(
2017
+ /\b(?:abstract|as|declare|implements|is|keyof|readonly|require)\b/,
2018
+ // keywords that have to be followed by an identifier
2019
+ /\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
2020
+ // This is for `import type *, {}`
2021
+ /\btype\b(?=\s*(?:[\{*]|$))/
2022
+ );
2023
+
2024
+ // doesn't work with TS because TS is too complex
2025
+ delete Prism.languages.typescript['parameter'];
2026
+
2027
+ // a version of typescript specifically for highlighting types
2028
+ var typeInside = Prism.languages.extend('typescript', {});
2029
+ delete typeInside['class-name'];
2030
+
2031
+ Prism.languages.typescript['class-name'].inside = typeInside;
2032
+
2033
+ Prism.languages.insertBefore('typescript', 'function', {
2034
+ 'decorator': {
2035
+ pattern: /@[$\w\xA0-\uFFFF]+/,
2036
+ inside: {
2037
+ 'at': {
2038
+ pattern: /^@/,
2039
+ alias: 'operator'
2040
+ },
2041
+ 'function': /^[\s\S]+/
2042
+ }
2043
+ },
2044
+ 'generic-function': {
2045
+ // e.g. foo<T extends "bar" | "baz">( ...
2046
+ pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
2047
+ greedy: true,
2048
+ inside: {
2049
+ 'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
2050
+ 'generic': {
2051
+ pattern: /<[\s\S]+/, // everything after the first <
2052
+ alias: 'class-name',
2053
+ inside: typeInside
2054
+ }
2055
+ }
2056
+ }
2057
+ });
2058
+
2059
+ Prism.languages.ts = Prism.languages.typescript;
2060
+
2061
+ }(Prism));
2062
+
2063
+ Prism.languages.markup = {
2064
+ 'comment': {
2065
+ pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
2066
+ greedy: true
2067
+ },
2068
+ 'prolog': {
2069
+ pattern: /<\?[\s\S]+?\?>/,
2070
+ greedy: true
2071
+ },
2072
+ 'doctype': {
2073
+ // https://www.w3.org/TR/xml/#NT-doctypedecl
2074
+ pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
2075
+ greedy: true,
2076
+ inside: {
2077
+ 'internal-subset': {
2078
+ pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
2079
+ lookbehind: true,
2080
+ greedy: true,
2081
+ inside: null // see below
2082
+ },
2083
+ 'string': {
2084
+ pattern: /"[^"]*"|'[^']*'/,
2085
+ greedy: true
2086
+ },
2087
+ 'punctuation': /^<!|>$|[[\]]/,
2088
+ 'doctype-tag': /^DOCTYPE/i,
2089
+ 'name': /[^\s<>'"]+/
2090
+ }
2091
+ },
2092
+ 'cdata': {
2093
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
2094
+ greedy: true
2095
+ },
2096
+ 'tag': {
2097
+ pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
2098
+ greedy: true,
2099
+ inside: {
2100
+ 'tag': {
2101
+ pattern: /^<\/?[^\s>\/]+/,
2102
+ inside: {
2103
+ 'punctuation': /^<\/?/,
2104
+ 'namespace': /^[^\s>\/:]+:/
2105
+ }
2106
+ },
2107
+ 'special-attr': [],
2108
+ 'attr-value': {
2109
+ pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
2110
+ inside: {
2111
+ 'punctuation': [
2112
+ {
2113
+ pattern: /^=/,
2114
+ alias: 'attr-equals'
2115
+ },
2116
+ /"|'/
2117
+ ]
2118
+ }
2119
+ },
2120
+ 'punctuation': /\/?>/,
2121
+ 'attr-name': {
2122
+ pattern: /[^\s>\/]+/,
2123
+ inside: {
2124
+ 'namespace': /^[^\s>\/:]+:/
2125
+ }
2126
+ }
2127
+
2128
+ }
2129
+ },
2130
+ 'entity': [
2131
+ {
2132
+ pattern: /&[\da-z]{1,8};/i,
2133
+ alias: 'named-entity'
2134
+ },
2135
+ /&#x?[\da-f]{1,8};/i
2136
+ ]
2137
+ };
2138
+
2139
+ Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
2140
+ Prism.languages.markup['entity'];
2141
+ Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
2142
+
2143
+ // Plugin to make entity title show the real entity, idea by Roman Komarov
2144
+ Prism.hooks.add('wrap', function (env) {
2145
+
2146
+ if (env.type === 'entity') {
2147
+ env.attributes['title'] = env.content.replace(/&amp;/, '&');
2148
+ }
2149
+ });
2150
+
2151
+ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
2152
+ /**
2153
+ * Adds an inlined language to markup.
2154
+ *
2155
+ * An example of an inlined language is CSS with `<style>` tags.
2156
+ *
2157
+ * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
2158
+ * case insensitive.
2159
+ * @param {string} lang The language key.
2160
+ * @example
2161
+ * addInlined('style', 'css');
2162
+ */
2163
+ value: function addInlined(tagName, lang) {
2164
+ var includedCdataInside = {};
2165
+ includedCdataInside['language-' + lang] = {
2166
+ pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
2167
+ lookbehind: true,
2168
+ inside: Prism.languages[lang]
2169
+ };
2170
+ includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
2171
+
2172
+ var inside = {
2173
+ 'included-cdata': {
2174
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
2175
+ inside: includedCdataInside
2176
+ }
2177
+ };
2178
+ inside['language-' + lang] = {
2179
+ pattern: /[\s\S]+/,
2180
+ inside: Prism.languages[lang]
2181
+ };
2182
+
2183
+ var def = {};
2184
+ def[tagName] = {
2185
+ pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
2186
+ lookbehind: true,
2187
+ greedy: true,
2188
+ inside: inside
2189
+ };
2190
+
2191
+ Prism.languages.insertBefore('markup', 'cdata', def);
2192
+ }
2193
+ });
2194
+ Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
2195
+ /**
2196
+ * Adds an pattern to highlight languages embedded in HTML attributes.
2197
+ *
2198
+ * An example of an inlined language is CSS with `style` attributes.
2199
+ *
2200
+ * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
2201
+ * case insensitive.
2202
+ * @param {string} lang The language key.
2203
+ * @example
2204
+ * addAttribute('style', 'css');
2205
+ */
2206
+ value: function (attrName, lang) {
2207
+ Prism.languages.markup.tag.inside['special-attr'].push({
2208
+ pattern: RegExp(
2209
+ /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
2210
+ 'i'
2211
+ ),
2212
+ lookbehind: true,
2213
+ inside: {
2214
+ 'attr-name': /^[^\s=]+/,
2215
+ 'attr-value': {
2216
+ pattern: /=[\s\S]+/,
2217
+ inside: {
2218
+ 'value': {
2219
+ pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
2220
+ lookbehind: true,
2221
+ alias: [lang, 'language-' + lang],
2222
+ inside: Prism.languages[lang]
2223
+ },
2224
+ 'punctuation': [
2225
+ {
2226
+ pattern: /^=/,
2227
+ alias: 'attr-equals'
2228
+ },
2229
+ /"|'/
2230
+ ]
2231
+ }
2232
+ }
2233
+ }
2234
+ });
2235
+ }
2236
+ });
2237
+
2238
+ Prism.languages.html = Prism.languages.markup;
2239
+ Prism.languages.mathml = Prism.languages.markup;
2240
+ Prism.languages.svg = Prism.languages.markup;
2241
+
2242
+ Prism.languages.xml = Prism.languages.extend('markup', {});
2243
+ Prism.languages.ssml = Prism.languages.xml;
2244
+ Prism.languages.atom = Prism.languages.xml;
2245
+ Prism.languages.rss = Prism.languages.xml;
2246
+
2247
+ Prism.languages.go = Prism.languages.extend('clike', {
2248
+ 'string': {
2249
+ pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
2250
+ greedy: true
2251
+ },
2252
+ '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/,
2253
+ 'boolean': /\b(?:_|iota|nil|true|false)\b/,
2254
+ 'number': /(?:\b0x[a-f\d]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[-+]?\d+)?)i?/i,
2255
+ 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
2256
+ '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/
2257
+ });
2258
+ delete Prism.languages.go['class-name'];
2259
+
2260
+ /**
2261
+ * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
2262
+ * Modified by Miles Johnson: http://milesj.me
2263
+ * Rewritten by Tom Pavelec
2264
+ *
2265
+ * Supports PHP 5.3 - 8.0
2266
+ */
2267
+ (function (Prism) {
2268
+ var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
2269
+ var constant = [
2270
+ {
2271
+ pattern: /\b(?:false|true)\b/i,
2272
+ alias: 'boolean'
2273
+ },
2274
+ {
2275
+ pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
2276
+ greedy: true,
2277
+ lookbehind: true,
2278
+ },
2279
+ {
2280
+ pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
2281
+ greedy: true,
2282
+ lookbehind: true,
2283
+ },
2284
+ /\b(?:null)\b/i,
2285
+ /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
2286
+ ];
2287
+ 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;
2288
+ var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
2289
+ var punctuation = /[{}\[\](),:;]/;
2290
+
2291
+ Prism.languages.php = {
2292
+ 'delimiter': {
2293
+ pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
2294
+ alias: 'important'
2295
+ },
2296
+ 'comment': comment,
2297
+ 'variable': /\$+(?:\w+\b|(?=\{))/i,
2298
+ 'package': {
2299
+ pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
2300
+ lookbehind: true,
2301
+ inside: {
2302
+ 'punctuation': /\\/
2303
+ }
2304
+ },
2305
+ 'class-name-definition': {
2306
+ pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
2307
+ lookbehind: true,
2308
+ alias: 'class-name'
2309
+ },
2310
+ 'function-definition': {
2311
+ pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
2312
+ lookbehind: true,
2313
+ alias: 'function'
2314
+ },
2315
+ 'keyword': [
2316
+ {
2317
+ pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,
2318
+ alias: 'type-casting',
2319
+ greedy: true,
2320
+ lookbehind: true
2321
+ },
2322
+ {
2323
+ pattern: /([(,?]\s*)\b(?:bool|int|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b(?=\s*\$)/i,
2324
+ alias: 'type-hint',
2325
+ greedy: true,
2326
+ lookbehind: true
2327
+ },
2328
+ {
2329
+ pattern: /([(,?]\s*[\w|]\|\s*)(?:null|false)\b(?=\s*\$)/i,
2330
+ alias: 'type-hint',
2331
+ greedy: true,
2332
+ lookbehind: true
2333
+ },
2334
+ {
2335
+ pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b/i,
2336
+ alias: 'return-type',
2337
+ greedy: true,
2338
+ lookbehind: true
2339
+ },
2340
+ {
2341
+ pattern: /(\)\s*:\s*(?:\?\s*)?[\w|]\|\s*)(?:null|false)\b/i,
2342
+ alias: 'return-type',
2343
+ greedy: true,
2344
+ lookbehind: true
2345
+ },
2346
+ {
2347
+ pattern: /\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|iterable|(?:null|false)(?=\s*\|))\b/i,
2348
+ alias: 'type-declaration',
2349
+ greedy: true
2350
+ },
2351
+ {
2352
+ pattern: /(\|\s*)(?:null|false)\b/i,
2353
+ alias: 'type-declaration',
2354
+ greedy: true,
2355
+ lookbehind: true
2356
+ },
2357
+ {
2358
+ pattern: /\b(?:parent|self|static)(?=\s*::)/i,
2359
+ alias: 'static-context',
2360
+ greedy: true
2361
+ },
2362
+ {
2363
+ // yield from
2364
+ pattern: /(\byield\s+)from\b/i,
2365
+ lookbehind: true
2366
+ },
2367
+ // `class` is always a keyword unlike other keywords
2368
+ /\bclass\b/i,
2369
+ {
2370
+ // https://www.php.net/manual/en/reserved.keywords.php
2371
+ //
2372
+ // keywords cannot be preceded by "->"
2373
+ // the complex lookbehind means `(?<!(?:->|::)\s*)`
2374
+ 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,
2375
+ lookbehind: true
2376
+ }
2377
+ ],
2378
+ 'argument-name': {
2379
+ pattern: /([(,]\s+)\b[a-z_]\w*(?=\s*:(?!:))/i,
2380
+ lookbehind: true
2381
+ },
2382
+ 'class-name': [
2383
+ {
2384
+ pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
2385
+ greedy: true,
2386
+ lookbehind: true
2387
+ },
2388
+ {
2389
+ pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
2390
+ greedy: true,
2391
+ lookbehind: true
2392
+ },
2393
+ {
2394
+ pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
2395
+ greedy: true
2396
+ },
2397
+ {
2398
+ pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
2399
+ alias: 'class-name-fully-qualified',
2400
+ greedy: true,
2401
+ lookbehind: true,
2402
+ inside: {
2403
+ 'punctuation': /\\/
2404
+ }
2405
+ },
2406
+ {
2407
+ pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
2408
+ alias: 'class-name-fully-qualified',
2409
+ greedy: true,
2410
+ inside: {
2411
+ 'punctuation': /\\/
2412
+ }
2413
+ },
2414
+ {
2415
+ pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
2416
+ alias: 'class-name-fully-qualified',
2417
+ greedy: true,
2418
+ lookbehind: true,
2419
+ inside: {
2420
+ 'punctuation': /\\/
2421
+ }
2422
+ },
2423
+ {
2424
+ pattern: /\b[a-z_]\w*(?=\s*\$)/i,
2425
+ alias: 'type-declaration',
2426
+ greedy: true
2427
+ },
2428
+ {
2429
+ pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
2430
+ alias: ['class-name-fully-qualified', 'type-declaration'],
2431
+ greedy: true,
2432
+ inside: {
2433
+ 'punctuation': /\\/
2434
+ }
2435
+ },
2436
+ {
2437
+ pattern: /\b[a-z_]\w*(?=\s*::)/i,
2438
+ alias: 'static-context',
2439
+ greedy: true
2440
+ },
2441
+ {
2442
+ pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
2443
+ alias: ['class-name-fully-qualified', 'static-context'],
2444
+ greedy: true,
2445
+ inside: {
2446
+ 'punctuation': /\\/
2447
+ }
2448
+ },
2449
+ {
2450
+ pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
2451
+ alias: 'type-hint',
2452
+ greedy: true,
2453
+ lookbehind: true
2454
+ },
2455
+ {
2456
+ pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
2457
+ alias: ['class-name-fully-qualified', 'type-hint'],
2458
+ greedy: true,
2459
+ lookbehind: true,
2460
+ inside: {
2461
+ 'punctuation': /\\/
2462
+ }
2463
+ },
2464
+ {
2465
+ pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
2466
+ alias: 'return-type',
2467
+ greedy: true,
2468
+ lookbehind: true
2469
+ },
2470
+ {
2471
+ pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
2472
+ alias: ['class-name-fully-qualified', 'return-type'],
2473
+ greedy: true,
2474
+ lookbehind: true,
2475
+ inside: {
2476
+ 'punctuation': /\\/
2477
+ }
2478
+ }
2479
+ ],
2480
+ 'constant': constant,
2481
+ 'function': {
2482
+ pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
2483
+ lookbehind: true,
2484
+ inside: {
2485
+ 'punctuation': /\\/
2486
+ }
2487
+ },
2488
+ 'property': {
2489
+ pattern: /(->\s*)\w+/,
2490
+ lookbehind: true
2491
+ },
2492
+ 'number': number,
2493
+ 'operator': operator,
2494
+ 'punctuation': punctuation
2495
+ };
2496
+
2497
+ var string_interpolation = {
2498
+ pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
2499
+ lookbehind: true,
2500
+ inside: Prism.languages.php
2501
+ };
2502
+
2503
+ var string = [
2504
+ {
2505
+ pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
2506
+ alias: 'nowdoc-string',
2507
+ greedy: true,
2508
+ inside: {
2509
+ 'delimiter': {
2510
+ pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
2511
+ alias: 'symbol',
2512
+ inside: {
2513
+ 'punctuation': /^<<<'?|[';]$/
2514
+ }
2515
+ }
2516
+ }
2517
+ },
2518
+ {
2519
+ pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
2520
+ alias: 'heredoc-string',
2521
+ greedy: true,
2522
+ inside: {
2523
+ 'delimiter': {
2524
+ pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
2525
+ alias: 'symbol',
2526
+ inside: {
2527
+ 'punctuation': /^<<<"?|[";]$/
2528
+ }
2529
+ },
2530
+ 'interpolation': string_interpolation
2531
+ }
2532
+ },
2533
+ {
2534
+ pattern: /`(?:\\[\s\S]|[^\\`])*`/,
2535
+ alias: 'backtick-quoted-string',
2536
+ greedy: true
2537
+ },
2538
+ {
2539
+ pattern: /'(?:\\[\s\S]|[^\\'])*'/,
2540
+ alias: 'single-quoted-string',
2541
+ greedy: true
2542
+ },
2543
+ {
2544
+ pattern: /"(?:\\[\s\S]|[^\\"])*"/,
2545
+ alias: 'double-quoted-string',
2546
+ greedy: true,
2547
+ inside: {
2548
+ 'interpolation': string_interpolation
2549
+ }
2550
+ }
2551
+ ];
2552
+
2553
+ Prism.languages.insertBefore('php', 'variable', {
2554
+ 'string': string,
2555
+ 'attribute': {
2556
+ pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,
2557
+ greedy: true,
2558
+ inside: {
2559
+ 'attribute-content': {
2560
+ pattern: /^(#\[)[\s\S]+(?=\]$)/,
2561
+ lookbehind: true,
2562
+ // inside can appear subset of php
2563
+ inside: {
2564
+ 'comment': comment,
2565
+ 'string': string,
2566
+ 'attribute-class-name': [
2567
+ {
2568
+ pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
2569
+ alias: 'class-name',
2570
+ greedy: true,
2571
+ lookbehind: true
2572
+ },
2573
+ {
2574
+ pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
2575
+ alias: [
2576
+ 'class-name',
2577
+ 'class-name-fully-qualified'
2578
+ ],
2579
+ greedy: true,
2580
+ lookbehind: true,
2581
+ inside: {
2582
+ 'punctuation': /\\/
2583
+ }
2584
+ }
2585
+ ],
2586
+ 'constant': constant,
2587
+ 'number': number,
2588
+ 'operator': operator,
2589
+ 'punctuation': punctuation
2590
+ }
2591
+ },
2592
+ 'delimiter': {
2593
+ pattern: /^#\[|\]$/,
2594
+ alias: 'punctuation'
2595
+ }
2596
+ }
2597
+ },
2598
+ });
2599
+
2600
+ Prism.hooks.add('before-tokenize', function (env) {
2601
+ if (!/<\?/.test(env.code)) {
2602
+ return;
2603
+ }
2604
+
2605
+ var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/gi;
2606
+ Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
2607
+ });
2608
+
2609
+ Prism.hooks.add('after-tokenize', function (env) {
2610
+ Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
2611
+ });
2612
+
2613
+ }(Prism));
2614
+
2615
+ Prism.languages.c = Prism.languages.extend('clike', {
2616
+ 'comment': {
2617
+ pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
2618
+ greedy: true
2619
+ },
2620
+ 'class-name': {
2621
+ pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
2622
+ lookbehind: true
2623
+ },
2624
+ '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/,
2625
+ 'function': /\b[a-z_]\w*(?=\s*\()/i,
2626
+ 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
2627
+ 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
2628
+ });
2629
+
2630
+ Prism.languages.insertBefore('c', 'string', {
2631
+ 'macro': {
2632
+ // allow for multiline macro definitions
2633
+ // spaces after the # character compile fine with gcc
2634
+ pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
2635
+ lookbehind: true,
2636
+ greedy: true,
2637
+ alias: 'property',
2638
+ inside: {
2639
+ 'string': [
2640
+ {
2641
+ // highlight the path of the include statement as a string
2642
+ pattern: /^(#\s*include\s*)<[^>]+>/,
2643
+ lookbehind: true
2644
+ },
2645
+ Prism.languages.c['string']
2646
+ ],
2647
+ 'comment': Prism.languages.c['comment'],
2648
+ 'macro-name': [
2649
+ {
2650
+ pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
2651
+ lookbehind: true
2652
+ },
2653
+ {
2654
+ pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
2655
+ lookbehind: true,
2656
+ alias: 'function'
2657
+ }
2658
+ ],
2659
+ // highlight macro directives as keywords
2660
+ 'directive': {
2661
+ pattern: /^(#\s*)[a-z]+/,
2662
+ lookbehind: true,
2663
+ alias: 'keyword'
2664
+ },
2665
+ 'directive-hash': /^#/,
2666
+ 'punctuation': /##|\\(?=[\r\n])/,
2667
+ 'expression': {
2668
+ pattern: /\S[\s\S]*/,
2669
+ inside: Prism.languages.c
2670
+ }
2671
+ }
2672
+ },
2673
+ // highlight predefined macros as constants
2674
+ 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
2675
+ });
2676
+
2677
+ delete Prism.languages.c['boolean'];
2678
+
2679
+ Prism.languages.python = {
2680
+ 'comment': {
2681
+ pattern: /(^|[^\\])#.*/,
2682
+ lookbehind: true
2683
+ },
2684
+ 'string-interpolation': {
2685
+ pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
2686
+ greedy: true,
2687
+ inside: {
2688
+ 'interpolation': {
2689
+ // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
2690
+ pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
2691
+ lookbehind: true,
2692
+ inside: {
2693
+ 'format-spec': {
2694
+ pattern: /(:)[^:(){}]+(?=\}$)/,
2695
+ lookbehind: true
2696
+ },
2697
+ 'conversion-option': {
2698
+ pattern: /![sra](?=[:}]$)/,
2699
+ alias: 'punctuation'
2700
+ },
2701
+ rest: null
2702
+ }
2703
+ },
2704
+ 'string': /[\s\S]+/
2705
+ }
2706
+ },
2707
+ 'triple-quoted-string': {
2708
+ pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,
2709
+ greedy: true,
2710
+ alias: 'string'
2711
+ },
2712
+ 'string': {
2713
+ pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
2714
+ greedy: true
2715
+ },
2716
+ 'function': {
2717
+ pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
2718
+ lookbehind: true
2719
+ },
2720
+ 'class-name': {
2721
+ pattern: /(\bclass\s+)\w+/i,
2722
+ lookbehind: true
2723
+ },
2724
+ 'decorator': {
2725
+ pattern: /(^[\t ]*)@\w+(?:\.\w+)*/im,
2726
+ lookbehind: true,
2727
+ alias: ['annotation', 'punctuation'],
2728
+ inside: {
2729
+ 'punctuation': /\./
2730
+ }
2731
+ },
2732
+ '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/,
2733
+ '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/,
2734
+ 'boolean': /\b(?:True|False|None)\b/,
2735
+ '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,
2736
+ 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
2737
+ 'punctuation': /[{}[\];(),.:]/
2738
+ };
2739
+
2740
+ Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
2741
+
2742
+ Prism.languages.py = Prism.languages.python;
2743
+
2744
+ (function (Prism) {
2745
+
2746
+ 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/;
2747
+
2748
+ // full package (optional) + parent classes (optional)
2749
+ var classNamePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
2750
+
2751
+ // based on the java naming conventions
2752
+ var className = {
2753
+ pattern: RegExp(classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
2754
+ lookbehind: true,
2755
+ inside: {
2756
+ 'namespace': {
2757
+ pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
2758
+ inside: {
2759
+ 'punctuation': /\./
2760
+ }
2761
+ },
2762
+ 'punctuation': /\./
2763
+ }
2764
+ };
2765
+
2766
+ Prism.languages.java = Prism.languages.extend('clike', {
2767
+ 'class-name': [
2768
+ className,
2769
+ {
2770
+ // variables and parameters
2771
+ // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
2772
+ pattern: RegExp(classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source),
2773
+ lookbehind: true,
2774
+ inside: className.inside
2775
+ }
2776
+ ],
2777
+ 'keyword': keywords,
2778
+ 'function': [
2779
+ Prism.languages.clike.function,
2780
+ {
2781
+ pattern: /(::\s*)[a-z_]\w*/,
2782
+ lookbehind: true
2783
+ }
2784
+ ],
2785
+ '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,
2786
+ 'operator': {
2787
+ pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
2788
+ lookbehind: true
2789
+ }
2790
+ });
2791
+
2792
+ Prism.languages.insertBefore('java', 'string', {
2793
+ 'triple-quoted-string': {
2794
+ // http://openjdk.java.net/jeps/355#Description
2795
+ pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
2796
+ greedy: true,
2797
+ alias: 'string'
2798
+ }
2799
+ });
2800
+
2801
+ Prism.languages.insertBefore('java', 'class-name', {
2802
+ 'annotation': {
2803
+ pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
2804
+ lookbehind: true,
2805
+ alias: 'punctuation'
2806
+ },
2807
+ 'generics': {
2808
+ pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
2809
+ inside: {
2810
+ 'class-name': className,
2811
+ 'keyword': keywords,
2812
+ 'punctuation': /[<>(),.:]/,
2813
+ 'operator': /[?&|]/
2814
+ }
2815
+ },
2816
+ 'namespace': {
2817
+ pattern: RegExp(
2818
+ /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
2819
+ .source.replace(/<keyword>/g, function () { return keywords.source; })),
2820
+ lookbehind: true,
2821
+ inside: {
2822
+ 'punctuation': /\./,
2823
+ }
2824
+ }
2825
+ });
2826
+ }(Prism));
2827
+
2828
+ (function (Prism) {
2829
+
2830
+ 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/;
2831
+ var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; });
2832
+
2833
+ Prism.languages.cpp = Prism.languages.extend('c', {
2834
+ 'class-name': [
2835
+ {
2836
+ pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
2837
+ .replace(/<keyword>/g, function () { return keyword.source; })),
2838
+ lookbehind: true
2839
+ },
2840
+ // This is intended to capture the class name of method implementations like:
2841
+ // void foo::bar() const {}
2842
+ // However! The `foo` in the above example could also be a namespace, so we only capture the class name if
2843
+ // it starts with an uppercase letter. This approximation should give decent results.
2844
+ /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
2845
+ // This will capture the class name before destructors like:
2846
+ // Foo::~Foo() {}
2847
+ /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
2848
+ // This also intends to capture the class name of method implementations but here the class has template
2849
+ // parameters, so it can't be a namespace (until C++ adds generic namespaces).
2850
+ /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
2851
+ ],
2852
+ 'keyword': keyword,
2853
+ 'number': {
2854
+ pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
2855
+ greedy: true
2856
+ },
2857
+ 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
2858
+ 'boolean': /\b(?:true|false)\b/
2859
+ });
2860
+
2861
+ Prism.languages.insertBefore('cpp', 'string', {
2862
+ 'module': {
2863
+ // https://en.cppreference.com/w/cpp/language/modules
2864
+ pattern: RegExp(
2865
+ /(\b(?:module|import)\s+)/.source +
2866
+ '(?:' +
2867
+ // header-name
2868
+ /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
2869
+ '|' +
2870
+ // module name or partition or both
2871
+ /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) +
2872
+ ')'
2873
+ ),
2874
+ lookbehind: true,
2875
+ greedy: true,
2876
+ inside: {
2877
+ 'string': /^[<"][\s\S]+/,
2878
+ 'operator': /:/,
2879
+ 'punctuation': /\./
2880
+ }
2881
+ },
2882
+ 'raw-string': {
2883
+ pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
2884
+ alias: 'string',
2885
+ greedy: true
2886
+ }
2887
+ });
2888
+
2889
+ Prism.languages.insertBefore('cpp', 'keyword', {
2890
+ 'generic-function': {
2891
+ pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
2892
+ inside: {
2893
+ 'function': /^\w+/,
2894
+ 'generic': {
2895
+ pattern: /<[\s\S]+/,
2896
+ alias: 'class-name',
2897
+ inside: Prism.languages.cpp
2898
+ }
2899
+ }
2900
+ }
2901
+ });
2902
+
2903
+ Prism.languages.insertBefore('cpp', 'operator', {
2904
+ 'double-colon': {
2905
+ pattern: /::/,
2906
+ alias: 'punctuation'
2907
+ }
2908
+ });
2909
+
2910
+ Prism.languages.insertBefore('cpp', 'class-name', {
2911
+ // the base clause is an optional list of parent classes
2912
+ // https://en.cppreference.com/w/cpp/language/class
2913
+ 'base-clause': {
2914
+ pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
2915
+ lookbehind: true,
2916
+ greedy: true,
2917
+ inside: Prism.languages.extend('cpp', {})
2918
+ }
2919
+ });
2920
+
2921
+ Prism.languages.insertBefore('inside', 'double-colon', {
2922
+ // All untokenized words that are not namespaces should be class names
2923
+ 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i
2924
+ }, Prism.languages.cpp['base-clause']);
2925
+
2926
+ }(Prism));
2927
+
2928
+ (function (Prism) {
2929
+
2930
+ /**
2931
+ * Replaces all placeholders "<<n>>" of given pattern with the n-th replacement (zero based).
2932
+ *
2933
+ * Note: This is a simple text based replacement. Be careful when using backreferences!
2934
+ *
2935
+ * @param {string} pattern the given pattern.
2936
+ * @param {string[]} replacements a list of replacement which can be inserted into the given pattern.
2937
+ * @returns {string} the pattern with all placeholders replaced with their corresponding replacements.
2938
+ * @example replace(/a<<0>>a/.source, [/b+/.source]) === /a(?:b+)a/.source
2939
+ */
2940
+ function replace(pattern, replacements) {
2941
+ return pattern.replace(/<<(\d+)>>/g, function (m, index) {
2942
+ return '(?:' + replacements[+index] + ')';
2943
+ });
2944
+ }
2945
+ /**
2946
+ * @param {string} pattern
2947
+ * @param {string[]} replacements
2948
+ * @param {string} [flags]
2949
+ * @returns {RegExp}
2950
+ */
2951
+ function re(pattern, replacements, flags) {
2952
+ return RegExp(replace(pattern, replacements), flags || '');
2953
+ }
2954
+
2955
+ /**
2956
+ * Creates a nested pattern where all occurrences of the string `<<self>>` are replaced with the pattern itself.
2957
+ *
2958
+ * @param {string} pattern
2959
+ * @param {number} depthLog2
2960
+ * @returns {string}
2961
+ */
2962
+ function nested(pattern, depthLog2) {
2963
+ for (var i = 0; i < depthLog2; i++) {
2964
+ pattern = pattern.replace(/<<self>>/g, function () { return '(?:' + pattern + ')'; });
2965
+ }
2966
+ return pattern.replace(/<<self>>/g, '[^\\s\\S]');
2967
+ }
2968
+
2969
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
2970
+ var keywordKinds = {
2971
+ // keywords which represent a return or variable type
2972
+ type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void',
2973
+ // keywords which are used to declare a type
2974
+ typeDeclaration: 'class enum interface record struct',
2975
+ // contextual keywords
2976
+ // ("var" and "dynamic" are missing because they are used like types)
2977
+ 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*{)',
2978
+ // all other keywords
2979
+ 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'
2980
+ };
2981
+
2982
+ // keywords
2983
+ function keywordsToPattern(words) {
2984
+ return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b';
2985
+ }
2986
+ var typeDeclarationKeywords = keywordsToPattern(keywordKinds.typeDeclaration);
2987
+ var keywords = RegExp(keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other));
2988
+ var nonTypeKeywords = keywordsToPattern(keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other);
2989
+ var nonContextualKeywords = keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.other);
2990
+
2991
+ // types
2992
+ var generic = nested(/<(?:[^<>;=+\-*/%&|^]|<<self>>)*>/.source, 2); // the idea behind the other forbidden characters is to prevent false positives. Same for tupleElement.
2993
+ var nestedRound = nested(/\((?:[^()]|<<self>>)*\)/.source, 2);
2994
+ var name = /@?\b[A-Za-z_]\w*\b/.source;
2995
+ var genericName = replace(/<<0>>(?:\s*<<1>>)?/.source, [name, generic]);
2996
+ var identifier = replace(/(?!<<0>>)<<1>>(?:\s*\.\s*<<1>>)*/.source, [nonTypeKeywords, genericName]);
2997
+ var array = /\[\s*(?:,\s*)*\]/.source;
2998
+ var typeExpressionWithoutTuple = replace(/<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, [identifier, array]);
2999
+ var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [generic, nestedRound, array]);
3000
+ var tuple = replace(/\(<<0>>+(?:,<<0>>+)+\)/.source, [tupleElement]);
3001
+ var typeExpression = replace(/(?:<<0>>|<<1>>)(?:\s*(?:\?\s*)?<<2>>)*(?:\s*\?)?/.source, [tuple, identifier, array]);
3002
+
3003
+ var typeInside = {
3004
+ 'keyword': keywords,
3005
+ 'punctuation': /[<>()?,.:[\]]/
3006
+ };
3007
+
3008
+ // strings & characters
3009
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#character-literals
3010
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#string-literals
3011
+ var character = /'(?:[^\r\n'\\]|\\.|\\[Uux][\da-fA-F]{1,8})'/.source; // simplified pattern
3012
+ var regularString = /"(?:\\.|[^\\"\r\n])*"/.source;
3013
+ var verbatimString = /@"(?:""|\\[\s\S]|[^\\"])*"(?!")/.source;
3014
+
3015
+
3016
+ Prism.languages.csharp = Prism.languages.extend('clike', {
3017
+ 'string': [
3018
+ {
3019
+ pattern: re(/(^|[^$\\])<<0>>/.source, [verbatimString]),
3020
+ lookbehind: true,
3021
+ greedy: true
3022
+ },
3023
+ {
3024
+ pattern: re(/(^|[^@$\\])<<0>>/.source, [regularString]),
3025
+ lookbehind: true,
3026
+ greedy: true
3027
+ },
3028
+ {
3029
+ pattern: RegExp(character),
3030
+ greedy: true,
3031
+ alias: 'character'
3032
+ }
3033
+ ],
3034
+ 'class-name': [
3035
+ {
3036
+ // Using static
3037
+ // using static System.Math;
3038
+ pattern: re(/(\busing\s+static\s+)<<0>>(?=\s*;)/.source, [identifier]),
3039
+ lookbehind: true,
3040
+ inside: typeInside
3041
+ },
3042
+ {
3043
+ // Using alias (type)
3044
+ // using Project = PC.MyCompany.Project;
3045
+ pattern: re(/(\busing\s+<<0>>\s*=\s*)<<1>>(?=\s*;)/.source, [name, typeExpression]),
3046
+ lookbehind: true,
3047
+ inside: typeInside
3048
+ },
3049
+ {
3050
+ // Using alias (alias)
3051
+ // using Project = PC.MyCompany.Project;
3052
+ pattern: re(/(\busing\s+)<<0>>(?=\s*=)/.source, [name]),
3053
+ lookbehind: true
3054
+ },
3055
+ {
3056
+ // Type declarations
3057
+ // class Foo<A, B>
3058
+ // interface Foo<out A, B>
3059
+ pattern: re(/(\b<<0>>\s+)<<1>>/.source, [typeDeclarationKeywords, genericName]),
3060
+ lookbehind: true,
3061
+ inside: typeInside
3062
+ },
3063
+ {
3064
+ // Single catch exception declaration
3065
+ // catch(Foo)
3066
+ // (things like catch(Foo e) is covered by variable declaration)
3067
+ pattern: re(/(\bcatch\s*\(\s*)<<0>>/.source, [identifier]),
3068
+ lookbehind: true,
3069
+ inside: typeInside
3070
+ },
3071
+ {
3072
+ // Name of the type parameter of generic constraints
3073
+ // where Foo : class
3074
+ pattern: re(/(\bwhere\s+)<<0>>/.source, [name]),
3075
+ lookbehind: true
3076
+ },
3077
+ {
3078
+ // Casts and checks via as and is.
3079
+ // as Foo<A>, is Bar<B>
3080
+ // (things like if(a is Foo b) is covered by variable declaration)
3081
+ pattern: re(/(\b(?:is(?:\s+not)?|as)\s+)<<0>>/.source, [typeExpressionWithoutTuple]),
3082
+ lookbehind: true,
3083
+ inside: typeInside
3084
+ },
3085
+ {
3086
+ // Variable, field and parameter declaration
3087
+ // (Foo bar, Bar baz, Foo[,,] bay, Foo<Bar, FooBar<Bar>> bax)
3088
+ pattern: re(/\b<<0>>(?=\s+(?!<<1>>|with\s*\{)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [typeExpression, nonContextualKeywords, name]),
3089
+ inside: typeInside
3090
+ }
3091
+ ],
3092
+ 'keyword': keywords,
3093
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#literals
3094
+ '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,
3095
+ 'operator': />>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,
3096
+ 'punctuation': /\?\.?|::|[{}[\];(),.:]/
3097
+ });
3098
+
3099
+ Prism.languages.insertBefore('csharp', 'number', {
3100
+ 'range': {
3101
+ pattern: /\.\./,
3102
+ alias: 'operator'
3103
+ }
3104
+ });
3105
+
3106
+ Prism.languages.insertBefore('csharp', 'punctuation', {
3107
+ 'named-parameter': {
3108
+ pattern: re(/([(,]\s*)<<0>>(?=\s*:)/.source, [name]),
3109
+ lookbehind: true,
3110
+ alias: 'punctuation'
3111
+ }
3112
+ });
3113
+
3114
+ Prism.languages.insertBefore('csharp', 'class-name', {
3115
+ 'namespace': {
3116
+ // namespace Foo.Bar {}
3117
+ // using Foo.Bar;
3118
+ pattern: re(/(\b(?:namespace|using)\s+)<<0>>(?:\s*\.\s*<<0>>)*(?=\s*[;{])/.source, [name]),
3119
+ lookbehind: true,
3120
+ inside: {
3121
+ 'punctuation': /\./
3122
+ }
3123
+ },
3124
+ 'type-expression': {
3125
+ // default(Foo), typeof(Foo<Bar>), sizeof(int)
3126
+ pattern: re(/(\b(?:default|typeof|sizeof)\s*\(\s*(?!\s))(?:[^()\s]|\s(?!\s)|<<0>>)*(?=\s*\))/.source, [nestedRound]),
3127
+ lookbehind: true,
3128
+ alias: 'class-name',
3129
+ inside: typeInside
3130
+ },
3131
+ 'return-type': {
3132
+ // Foo<Bar> ForBar(); Foo IFoo.Bar() => 0
3133
+ // int this[int index] => 0; T IReadOnlyList<T>.this[int index] => this[index];
3134
+ // int Foo => 0; int Foo { get; set } = 0;
3135
+ pattern: re(/<<0>>(?=\s+(?:<<1>>\s*(?:=>|[({]|\.\s*this\s*\[)|this\s*\[))/.source, [typeExpression, identifier]),
3136
+ inside: typeInside,
3137
+ alias: 'class-name'
3138
+ },
3139
+ 'constructor-invocation': {
3140
+ // new List<Foo<Bar[]>> { }
3141
+ pattern: re(/(\bnew\s+)<<0>>(?=\s*[[({])/.source, [typeExpression]),
3142
+ lookbehind: true,
3143
+ inside: typeInside,
3144
+ alias: 'class-name'
3145
+ },
3146
+ /*'explicit-implementation': {
3147
+ // int IFoo<Foo>.Bar => 0; void IFoo<Foo<Foo>>.Foo<T>();
3148
+ pattern: replace(/\b<<0>>(?=\.<<1>>)/, className, methodOrPropertyDeclaration),
3149
+ inside: classNameInside,
3150
+ alias: 'class-name'
3151
+ },*/
3152
+ 'generic-method': {
3153
+ // foo<Bar>()
3154
+ pattern: re(/<<0>>\s*<<1>>(?=\s*\()/.source, [name, generic]),
3155
+ inside: {
3156
+ 'function': re(/^<<0>>/.source, [name]),
3157
+ 'generic': {
3158
+ pattern: RegExp(generic),
3159
+ alias: 'class-name',
3160
+ inside: typeInside
3161
+ }
3162
+ }
3163
+ },
3164
+ 'type-list': {
3165
+ // The list of types inherited or of generic constraints
3166
+ // class Foo<F> : Bar, IList<FooBar>
3167
+ // where F : Bar, IList<int>
3168
+ pattern: re(
3169
+ /\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,
3170
+ [typeDeclarationKeywords, genericName, name, typeExpression, keywords.source, nestedRound, /\bnew\s*\(\s*\)/.source]
3171
+ ),
3172
+ lookbehind: true,
3173
+ inside: {
3174
+ 'record-arguments': {
3175
+ pattern: re(/(^(?!new\s*\()<<0>>\s*)<<1>>/.source, [genericName, nestedRound]),
3176
+ lookbehind: true,
3177
+ greedy: true,
3178
+ inside: Prism.languages.csharp
3179
+ },
3180
+ 'keyword': keywords,
3181
+ 'class-name': {
3182
+ pattern: RegExp(typeExpression),
3183
+ greedy: true,
3184
+ inside: typeInside
3185
+ },
3186
+ 'punctuation': /[,()]/
3187
+ }
3188
+ },
3189
+ 'preprocessor': {
3190
+ pattern: /(^[\t ]*)#.*/m,
3191
+ lookbehind: true,
3192
+ alias: 'property',
3193
+ inside: {
3194
+ // highlight preprocessor directives as keywords
3195
+ 'directive': {
3196
+ pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,
3197
+ lookbehind: true,
3198
+ alias: 'keyword'
3199
+ }
3200
+ }
3201
+ }
3202
+ });
3203
+
3204
+ // attributes
3205
+ var regularStringOrCharacter = regularString + '|' + character;
3206
+ var regularStringCharacterOrComment = replace(/\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>/.source, [regularStringOrCharacter]);
3207
+ var roundExpression = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
3208
+
3209
+ // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/#attribute-targets
3210
+ var attrTarget = /\b(?:assembly|event|field|method|module|param|property|return|type)\b/.source;
3211
+ var attr = replace(/<<0>>(?:\s*\(<<1>>*\))?/.source, [identifier, roundExpression]);
3212
+
3213
+ Prism.languages.insertBefore('csharp', 'class-name', {
3214
+ 'attribute': {
3215
+ // Attributes
3216
+ // [Foo], [Foo(1), Bar(2, Prop = "foo")], [return: Foo(1), Bar(2)], [assembly: Foo(Bar)]
3217
+ pattern: re(/((?:^|[^\s\w>)?])\s*\[\s*)(?:<<0>>\s*:\s*)?<<1>>(?:\s*,\s*<<1>>)*(?=\s*\])/.source, [attrTarget, attr]),
3218
+ lookbehind: true,
3219
+ greedy: true,
3220
+ inside: {
3221
+ 'target': {
3222
+ pattern: re(/^<<0>>(?=\s*:)/.source, [attrTarget]),
3223
+ alias: 'keyword'
3224
+ },
3225
+ 'attribute-arguments': {
3226
+ pattern: re(/\(<<0>>*\)/.source, [roundExpression]),
3227
+ inside: Prism.languages.csharp
3228
+ },
3229
+ 'class-name': {
3230
+ pattern: RegExp(identifier),
3231
+ inside: {
3232
+ 'punctuation': /\./
3233
+ }
3234
+ },
3235
+ 'punctuation': /[:,]/
3236
+ }
3237
+ }
3238
+ });
3239
+
3240
+
3241
+ // string interpolation
3242
+ var formatString = /:[^}\r\n]+/.source;
3243
+ // multi line
3244
+ var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
3245
+ var mInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [mInterpolationRound, formatString]);
3246
+ // single line
3247
+ var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<<self>>*\)/.source, [regularStringOrCharacter]), 2);
3248
+ var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [sInterpolationRound, formatString]);
3249
+
3250
+ function createInterpolationInside(interpolation, interpolationRound) {
3251
+ return {
3252
+ 'interpolation': {
3253
+ pattern: re(/((?:^|[^{])(?:\{\{)*)<<0>>/.source, [interpolation]),
3254
+ lookbehind: true,
3255
+ inside: {
3256
+ 'format-string': {
3257
+ pattern: re(/(^\{(?:(?![}:])<<0>>)*)<<1>>(?=\}$)/.source, [interpolationRound, formatString]),
3258
+ lookbehind: true,
3259
+ inside: {
3260
+ 'punctuation': /^:/
3261
+ }
3262
+ },
3263
+ 'punctuation': /^\{|\}$/,
3264
+ 'expression': {
3265
+ pattern: /[\s\S]+/,
3266
+ alias: 'language-csharp',
3267
+ inside: Prism.languages.csharp
3268
+ }
3269
+ }
3270
+ },
3271
+ 'string': /[\s\S]+/
3272
+ };
3273
+ }
3274
+
3275
+ Prism.languages.insertBefore('csharp', 'string', {
3276
+ 'interpolation-string': [
3277
+ {
3278
+ pattern: re(/(^|[^\\])(?:\$@|@\$)"(?:""|\\[\s\S]|\{\{|<<0>>|[^\\{"])*"/.source, [mInterpolation]),
3279
+ lookbehind: true,
3280
+ greedy: true,
3281
+ inside: createInterpolationInside(mInterpolation, mInterpolationRound),
3282
+ },
3283
+ {
3284
+ pattern: re(/(^|[^@\\])\$"(?:\\.|\{\{|<<0>>|[^\\"{])*"/.source, [sInterpolation]),
3285
+ lookbehind: true,
3286
+ greedy: true,
3287
+ inside: createInterpolationInside(sInterpolation, sInterpolationRound),
3288
+ }
3289
+ ]
3290
+ });
3291
+
3292
+ }(Prism));
3293
+
3294
+ Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp;
3295
+
3296
+ Prism.languages['visual-basic'] = {
3297
+ 'comment': {
3298
+ pattern: /(?:['‘’]|REM\b)(?:[^\r\n_]|_(?:\r\n?|\n)?)*/i,
3299
+ inside: {
3300
+ 'keyword': /^REM/i
3301
+ }
3302
+ },
3303
+ 'directive': {
3304
+ pattern: /#(?:Const|Else|ElseIf|End|ExternalChecksum|ExternalSource|If|Region)(?:[^\S\r\n]_[^\S\r\n]*(?:\r\n?|\n)|.)+/i,
3305
+ alias: 'comment',
3306
+ greedy: true
3307
+ },
3308
+ 'string': {
3309
+ pattern: /\$?["“”](?:["“”]{2}|[^"“”])*["“”]C?/i,
3310
+ greedy: true
3311
+ },
3312
+ 'date': {
3313
+ 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,
3314
+ alias: 'builtin'
3315
+ },
3316
+ 'number': /(?:(?:\b\d+(?:\.\d+)?|\.\d+)(?:E[+-]?\d+)?|&[HO][\dA-F]+)(?:U?[ILS]|[FRD])?/i,
3317
+ 'boolean': /\b(?:True|False|Nothing)\b/i,
3318
+ '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,
3319
+ 'operator': [
3320
+ /[+\-*/\\^<=>&#@$%!]/,
3321
+ {
3322
+ pattern: /([^\S\r\n])_(?=[^\S\r\n]*[\r\n])/,
3323
+ lookbehind: true
3324
+ }
3325
+ ],
3326
+ 'punctuation': /[{}().,:?]/
3327
+ };
3328
+
3329
+ Prism.languages.vb = Prism.languages['visual-basic'];
3330
+ Prism.languages.vba = Prism.languages['visual-basic'];
3331
+
3332
+ Prism.languages.sql = {
3333
+ 'comment': {
3334
+ pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
3335
+ lookbehind: true
3336
+ },
3337
+ 'variable': [
3338
+ {
3339
+ pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
3340
+ greedy: true
3341
+ },
3342
+ /@[\w.$]+/
3343
+ ],
3344
+ 'string': {
3345
+ pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
3346
+ greedy: true,
3347
+ lookbehind: true
3348
+ },
3349
+ '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?
3350
+ '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,
3351
+ 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
3352
+ 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
3353
+ 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|IN|ILIKE|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
3354
+ 'punctuation': /[;[\]()`,.]/
3355
+ };
3356
+
3357
+ /**
3358
+ * Original by Samuel Flores
3359
+ *
3360
+ * Adds the following new token classes:
3361
+ * constant, builtin, variable, symbol, regex
3362
+ */
3363
+ (function (Prism) {
3364
+ Prism.languages.ruby = Prism.languages.extend('clike', {
3365
+ 'comment': [
3366
+ /#.*/,
3367
+ {
3368
+ pattern: /^=begin\s[\s\S]*?^=end/m,
3369
+ greedy: true
3370
+ }
3371
+ ],
3372
+ 'class-name': {
3373
+ pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
3374
+ lookbehind: true,
3375
+ inside: {
3376
+ 'punctuation': /[.\\]/
3377
+ }
3378
+ },
3379
+ '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/
3380
+ });
3381
+
3382
+ var interpolation = {
3383
+ pattern: /#\{[^}]+\}/,
3384
+ inside: {
3385
+ 'delimiter': {
3386
+ pattern: /^#\{|\}$/,
3387
+ alias: 'tag'
3388
+ },
3389
+ rest: Prism.languages.ruby
3390
+ }
3391
+ };
3392
+
3393
+ delete Prism.languages.ruby.function;
3394
+
3395
+ Prism.languages.insertBefore('ruby', 'keyword', {
3396
+ 'regex': [
3397
+ {
3398
+ pattern: RegExp(/%r/.source + '(?:' + [
3399
+ /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
3400
+ /\((?:[^()\\]|\\[\s\S])*\)/.source,
3401
+ // Here we need to specifically allow interpolation
3402
+ /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
3403
+ /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
3404
+ /<(?:[^<>\\]|\\[\s\S])*>/.source
3405
+ ].join('|') + ')' + /[egimnosux]{0,6}/.source),
3406
+ greedy: true,
3407
+ inside: {
3408
+ 'interpolation': interpolation
3409
+ }
3410
+ },
3411
+ {
3412
+ pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
3413
+ lookbehind: true,
3414
+ greedy: true,
3415
+ inside: {
3416
+ 'interpolation': interpolation
3417
+ }
3418
+ }
3419
+ ],
3420
+ 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
3421
+ 'symbol': {
3422
+ pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
3423
+ lookbehind: true
3424
+ },
3425
+ 'method-definition': {
3426
+ pattern: /(\bdef\s+)[\w.]+/,
3427
+ lookbehind: true,
3428
+ inside: {
3429
+ 'function': /\w+$/,
3430
+ rest: Prism.languages.ruby
3431
+ }
3432
+ }
3433
+ });
3434
+
3435
+ Prism.languages.insertBefore('ruby', 'number', {
3436
+ '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/,
3437
+ 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
3438
+ });
3439
+
3440
+ Prism.languages.ruby.string = [
3441
+ {
3442
+ pattern: RegExp(/%[qQiIwWxs]?/.source + '(?:' + [
3443
+ /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
3444
+ /\((?:[^()\\]|\\[\s\S])*\)/.source,
3445
+ // Here we need to specifically allow interpolation
3446
+ /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
3447
+ /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
3448
+ /<(?:[^<>\\]|\\[\s\S])*>/.source
3449
+ ].join('|') + ')'),
3450
+ greedy: true,
3451
+ inside: {
3452
+ 'interpolation': interpolation
3453
+ }
3454
+ },
3455
+ {
3456
+ pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
3457
+ greedy: true,
3458
+ inside: {
3459
+ 'interpolation': interpolation
3460
+ }
3461
+ },
3462
+ {
3463
+ pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
3464
+ alias: 'heredoc-string',
3465
+ greedy: true,
3466
+ inside: {
3467
+ 'delimiter': {
3468
+ pattern: /^<<[-~]?[a-z_]\w*|[a-z_]\w*$/i,
3469
+ alias: 'symbol',
3470
+ inside: {
3471
+ 'punctuation': /^<<[-~]?/
3472
+ }
3473
+ },
3474
+ 'interpolation': interpolation
3475
+ }
3476
+ },
3477
+ {
3478
+ pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
3479
+ alias: 'heredoc-string',
3480
+ greedy: true,
3481
+ inside: {
3482
+ 'delimiter': {
3483
+ pattern: /^<<[-~]?'[a-z_]\w*'|[a-z_]\w*$/i,
3484
+ alias: 'symbol',
3485
+ inside: {
3486
+ 'punctuation': /^<<[-~]?'|'$/,
3487
+ }
3488
+ }
3489
+ }
3490
+ }
3491
+ ];
3492
+
3493
+ Prism.languages.rb = Prism.languages.ruby;
3494
+ }(Prism));
3495
+
3496
+ Prism.languages.swift = {
3497
+ 'comment': {
3498
+ // Nested comments are supported up to 2 levels
3499
+ pattern: /(^|[^\\:])(?:\/\/.*|\/\*(?:[^/*]|\/(?!\*)|\*(?!\/)|\/\*(?:[^*]|\*(?!\/))*\*\/)*\*\/)/,
3500
+ lookbehind: true,
3501
+ greedy: true
3502
+ },
3503
+ 'string-literal': [
3504
+ // https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html
3505
+ {
3506
+ pattern: RegExp(
3507
+ /(^|[^"#])/.source
3508
+ + '(?:'
3509
+ // single-line string
3510
+ + /"(?:\\(?:\((?:[^()]|\([^()]*\))*\)|\r\n|[^(])|[^\\\r\n"])*"/.source
3511
+ + '|'
3512
+ // multi-line string
3513
+ + /"""(?:\\(?:\((?:[^()]|\([^()]*\))*\)|[^(])|[^\\"]|"(?!""))*"""/.source
3514
+ + ')'
3515
+ + /(?!["#])/.source
3516
+ ),
3517
+ lookbehind: true,
3518
+ greedy: true,
3519
+ inside: {
3520
+ 'interpolation': {
3521
+ pattern: /(\\\()(?:[^()]|\([^()]*\))*(?=\))/,
3522
+ lookbehind: true,
3523
+ inside: null // see below
3524
+ },
3525
+ 'interpolation-punctuation': {
3526
+ pattern: /^\)|\\\($/,
3527
+ alias: 'punctuation'
3528
+ },
3529
+ 'punctuation': /\\(?=[\r\n])/,
3530
+ 'string': /[\s\S]+/
3531
+ }
3532
+ },
3533
+ {
3534
+ pattern: RegExp(
3535
+ /(^|[^"#])(#+)/.source
3536
+ + '(?:'
3537
+ // single-line string
3538
+ + /"(?:\\(?:#+\((?:[^()]|\([^()]*\))*\)|\r\n|[^#])|[^\\\r\n])*?"/.source
3539
+ + '|'
3540
+ // multi-line string
3541
+ + /"""(?:\\(?:#+\((?:[^()]|\([^()]*\))*\)|[^#])|[^\\])*?"""/.source
3542
+ + ')'
3543
+ + '\\2'
3544
+ ),
3545
+ lookbehind: true,
3546
+ greedy: true,
3547
+ inside: {
3548
+ 'interpolation': {
3549
+ pattern: /(\\#+\()(?:[^()]|\([^()]*\))*(?=\))/,
3550
+ lookbehind: true,
3551
+ inside: null // see below
3552
+ },
3553
+ 'interpolation-punctuation': {
3554
+ pattern: /^\)|\\#+\($/,
3555
+ alias: 'punctuation'
3556
+ },
3557
+ 'string': /[\s\S]+/
3558
+ }
3559
+ },
3560
+ ],
3561
+
3562
+ 'directive': {
3563
+ // directives with conditions
3564
+ pattern: RegExp(
3565
+ /#/.source
3566
+ + '(?:'
3567
+ + (
3568
+ /(?:elseif|if)\b/.source
3569
+ + '(?:[ \t]*'
3570
+ // This regex is a little complex. It's equivalent to this:
3571
+ // (?:![ \t]*)?(?:\b\w+\b(?:[ \t]*<round>)?|<round>)(?:[ \t]*(?:&&|\|\|))?
3572
+ // where <round> is a general parentheses expression.
3573
+ + /(?:![ \t]*)?(?:\b\w+\b(?:[ \t]*\((?:[^()]|\([^()]*\))*\))?|\((?:[^()]|\([^()]*\))*\))(?:[ \t]*(?:&&|\|\|))?/.source
3574
+ + ')+'
3575
+ )
3576
+ + '|'
3577
+ + /(?:else|endif)\b/.source
3578
+ + ')'
3579
+ ),
3580
+ alias: 'property',
3581
+ inside: {
3582
+ 'directive-name': /^#\w+/,
3583
+ 'boolean': /\b(?:true|false)\b/,
3584
+ 'number': /\b\d+(?:\.\d+)*\b/,
3585
+ 'operator': /!|&&|\|\||[<>]=?/,
3586
+ 'punctuation': /[(),]/
3587
+ }
3588
+ },
3589
+ 'literal': {
3590
+ pattern: /#(?:colorLiteral|column|dsohandle|file(?:ID|Literal|Path)?|function|imageLiteral|line)\b/,
3591
+ alias: 'constant'
3592
+ },
3593
+ 'other-directive': {
3594
+ pattern: /#\w+\b/,
3595
+ alias: 'property'
3596
+ },
3597
+
3598
+ 'attribute': {
3599
+ pattern: /@\w+/,
3600
+ alias: 'atrule'
3601
+ },
3602
+
3603
+ 'function-definition': {
3604
+ pattern: /(\bfunc\s+)\w+/,
3605
+ lookbehind: true,
3606
+ alias: 'function'
3607
+ },
3608
+ 'label': {
3609
+ // https://docs.swift.org/swift-book/LanguageGuide/ControlFlow.html#ID141
3610
+ pattern: /\b(break|continue)\s+\w+|\b[a-zA-Z_]\w*(?=\s*:\s*(?:for|repeat|while)\b)/,
3611
+ lookbehind: true,
3612
+ alias: 'important'
3613
+ },
3614
+
3615
+ '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/,
3616
+ 'boolean': /\b(?:true|false)\b/,
3617
+ 'nil': {
3618
+ pattern: /\bnil\b/,
3619
+ alias: 'constant'
3620
+ },
3621
+
3622
+ 'short-argument': /\$\d+\b/,
3623
+ 'omit': {
3624
+ pattern: /\b_\b/,
3625
+ alias: 'keyword'
3626
+ },
3627
+ 'number': /\b(?:[\d_]+(?:\.[\de_]+)?|0x[a-f0-9_]+(?:\.[a-f0-9p_]+)?|0b[01_]+|0o[0-7_]+)\b/i,
3628
+
3629
+ // A class name must start with an upper-case letter and be either 1 letter long or contain a lower-case letter.
3630
+ 'class-name': /\b[A-Z](?:[A-Z_\d]*[a-z]\w*)?\b/,
3631
+ 'function': /\b[a-z_]\w*(?=\s*\()/i,
3632
+ 'constant': /\b(?:[A-Z_]{2,}|k[A-Z][A-Za-z_]+)\b/,
3633
+
3634
+ // Operators are generic in Swift. Developers can even create new operators (e.g. +++).
3635
+ // https://docs.swift.org/swift-book/ReferenceManual/zzSummaryOfTheGrammar.html#ID481
3636
+ // This regex only supports ASCII operators.
3637
+ 'operator': /[-+*/%=!<>&|^~?]+|\.[.\-+*/%=!<>&|^~?]+/,
3638
+ 'punctuation': /[{}[\]();,.:\\]/
3639
+ };
3640
+
3641
+ Prism.languages.swift['string-literal'].forEach(function (rule) {
3642
+ rule.inside['interpolation'].inside = Prism.languages.swift;
3643
+ });
3644
+
3645
+ (function (Prism) {
3646
+ // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
3647
+ // + LC_ALL, RANDOM, REPLY, SECONDS.
3648
+ // + make sure PS1..4 are here as they are not always set,
3649
+ // - some useless things.
3650
+ 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';
3651
+
3652
+ var commandAfterHeredoc = {
3653
+ pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
3654
+ lookbehind: true,
3655
+ alias: 'punctuation', // this looks reasonably well in all themes
3656
+ inside: null // see below
3657
+ };
3658
+
3659
+ var insideString = {
3660
+ 'bash': commandAfterHeredoc,
3661
+ 'environment': {
3662
+ pattern: RegExp('\\$' + envVars),
3663
+ alias: 'constant'
3664
+ },
3665
+ 'variable': [
3666
+ // [0]: Arithmetic Environment
3667
+ {
3668
+ pattern: /\$?\(\([\s\S]+?\)\)/,
3669
+ greedy: true,
3670
+ inside: {
3671
+ // If there is a $ sign at the beginning highlight $(( and )) as variable
3672
+ 'variable': [
3673
+ {
3674
+ pattern: /(^\$\(\([\s\S]+)\)\)/,
3675
+ lookbehind: true
3676
+ },
3677
+ /^\$\(\(/
3678
+ ],
3679
+ 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
3680
+ // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
3681
+ 'operator': /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
3682
+ // If there is no $ sign at the beginning highlight (( and )) as punctuation
3683
+ 'punctuation': /\(\(?|\)\)?|,|;/
3684
+ }
3685
+ },
3686
+ // [1]: Command Substitution
3687
+ {
3688
+ pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
3689
+ greedy: true,
3690
+ inside: {
3691
+ 'variable': /^\$\(|^`|\)$|`$/
3692
+ }
3693
+ },
3694
+ // [2]: Brace expansion
3695
+ {
3696
+ pattern: /\$\{[^}]+\}/,
3697
+ greedy: true,
3698
+ inside: {
3699
+ 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
3700
+ 'punctuation': /[\[\]]/,
3701
+ 'environment': {
3702
+ pattern: RegExp('(\\{)' + envVars),
3703
+ lookbehind: true,
3704
+ alias: 'constant'
3705
+ }
3706
+ }
3707
+ },
3708
+ /\$(?:\w+|[#?*!@$])/
3709
+ ],
3710
+ // Escape sequences from echo and printf's manuals, and escaped quotes.
3711
+ '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})/
3712
+ };
3713
+
3714
+ Prism.languages.bash = {
3715
+ 'shebang': {
3716
+ pattern: /^#!\s*\/.*/,
3717
+ alias: 'important'
3718
+ },
3719
+ 'comment': {
3720
+ pattern: /(^|[^"{\\$])#.*/,
3721
+ lookbehind: true
3722
+ },
3723
+ 'function-name': [
3724
+ // a) function foo {
3725
+ // b) foo() {
3726
+ // c) function foo() {
3727
+ // but not “foo {”
3728
+ {
3729
+ // a) and c)
3730
+ pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
3731
+ lookbehind: true,
3732
+ alias: 'function'
3733
+ },
3734
+ {
3735
+ // b)
3736
+ pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/,
3737
+ alias: 'function'
3738
+ }
3739
+ ],
3740
+ // Highlight variable names as variables in for and select beginnings.
3741
+ 'for-or-select': {
3742
+ pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
3743
+ alias: 'variable',
3744
+ lookbehind: true
3745
+ },
3746
+ // Highlight variable names as variables in the left-hand part
3747
+ // of assignments (“=” and “+=”).
3748
+ 'assign-left': {
3749
+ pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
3750
+ inside: {
3751
+ 'environment': {
3752
+ pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars),
3753
+ lookbehind: true,
3754
+ alias: 'constant'
3755
+ }
3756
+ },
3757
+ alias: 'variable',
3758
+ lookbehind: true
3759
+ },
3760
+ 'string': [
3761
+ // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
3762
+ {
3763
+ pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,
3764
+ lookbehind: true,
3765
+ greedy: true,
3766
+ inside: insideString
3767
+ },
3768
+ // Here-document with quotes around the tag
3769
+ // → No expansion (so no “inside”).
3770
+ {
3771
+ pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
3772
+ lookbehind: true,
3773
+ greedy: true,
3774
+ inside: {
3775
+ 'bash': commandAfterHeredoc
3776
+ }
3777
+ },
3778
+ // “Normal” string
3779
+ {
3780
+ // https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
3781
+ pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
3782
+ lookbehind: true,
3783
+ greedy: true,
3784
+ inside: insideString
3785
+ },
3786
+ {
3787
+ // https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html
3788
+ pattern: /(^|[^$\\])'[^']*'/,
3789
+ lookbehind: true,
3790
+ greedy: true
3791
+ },
3792
+ {
3793
+ // https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
3794
+ pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
3795
+ greedy: true,
3796
+ inside: {
3797
+ 'entity': insideString.entity
3798
+ }
3799
+ }
3800
+ ],
3801
+ 'environment': {
3802
+ pattern: RegExp('\\$?' + envVars),
3803
+ alias: 'constant'
3804
+ },
3805
+ 'variable': insideString.variable,
3806
+ 'function': {
3807
+ 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;|&])/,
3808
+ lookbehind: true
3809
+ },
3810
+ 'keyword': {
3811
+ pattern: /(^|[\s;|&]|[<>]\()(?:if|then|else|elif|fi|for|while|in|case|esac|function|select|do|done|until)(?=$|[)\s;|&])/,
3812
+ lookbehind: true
3813
+ },
3814
+ // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
3815
+ 'builtin': {
3816
+ 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;|&])/,
3817
+ lookbehind: true,
3818
+ // Alias added to make those easier to distinguish from strings.
3819
+ alias: 'class-name'
3820
+ },
3821
+ 'boolean': {
3822
+ pattern: /(^|[\s;|&]|[<>]\()(?:true|false)(?=$|[)\s;|&])/,
3823
+ lookbehind: true
3824
+ },
3825
+ 'file-descriptor': {
3826
+ pattern: /\B&\d\b/,
3827
+ alias: 'important'
3828
+ },
3829
+ 'operator': {
3830
+ // Lots of redirections here, but not just that.
3831
+ pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,
3832
+ inside: {
3833
+ 'file-descriptor': {
3834
+ pattern: /^\d/,
3835
+ alias: 'important'
3836
+ }
3837
+ }
3838
+ },
3839
+ 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
3840
+ 'number': {
3841
+ pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
3842
+ lookbehind: true
3843
+ }
3844
+ };
3845
+
3846
+ commandAfterHeredoc.inside = Prism.languages.bash;
3847
+
3848
+ /* Patterns in command substitution. */
3849
+ var toBeCopied = [
3850
+ 'comment',
3851
+ 'function-name',
3852
+ 'for-or-select',
3853
+ 'assign-left',
3854
+ 'string',
3855
+ 'environment',
3856
+ 'function',
3857
+ 'keyword',
3858
+ 'builtin',
3859
+ 'boolean',
3860
+ 'file-descriptor',
3861
+ 'operator',
3862
+ 'punctuation',
3863
+ 'number'
3864
+ ];
3865
+ var inside = insideString.variable[1].inside;
3866
+ for (var i = 0; i < toBeCopied.length; i++) {
3867
+ inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
3868
+ }
3869
+
3870
+ Prism.languages.shell = Prism.languages.bash;
3871
+ }(Prism));
3872
+
3873
+ (function (Prism) {
3874
+
3875
+ // Allow only one line break
3876
+ var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;
3877
+
3878
+ /**
3879
+ * This function is intended for the creation of the bold or italic pattern.
3880
+ *
3881
+ * This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
3882
+ *
3883
+ * _Note:_ Keep in mind that this adds a capturing group.
3884
+ *
3885
+ * @param {string} pattern
3886
+ * @returns {RegExp}
3887
+ */
3888
+ function createInline(pattern) {
3889
+ pattern = pattern.replace(/<inner>/g, function () { return inner; });
3890
+ return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')');
3891
+ }
3892
+
3893
+
3894
+ var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
3895
+ var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g, function () { return tableCell; });
3896
+ var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
3897
+
3898
+
3899
+ Prism.languages.markdown = Prism.languages.extend('markup', {});
3900
+ Prism.languages.insertBefore('markdown', 'prolog', {
3901
+ 'front-matter-block': {
3902
+ pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
3903
+ lookbehind: true,
3904
+ greedy: true,
3905
+ inside: {
3906
+ 'punctuation': /^---|---$/,
3907
+ 'font-matter': {
3908
+ pattern: /\S+(?:\s+\S+)*/,
3909
+ alias: ['yaml', 'language-yaml'],
3910
+ inside: Prism.languages.yaml
3911
+ }
3912
+ }
3913
+ },
3914
+ 'blockquote': {
3915
+ // > ...
3916
+ pattern: /^>(?:[\t ]*>)*/m,
3917
+ alias: 'punctuation'
3918
+ },
3919
+ 'table': {
3920
+ pattern: RegExp('^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm'),
3921
+ inside: {
3922
+ 'table-data-rows': {
3923
+ pattern: RegExp('^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$'),
3924
+ lookbehind: true,
3925
+ inside: {
3926
+ 'table-data': {
3927
+ pattern: RegExp(tableCell),
3928
+ inside: Prism.languages.markdown
3929
+ },
3930
+ 'punctuation': /\|/
3931
+ }
3932
+ },
3933
+ 'table-line': {
3934
+ pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'),
3935
+ lookbehind: true,
3936
+ inside: {
3937
+ 'punctuation': /\||:?-{3,}:?/
3938
+ }
3939
+ },
3940
+ 'table-header-row': {
3941
+ pattern: RegExp('^' + tableRow + '$'),
3942
+ inside: {
3943
+ 'table-header': {
3944
+ pattern: RegExp(tableCell),
3945
+ alias: 'important',
3946
+ inside: Prism.languages.markdown
3947
+ },
3948
+ 'punctuation': /\|/
3949
+ }
3950
+ }
3951
+ }
3952
+ },
3953
+ 'code': [
3954
+ {
3955
+ // Prefixed by 4 spaces or 1 tab and preceded by an empty line
3956
+ pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
3957
+ lookbehind: true,
3958
+ alias: 'keyword'
3959
+ },
3960
+ {
3961
+ // ```optional language
3962
+ // code block
3963
+ // ```
3964
+ pattern: /^```[\s\S]*?^```$/m,
3965
+ greedy: true,
3966
+ inside: {
3967
+ 'code-block': {
3968
+ pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
3969
+ lookbehind: true
3970
+ },
3971
+ 'code-language': {
3972
+ pattern: /^(```).+/,
3973
+ lookbehind: true
3974
+ },
3975
+ 'punctuation': /```/
3976
+ }
3977
+ }
3978
+ ],
3979
+ 'title': [
3980
+ {
3981
+ // title 1
3982
+ // =======
3983
+
3984
+ // title 2
3985
+ // -------
3986
+ pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
3987
+ alias: 'important',
3988
+ inside: {
3989
+ punctuation: /==+$|--+$/
3990
+ }
3991
+ },
3992
+ {
3993
+ // # title 1
3994
+ // ###### title 6
3995
+ pattern: /(^\s*)#.+/m,
3996
+ lookbehind: true,
3997
+ alias: 'important',
3998
+ inside: {
3999
+ punctuation: /^#+|#+$/
4000
+ }
4001
+ }
4002
+ ],
4003
+ 'hr': {
4004
+ // ***
4005
+ // ---
4006
+ // * * *
4007
+ // -----------
4008
+ pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
4009
+ lookbehind: true,
4010
+ alias: 'punctuation'
4011
+ },
4012
+ 'list': {
4013
+ // * item
4014
+ // + item
4015
+ // - item
4016
+ // 1. item
4017
+ pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
4018
+ lookbehind: true,
4019
+ alias: 'punctuation'
4020
+ },
4021
+ 'url-reference': {
4022
+ // [id]: http://example.com "Optional title"
4023
+ // [id]: http://example.com 'Optional title'
4024
+ // [id]: http://example.com (Optional title)
4025
+ // [id]: <http://example.com> "Optional title"
4026
+ pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
4027
+ inside: {
4028
+ 'variable': {
4029
+ pattern: /^(!?\[)[^\]]+/,
4030
+ lookbehind: true
4031
+ },
4032
+ 'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
4033
+ 'punctuation': /^[\[\]!:]|[<>]/
4034
+ },
4035
+ alias: 'url'
4036
+ },
4037
+ 'bold': {
4038
+ // **strong**
4039
+ // __strong__
4040
+
4041
+ // allow one nested instance of italic text using the same delimiter
4042
+ pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
4043
+ lookbehind: true,
4044
+ greedy: true,
4045
+ inside: {
4046
+ 'content': {
4047
+ pattern: /(^..)[\s\S]+(?=..$)/,
4048
+ lookbehind: true,
4049
+ inside: {} // see below
4050
+ },
4051
+ 'punctuation': /\*\*|__/
4052
+ }
4053
+ },
4054
+ 'italic': {
4055
+ // *em*
4056
+ // _em_
4057
+
4058
+ // allow one nested instance of bold text using the same delimiter
4059
+ pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
4060
+ lookbehind: true,
4061
+ greedy: true,
4062
+ inside: {
4063
+ 'content': {
4064
+ pattern: /(^.)[\s\S]+(?=.$)/,
4065
+ lookbehind: true,
4066
+ inside: {} // see below
4067
+ },
4068
+ 'punctuation': /[*_]/
4069
+ }
4070
+ },
4071
+ 'strike': {
4072
+ // ~~strike through~~
4073
+ // ~strike~
4074
+ // eslint-disable-next-line regexp/strict
4075
+ pattern: createInline(/(~~?)(?:(?!~)<inner>)+\2/.source),
4076
+ lookbehind: true,
4077
+ greedy: true,
4078
+ inside: {
4079
+ 'content': {
4080
+ pattern: /(^~~?)[\s\S]+(?=\1$)/,
4081
+ lookbehind: true,
4082
+ inside: {} // see below
4083
+ },
4084
+ 'punctuation': /~~?/
4085
+ }
4086
+ },
4087
+ 'code-snippet': {
4088
+ // `code`
4089
+ // ``code``
4090
+ pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,
4091
+ lookbehind: true,
4092
+ greedy: true,
4093
+ alias: ['code', 'keyword']
4094
+ },
4095
+ 'url': {
4096
+ // [example](http://example.com "Optional title")
4097
+ // [example][id]
4098
+ // [example] [id]
4099
+ pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\])<inner>)+\])/.source),
4100
+ lookbehind: true,
4101
+ greedy: true,
4102
+ inside: {
4103
+ 'operator': /^!/,
4104
+ 'content': {
4105
+ pattern: /(^\[)[^\]]+(?=\])/,
4106
+ lookbehind: true,
4107
+ inside: {} // see below
4108
+ },
4109
+ 'variable': {
4110
+ pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/,
4111
+ lookbehind: true
4112
+ },
4113
+ 'url': {
4114
+ pattern: /(^\]\()[^\s)]+/,
4115
+ lookbehind: true
4116
+ },
4117
+ 'string': {
4118
+ pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,
4119
+ lookbehind: true
4120
+ }
4121
+ }
4122
+ }
4123
+ });
4124
+
4125
+ ['url', 'bold', 'italic', 'strike'].forEach(function (token) {
4126
+ ['url', 'bold', 'italic', 'strike', 'code-snippet'].forEach(function (inside) {
4127
+ if (token !== inside) {
4128
+ Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
4129
+ }
4130
+ });
4131
+ });
4132
+
4133
+ Prism.hooks.add('after-tokenize', function (env) {
4134
+ if (env.language !== 'markdown' && env.language !== 'md') {
4135
+ return;
4136
+ }
4137
+
4138
+ function walkTokens(tokens) {
4139
+ if (!tokens || typeof tokens === 'string') {
4140
+ return;
4141
+ }
4142
+
4143
+ for (var i = 0, l = tokens.length; i < l; i++) {
4144
+ var token = tokens[i];
4145
+
4146
+ if (token.type !== 'code') {
4147
+ walkTokens(token.content);
4148
+ continue;
4149
+ }
4150
+
4151
+ /*
4152
+ * Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
4153
+ * is optional. But the grammar is defined so that there is only one case we have to handle:
4154
+ *
4155
+ * token.content = [
4156
+ * <span class="punctuation">```</span>,
4157
+ * <span class="code-language">xxxx</span>,
4158
+ * '\n', // exactly one new lines (\r or \n or \r\n)
4159
+ * <span class="code-block">...</span>,
4160
+ * '\n', // exactly one new lines again
4161
+ * <span class="punctuation">```</span>
4162
+ * ];
4163
+ */
4164
+
4165
+ var codeLang = token.content[1];
4166
+ var codeBlock = token.content[3];
4167
+
4168
+ if (codeLang && codeBlock &&
4169
+ codeLang.type === 'code-language' && codeBlock.type === 'code-block' &&
4170
+ typeof codeLang.content === 'string') {
4171
+
4172
+ // this might be a language that Prism does not support
4173
+
4174
+ // do some replacements to support C++, C#, and F#
4175
+ var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp');
4176
+ // only use the first word
4177
+ lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase();
4178
+ var alias = 'language-' + lang;
4179
+
4180
+ // add alias
4181
+ if (!codeBlock.alias) {
4182
+ codeBlock.alias = [alias];
4183
+ } else if (typeof codeBlock.alias === 'string') {
4184
+ codeBlock.alias = [codeBlock.alias, alias];
4185
+ } else {
4186
+ codeBlock.alias.push(alias);
4187
+ }
4188
+ }
4189
+ }
4190
+ }
4191
+
4192
+ walkTokens(env.tokens);
4193
+ });
4194
+
4195
+ Prism.hooks.add('wrap', function (env) {
4196
+ if (env.type !== 'code-block') {
4197
+ return;
4198
+ }
4199
+
4200
+ var codeLang = '';
4201
+ for (var i = 0, l = env.classes.length; i < l; i++) {
4202
+ var cls = env.classes[i];
4203
+ var match = /language-(.+)/.exec(cls);
4204
+ if (match) {
4205
+ codeLang = match[1];
4206
+ break;
4207
+ }
4208
+ }
4209
+
4210
+ var grammar = Prism.languages[codeLang];
4211
+
4212
+ if (!grammar) {
4213
+ if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) {
4214
+ var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16);
4215
+ env.attributes['id'] = id;
4216
+
4217
+ Prism.plugins.autoloader.loadLanguages(codeLang, function () {
4218
+ var ele = document.getElementById(id);
4219
+ if (ele) {
4220
+ ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
4221
+ }
4222
+ });
4223
+ }
4224
+ } else {
4225
+ env.content = Prism.highlight(textContent(env.content), grammar, codeLang);
4226
+ }
4227
+ });
4228
+
4229
+ var tagPattern = RegExp(Prism.languages.markup.tag.pattern.source, 'gi');
4230
+
4231
+ /**
4232
+ * A list of known entity names.
4233
+ *
4234
+ * This will always be incomplete to save space. The current list is the one used by lowdash's unescape function.
4235
+ *
4236
+ * @see {@link https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/unescape.js#L2}
4237
+ */
4238
+ var KNOWN_ENTITY_NAMES = {
4239
+ 'amp': '&',
4240
+ 'lt': '<',
4241
+ 'gt': '>',
4242
+ 'quot': '"',
4243
+ };
4244
+
4245
+ // IE 11 doesn't support `String.fromCodePoint`
4246
+ var fromCodePoint = String.fromCodePoint || String.fromCharCode;
4247
+
4248
+ /**
4249
+ * Returns the text content of a given HTML source code string.
4250
+ *
4251
+ * @param {string} html
4252
+ * @returns {string}
4253
+ */
4254
+ function textContent(html) {
4255
+ // remove all tags
4256
+ var text = html.replace(tagPattern, '');
4257
+
4258
+ // decode known entities
4259
+ text = text.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi, function (m, code) {
4260
+ code = code.toLowerCase();
4261
+
4262
+ if (code[0] === '#') {
4263
+ var value;
4264
+ if (code[1] === 'x') {
4265
+ value = parseInt(code.slice(2), 16);
4266
+ } else {
4267
+ value = Number(code.slice(1));
4268
+ }
4269
+
4270
+ return fromCodePoint(value);
4271
+ } else {
4272
+ var known = KNOWN_ENTITY_NAMES[code];
4273
+ if (known) {
4274
+ return known;
4275
+ }
4276
+
4277
+ // unable to decode
4278
+ return m;
4279
+ }
4280
+ });
4281
+
4282
+ return text;
4283
+ }
4284
+
4285
+ Prism.languages.md = Prism.languages.markdown;
4286
+
4287
+ }(Prism));
4288
+
4289
+ Prism.languages.lua = {
4290
+ 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
4291
+ // \z may be used to skip the following space
4292
+ 'string': {
4293
+ pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
4294
+ greedy: true
4295
+ },
4296
+ 'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
4297
+ '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/,
4298
+ 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
4299
+ 'operator': [
4300
+ /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
4301
+ {
4302
+ // Match ".." but don't break "..."
4303
+ pattern: /(^|[^.])\.\.(?!\.)/,
4304
+ lookbehind: true
4305
+ }
4306
+ ],
4307
+ 'punctuation': /[\[\](){},;]|\.+|:+/
4308
+ };
4309
+
4310
+ Prism.languages.groovy = Prism.languages.extend('clike', {
4311
+ 'string': [
4312
+ {
4313
+ // https://groovy-lang.org/syntax.html#_dollar_slashy_string
4314
+ pattern: /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
4315
+ greedy: true
4316
+ },
4317
+ {
4318
+ // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
4319
+ // simple division (see JS regex), so find a fix maybe?
4320
+ pattern: /(["'/])(?:\\.|(?!\1)[^\\\r\n])*\1/,
4321
+ greedy: true
4322
+ }
4323
+ ],
4324
+ '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/,
4325
+ 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
4326
+ 'operator': {
4327
+ pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
4328
+ lookbehind: true
4329
+ },
4330
+ 'punctuation': /\.+|[{}[\];(),:$]/
4331
+ });
4332
+
4333
+ Prism.languages.insertBefore('groovy', 'string', {
4334
+ 'shebang': {
4335
+ pattern: /#!.+/,
4336
+ alias: 'comment'
4337
+ }
4338
+ });
4339
+
4340
+ Prism.languages.insertBefore('groovy', 'punctuation', {
4341
+ 'spock-block': /\b(?:setup|given|when|then|and|cleanup|expect|where):/
4342
+ });
4343
+
4344
+ Prism.languages.insertBefore('groovy', 'function', {
4345
+ 'annotation': {
4346
+ pattern: /(^|[^.])@\w+/,
4347
+ lookbehind: true,
4348
+ alias: 'punctuation'
4349
+ }
4350
+ });
4351
+
4352
+ // Handle string interpolation
4353
+ Prism.hooks.add('wrap', function (env) {
4354
+ if (env.language === 'groovy' && env.type === 'string') {
4355
+ var delimiter = env.content[0];
4356
+
4357
+ if (delimiter != "'") {
4358
+ var pattern = /([^\\])(?:\$(?:\{.*?\}|[\w.]+))/;
4359
+ if (delimiter === '$') {
4360
+ pattern = /([^\$])(?:\$(?:\{.*?\}|[\w.]+))/;
4361
+ }
4362
+
4363
+ // To prevent double HTML-encoding we have to decode env.content first
4364
+ env.content = env.content.replace(/&lt;/g, '<').replace(/&amp;/g, '&');
4365
+
4366
+ env.content = Prism.highlight(env.content, {
4367
+ 'expression': {
4368
+ pattern: pattern,
4369
+ lookbehind: true,
4370
+ inside: Prism.languages.groovy
4371
+ }
4372
+ });
4373
+
4374
+ env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
4375
+ }
4376
+ }
4377
+ });
4378
+
4379
+ Prism.languages.abap = {
4380
+ 'comment': /^\*.*/m,
4381
+ 'string': /(`|')(?:\\.|(?!\1)[^\\\r\n])*\1/m,
4382
+ 'string-template': {
4383
+ pattern: /([|}])(?:\\.|[^\\|{\r\n])*(?=[|{])/,
4384
+ lookbehind: true,
4385
+ alias: 'string'
4386
+ },
4387
+ /* End Of Line comments should not interfere with strings when the
4388
+ quote character occurs within them. We assume a string being highlighted
4389
+ inside an EOL comment is more acceptable than the opposite.
4390
+ */
4391
+ 'eol-comment': {
4392
+ pattern: /(^|\s)".*/m,
4393
+ lookbehind: true,
4394
+ alias: 'comment'
4395
+ },
4396
+ 'keyword': {
4397
+ 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,
4398
+ lookbehind: true
4399
+ },
4400
+ /* Numbers can be only integers. Decimal or Hex appear only as strings */
4401
+ 'number': /\b\d+\b/,
4402
+ /* Operators must always be surrounded by whitespace, they cannot be put
4403
+ adjacent to operands.
4404
+ */
4405
+ 'operator': {
4406
+ pattern: /(\s)(?:\*\*?|<[=>]?|>=?|\?=|[-+\/=])(?=\s)/,
4407
+ lookbehind: true
4408
+ },
4409
+ 'string-operator': {
4410
+ pattern: /(\s)&&?(?=\s)/,
4411
+ lookbehind: true,
4412
+ /* The official editor highlights */
4413
+ alias: 'keyword'
4414
+ },
4415
+ 'token-operator': [{
4416
+ /* Special operators used to access structure components, class methods/attributes, etc. */
4417
+ pattern: /(\w)(?:->?|=>|[~|{}])(?=\w)/,
4418
+ lookbehind: true,
4419
+ alias: 'punctuation'
4420
+ }, {
4421
+ /* Special tokens used do delimit string templates */
4422
+ pattern: /[|{}]/,
4423
+ alias: 'punctuation'
4424
+ }],
4425
+ 'punctuation': /[,.:()]/
4426
+ };
4427
+
4428
+ /**
4429
+ * @description prismjs
4430
+ * @author wangfupeng
4431
+ */
4432
+ // 语言模块,参考 https://github.com/PrismJS/prism/tree/master/components
4433
+ // prismjs 的 token 类型汇总
4434
+ var prismTokenTypes = [
4435
+ 'comment',
4436
+ 'prolog',
4437
+ 'doctype',
4438
+ 'cdata',
4439
+ 'punctuation',
4440
+ 'namespace',
4441
+ 'property',
4442
+ 'tag',
4443
+ 'boolean',
4444
+ 'number',
4445
+ 'constant',
4446
+ 'symbol',
4447
+ 'deleted',
4448
+ 'selector',
4449
+ 'attr-name',
4450
+ 'string',
4451
+ 'builtin',
4452
+ 'inserted',
4453
+ 'operator',
4454
+ 'entity',
4455
+ 'url',
4456
+ 'string',
4457
+ 'atrule',
4458
+ 'attr-value',
4459
+ 'keyword',
4460
+ 'function',
4461
+ 'class-name',
4462
+ 'regex',
4463
+ 'important',
4464
+ 'variable',
4465
+ 'bold',
4466
+ 'italic',
4467
+ 'entity',
4468
+ 'char',
4469
+ ];
4470
+ /**
4471
+ * 获取 prism token 的字符串长度
4472
+ * @param token prism token
4473
+ */
4474
+ function getPrismTokenLength(token) {
4475
+ if (typeof token === 'string') {
4476
+ return token.length;
4477
+ }
4478
+ else if (typeof token.content === 'string') {
4479
+ return token.content.length;
4480
+ }
4481
+ else {
4482
+ // 累加 length
4483
+ return token.content.reduce(
4484
+ // @ts-ignore
4485
+ function (l, t) { return l + getPrismTokenLength(t); }, 0);
4486
+ }
4487
+ }
4488
+ /**
4489
+ * 获取 prism 解析的 token 列表
4490
+ * @param textNode text node
4491
+ * @param language 代码语言
4492
+ */
4493
+ function getPrismTokens(textNode, language) {
4494
+ if (!language)
4495
+ return [];
4496
+ var langGrammar = prism.languages[language];
4497
+ if (!langGrammar)
4498
+ return [];
4499
+ return prism.tokenize(textNode.text, langGrammar);
4500
+ // tokens 即 Prism 对整个字符串的拆分,有普通文字也有高亮的关键字
4501
+ // 例如 `const a = 100;` 的 tokens 是一个数组 [ token, ' a ', token, ' ', token ] ,有对象有字符串,对象就表示关键字
4502
+ // 如数组第一个 token 是 { type: "keyword", content: "const" } 。关键字类型不同 type 也不同
4503
+ }
4504
+
4505
+ /**
4506
+ * @description render code highlight style
4507
+ * @author wangfupeng
4508
+ */
4509
+ /**
4510
+ * 添加样式
4511
+ * @param node slate text
4512
+ * @param vnode vnode
4513
+ * @returns vnode
4514
+ */
4515
+ function renderStyle(node, vnode) {
4516
+ var leafNode = node;
4517
+ var styleVnode = vnode;
4518
+ var className = '';
4519
+ prismTokenTypes.forEach(function (type) {
4520
+ if (leafNode[type])
4521
+ className = type;
4522
+ });
4523
+ if (className) {
4524
+ className = "token " + className; // 如 'token keyword' - prismjs 渲染的规则
4525
+ addVnodeClassName(styleVnode, className);
4526
+ }
4527
+ return styleVnode;
4528
+ }
4529
+
4530
+ /**
4531
+ * @description DOM 操作
4532
+ * @author wangfupeng
4533
+ */
4534
+ if ($.attr)
4535
+ $__default["default"].fn.attr = $.attr;
4536
+
4537
+ /**
4538
+ * @description parse style html
4539
+ * @author wangfupeng
4540
+ */
4541
+ function parseCodeStyleHtml(elem, node, editor) {
4542
+ var $elem = $__default["default"](elem);
4543
+ if (!slate.Element.isElement(node))
4544
+ return node;
4545
+ if (core.DomEditor.getNodeType(node) !== 'code')
4546
+ return node; // 只针对 pre/code 元素
4547
+ var elemNode = node;
4548
+ var langAttr = $elem.attr('class') || '';
4549
+ if (langAttr.indexOf('language-') === 0) {
4550
+ // V5 版本,格式如 class="language-javascript"
4551
+ elemNode.language = langAttr.split('-')[1] || ''; // 获取 'javascript'
4552
+ }
4553
+ else {
4554
+ // 兼容 V4 版本,格式如 class="Javascript"
4555
+ elemNode.language = langAttr.toLowerCase();
4556
+ }
4557
+ return elemNode;
4558
+ }
4559
+
4560
+ /**
4561
+ * @description icon svg
4562
+ * @author wangfupeng
4563
+ */
4564
+ /**
4565
+ * 【注意】svg 字符串的长度 ,否则会导致代码体积过大
4566
+ * 尽量选择 https://www.iconfont.cn/collections/detail?spm=a313x.7781069.0.da5a778a4&cid=20293
4567
+ * 找不到再从 iconfont.com 搜索
4568
+ */
4569
+ 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>';
4570
+
4571
+ /**
4572
+ * @description code-highlight select lang
4573
+ * @author wangfupeng
4574
+ */
4575
+ var SelectLangMenu = /** @class */ (function () {
4576
+ function SelectLangMenu() {
4577
+ this.title = core.t('highLightModule.selectLang');
4578
+ this.iconSvg = JS_SVG;
4579
+ this.tag = 'select';
4580
+ this.width = 95;
4581
+ this.selectPanelWidth = 115;
4582
+ }
4583
+ SelectLangMenu.prototype.getOptions = function (editor) {
4584
+ var options = [];
4585
+ // 获取配置,参考 './config.ts'
4586
+ var _a = editor.getMenuConfig('codeSelectLang').codeLangs, codeLangs = _a === void 0 ? [] : _a; // 第二个参数 menu key
4587
+ options.push({
4588
+ text: 'plain text',
4589
+ value: '', // getValue 默认会返回 ''
4590
+ });
4591
+ codeLangs.forEach(function (lang) {
4592
+ var text = lang.text, value = lang.value;
4593
+ options.push({ text: text, value: value });
4594
+ });
4595
+ // 设置 selected
4596
+ var curValue = this.getValue(editor);
4597
+ options.forEach(function (opt) {
4598
+ if (opt.value === curValue) {
4599
+ opt.selected = true;
4600
+ }
4601
+ else {
4602
+ delete opt.selected;
4603
+ }
4604
+ });
4605
+ return options;
4606
+ };
4607
+ SelectLangMenu.prototype.isActive = function (editor) {
4608
+ // select menu 会显示 selected value ,用不到 active
4609
+ return false;
4610
+ };
4611
+ /**
4612
+ * 获取语言类型
4613
+ * @param editor editor
4614
+ */
4615
+ SelectLangMenu.prototype.getValue = function (editor) {
4616
+ var elem = this.getSelectCodeElem(editor);
4617
+ if (elem == null)
4618
+ return '';
4619
+ if (!slate.Element.isElement(elem))
4620
+ return '';
4621
+ var lang = elem.language.toString();
4622
+ // 当前 elem.language 是否在已配置的 langs 中?
4623
+ var _a = editor.getMenuConfig('codeSelectLang').codeLangs, codeLangs = _a === void 0 ? [] : _a;
4624
+ var hasLang = codeLangs.some(function (item) { return item.value === lang; });
4625
+ if (hasLang)
4626
+ return lang;
4627
+ return '';
4628
+ };
4629
+ SelectLangMenu.prototype.isDisabled = function (editor) {
4630
+ if (editor.selection == null)
4631
+ return true;
4632
+ var elem = this.getSelectCodeElem(editor);
4633
+ if (elem)
4634
+ return false;
4635
+ return true;
4636
+ };
4637
+ SelectLangMenu.prototype.exec = function (editor, value) {
4638
+ var elem = this.getSelectCodeElem(editor);
4639
+ if (elem == null)
4640
+ return;
4641
+ // 设置语言
4642
+ var props = { language: value.toString() };
4643
+ slate.Transforms.setNodes(editor, props, {
4644
+ match: function (n) { return core.DomEditor.checkNodeType(n, 'code'); },
4645
+ });
4646
+ };
4647
+ SelectLangMenu.prototype.getSelectCodeElem = function (editor) {
4648
+ var codeNode = core.DomEditor.getSelectedNodeByType(editor, 'code');
4649
+ if (codeNode == null)
4650
+ return null;
4651
+ var preNode = core.DomEditor.getParentNode(editor, codeNode);
4652
+ if (!slate.Element.isElement(preNode))
4653
+ return null;
4654
+ if (preNode.type !== 'pre')
4655
+ return null;
4656
+ return codeNode;
4657
+ };
4658
+ return SelectLangMenu;
4659
+ }());
4660
+
4661
+ /**
4662
+ * @description menu config
4663
+ * @author wangfupeng
4664
+ */
4665
+ function genCodeLangs() {
4666
+ // 1. text value 对应关系参考 prism 官网 https://prismjs.com/#supported-languages
4667
+ // 2. 要加入一个新语言时,要引入相应的 js 模块(代码在 `vender/prism.ts`),例如 `import 'prismjs/components/prism-php'`
4668
+ return [
4669
+ { text: 'CSS', value: 'css' },
4670
+ { text: 'HTML', value: 'html' },
4671
+ { text: 'XML', value: 'xml' },
4672
+ { text: 'Javascript', value: 'javascript' },
4673
+ { text: 'Typescript', value: 'typescript' },
4674
+ { text: 'JSX', value: 'jsx' },
4675
+ { text: 'Go', value: 'go' },
4676
+ { text: 'PHP', value: 'php' },
4677
+ { text: 'C', value: 'c' },
4678
+ { text: 'Python', value: 'python' },
4679
+ { text: 'Java', value: 'java' },
4680
+ { text: 'C++', value: 'cpp' },
4681
+ { text: 'C#', value: 'csharp' },
4682
+ { text: 'Visual Basic', value: 'visual-basic' },
4683
+ { text: 'SQL', value: 'sql' },
4684
+ { text: 'Ruby', value: 'ruby' },
4685
+ { text: 'Swift', value: 'swift' },
4686
+ { text: 'Bash', value: 'bash' },
4687
+ { text: 'Lua', value: 'lua' },
4688
+ { text: 'Groovy', value: 'groovy' },
4689
+ { text: 'Markdown', value: 'markdown' },
4690
+ { text: 'ABAP', value: 'abap' },
4691
+ ];
4692
+ }
4693
+
4694
+ /**
4695
+ * @description code-highlight menu
4696
+ * @author wangfupeng
4697
+ */
4698
+ var selectLangMenuConf = {
4699
+ key: 'codeSelectLang',
4700
+ factory: function () {
4701
+ return new SelectLangMenu();
4702
+ },
4703
+ config: {
4704
+ codeLangs: genCodeLangs(),
4705
+ },
4706
+ };
4707
+
4708
+ /**
4709
+ * @description to html
4710
+ * @author wangfupeng
4711
+ */
4712
+ function codeToHtml(elem, childrenHtml) {
4713
+ var _a = elem.language, language = _a === void 0 ? '' : _a;
4714
+ var cssClass = language
4715
+ ? "class=\"language-" + language + "\"" // prism.js 根据 language 代码高亮
4716
+ : '';
4717
+ return "<code " + cssClass + ">" + childrenHtml + "</code>";
4718
+ }
4719
+ // 覆盖 basic-module 中的 code to html
4720
+ var codeToHtmlConf = {
4721
+ type: 'code',
4722
+ elemToHtml: codeToHtml,
4723
+ };
4724
+
4725
+ /**
4726
+ * @description code highlight module
4727
+ * @author wangfupeng
4728
+ */
4729
+ var codeHighlightModule = {
4730
+ renderStyle: renderStyle,
4731
+ parseStyleHtml: parseCodeStyleHtml,
4732
+ menus: [selectLangMenuConf],
4733
+ elemsToHtml: [codeToHtmlConf],
4734
+ };
4735
+
4736
+ /*! *****************************************************************************
4737
+ Copyright (c) Microsoft Corporation.
4738
+
4739
+ Permission to use, copy, modify, and/or distribute this software for any
4740
+ purpose with or without fee is hereby granted.
4741
+
4742
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4743
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4744
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4745
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4746
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4747
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4748
+ PERFORMANCE OF THIS SOFTWARE.
4749
+ ***************************************************************************** */
4750
+
4751
+ function __values(o) {
4752
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4753
+ if (m) return m.call(o);
4754
+ if (o && typeof o.length === "number") return {
4755
+ next: function () {
4756
+ if (o && i >= o.length) o = void 0;
4757
+ return { value: o && o[i++], done: !o };
4758
+ }
4759
+ };
4760
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
4761
+ }
4762
+
4763
+ function __read(o, n) {
4764
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4765
+ if (!m) return o;
4766
+ var i = m.call(o), r, ar = [], e;
4767
+ try {
4768
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
4769
+ }
4770
+ catch (error) { e = { error: error }; }
4771
+ finally {
4772
+ try {
4773
+ if (r && !r.done && (m = i["return"])) m.call(i);
4774
+ }
4775
+ finally { if (e) throw e.error; }
4776
+ }
4777
+ return ar;
4778
+ }
4779
+
4780
+ /**
4781
+ * @description code-highlight decorate
4782
+ * @author wangfupeng
4783
+ */
4784
+ /**
4785
+ * 获取 code elem
4786
+ * @param node text node
4787
+ */
4788
+ function getCodeElem(textNode) {
4789
+ if (!slate.Text.isText(textNode))
4790
+ return null; // 非文本 node
4791
+ var codeNode = core.DomEditor.getParentNode(null, textNode);
4792
+ if (codeNode && core.DomEditor.getNodeType(codeNode) === 'code') {
4793
+ var preNode = core.DomEditor.getParentNode(null, codeNode);
4794
+ if (preNode && core.DomEditor.getNodeType(preNode) === 'pre') {
4795
+ return codeNode;
4796
+ }
4797
+ }
4798
+ return null;
4799
+ }
4800
+ var codeHighLightDecorate = function (nodeEntry) {
4801
+ var e_1, _a, _b;
4802
+ var _c = __read(nodeEntry, 2), n = _c[0], path = _c[1];
4803
+ var ranges = [];
4804
+ // 节点不合法,则不处理
4805
+ var codeElem = getCodeElem(n);
4806
+ if (codeElem == null)
4807
+ return ranges;
4808
+ var _d = codeElem.language, language = _d === void 0 ? '' : _d;
4809
+ if (!language)
4810
+ return ranges;
4811
+ var textNode = n;
4812
+ var tokens = getPrismTokens(textNode, language);
4813
+ var start = 0;
4814
+ try {
4815
+ for (var tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
4816
+ var token = tokens_1_1.value;
4817
+ var length_1 = getPrismTokenLength(token);
4818
+ var end = start + length_1;
4819
+ if (typeof token !== 'string') {
4820
+ // 遇到关键字,则拆分多个 range —— decorate 规则
4821
+ ranges.push((_b = {},
4822
+ _b[token.type] = true,
4823
+ _b.anchor = { path: path, offset: start },
4824
+ _b.focus = { path: path, offset: end },
4825
+ _b));
4826
+ }
4827
+ start = end;
4828
+ }
4829
+ }
4830
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
4831
+ finally {
4832
+ try {
4833
+ if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
4834
+ }
4835
+ finally { if (e_1) throw e_1.error; }
4836
+ }
4837
+ return ranges;
4838
+ };
4839
+
4840
+ exports.wangEditorCodeHighLightDecorate = codeHighLightDecorate;
4841
+ exports.wangEditorCodeHighlightModule = codeHighlightModule;
4842
+
4843
+ Object.defineProperty(exports, '__esModule', { value: true });
4844
+
4845
+ }));