cleanup/add prism classes
Hunter
Monday, July 7th, 2025 at 3:03 PM
9 --bg-color: #2d2d2d;
10 --text-color: #f8f8f2;
11 --editor-bg: #1e1e1e;
- --border-color: #222;
- --header-bg: #333;
- --header-text: #ccc;
12 --preview-bg: #2d2d2d;
13 }
14
17 --bg-color: #f0f0f0;
18 --text-color: #333;
19 --editor-bg: #fafafa;
- --border-color: #ccc;
- --header-bg: #ddd;
- --header-text: #666;
20 --preview-bg: white;
21 }
22 }
40 width: 50%;
41 height: 100vh;
42 background: var(--preview-bg);
- border-right: 1px solid var(--border-color);
43 position: relative;
44 }
45
1 +/* PrismJS 1.30.0
2 +https://prismjs.com/download#themes=prism-funky&languages=markup+css+clike+javascript+css-extras&plugins=line-numbers+toolbar+match-braces */
3 +/**
4 + * prism.js Funky theme
5 + * Based on “Polyfilling the gaps” talk slides http://lea.verou.me/polyfilling-the-gaps/
6 + * @author Lea Verou
7 + */
8 +
9 +code[class*="language-"],
10 +pre[class*="language-"] {
11 + font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
12 + font-size: 1em;
13 + text-align: left;
14 + white-space: pre;
15 + word-spacing: normal;
16 + word-break: normal;
17 + word-wrap: normal;
18 + line-height: 1.5;
19 +
20 + -moz-tab-size: 4;
21 + -o-tab-size: 4;
22 + tab-size: 4;
23 +
24 + -webkit-hyphens: none;
25 + -moz-hyphens: none;
26 + -ms-hyphens: none;
27 + hyphens: none;
28 +}
29 +
30 +/* Code blocks */
31 +pre[class*="language-"] {
32 + padding: .4em .8em;
33 + margin: .5em 0;
34 + overflow: auto;
35 + background: url('data:image/svg+xml;charset=utf-8,<svg%20version%3D"1.1"%20xmlns%3D"http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg"%20width%3D"100"%20height%3D"100"%20fill%3D"rgba(0%2C0%2C0%2C.2)">%0D%0A<polygon%20points%3D"0%2C50%2050%2C0%200%2C0"%20%2F>%0D%0A<polygon%20points%3D"0%2C100%2050%2C100%20100%2C50%20100%2C0"%20%2F>%0D%0A<%2Fsvg>');
36 + background-size: 1em 1em;
37 +}
38 +
39 +code[class*="language-"] {
40 + background: black;
41 + color: white;
42 + box-shadow: -.3em 0 0 .3em black, .3em 0 0 .3em black;
43 +}
44 +
45 +/* Inline code */
46 +:not(pre) > code[class*="language-"] {
47 + padding: .2em;
48 + border-radius: .3em;
49 + box-shadow: none;
50 + white-space: normal;
51 +}
52 +
53 +.token.comment,
54 +.token.prolog,
55 +.token.doctype,
56 +.token.cdata {
57 + color: #aaa;
58 +}
59 +
60 +.token.punctuation {
61 + color: #999;
62 +}
63 +
64 +.token.namespace {
65 + opacity: .7;
66 +}
67 +
68 +.token.property,
69 +.token.tag,
70 +.token.boolean,
71 +.token.number,
72 +.token.constant,
73 +.token.symbol {
74 + color: #0cf;
75 +}
76 +
77 +.token.selector,
78 +.token.attr-name,
79 +.token.string,
80 +.token.char,
81 +.token.builtin {
82 + color: yellow;
83 +}
84 +
85 +.token.operator,
86 +.token.entity,
87 +.token.url,
88 +.language-css .token.string,
89 +.token.variable,
90 +.token.inserted {
91 + color: yellowgreen;
92 +}
93 +
94 +.token.atrule,
95 +.token.attr-value,
96 +.token.keyword {
97 + color: deeppink;
98 +}
99 +
100 +.token.regex,
101 +.token.important {
102 + color: orange;
103 +}
104 +
105 +.token.important,
106 +.token.bold {
107 + font-weight: bold;
108 +}
109 +.token.italic {
110 + font-style: italic;
111 +}
112 +
113 +.token.entity {
114 + cursor: help;
115 +}
116 +
117 +.token.deleted {
118 + color: red;
119 +}
120 +
121 +/* Plugin styles: Diff Highlight */
122 +pre.diff-highlight.diff-highlight > code .token.deleted:not(.prefix),
123 +pre > code.diff-highlight.diff-highlight .token.deleted:not(.prefix) {
124 + background-color: rgba(255, 0, 0, .3);
125 + display: inline;
126 +}
127 +
128 +pre.diff-highlight.diff-highlight > code .token.inserted:not(.prefix),
129 +pre > code.diff-highlight.diff-highlight .token.inserted:not(.prefix) {
130 + background-color: rgba(0, 255, 128, .3);
131 + display: inline;
132 +}
133 +
134 +pre[class*="language-"].line-numbers {
135 + position: relative;
136 + padding-left: 3.8em;
137 + counter-reset: linenumber;
138 +}
139 +
140 +pre[class*="language-"].line-numbers > code {
141 + position: relative;
142 + white-space: inherit;
143 +}
144 +
145 +.line-numbers .line-numbers-rows {
146 + position: absolute;
147 + pointer-events: none;
148 + top: 0;
149 + font-size: 100%;
150 + left: -3.8em;
151 + width: 3em; /* works for line-numbers below 1000 lines */
152 + letter-spacing: -1px;
153 + border-right: 1px solid #999;
154 +
155 + -webkit-user-select: none;
156 + -moz-user-select: none;
157 + -ms-user-select: none;
158 + user-select: none;
159 +
160 +}
161 +
162 + .line-numbers-rows > span {
163 + display: block;
164 + counter-increment: linenumber;
165 + }
166 +
167 + .line-numbers-rows > span:before {
168 + content: counter(linenumber);
169 + color: #999;
170 + display: block;
171 + padding-right: 0.8em;
172 + text-align: right;
173 + }
174 +
175 +div.code-toolbar {
176 + position: relative;
177 +}
178 +
179 +div.code-toolbar > .toolbar {
180 + position: absolute;
181 + z-index: 10;
182 + top: .3em;
183 + right: .2em;
184 + transition: opacity 0.3s ease-in-out;
185 + opacity: 0;
186 +}
187 +
188 +div.code-toolbar:hover > .toolbar {
189 + opacity: 1;
190 +}
191 +
192 +/* Separate line b/c rules are thrown out if selector is invalid.
193 + IE11 and old Edge versions don't support :focus-within. */
194 +div.code-toolbar:focus-within > .toolbar {
195 + opacity: 1;
196 +}
197 +
198 +div.code-toolbar > .toolbar > .toolbar-item {
199 + display: inline-block;
200 +}
201 +
202 +div.code-toolbar > .toolbar > .toolbar-item > a {
203 + cursor: pointer;
204 +}
205 +
206 +div.code-toolbar > .toolbar > .toolbar-item > button {
207 + background: none;
208 + border: 0;
209 + color: inherit;
210 + font: inherit;
211 + line-height: normal;
212 + overflow: visible;
213 + padding: 0;
214 + -webkit-user-select: none; /* for button */
215 + -moz-user-select: none;
216 + -ms-user-select: none;
217 +}
218 +
219 +div.code-toolbar > .toolbar > .toolbar-item > a,
220 +div.code-toolbar > .toolbar > .toolbar-item > button,
221 +div.code-toolbar > .toolbar > .toolbar-item > span {
222 + color: #bbb;
223 + font-size: .8em;
224 + padding: 0 .5em;
225 + background: #f5f2f0;
226 + background: rgba(224, 224, 224, 0.2);
227 + box-shadow: 0 2px 0 0 rgba(0,0,0,0.2);
228 + border-radius: .5em;
229 +}
230 +
231 +div.code-toolbar > .toolbar > .toolbar-item > a:hover,
232 +div.code-toolbar > .toolbar > .toolbar-item > a:focus,
233 +div.code-toolbar > .toolbar > .toolbar-item > button:hover,
234 +div.code-toolbar > .toolbar > .toolbar-item > button:focus,
235 +div.code-toolbar > .toolbar > .toolbar-item > span:hover,
236 +div.code-toolbar > .toolbar > .toolbar-item > span:focus {
237 + color: inherit;
238 + text-decoration: none;
239 +}
240 +
241 +.token.punctuation.brace-hover,
242 +.token.punctuation.brace-selected {
243 + outline: solid 1px;
244 +}
245 +
246 +.rainbow-braces .token.punctuation.brace-level-1,
247 +.rainbow-braces .token.punctuation.brace-level-5,
248 +.rainbow-braces .token.punctuation.brace-level-9 {
249 + color: #E50;
250 + opacity: 1;
251 +}
252 +.rainbow-braces .token.punctuation.brace-level-2,
253 +.rainbow-braces .token.punctuation.brace-level-6,
254 +.rainbow-braces .token.punctuation.brace-level-10 {
255 + color: #0B3;
256 + opacity: 1;
257 +}
258 +.rainbow-braces .token.punctuation.brace-level-3,
259 +.rainbow-braces .token.punctuation.brace-level-7,
260 +.rainbow-braces .token.punctuation.brace-level-11 {
261 + color: #26F;
262 + opacity: 1;
263 +}
264 +.rainbow-braces .token.punctuation.brace-level-4,
265 +.rainbow-braces .token.punctuation.brace-level-8,
266 +.rainbow-braces .token.punctuation.brace-level-12 {
267 + color: #E0E;
268 + opacity: 1;
269 +}
270 +
1 +/* PrismJS 1.30.0
2 +https://prismjs.com/download#themes=prism-funky&languages=markup+css+clike+javascript+css-extras&plugins=line-numbers+toolbar+match-braces */
3 +/// <reference lib="WebWorker"/>
4 +
5 +var _self = (typeof window !== 'undefined')
6 + ? window // if in browser
7 + : (
8 + (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
9 + ? self // if in worker
10 + : {} // if in node js
11 + );
12 +
13 +/**
14 + * Prism: Lightweight, robust, elegant syntax highlighting
15 + *
16 + * @license MIT <https://opensource.org/licenses/MIT>
17 + * @author Lea Verou <https://lea.verou.me>
18 + * @namespace
19 + * @public
20 + */
21 +var Prism = (function (_self) {
22 +
23 + // Private helper vars
24 + var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
25 + var uniqueId = 0;
26 +
27 + // The grammar object for plaintext
28 + var plainTextGrammar = {};
29 +
30 +
31 + var _ = {
32 + /**
33 + * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
34 + * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
35 + * additional languages or plugins yourself.
36 + *
37 + * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
38 + *
39 + * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
40 + * empty Prism object into the global scope before loading the Prism script like this:
41 + *
42 + * ```js
43 + * window.Prism = window.Prism || {};
44 + * Prism.manual = true;
45 + * // add a new <script> to load Prism's script
46 + * ```
47 + *
48 + * @default false
49 + * @type {boolean}
50 + * @memberof Prism
51 + * @public
52 + */
53 + manual: _self.Prism && _self.Prism.manual,
54 + /**
55 + * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
56 + * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
57 + * own worker, you don't want it to do this.
58 + *
59 + * By setting this value to `true`, Prism will not add its own listeners to the worker.
60 + *
61 + * You obviously have to change this value before Prism executes. To do this, you can add an
62 + * empty Prism object into the global scope before loading the Prism script like this:
63 + *
64 + * ```js
65 + * window.Prism = window.Prism || {};
66 + * Prism.disableWorkerMessageHandler = true;
67 + * // Load Prism's script
68 + * ```
69 + *
70 + * @default false
71 + * @type {boolean}
72 + * @memberof Prism
73 + * @public
74 + */
75 + disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
76 +
77 + /**
78 + * A namespace for utility methods.
79 + *
80 + * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
81 + * change or disappear at any time.
82 + *
83 + * @namespace
84 + * @memberof Prism
85 + */
86 + util: {
87 + encode: function encode(tokens) {
88 + if (tokens instanceof Token) {
89 + return new Token(tokens.type, encode(tokens.content), tokens.alias);
90 + } else if (Array.isArray(tokens)) {
91 + return tokens.map(encode);
92 + } else {
93 + return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
94 + }
95 + },
96 +
97 + /**
98 + * Returns the name of the type of the given value.
99 + *
100 + * @param {any} o
101 + * @returns {string}
102 + * @example
103 + * type(null) === 'Null'
104 + * type(undefined) === 'Undefined'
105 + * type(123) === 'Number'
106 + * type('foo') === 'String'
107 + * type(true) === 'Boolean'
108 + * type([1, 2]) === 'Array'
109 + * type({}) === 'Object'
110 + * type(String) === 'Function'
111 + * type(/abc+/) === 'RegExp'
112 + */
113 + type: function (o) {
114 + return Object.prototype.toString.call(o).slice(8, -1);
115 + },
116 +
117 + /**
118 + * Returns a unique number for the given object. Later calls will still return the same number.
119 + *
120 + * @param {Object} obj
121 + * @returns {number}
122 + */
123 + objId: function (obj) {
124 + if (!obj['__id']) {
125 + Object.defineProperty(obj, '__id', { value: ++uniqueId });
126 + }
127 + return obj['__id'];
128 + },
129 +
130 + /**
131 + * Creates a deep clone of the given object.
132 + *
133 + * The main intended use of this function is to clone language definitions.
134 + *
135 + * @param {T} o
136 + * @param {Record<number, any>} [visited]
137 + * @returns {T}
138 + * @template T
139 + */
140 + clone: function deepClone(o, visited) {
141 + visited = visited || {};
142 +
143 + var clone; var id;
144 + switch (_.util.type(o)) {
145 + case 'Object':
146 + id = _.util.objId(o);
147 + if (visited[id]) {
148 + return visited[id];
149 + }
150 + clone = /** @type {Record<string, any>} */ ({});
151 + visited[id] = clone;
152 +
153 + for (var key in o) {
154 + if (o.hasOwnProperty(key)) {
155 + clone[key] = deepClone(o[key], visited);
156 + }
157 + }
158 +
159 + return /** @type {any} */ (clone);
160 +
161 + case 'Array':
162 + id = _.util.objId(o);
163 + if (visited[id]) {
164 + return visited[id];
165 + }
166 + clone = [];
167 + visited[id] = clone;
168 +
169 + (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
170 + clone[i] = deepClone(v, visited);
171 + });
172 +
173 + return /** @type {any} */ (clone);
174 +
175 + default:
176 + return o;
177 + }
178 + },
179 +
180 + /**
181 + * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
182 + *
183 + * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
184 + *
185 + * @param {Element} element
186 + * @returns {string}
187 + */
188 + getLanguage: function (element) {
189 + while (element) {
190 + var m = lang.exec(element.className);
191 + if (m) {
192 + return m[1].toLowerCase();
193 + }
194 + element = element.parentElement;
195 + }
196 + return 'none';
197 + },
198 +
199 + /**
200 + * Sets the Prism `language-xxxx` class of the given element.
201 + *
202 + * @param {Element} element
203 + * @param {string} language
204 + * @returns {void}
205 + */
206 + setLanguage: function (element, language) {
207 + // remove all `language-xxxx` classes
208 + // (this might leave behind a leading space)
209 + element.className = element.className.replace(RegExp(lang, 'gi'), '');
210 +
211 + // add the new `language-xxxx` class
212 + // (using `classList` will automatically clean up spaces for us)
213 + element.classList.add('language-' + language);
214 + },
215 +
216 + /**
217 + * Returns the script element that is currently executing.
218 + *
219 + * This does __not__ work for line script element.
220 + *
221 + * @returns {HTMLScriptElement | null}
222 + */
223 + currentScript: function () {
224 + if (typeof document === 'undefined') {
225 + return null;
226 + }
227 + if (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 1 < 2 /* hack to trip TS' flow analysis */) {
228 + return /** @type {any} */ (document.currentScript);
229 + }
230 +
231 + // IE11 workaround
232 + // we'll get the src of the current script by parsing IE11's error stack trace
233 + // this will not work for inline scripts
234 +
235 + try {
236 + throw new Error();
237 + } catch (err) {
238 + // Get file src url from stack. Specifically works with the format of stack traces in IE.
239 + // A stack will look like this:
240 + //
241 + // Error
242 + // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
243 + // at Global code (http://localhost/components/prism-core.js:606:1)
244 +
245 + var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
246 + if (src) {
247 + var scripts = document.getElementsByTagName('script');
248 + for (var i in scripts) {
249 + if (scripts[i].src == src) {
250 + return scripts[i];
251 + }
252 + }
253 + }
254 + return null;
255 + }
256 + },
257 +
258 + /**
259 + * Returns whether a given class is active for `element`.
260 + *
261 + * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
262 + * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
263 + * given class is just the given class with a `no-` prefix.
264 + *
265 + * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
266 + * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
267 + * ancestors have the given class or the negated version of it, then the default activation will be returned.
268 + *
269 + * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
270 + * version of it, the class is considered active.
271 + *
272 + * @param {Element} element
273 + * @param {string} className
274 + * @param {boolean} [defaultActivation=false]
275 + * @returns {boolean}
276 + */
277 + isActive: function (element, className, defaultActivation) {
278 + var no = 'no-' + className;
279 +
280 + while (element) {
281 + var classList = element.classList;
282 + if (classList.contains(className)) {
283 + return true;
284 + }
285 + if (classList.contains(no)) {
286 + return false;
287 + }
288 + element = element.parentElement;
289 + }
290 + return !!defaultActivation;
291 + }
292 + },
293 +
294 + /**
295 + * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
296 + *
297 + * @namespace
298 + * @memberof Prism
299 + * @public
300 + */
301 + languages: {
302 + /**
303 + * The grammar for plain, unformatted text.
304 + */
305 + plain: plainTextGrammar,
306 + plaintext: plainTextGrammar,
307 + text: plainTextGrammar,
308 + txt: plainTextGrammar,
309 +
310 + /**
311 + * Creates a deep copy of the language with the given id and appends the given tokens.
312 + *
313 + * If a token in `redef` also appears in the copied language, then the existing token in the copied language
314 + * will be overwritten at its original position.
315 + *
316 + * ## Best practices
317 + *
318 + * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
319 + * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
320 + * understand the language definition because, normally, the order of tokens matters in Prism grammars.
321 + *
322 + * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
323 + * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
324 + *
325 + * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
326 + * @param {Grammar} redef The new tokens to append.
327 + * @returns {Grammar} The new language created.
328 + * @public
329 + * @example
330 + * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
331 + * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
332 + * // at its original position
333 + * 'comment': { ... },
334 + * // CSS doesn't have a 'color' token, so this token will be appended
335 + * 'color': /\b(?:red|green|blue)\b/
336 + * });
337 + */
338 + extend: function (id, redef) {
339 + var lang = _.util.clone(_.languages[id]);
340 +
341 + for (var key in redef) {
342 + lang[key] = redef[key];
343 + }
344 +
345 + return lang;
346 + },
347 +
348 + /**
349 + * Inserts tokens _before_ another token in a language definition or any other grammar.
350 + *
351 + * ## Usage
352 + *
353 + * This helper method makes it easy to modify existing languages. For example, the CSS language definition
354 + * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
355 + * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
356 + * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
357 + * this:
358 + *
359 + * ```js
360 + * Prism.languages.markup.style = {
361 + * // token
362 + * };
363 + * ```
364 + *
365 + * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
366 + * before existing tokens. For the CSS example above, you would use it like this:
367 + *
368 + * ```js
369 + * Prism.languages.insertBefore('markup', 'cdata', {
370 + * 'style': {
371 + * // token
372 + * }
373 + * });
374 + * ```
375 + *
376 + * ## Special cases
377 + *
378 + * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
379 + * will be ignored.
380 + *
381 + * This behavior can be used to insert tokens after `before`:
382 + *
383 + * ```js
384 + * Prism.languages.insertBefore('markup', 'comment', {
385 + * 'comment': Prism.languages.markup.comment,
386 + * // tokens after 'comment'
387 + * });
388 + * ```
389 + *
390 + * ## Limitations
391 + *
392 + * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
393 + * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
394 + * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
395 + * deleting properties which is necessary to insert at arbitrary positions.
396 + *
397 + * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
398 + * Instead, it will create a new object and replace all references to the target object with the new one. This
399 + * can be done without temporarily deleting properties, so the iteration order is well-defined.
400 + *
401 + * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
402 + * you hold the target object in a variable, then the value of the variable will not change.
403 + *
404 + * ```js
405 + * var oldMarkup = Prism.languages.markup;
406 + * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
407 + *
408 + * assert(oldMarkup !== Prism.languages.markup);
409 + * assert(newMarkup === Prism.languages.markup);
410 + * ```
411 + *
412 + * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
413 + * object to be modified.
414 + * @param {string} before The key to insert before.
415 + * @param {Grammar} insert An object containing the key-value pairs to be inserted.
416 + * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
417 + * object to be modified.
418 + *
419 + * Defaults to `Prism.languages`.
420 + * @returns {Grammar} The new grammar object.
421 + * @public
422 + */
423 + insertBefore: function (inside, before, insert, root) {
424 + root = root || /** @type {any} */ (_.languages);
425 + var grammar = root[inside];
426 + /** @type {Grammar} */
427 + var ret = {};
428 +
429 + for (var token in grammar) {
430 + if (grammar.hasOwnProperty(token)) {
431 +
432 + if (token == before) {
433 + for (var newToken in insert) {
434 + if (insert.hasOwnProperty(newToken)) {
435 + ret[newToken] = insert[newToken];
436 + }
437 + }
438 + }
439 +
440 + // Do not insert token which also occur in insert. See #1525
441 + if (!insert.hasOwnProperty(token)) {
442 + ret[token] = grammar[token];
443 + }
444 + }
445 + }
446 +
447 + var old = root[inside];
448 + root[inside] = ret;
449 +
450 + // Update references in other language definitions
451 + _.languages.DFS(_.languages, function (key, value) {
452 + if (value === old && key != inside) {
453 + this[key] = ret;
454 + }
455 + });
456 +
457 + return ret;
458 + },
459 +
460 + // Traverse a language definition with Depth First Search
461 + DFS: function DFS(o, callback, type, visited) {
462 + visited = visited || {};
463 +
464 + var objId = _.util.objId;
465 +
466 + for (var i in o) {
467 + if (o.hasOwnProperty(i)) {
468 + callback.call(o, i, o[i], type || i);
469 +
470 + var property = o[i];
471 + var propertyType = _.util.type(property);
472 +
473 + if (propertyType === 'Object' && !visited[objId(property)]) {
474 + visited[objId(property)] = true;
475 + DFS(property, callback, null, visited);
476 + } else if (propertyType === 'Array' && !visited[objId(property)]) {
477 + visited[objId(property)] = true;
478 + DFS(property, callback, i, visited);
479 + }
480 + }
481 + }
482 + }
483 + },
484 +
485 + plugins: {},
486 +
487 + /**
488 + * This is the most high-level function in Prism’s API.
489 + * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
490 + * each one of them.
491 + *
492 + * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
493 + *
494 + * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
495 + * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
496 + * @memberof Prism
497 + * @public
498 + */
499 + highlightAll: function (async, callback) {
500 + _.highlightAllUnder(document, async, callback);
501 + },
502 +
503 + /**
504 + * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
505 + * {@link Prism.highlightElement} on each one of them.
506 + *
507 + * The following hooks will be run:
508 + * 1. `before-highlightall`
509 + * 2. `before-all-elements-highlight`
510 + * 3. All hooks of {@link Prism.highlightElement} for each element.
511 + *
512 + * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
513 + * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
514 + * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
515 + * @memberof Prism
516 + * @public
517 + */
518 + highlightAllUnder: function (container, async, callback) {
519 + var env = {
520 + callback: callback,
521 + container: container,
522 + selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
523 + };
524 +
525 + _.hooks.run('before-highlightall', env);
526 +
527 + env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
528 +
529 + _.hooks.run('before-all-elements-highlight', env);
530 +
531 + for (var i = 0, element; (element = env.elements[i++]);) {
532 + _.highlightElement(element, async === true, env.callback);
533 + }
534 + },
535 +
536 + /**
537 + * Highlights the code inside a single element.
538 + *
539 + * The following hooks will be run:
540 + * 1. `before-sanity-check`
541 + * 2. `before-highlight`
542 + * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
543 + * 4. `before-insert`
544 + * 5. `after-highlight`
545 + * 6. `complete`
546 + *
547 + * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
548 + * the element's language.
549 + *
550 + * @param {Element} element The element containing the code.
551 + * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
552 + * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
553 + * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
554 + * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
555 + *
556 + * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
557 + * asynchronous highlighting to work. You can build your own bundle on the
558 + * [Download page](https://prismjs.com/download.html).
559 + * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
560 + * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
561 + * @memberof Prism
562 + * @public
563 + */
564 + highlightElement: function (element, async, callback) {
565 + // Find language
566 + var language = _.util.getLanguage(element);
567 + var grammar = _.languages[language];
568 +
569 + // Set language on the element, if not present
570 + _.util.setLanguage(element, language);
571 +
572 + // Set language on the parent, for styling
573 + var parent = element.parentElement;
574 + if (parent && parent.nodeName.toLowerCase() === 'pre') {
575 + _.util.setLanguage(parent, language);
576 + }
577 +
578 + var code = element.textContent;
579 +
580 + var env = {
581 + element: element,
582 + language: language,
583 + grammar: grammar,
584 + code: code
585 + };
586 +
587 + function insertHighlightedCode(highlightedCode) {
588 + env.highlightedCode = highlightedCode;
589 +
590 + _.hooks.run('before-insert', env);
591 +
592 + env.element.innerHTML = env.highlightedCode;
593 +
594 + _.hooks.run('after-highlight', env);
595 + _.hooks.run('complete', env);
596 + callback && callback.call(env.element);
597 + }
598 +
599 + _.hooks.run('before-sanity-check', env);
600 +
601 + // plugins may change/add the parent/element
602 + parent = env.element.parentElement;
603 + if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
604 + parent.setAttribute('tabindex', '0');
605 + }
606 +
607 + if (!env.code) {
608 + _.hooks.run('complete', env);
609 + callback && callback.call(env.element);
610 + return;
611 + }
612 +
613 + _.hooks.run('before-highlight', env);
614 +
615 + if (!env.grammar) {
616 + insertHighlightedCode(_.util.encode(env.code));
617 + return;
618 + }
619 +
620 + if (async && _self.Worker) {
621 + var worker = new Worker(_.filename);
622 +
623 + worker.onmessage = function (evt) {
624 + insertHighlightedCode(evt.data);
625 + };
626 +
627 + worker.postMessage(JSON.stringify({
628 + language: env.language,
629 + code: env.code,
630 + immediateClose: true
631 + }));
632 + } else {
633 + insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
634 + }
635 + },
636 +
637 + /**
638 + * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
639 + * and the language definitions to use, and returns a string with the HTML produced.
640 + *
641 + * The following hooks will be run:
642 + * 1. `before-tokenize`
643 + * 2. `after-tokenize`
644 + * 3. `wrap`: On each {@link Token}.
645 + *
646 + * @param {string} text A string with the code to be highlighted.
647 + * @param {Grammar} grammar An object containing the tokens to use.
648 + *
649 + * Usually a language definition like `Prism.languages.markup`.
650 + * @param {string} language The name of the language definition passed to `grammar`.
651 + * @returns {string} The highlighted HTML.
652 + * @memberof Prism
653 + * @public
654 + * @example
655 + * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
656 + */
657 + highlight: function (text, grammar, language) {
658 + var env = {
659 + code: text,
660 + grammar: grammar,
661 + language: language
662 + };
663 + _.hooks.run('before-tokenize', env);
664 + if (!env.grammar) {
665 + throw new Error('The language "' + env.language + '" has no grammar.');
666 + }
667 + env.tokens = _.tokenize(env.code, env.grammar);
668 + _.hooks.run('after-tokenize', env);
669 + return Token.stringify(_.util.encode(env.tokens), env.language);
670 + },
671 +
672 + /**
673 + * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
674 + * and the language definitions to use, and returns an array with the tokenized code.
675 + *
676 + * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
677 + *
678 + * This method could be useful in other contexts as well, as a very crude parser.
679 + *
680 + * @param {string} text A string with the code to be highlighted.
681 + * @param {Grammar} grammar An object containing the tokens to use.
682 + *
683 + * Usually a language definition like `Prism.languages.markup`.
684 + * @returns {TokenStream} An array of strings and tokens, a token stream.
685 + * @memberof Prism
686 + * @public
687 + * @example
688 + * let code = `var foo = 0;`;
689 + * let tokens = Prism.tokenize(code, Prism.languages.javascript);
690 + * tokens.forEach(token => {
691 + * if (token instanceof Prism.Token && token.type === 'number') {
692 + * console.log(`Found numeric literal: ${token.content}`);
693 + * }
694 + * });
695 + */
696 + tokenize: function (text, grammar) {
697 + var rest = grammar.rest;
698 + if (rest) {
699 + for (var token in rest) {
700 + grammar[token] = rest[token];
701 + }
702 +
703 + delete grammar.rest;
704 + }
705 +
706 + var tokenList = new LinkedList();
707 + addAfter(tokenList, tokenList.head, text);
708 +
709 + matchGrammar(text, tokenList, grammar, tokenList.head, 0);
710 +
711 + return toArray(tokenList);
712 + },
713 +
714 + /**
715 + * @namespace
716 + * @memberof Prism
717 + * @public
718 + */
719 + hooks: {
720 + all: {},
721 +
722 + /**
723 + * Adds the given callback to the list of callbacks for the given hook.
724 + *
725 + * The callback will be invoked when the hook it is registered for is run.
726 + * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
727 + *
728 + * One callback function can be registered to multiple hooks and the same hook multiple times.
729 + *
730 + * @param {string} name The name of the hook.
731 + * @param {HookCallback} callback The callback function which is given environment variables.
732 + * @public
733 + */
734 + add: function (name, callback) {
735 + var hooks = _.hooks.all;
736 +
737 + hooks[name] = hooks[name] || [];
738 +
739 + hooks[name].push(callback);
740 + },
741 +
742 + /**
743 + * Runs a hook invoking all registered callbacks with the given environment variables.
744 + *
745 + * Callbacks will be invoked synchronously and in the order in which they were registered.
746 + *
747 + * @param {string} name The name of the hook.
748 + * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
749 + * @public
750 + */
751 + run: function (name, env) {
752 + var callbacks = _.hooks.all[name];
753 +
754 + if (!callbacks || !callbacks.length) {
755 + return;
756 + }
757 +
758 + for (var i = 0, callback; (callback = callbacks[i++]);) {
759 + callback(env);
760 + }
761 + }
762 + },
763 +
764 + Token: Token
765 + };
766 + _self.Prism = _;
767 +
768 +
769 + // Typescript note:
770 + // The following can be used to import the Token type in JSDoc:
771 + //
772 + // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
773 +
774 + /**
775 + * Creates a new token.
776 + *
777 + * @param {string} type See {@link Token#type type}
778 + * @param {string | TokenStream} content See {@link Token#content content}
779 + * @param {string|string[]} [alias] The alias(es) of the token.
780 + * @param {string} [matchedStr=""] A copy of the full string this token was created from.
781 + * @class
782 + * @global
783 + * @public
784 + */
785 + function Token(type, content, alias, matchedStr) {
786 + /**
787 + * The type of the token.
788 + *
789 + * This is usually the key of a pattern in a {@link Grammar}.
790 + *
791 + * @type {string}
792 + * @see GrammarToken
793 + * @public
794 + */
795 + this.type = type;
796 + /**
797 + * The strings or tokens contained by this token.
798 + *
799 + * This will be a token stream if the pattern matched also defined an `inside` grammar.
800 + *
801 + * @type {string | TokenStream}
802 + * @public
803 + */
804 + this.content = content;
805 + /**
806 + * The alias(es) of the token.
807 + *
808 + * @type {string|string[]}
809 + * @see GrammarToken
810 + * @public
811 + */
812 + this.alias = alias;
813 + // Copy of the full string this token was created from
814 + this.length = (matchedStr || '').length | 0;
815 + }
816 +
817 + /**
818 + * A token stream is an array of strings and {@link Token Token} objects.
819 + *
820 + * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
821 + * them.
822 + *
823 + * 1. No adjacent strings.
824 + * 2. No empty strings.
825 + *
826 + * The only exception here is the token stream that only contains the empty string and nothing else.
827 + *
828 + * @typedef {Array<string | Token>} TokenStream
829 + * @global
830 + * @public
831 + */
832 +
833 + /**
834 + * Converts the given token or token stream to an HTML representation.
835 + *
836 + * The following hooks will be run:
837 + * 1. `wrap`: On each {@link Token}.
838 + *
839 + * @param {string | Token | TokenStream} o The token or token stream to be converted.
840 + * @param {string} language The name of current language.
841 + * @returns {string} The HTML representation of the token or token stream.
842 + * @memberof Token
843 + * @static
844 + */
845 + Token.stringify = function stringify(o, language) {
846 + if (typeof o == 'string') {
847 + return o;
848 + }
849 + if (Array.isArray(o)) {
850 + var s = '';
851 + o.forEach(function (e) {
852 + s += stringify(e, language);
853 + });
854 + return s;
855 + }
856 +
857 + var env = {
858 + type: o.type,
859 + content: stringify(o.content, language),
860 + tag: 'span',
861 + classes: ['token', o.type],
862 + attributes: {},
863 + language: language
864 + };
865 +
866 + var aliases = o.alias;
867 + if (aliases) {
868 + if (Array.isArray(aliases)) {
869 + Array.prototype.push.apply(env.classes, aliases);
870 + } else {
871 + env.classes.push(aliases);
872 + }
873 + }
874 +
875 + _.hooks.run('wrap', env);
876 +
877 + var attributes = '';
878 + for (var name in env.attributes) {
879 + attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
880 + }
881 +
882 + return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
883 + };
884 +
885 + /**
886 + * @param {RegExp} pattern
887 + * @param {number} pos
888 + * @param {string} text
889 + * @param {boolean} lookbehind
890 + * @returns {RegExpExecArray | null}
891 + */
892 + function matchPattern(pattern, pos, text, lookbehind) {
893 + pattern.lastIndex = pos;
894 + var match = pattern.exec(text);
895 + if (match && lookbehind && match[1]) {
896 + // change the match to remove the text matched by the Prism lookbehind group
897 + var lookbehindLength = match[1].length;
898 + match.index += lookbehindLength;
899 + match[0] = match[0].slice(lookbehindLength);
900 + }
901 + return match;
902 + }
903 +
904 + /**
905 + * @param {string} text
906 + * @param {LinkedList<string | Token>} tokenList
907 + * @param {any} grammar
908 + * @param {LinkedListNode<string | Token>} startNode
909 + * @param {number} startPos
910 + * @param {RematchOptions} [rematch]
911 + * @returns {void}
912 + * @private
913 + *
914 + * @typedef RematchOptions
915 + * @property {string} cause
916 + * @property {number} reach
917 + */
918 + function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
919 + for (var token in grammar) {
920 + if (!grammar.hasOwnProperty(token) || !grammar[token]) {
921 + continue;
922 + }
923 +
924 + var patterns = grammar[token];
925 + patterns = Array.isArray(patterns) ? patterns : [patterns];
926 +
927 + for (var j = 0; j < patterns.length; ++j) {
928 + if (rematch && rematch.cause == token + ',' + j) {
929 + return;
930 + }
931 +
932 + var patternObj = patterns[j];
933 + var inside = patternObj.inside;
934 + var lookbehind = !!patternObj.lookbehind;
935 + var greedy = !!patternObj.greedy;
936 + var alias = patternObj.alias;
937 +
938 + if (greedy && !patternObj.pattern.global) {
939 + // Without the global flag, lastIndex won't work
940 + var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
941 + patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
942 + }
943 +
944 + /** @type {RegExp} */
945 + var pattern = patternObj.pattern || patternObj;
946 +
947 + for ( // iterate the token list and keep track of the current token/string position
948 + var currentNode = startNode.next, pos = startPos;
949 + currentNode !== tokenList.tail;
950 + pos += currentNode.value.length, currentNode = currentNode.next
951 + ) {
952 +
953 + if (rematch && pos >= rematch.reach) {
954 + break;
955 + }
956 +
957 + var str = currentNode.value;
958 +
959 + if (tokenList.length > text.length) {
960 + // Something went terribly wrong, ABORT, ABORT!
961 + return;
962 + }
963 +
964 + if (str instanceof Token) {
965 + continue;
966 + }
967 +
968 + var removeCount = 1; // this is the to parameter of removeBetween
969 + var match;
970 +
971 + if (greedy) {
972 + match = matchPattern(pattern, pos, text, lookbehind);
973 + if (!match || match.index >= text.length) {
974 + break;
975 + }
976 +
977 + var from = match.index;
978 + var to = match.index + match[0].length;
979 + var p = pos;
980 +
981 + // find the node that contains the match
982 + p += currentNode.value.length;
983 + while (from >= p) {
984 + currentNode = currentNode.next;
985 + p += currentNode.value.length;
986 + }
987 + // adjust pos (and p)
988 + p -= currentNode.value.length;
989 + pos = p;
990 +
991 + // the current node is a Token, then the match starts inside another Token, which is invalid
992 + if (currentNode.value instanceof Token) {
993 + continue;
994 + }
995 +
996 + // find the last node which is affected by this match
997 + for (
998 + var k = currentNode;
999 + k !== tokenList.tail && (p < to || typeof k.value === 'string');
1000 + k = k.next
1001 + ) {
1002 + removeCount++;
1003 + p += k.value.length;
1004 + }
1005 + removeCount--;
1006 +
1007 + // replace with the new match
1008 + str = text.slice(pos, p);
1009 + match.index -= pos;
1010 + } else {
1011 + match = matchPattern(pattern, 0, str, lookbehind);
1012 + if (!match) {
1013 + continue;
1014 + }
1015 + }
1016 +
1017 + // eslint-disable-next-line no-redeclare
1018 + var from = match.index;
1019 + var matchStr = match[0];
1020 + var before = str.slice(0, from);
1021 + var after = str.slice(from + matchStr.length);
1022 +
1023 + var reach = pos + str.length;
1024 + if (rematch && reach > rematch.reach) {
1025 + rematch.reach = reach;
1026 + }
1027 +
1028 + var removeFrom = currentNode.prev;
1029 +
1030 + if (before) {
1031 + removeFrom = addAfter(tokenList, removeFrom, before);
1032 + pos += before.length;
1033 + }
1034 +
1035 + removeRange(tokenList, removeFrom, removeCount);
1036 +
1037 + var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
1038 + currentNode = addAfter(tokenList, removeFrom, wrapped);
1039 +
1040 + if (after) {
1041 + addAfter(tokenList, currentNode, after);
1042 + }
1043 +
1044 + if (removeCount > 1) {
1045 + // at least one Token object was removed, so we have to do some rematching
1046 + // this can only happen if the current pattern is greedy
1047 +
1048 + /** @type {RematchOptions} */
1049 + var nestedRematch = {
1050 + cause: token + ',' + j,
1051 + reach: reach
1052 + };
1053 + matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
1054 +
1055 + // the reach might have been extended because of the rematching
1056 + if (rematch && nestedRematch.reach > rematch.reach) {
1057 + rematch.reach = nestedRematch.reach;
1058 + }
1059 + }
1060 + }
1061 + }
1062 + }
1063 + }
1064 +
1065 + /**
1066 + * @typedef LinkedListNode
1067 + * @property {T} value
1068 + * @property {LinkedListNode<T> | null} prev The previous node.
1069 + * @property {LinkedListNode<T> | null} next The next node.
1070 + * @template T
1071 + * @private
1072 + */
1073 +
1074 + /**
1075 + * @template T
1076 + * @private
1077 + */
1078 + function LinkedList() {
1079 + /** @type {LinkedListNode<T>} */
1080 + var head = { value: null, prev: null, next: null };
1081 + /** @type {LinkedListNode<T>} */
1082 + var tail = { value: null, prev: head, next: null };
1083 + head.next = tail;
1084 +
1085 + /** @type {LinkedListNode<T>} */
1086 + this.head = head;
1087 + /** @type {LinkedListNode<T>} */
1088 + this.tail = tail;
1089 + this.length = 0;
1090 + }
1091 +
1092 + /**
1093 + * Adds a new node with the given value to the list.
1094 + *
1095 + * @param {LinkedList<T>} list
1096 + * @param {LinkedListNode<T>} node
1097 + * @param {T} value
1098 + * @returns {LinkedListNode<T>} The added node.
1099 + * @template T
1100 + */
1101 + function addAfter(list, node, value) {
1102 + // assumes that node != list.tail && values.length >= 0
1103 + var next = node.next;
1104 +
1105 + var newNode = { value: value, prev: node, next: next };
1106 + node.next = newNode;
1107 + next.prev = newNode;
1108 + list.length++;
1109 +
1110 + return newNode;
1111 + }
1112 + /**
1113 + * Removes `count` nodes after the given node. The given node will not be removed.
1114 + *
1115 + * @param {LinkedList<T>} list
1116 + * @param {LinkedListNode<T>} node
1117 + * @param {number} count
1118 + * @template T
1119 + */
1120 + function removeRange(list, node, count) {
1121 + var next = node.next;
1122 + for (var i = 0; i < count && next !== list.tail; i++) {
1123 + next = next.next;
1124 + }
1125 + node.next = next;
1126 + next.prev = node;
1127 + list.length -= i;
1128 + }
1129 + /**
1130 + * @param {LinkedList<T>} list
1131 + * @returns {T[]}
1132 + * @template T
1133 + */
1134 + function toArray(list) {
1135 + var array = [];
1136 + var node = list.head.next;
1137 + while (node !== list.tail) {
1138 + array.push(node.value);
1139 + node = node.next;
1140 + }
1141 + return array;
1142 + }
1143 +
1144 +
1145 + if (!_self.document) {
1146 + if (!_self.addEventListener) {
1147 + // in Node.js
1148 + return _;
1149 + }
1150 +
1151 + if (!_.disableWorkerMessageHandler) {
1152 + // In worker
1153 + _self.addEventListener('message', function (evt) {
1154 + var message = JSON.parse(evt.data);
1155 + var lang = message.language;
1156 + var code = message.code;
1157 + var immediateClose = message.immediateClose;
1158 +
1159 + _self.postMessage(_.highlight(code, _.languages[lang], lang));
1160 + if (immediateClose) {
1161 + _self.close();
1162 + }
1163 + }, false);
1164 + }
1165 +
1166 + return _;
1167 + }
1168 +
1169 + // Get current script and highlight
1170 + var script = _.util.currentScript();
1171 +
1172 + if (script) {
1173 + _.filename = script.src;
1174 +
1175 + if (script.hasAttribute('data-manual')) {
1176 + _.manual = true;
1177 + }
1178 + }
1179 +
1180 + function highlightAutomaticallyCallback() {
1181 + if (!_.manual) {
1182 + _.highlightAll();
1183 + }
1184 + }
1185 +
1186 + if (!_.manual) {
1187 + // If the document state is "loading", then we'll use DOMContentLoaded.
1188 + // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
1189 + // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
1190 + // might take longer one animation frame to execute which can create a race condition where only some plugins have
1191 + // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
1192 + // See https://github.com/PrismJS/prism/issues/2102
1193 + var readyState = document.readyState;
1194 + if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
1195 + document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
1196 + } else {
1197 + if (window.requestAnimationFrame) {
1198 + window.requestAnimationFrame(highlightAutomaticallyCallback);
1199 + } else {
1200 + window.setTimeout(highlightAutomaticallyCallback, 16);
1201 + }
1202 + }
1203 + }
1204 +
1205 + return _;
1206 +
1207 +}(_self));
1208 +
1209 +if (typeof module !== 'undefined' && module.exports) {
1210 + module.exports = Prism;
1211 +}
1212 +
1213 +// hack for components to work correctly in node.js
1214 +if (typeof global !== 'undefined') {
1215 + global.Prism = Prism;
1216 +}
1217 +
1218 +// some additional documentation/types
1219 +
1220 +/**
1221 + * The expansion of a simple `RegExp` literal to support additional properties.
1222 + *
1223 + * @typedef GrammarToken
1224 + * @property {RegExp} pattern The regular expression of the token.
1225 + * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
1226 + * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
1227 + * @property {boolean} [greedy=false] Whether the token is greedy.
1228 + * @property {string|string[]} [alias] An optional alias or list of aliases.
1229 + * @property {Grammar} [inside] The nested grammar of this token.
1230 + *
1231 + * The `inside` grammar will be used to tokenize the text value of each token of this kind.
1232 + *
1233 + * This can be used to make nested and even recursive language definitions.
1234 + *
1235 + * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
1236 + * each another.
1237 + * @global
1238 + * @public
1239 + */
1240 +
1241 +/**
1242 + * @typedef Grammar
1243 + * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
1244 + * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
1245 + * @global
1246 + * @public
1247 + */
1248 +
1249 +/**
1250 + * A function which will invoked after an element was successfully highlighted.
1251 + *
1252 + * @callback HighlightCallback
1253 + * @param {Element} element The element successfully highlighted.
1254 + * @returns {void}
1255 + * @global
1256 + * @public
1257 + */
1258 +
1259 +/**
1260 + * @callback HookCallback
1261 + * @param {Object<string, any>} env The environment variables of the hook.
1262 + * @returns {void}
1263 + * @global
1264 + * @public
1265 + */
1266 +;
1267 +Prism.languages.markup = {
1268 + 'comment': {
1269 + pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
1270 + greedy: true
1271 + },
1272 + 'prolog': {
1273 + pattern: /<\?[\s\S]+?\?>/,
1274 + greedy: true
1275 + },
1276 + 'doctype': {
1277 + // https://www.w3.org/TR/xml/#NT-doctypedecl
1278 + pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
1279 + greedy: true,
1280 + inside: {
1281 + 'internal-subset': {
1282 + pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
1283 + lookbehind: true,
1284 + greedy: true,
1285 + inside: null // see below
1286 + },
1287 + 'string': {
1288 + pattern: /"[^"]*"|'[^']*'/,
1289 + greedy: true
1290 + },
1291 + 'punctuation': /^<!|>$|[[\]]/,
1292 + 'doctype-tag': /^DOCTYPE/i,
1293 + 'name': /[^\s<>'"]+/
1294 + }
1295 + },
1296 + 'cdata': {
1297 + pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1298 + greedy: true
1299 + },
1300 + 'tag': {
1301 + pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
1302 + greedy: true,
1303 + inside: {
1304 + 'tag': {
1305 + pattern: /^<\/?[^\s>\/]+/,
1306 + inside: {
1307 + 'punctuation': /^<\/?/,
1308 + 'namespace': /^[^\s>\/:]+:/
1309 + }
1310 + },
1311 + 'special-attr': [],
1312 + 'attr-value': {
1313 + pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
1314 + inside: {
1315 + 'punctuation': [
1316 + {
1317 + pattern: /^=/,
1318 + alias: 'attr-equals'
1319 + },
1320 + {
1321 + pattern: /^(\s*)["']|["']$/,
1322 + lookbehind: true
1323 + }
1324 + ]
1325 + }
1326 + },
1327 + 'punctuation': /\/?>/,
1328 + 'attr-name': {
1329 + pattern: /[^\s>\/]+/,
1330 + inside: {
1331 + 'namespace': /^[^\s>\/:]+:/
1332 + }
1333 + }
1334 +
1335 + }
1336 + },
1337 + 'entity': [
1338 + {
1339 + pattern: /&[\da-z]{1,8};/i,
1340 + alias: 'named-entity'
1341 + },
1342 + /&#x?[\da-f]{1,8};/i
1343 + ]
1344 +};
1345 +
1346 +Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
1347 + Prism.languages.markup['entity'];
1348 +Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
1349 +
1350 +// Plugin to make entity title show the real entity, idea by Roman Komarov
1351 +Prism.hooks.add('wrap', function (env) {
1352 +
1353 + if (env.type === 'entity') {
1354 + env.attributes['title'] = env.content.replace(/&/, '&');
1355 + }
1356 +});
1357 +
1358 +Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
1359 + /**
1360 + * Adds an inlined language to markup.
1361 + *
1362 + * An example of an inlined language is CSS with `<style>` tags.
1363 + *
1364 + * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
1365 + * case insensitive.
1366 + * @param {string} lang The language key.
1367 + * @example
1368 + * addInlined('style', 'css');
1369 + */
1370 + value: function addInlined(tagName, lang) {
1371 + var includedCdataInside = {};
1372 + includedCdataInside['language-' + lang] = {
1373 + pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
1374 + lookbehind: true,
1375 + inside: Prism.languages[lang]
1376 + };
1377 + includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
1378 +
1379 + var inside = {
1380 + 'included-cdata': {
1381 + pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
1382 + inside: includedCdataInside
1383 + }
1384 + };
1385 + inside['language-' + lang] = {
1386 + pattern: /[\s\S]+/,
1387 + inside: Prism.languages[lang]
1388 + };
1389 +
1390 + var def = {};
1391 + def[tagName] = {
1392 + pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
1393 + lookbehind: true,
1394 + greedy: true,
1395 + inside: inside
1396 + };
1397 +
1398 + Prism.languages.insertBefore('markup', 'cdata', def);
1399 + }
1400 +});
1401 +Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
1402 + /**
1403 + * Adds an pattern to highlight languages embedded in HTML attributes.
1404 + *
1405 + * An example of an inlined language is CSS with `style` attributes.
1406 + *
1407 + * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
1408 + * case insensitive.
1409 + * @param {string} lang The language key.
1410 + * @example
1411 + * addAttribute('style', 'css');
1412 + */
1413 + value: function (attrName, lang) {
1414 + Prism.languages.markup.tag.inside['special-attr'].push({
1415 + pattern: RegExp(
1416 + /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
1417 + 'i'
1418 + ),
1419 + lookbehind: true,
1420 + inside: {
1421 + 'attr-name': /^[^\s=]+/,
1422 + 'attr-value': {
1423 + pattern: /=[\s\S]+/,
1424 + inside: {
1425 + 'value': {
1426 + pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
1427 + lookbehind: true,
1428 + alias: [lang, 'language-' + lang],
1429 + inside: Prism.languages[lang]
1430 + },
1431 + 'punctuation': [
1432 + {
1433 + pattern: /^=/,
1434 + alias: 'attr-equals'
1435 + },
1436 + /"|'/
1437 + ]
1438 + }
1439 + }
1440 + }
1441 + });
1442 + }
1443 +});
1444 +
1445 +Prism.languages.html = Prism.languages.markup;
1446 +Prism.languages.mathml = Prism.languages.markup;
1447 +Prism.languages.svg = Prism.languages.markup;
1448 +
1449 +Prism.languages.xml = Prism.languages.extend('markup', {});
1450 +Prism.languages.ssml = Prism.languages.xml;
1451 +Prism.languages.atom = Prism.languages.xml;
1452 +Prism.languages.rss = Prism.languages.xml;
1453 +
1454 +(function (Prism) {
1455 +
1456 + var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
1457 +
1458 + Prism.languages.css = {
1459 + 'comment': /\/\*[\s\S]*?\*\//,
1460 + 'atrule': {
1461 + pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
1462 + inside: {
1463 + 'rule': /^@[\w-]+/,
1464 + 'selector-function-argument': {
1465 + pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
1466 + lookbehind: true,
1467 + alias: 'selector'
1468 + },
1469 + 'keyword': {
1470 + pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
1471 + lookbehind: true
1472 + }
1473 + // See rest below
1474 + }
1475 + },
1476 + 'url': {
1477 + // https://drafts.csswg.org/css-values-3/#urls
1478 + pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
1479 + greedy: true,
1480 + inside: {
1481 + 'function': /^url/i,
1482 + 'punctuation': /^\(|\)$/,
1483 + 'string': {
1484 + pattern: RegExp('^' + string.source + '$'),
1485 + alias: 'url'
1486 + }
1487 + }
1488 + },
1489 + 'selector': {
1490 + pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
1491 + lookbehind: true
1492 + },
1493 + 'string': {
1494 + pattern: string,
1495 + greedy: true
1496 + },
1497 + 'property': {
1498 + pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
1499 + lookbehind: true
1500 + },
1501 + 'important': /!important\b/i,
1502 + 'function': {
1503 + pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
1504 + lookbehind: true
1505 + },
1506 + 'punctuation': /[(){};:,]/
1507 + };
1508 +
1509 + Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
1510 +
1511 + var markup = Prism.languages.markup;
1512 + if (markup) {
1513 + markup.tag.addInlined('style', 'css');
1514 + markup.tag.addAttribute('style', 'css');
1515 + }
1516 +
1517 +}(Prism));
1518 +
1519 +Prism.languages.clike = {
1520 + 'comment': [
1521 + {
1522 + pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
1523 + lookbehind: true,
1524 + greedy: true
1525 + },
1526 + {
1527 + pattern: /(^|[^\\:])\/\/.*/,
1528 + lookbehind: true,
1529 + greedy: true
1530 + }
1531 + ],
1532 + 'string': {
1533 + pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
1534 + greedy: true
1535 + },
1536 + 'class-name': {
1537 + pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
1538 + lookbehind: true,
1539 + inside: {
1540 + 'punctuation': /[.\\]/
1541 + }
1542 + },
1543 + 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
1544 + 'boolean': /\b(?:false|true)\b/,
1545 + 'function': /\b\w+(?=\()/,
1546 + 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
1547 + 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
1548 + 'punctuation': /[{}[\];(),.:]/
1549 +};
1550 +
1551 +Prism.languages.javascript = Prism.languages.extend('clike', {
1552 + 'class-name': [
1553 + Prism.languages.clike['class-name'],
1554 + {
1555 + pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
1556 + lookbehind: true
1557 + }
1558 + ],
1559 + 'keyword': [
1560 + {
1561 + pattern: /((?:^|\})\s*)catch\b/,
1562 + lookbehind: true
1563 + },
1564 + {
1565 + 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/,
1566 + lookbehind: true
1567 + },
1568 + ],
1569 + // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
1570 + 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
1571 + 'number': {
1572 + pattern: RegExp(
1573 + /(^|[^\w$])/.source +
1574 + '(?:' +
1575 + (
1576 + // constant
1577 + /NaN|Infinity/.source +
1578 + '|' +
1579 + // binary integer
1580 + /0[bB][01]+(?:_[01]+)*n?/.source +
1581 + '|' +
1582 + // octal integer
1583 + /0[oO][0-7]+(?:_[0-7]+)*n?/.source +
1584 + '|' +
1585 + // hexadecimal integer
1586 + /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
1587 + '|' +
1588 + // decimal bigint
1589 + /\d+(?:_\d+)*n/.source +
1590 + '|' +
1591 + // decimal number (integer or float) but no bigint
1592 + /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
1593 + ) +
1594 + ')' +
1595 + /(?![\w$])/.source
1596 + ),
1597 + lookbehind: true
1598 + },
1599 + 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
1600 +});
1601 +
1602 +Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
1603 +
1604 +Prism.languages.insertBefore('javascript', 'keyword', {
1605 + 'regex': {
1606 + pattern: RegExp(
1607 + // lookbehind
1608 + // eslint-disable-next-line regexp/no-dupe-characters-character-class
1609 + /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
1610 + // Regex pattern:
1611 + // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
1612 + // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
1613 + // with the only syntax, so we have to define 2 different regex patterns.
1614 + /\//.source +
1615 + '(?:' +
1616 + /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
1617 + '|' +
1618 + // `v` flag syntax. This supports 3 levels of nested character classes.
1619 + /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
1620 + ')' +
1621 + // lookahead
1622 + /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
1623 + ),
1624 + lookbehind: true,
1625 + greedy: true,
1626 + inside: {
1627 + 'regex-source': {
1628 + pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
1629 + lookbehind: true,
1630 + alias: 'language-regex',
1631 + inside: Prism.languages.regex
1632 + },
1633 + 'regex-delimiter': /^\/|\/$/,
1634 + 'regex-flags': /^[a-z]+$/,
1635 + }
1636 + },
1637 + // This must be declared before keyword because we use "function" inside the look-forward
1638 + 'function-variable': {
1639 + 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*=>))/,
1640 + alias: 'function'
1641 + },
1642 + 'parameter': [
1643 + {
1644 + pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
1645 + lookbehind: true,
1646 + inside: Prism.languages.javascript
1647 + },
1648 + {
1649 + pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
1650 + lookbehind: true,
1651 + inside: Prism.languages.javascript
1652 + },
1653 + {
1654 + pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
1655 + lookbehind: true,
1656 + inside: Prism.languages.javascript
1657 + },
1658 + {
1659 + 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*\{)/,
1660 + lookbehind: true,
1661 + inside: Prism.languages.javascript
1662 + }
1663 + ],
1664 + 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
1665 +});
1666 +
1667 +Prism.languages.insertBefore('javascript', 'string', {
1668 + 'hashbang': {
1669 + pattern: /^#!.*/,
1670 + greedy: true,
1671 + alias: 'comment'
1672 + },
1673 + 'template-string': {
1674 + pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
1675 + greedy: true,
1676 + inside: {
1677 + 'template-punctuation': {
1678 + pattern: /^`|`$/,
1679 + alias: 'string'
1680 + },
1681 + 'interpolation': {
1682 + pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
1683 + lookbehind: true,
1684 + inside: {
1685 + 'interpolation-punctuation': {
1686 + pattern: /^\$\{|\}$/,
1687 + alias: 'punctuation'
1688 + },
1689 + rest: Prism.languages.javascript
1690 + }
1691 + },
1692 + 'string': /[\s\S]+/
1693 + }
1694 + },
1695 + 'string-property': {
1696 + pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
1697 + lookbehind: true,
1698 + greedy: true,
1699 + alias: 'property'
1700 + }
1701 +});
1702 +
1703 +Prism.languages.insertBefore('javascript', 'operator', {
1704 + 'literal-property': {
1705 + pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
1706 + lookbehind: true,
1707 + alias: 'property'
1708 + },
1709 +});
1710 +
1711 +if (Prism.languages.markup) {
1712 + Prism.languages.markup.tag.addInlined('script', 'javascript');
1713 +
1714 + // add attribute support for all DOM events.
1715 + // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
1716 + Prism.languages.markup.tag.addAttribute(
1717 + /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,
1718 + 'javascript'
1719 + );
1720 +}
1721 +
1722 +Prism.languages.js = Prism.languages.javascript;
1723 +
1724 +(function (Prism) {
1725 +
1726 + var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
1727 + var selectorInside;
1728 +
1729 + Prism.languages.css.selector = {
1730 + pattern: Prism.languages.css.selector.pattern,
1731 + lookbehind: true,
1732 + inside: selectorInside = {
1733 + 'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,
1734 + 'pseudo-class': /:[-\w]+/,
1735 + 'class': /\.[-\w]+/,
1736 + 'id': /#[-\w]+/,
1737 + 'attribute': {
1738 + pattern: RegExp('\\[(?:[^[\\]"\']|' + string.source + ')*\\]'),
1739 + greedy: true,
1740 + inside: {
1741 + 'punctuation': /^\[|\]$/,
1742 + 'case-sensitivity': {
1743 + pattern: /(\s)[si]$/i,
1744 + lookbehind: true,
1745 + alias: 'keyword'
1746 + },
1747 + 'namespace': {
1748 + pattern: /^(\s*)(?:(?!\s)[-*\w\xA0-\uFFFF])*\|(?!=)/,
1749 + lookbehind: true,
1750 + inside: {
1751 + 'punctuation': /\|$/
1752 + }
1753 + },
1754 + 'attr-name': {
1755 + pattern: /^(\s*)(?:(?!\s)[-\w\xA0-\uFFFF])+/,
1756 + lookbehind: true
1757 + },
1758 + 'attr-value': [
1759 + string,
1760 + {
1761 + pattern: /(=\s*)(?:(?!\s)[-\w\xA0-\uFFFF])+(?=\s*$)/,
1762 + lookbehind: true
1763 + }
1764 + ],
1765 + 'operator': /[|~*^$]?=/
1766 + }
1767 + },
1768 + 'n-th': [
1769 + {
1770 + pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,
1771 + lookbehind: true,
1772 + inside: {
1773 + 'number': /[\dn]+/,
1774 + 'operator': /[+-]/
1775 + }
1776 + },
1777 + {
1778 + pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i,
1779 + lookbehind: true
1780 + }
1781 + ],
1782 + 'combinator': />|\+|~|\|\|/,
1783 +
1784 + // the `tag` token has been existed and removed.
1785 + // because we can't find a perfect tokenize to match it.
1786 + // if you want to add it, please read https://github.com/PrismJS/prism/pull/2373 first.
1787 +
1788 + 'punctuation': /[(),]/,
1789 + }
1790 + };
1791 +
1792 + Prism.languages.css['atrule'].inside['selector-function-argument'].inside = selectorInside;
1793 +
1794 + Prism.languages.insertBefore('css', 'property', {
1795 + 'variable': {
1796 + pattern: /(^|[^-\w\xA0-\uFFFF])--(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*/i,
1797 + lookbehind: true
1798 + }
1799 + });
1800 +
1801 + var unit = {
1802 + pattern: /(\b\d+)(?:%|[a-z]+(?![\w-]))/,
1803 + lookbehind: true
1804 + };
1805 + // 123 -123 .123 -.123 12.3 -12.3
1806 + var number = {
1807 + pattern: /(^|[^\w.-])-?(?:\d+(?:\.\d+)?|\.\d+)/,
1808 + lookbehind: true
1809 + };
1810 +
1811 + Prism.languages.insertBefore('css', 'function', {
1812 + 'operator': {
1813 + pattern: /(\s)[+\-*\/](?=\s)/,
1814 + lookbehind: true
1815 + },
1816 + // CAREFUL!
1817 + // Previewers and Inline color use hexcode and color.
1818 + 'hexcode': {
1819 + pattern: /\B#[\da-f]{3,8}\b/i,
1820 + alias: 'color'
1821 + },
1822 + 'color': [
1823 + {
1824 + pattern: /(^|[^\w-])(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|RebeccaPurple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)(?![\w-])/i,
1825 + lookbehind: true
1826 + },
1827 + {
1828 + pattern: /\b(?:hsl|rgb)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:hsl|rgb)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,
1829 + inside: {
1830 + 'unit': unit,
1831 + 'number': number,
1832 + 'function': /[\w-]+(?=\()/,
1833 + 'punctuation': /[(),]/
1834 + }
1835 + }
1836 + ],
1837 + // it's important that there is no boundary assertion after the hex digits
1838 + 'entity': /\\[\da-f]{1,8}/i,
1839 + 'unit': unit,
1840 + 'number': number
1841 + });
1842 +
1843 +}(Prism));
1844 +
1845 +(function () {
1846 +
1847 + if (typeof Prism === 'undefined' || typeof document === 'undefined') {
1848 + return;
1849 + }
1850 +
1851 + /**
1852 + * Plugin name which is used as a class name for <pre> which is activating the plugin
1853 + *
1854 + * @type {string}
1855 + */
1856 + var PLUGIN_NAME = 'line-numbers';
1857 +
1858 + /**
1859 + * Regular expression used for determining line breaks
1860 + *
1861 + * @type {RegExp}
1862 + */
1863 + var NEW_LINE_EXP = /\n(?!$)/g;
1864 +
1865 +
1866 + /**
1867 + * Global exports
1868 + */
1869 + var config = Prism.plugins.lineNumbers = {
1870 + /**
1871 + * Get node for provided line number
1872 + *
1873 + * @param {Element} element pre element
1874 + * @param {number} number line number
1875 + * @returns {Element|undefined}
1876 + */
1877 + getLine: function (element, number) {
1878 + if (element.tagName !== 'PRE' || !element.classList.contains(PLUGIN_NAME)) {
1879 + return;
1880 + }
1881 +
1882 + var lineNumberRows = element.querySelector('.line-numbers-rows');
1883 + if (!lineNumberRows) {
1884 + return;
1885 + }
1886 + var lineNumberStart = parseInt(element.getAttribute('data-start'), 10) || 1;
1887 + var lineNumberEnd = lineNumberStart + (lineNumberRows.children.length - 1);
1888 +
1889 + if (number < lineNumberStart) {
1890 + number = lineNumberStart;
1891 + }
1892 + if (number > lineNumberEnd) {
1893 + number = lineNumberEnd;
1894 + }
1895 +
1896 + var lineIndex = number - lineNumberStart;
1897 +
1898 + return lineNumberRows.children[lineIndex];
1899 + },
1900 +
1901 + /**
1902 + * Resizes the line numbers of the given element.
1903 + *
1904 + * This function will not add line numbers. It will only resize existing ones.
1905 + *
1906 + * @param {HTMLElement} element A `<pre>` element with line numbers.
1907 + * @returns {void}
1908 + */
1909 + resize: function (element) {
1910 + resizeElements([element]);
1911 + },
1912 +
1913 + /**
1914 + * Whether the plugin can assume that the units font sizes and margins are not depended on the size of
1915 + * the current viewport.
1916 + *
1917 + * Setting this to `true` will allow the plugin to do certain optimizations for better performance.
1918 + *
1919 + * Set this to `false` if you use any of the following CSS units: `vh`, `vw`, `vmin`, `vmax`.
1920 + *
1921 + * @type {boolean}
1922 + */
1923 + assumeViewportIndependence: true
1924 + };
1925 +
1926 + /**
1927 + * Resizes the given elements.
1928 + *
1929 + * @param {HTMLElement[]} elements
1930 + */
1931 + function resizeElements(elements) {
1932 + elements = elements.filter(function (e) {
1933 + var codeStyles = getStyles(e);
1934 + var whiteSpace = codeStyles['white-space'];
1935 + return whiteSpace === 'pre-wrap' || whiteSpace === 'pre-line';
1936 + });
1937 +
1938 + if (elements.length == 0) {
1939 + return;
1940 + }
1941 +
1942 + var infos = elements.map(function (element) {
1943 + var codeElement = element.querySelector('code');
1944 + var lineNumbersWrapper = element.querySelector('.line-numbers-rows');
1945 + if (!codeElement || !lineNumbersWrapper) {
1946 + return undefined;
1947 + }
1948 +
1949 + /** @type {HTMLElement} */
1950 + var lineNumberSizer = element.querySelector('.line-numbers-sizer');
1951 + var codeLines = codeElement.textContent.split(NEW_LINE_EXP);
1952 +
1953 + if (!lineNumberSizer) {
1954 + lineNumberSizer = document.createElement('span');
1955 + lineNumberSizer.className = 'line-numbers-sizer';
1956 +
1957 + codeElement.appendChild(lineNumberSizer);
1958 + }
1959 +
1960 + lineNumberSizer.innerHTML = '0';
1961 + lineNumberSizer.style.display = 'block';
1962 +
1963 + var oneLinerHeight = lineNumberSizer.getBoundingClientRect().height;
1964 + lineNumberSizer.innerHTML = '';
1965 +
1966 + return {
1967 + element: element,
1968 + lines: codeLines,
1969 + lineHeights: [],
1970 + oneLinerHeight: oneLinerHeight,
1971 + sizer: lineNumberSizer,
1972 + };
1973 + }).filter(Boolean);
1974 +
1975 + infos.forEach(function (info) {
1976 + var lineNumberSizer = info.sizer;
1977 + var lines = info.lines;
1978 + var lineHeights = info.lineHeights;
1979 + var oneLinerHeight = info.oneLinerHeight;
1980 +
1981 + lineHeights[lines.length - 1] = undefined;
1982 + lines.forEach(function (line, index) {
1983 + if (line && line.length > 1) {
1984 + var e = lineNumberSizer.appendChild(document.createElement('span'));
1985 + e.style.display = 'block';
1986 + e.textContent = line;
1987 + } else {
1988 + lineHeights[index] = oneLinerHeight;
1989 + }
1990 + });
1991 + });
1992 +
1993 + infos.forEach(function (info) {
1994 + var lineNumberSizer = info.sizer;
1995 + var lineHeights = info.lineHeights;
1996 +
1997 + var childIndex = 0;
1998 + for (var i = 0; i < lineHeights.length; i++) {
1999 + if (lineHeights[i] === undefined) {
2000 + lineHeights[i] = lineNumberSizer.children[childIndex++].getBoundingClientRect().height;
2001 + }
2002 + }
2003 + });
2004 +
2005 + infos.forEach(function (info) {
2006 + var lineNumberSizer = info.sizer;
2007 + var wrapper = info.element.querySelector('.line-numbers-rows');
2008 +
2009 + lineNumberSizer.style.display = 'none';
2010 + lineNumberSizer.innerHTML = '';
2011 +
2012 + info.lineHeights.forEach(function (height, lineNumber) {
2013 + wrapper.children[lineNumber].style.height = height + 'px';
2014 + });
2015 + });
2016 + }
2017 +
2018 + /**
2019 + * Returns style declarations for the element
2020 + *
2021 + * @param {Element} element
2022 + */
2023 + function getStyles(element) {
2024 + if (!element) {
2025 + return null;
2026 + }
2027 +
2028 + return window.getComputedStyle ? getComputedStyle(element) : (element.currentStyle || null);
2029 + }
2030 +
2031 + var lastWidth = undefined;
2032 + window.addEventListener('resize', function () {
2033 + if (config.assumeViewportIndependence && lastWidth === window.innerWidth) {
2034 + return;
2035 + }
2036 + lastWidth = window.innerWidth;
2037 +
2038 + resizeElements(Array.prototype.slice.call(document.querySelectorAll('pre.' + PLUGIN_NAME)));
2039 + });
2040 +
2041 + Prism.hooks.add('complete', function (env) {
2042 + if (!env.code) {
2043 + return;
2044 + }
2045 +
2046 + var code = /** @type {Element} */ (env.element);
2047 + var pre = /** @type {HTMLElement} */ (code.parentNode);
2048 +
2049 + // works only for <code> wrapped inside <pre> (not inline)
2050 + if (!pre || !/pre/i.test(pre.nodeName)) {
2051 + return;
2052 + }
2053 +
2054 + // Abort if line numbers already exists
2055 + if (code.querySelector('.line-numbers-rows')) {
2056 + return;
2057 + }
2058 +
2059 + // only add line numbers if <code> or one of its ancestors has the `line-numbers` class
2060 + if (!Prism.util.isActive(code, PLUGIN_NAME)) {
2061 + return;
2062 + }
2063 +
2064 + // Remove the class 'line-numbers' from the <code>
2065 + code.classList.remove(PLUGIN_NAME);
2066 + // Add the class 'line-numbers' to the <pre>
2067 + pre.classList.add(PLUGIN_NAME);
2068 +
2069 + var match = env.code.match(NEW_LINE_EXP);
2070 + var linesNum = match ? match.length + 1 : 1;
2071 + var lineNumbersWrapper;
2072 +
2073 + var lines = new Array(linesNum + 1).join('<span></span>');
2074 +
2075 + lineNumbersWrapper = document.createElement('span');
2076 + lineNumbersWrapper.setAttribute('aria-hidden', 'true');
2077 + lineNumbersWrapper.className = 'line-numbers-rows';
2078 + lineNumbersWrapper.innerHTML = lines;
2079 +
2080 + if (pre.hasAttribute('data-start')) {
2081 + pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
2082 + }
2083 +
2084 + env.element.appendChild(lineNumbersWrapper);
2085 +
2086 + resizeElements([pre]);
2087 +
2088 + Prism.hooks.run('line-numbers', env);
2089 + });
2090 +
2091 + Prism.hooks.add('line-numbers', function (env) {
2092 + env.plugins = env.plugins || {};
2093 + env.plugins.lineNumbers = true;
2094 + });
2095 +
2096 +}());
2097 +
2098 +(function () {
2099 +
2100 + if (typeof Prism === 'undefined' || typeof document === 'undefined') {
2101 + return;
2102 + }
2103 +
2104 + var callbacks = [];
2105 + var map = {};
2106 + var noop = function () {};
2107 +
2108 + Prism.plugins.toolbar = {};
2109 +
2110 + /**
2111 + * @typedef ButtonOptions
2112 + * @property {string} text The text displayed.
2113 + * @property {string} [url] The URL of the link which will be created.
2114 + * @property {Function} [onClick] The event listener for the `click` event of the created button.
2115 + * @property {string} [className] The class attribute to include with element.
2116 + */
2117 +
2118 + /**
2119 + * Register a button callback with the toolbar.
2120 + *
2121 + * @param {string} key
2122 + * @param {ButtonOptions|Function} opts
2123 + */
2124 + var registerButton = Prism.plugins.toolbar.registerButton = function (key, opts) {
2125 + var callback;
2126 +
2127 + if (typeof opts === 'function') {
2128 + callback = opts;
2129 + } else {
2130 + callback = function (env) {
2131 + var element;
2132 +
2133 + if (typeof opts.onClick === 'function') {
2134 + element = document.createElement('button');
2135 + element.type = 'button';
2136 + element.addEventListener('click', function () {
2137 + opts.onClick.call(this, env);
2138 + });
2139 + } else if (typeof opts.url === 'string') {
2140 + element = document.createElement('a');
2141 + element.href = opts.url;
2142 + } else {
2143 + element = document.createElement('span');
2144 + }
2145 +
2146 + if (opts.className) {
2147 + element.classList.add(opts.className);
2148 + }
2149 +
2150 + element.textContent = opts.text;
2151 +
2152 + return element;
2153 + };
2154 + }
2155 +
2156 + if (key in map) {
2157 + console.warn('There is a button with the key "' + key + '" registered already.');
2158 + return;
2159 + }
2160 +
2161 + callbacks.push(map[key] = callback);
2162 + };
2163 +
2164 + /**
2165 + * Returns the callback order of the given element.
2166 + *
2167 + * @param {HTMLElement} element
2168 + * @returns {string[] | undefined}
2169 + */
2170 + function getOrder(element) {
2171 + while (element) {
2172 + var order = element.getAttribute('data-toolbar-order');
2173 + if (order != null) {
2174 + order = order.trim();
2175 + if (order.length) {
2176 + return order.split(/\s*,\s*/g);
2177 + } else {
2178 + return [];
2179 + }
2180 + }
2181 + element = element.parentElement;
2182 + }
2183 + }
2184 +
2185 + /**
2186 + * Post-highlight Prism hook callback.
2187 + *
2188 + * @param env
2189 + */
2190 + var hook = Prism.plugins.toolbar.hook = function (env) {
2191 + // Check if inline or actual code block (credit to line-numbers plugin)
2192 + var pre = env.element.parentNode;
2193 + if (!pre || !/pre/i.test(pre.nodeName)) {
2194 + return;
2195 + }
2196 +
2197 + // Autoloader rehighlights, so only do this once.
2198 + if (pre.parentNode.classList.contains('code-toolbar')) {
2199 + return;
2200 + }
2201 +
2202 + // Create wrapper for <pre> to prevent scrolling toolbar with content
2203 + var wrapper = document.createElement('div');
2204 + wrapper.classList.add('code-toolbar');
2205 + pre.parentNode.insertBefore(wrapper, pre);
2206 + wrapper.appendChild(pre);
2207 +
2208 + // Setup the toolbar
2209 + var toolbar = document.createElement('div');
2210 + toolbar.classList.add('toolbar');
2211 +
2212 + // order callbacks
2213 + var elementCallbacks = callbacks;
2214 + var order = getOrder(env.element);
2215 + if (order) {
2216 + elementCallbacks = order.map(function (key) {
2217 + return map[key] || noop;
2218 + });
2219 + }
2220 +
2221 + elementCallbacks.forEach(function (callback) {
2222 + var element = callback(env);
2223 +
2224 + if (!element) {
2225 + return;
2226 + }
2227 +
2228 + var item = document.createElement('div');
2229 + item.classList.add('toolbar-item');
2230 +
2231 + item.appendChild(element);
2232 + toolbar.appendChild(item);
2233 + });
2234 +
2235 + // Add our toolbar to the currently created wrapper of <pre> tag
2236 + wrapper.appendChild(toolbar);
2237 + };
2238 +
2239 + registerButton('label', function (env) {
2240 + var pre = env.element.parentNode;
2241 + if (!pre || !/pre/i.test(pre.nodeName)) {
2242 + return;
2243 + }
2244 +
2245 + if (!pre.hasAttribute('data-label')) {
2246 + return;
2247 + }
2248 +
2249 + var element; var template;
2250 + var text = pre.getAttribute('data-label');
2251 + try {
2252 + // Any normal text will blow up this selector.
2253 + template = document.querySelector('template#' + text);
2254 + } catch (e) { /* noop */ }
2255 +
2256 + if (template) {
2257 + element = template.content;
2258 + } else {
2259 + if (pre.hasAttribute('data-url')) {
2260 + element = document.createElement('a');
2261 + element.href = pre.getAttribute('data-url');
2262 + } else {
2263 + element = document.createElement('span');
2264 + }
2265 +
2266 + element.textContent = text;
2267 + }
2268 +
2269 + return element;
2270 + });
2271 +
2272 + /**
2273 + * Register the toolbar with Prism.
2274 + */
2275 + Prism.hooks.add('complete', hook);
2276 +}());
2277 +
2278 +(function () {
2279 +
2280 + if (typeof Prism === 'undefined' || typeof document === 'undefined') {
2281 + return;
2282 + }
2283 +
2284 + function mapClassName(name) {
2285 + var customClass = Prism.plugins.customClass;
2286 + if (customClass) {
2287 + return customClass.apply(name, 'none');
2288 + } else {
2289 + return name;
2290 + }
2291 + }
2292 +
2293 + var PARTNER = {
2294 + '(': ')',
2295 + '[': ']',
2296 + '{': '}',
2297 + };
2298 +
2299 + // The names for brace types.
2300 + // These names have two purposes: 1) they can be used for styling and 2) they are used to pair braces. Only braces
2301 + // of the same type are paired.
2302 + var NAMES = {
2303 + '(': 'brace-round',
2304 + '[': 'brace-square',
2305 + '{': 'brace-curly',
2306 + };
2307 +
2308 + // A map for brace aliases.
2309 + // This is useful for when some braces have a prefix/suffix as part of the punctuation token.
2310 + var BRACE_ALIAS_MAP = {
2311 + '${': '{', // JS template punctuation (e.g. `foo ${bar + 1}`)
2312 + };
2313 +
2314 + var LEVEL_WARP = 12;
2315 +
2316 + var pairIdCounter = 0;
2317 +
2318 + var BRACE_ID_PATTERN = /^(pair-\d+-)(close|open)$/;
2319 +
2320 + /**
2321 + * Returns the brace partner given one brace of a brace pair.
2322 + *
2323 + * @param {HTMLElement} brace
2324 + * @returns {HTMLElement}
2325 + */
2326 + function getPartnerBrace(brace) {
2327 + var match = BRACE_ID_PATTERN.exec(brace.id);
2328 + return document.querySelector('#' + match[1] + (match[2] == 'open' ? 'close' : 'open'));
2329 + }
2330 +
2331 + /**
2332 + * @this {HTMLElement}
2333 + */
2334 + function hoverBrace() {
2335 + if (!Prism.util.isActive(this, 'brace-hover', true)) {
2336 + return;
2337 + }
2338 +
2339 + [this, getPartnerBrace(this)].forEach(function (e) {
2340 + e.classList.add(mapClassName('brace-hover'));
2341 + });
2342 + }
2343 + /**
2344 + * @this {HTMLElement}
2345 + */
2346 + function leaveBrace() {
2347 + [this, getPartnerBrace(this)].forEach(function (e) {
2348 + e.classList.remove(mapClassName('brace-hover'));
2349 + });
2350 + }
2351 + /**
2352 + * @this {HTMLElement}
2353 + */
2354 + function clickBrace() {
2355 + if (!Prism.util.isActive(this, 'brace-select', true)) {
2356 + return;
2357 + }
2358 +
2359 + [this, getPartnerBrace(this)].forEach(function (e) {
2360 + e.classList.add(mapClassName('brace-selected'));
2361 + });
2362 + }
2363 +
2364 + Prism.hooks.add('complete', function (env) {
2365 +
2366 + /** @type {HTMLElement} */
2367 + var code = env.element;
2368 + var pre = code.parentElement;
2369 +
2370 + if (!pre || pre.tagName != 'PRE') {
2371 + return;
2372 + }
2373 +
2374 + // find the braces to match
2375 + /** @type {string[]} */
2376 + var toMatch = [];
2377 + if (Prism.util.isActive(code, 'match-braces')) {
2378 + toMatch.push('(', '[', '{');
2379 + }
2380 +
2381 + if (toMatch.length == 0) {
2382 + // nothing to match
2383 + return;
2384 + }
2385 +
2386 + if (!pre.__listenerAdded) {
2387 + // code blocks might be highlighted more than once
2388 + pre.addEventListener('mousedown', function removeBraceSelected() {
2389 + // the code element might have been replaced
2390 + var code = pre.querySelector('code');
2391 + var className = mapClassName('brace-selected');
2392 + Array.prototype.slice.call(code.querySelectorAll('.' + className)).forEach(function (e) {
2393 + e.classList.remove(className);
2394 + });
2395 + });
2396 + Object.defineProperty(pre, '__listenerAdded', { value: true });
2397 + }
2398 +
2399 + /** @type {HTMLSpanElement[]} */
2400 + var punctuation = Array.prototype.slice.call(
2401 + code.querySelectorAll('span.' + mapClassName('token') + '.' + mapClassName('punctuation'))
2402 + );
2403 +
2404 + /** @type {{ index: number, open: boolean, element: HTMLElement }[]} */
2405 + var allBraces = [];
2406 +
2407 + toMatch.forEach(function (open) {
2408 + var close = PARTNER[open];
2409 + var name = mapClassName(NAMES[open]);
2410 +
2411 + /** @type {[number, number][]} */
2412 + var pairs = [];
2413 + /** @type {number[]} */
2414 + var openStack = [];
2415 +
2416 + for (var i = 0; i < punctuation.length; i++) {
2417 + var element = punctuation[i];
2418 + if (element.childElementCount == 0) {
2419 + var text = element.textContent;
2420 + text = BRACE_ALIAS_MAP[text] || text;
2421 + if (text === open) {
2422 + allBraces.push({ index: i, open: true, element: element });
2423 + element.classList.add(name);
2424 + element.classList.add(mapClassName('brace-open'));
2425 + openStack.push(i);
2426 + } else if (text === close) {
2427 + allBraces.push({ index: i, open: false, element: element });
2428 + element.classList.add(name);
2429 + element.classList.add(mapClassName('brace-close'));
2430 + if (openStack.length) {
2431 + pairs.push([i, openStack.pop()]);
2432 + }
2433 + }
2434 + }
2435 + }
2436 +
2437 + pairs.forEach(function (pair) {
2438 + var pairId = 'pair-' + (pairIdCounter++) + '-';
2439 +
2440 + var opening = punctuation[pair[0]];
2441 + var closing = punctuation[pair[1]];
2442 +
2443 + opening.id = pairId + 'open';
2444 + closing.id = pairId + 'close';
2445 +
2446 + [opening, closing].forEach(function (e) {
2447 + e.addEventListener('mouseenter', hoverBrace);
2448 + e.addEventListener('mouseleave', leaveBrace);
2449 + e.addEventListener('click', clickBrace);
2450 + });
2451 + });
2452 + });
2453 +
2454 + var level = 0;
2455 + allBraces.sort(function (a, b) { return a.index - b.index; });
2456 + allBraces.forEach(function (brace) {
2457 + if (brace.open) {
2458 + brace.element.classList.add(mapClassName('brace-level-' + (level % LEVEL_WARP + 1)));
2459 + level++;
2460 + } else {
2461 + level = Math.max(0, level - 1);
2462 + brace.element.classList.add(mapClassName('brace-level-' + (level % LEVEL_WARP + 1)));
2463 + }
2464 + });
2465 + });
2466 +
2467 +}());
2468 +