Rev 1422 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
597 | daniel-mar | 1 | /** |
2 | * Copyright (c) Tiny Technologies, Inc. All rights reserved. |
||
3 | * Licensed under the LGPL or a commercial license. |
||
4 | * For LGPL see License.txt in the project root for license information. |
||
5 | * For commercial licenses see https://www.tiny.cloud/ |
||
6 | * |
||
1434 | daniel-mar | 7 | * Version: 5.10.9 (2023-11-15) |
597 | daniel-mar | 8 | */ |
9 | (function () { |
||
10 | 'use strict'; |
||
11 | |||
637 | daniel-mar | 12 | var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager'); |
597 | daniel-mar | 13 | |
14 | var noop = function () { |
||
15 | }; |
||
16 | var constant = function (value) { |
||
17 | return function () { |
||
18 | return value; |
||
19 | }; |
||
20 | }; |
||
637 | daniel-mar | 21 | var identity = function (x) { |
22 | return x; |
||
23 | }; |
||
597 | daniel-mar | 24 | var never = constant(false); |
25 | var always = constant(true); |
||
26 | |||
27 | var none = function () { |
||
28 | return NONE; |
||
29 | }; |
||
30 | var NONE = function () { |
||
31 | var call = function (thunk) { |
||
32 | return thunk(); |
||
33 | }; |
||
637 | daniel-mar | 34 | var id = identity; |
597 | daniel-mar | 35 | var me = { |
36 | fold: function (n, _s) { |
||
37 | return n(); |
||
38 | }, |
||
39 | isSome: never, |
||
40 | isNone: always, |
||
41 | getOr: id, |
||
42 | getOrThunk: call, |
||
43 | getOrDie: function (msg) { |
||
44 | throw new Error(msg || 'error: getOrDie called on none.'); |
||
45 | }, |
||
46 | getOrNull: constant(null), |
||
47 | getOrUndefined: constant(undefined), |
||
48 | or: id, |
||
49 | orThunk: call, |
||
50 | map: none, |
||
51 | each: noop, |
||
52 | bind: none, |
||
53 | exists: never, |
||
54 | forall: always, |
||
637 | daniel-mar | 55 | filter: function () { |
56 | return none(); |
||
57 | }, |
||
597 | daniel-mar | 58 | toArray: function () { |
59 | return []; |
||
60 | }, |
||
61 | toString: constant('none()') |
||
62 | }; |
||
63 | return me; |
||
64 | }(); |
||
65 | var some = function (a) { |
||
66 | var constant_a = constant(a); |
||
67 | var self = function () { |
||
68 | return me; |
||
69 | }; |
||
70 | var bind = function (f) { |
||
71 | return f(a); |
||
72 | }; |
||
73 | var me = { |
||
74 | fold: function (n, s) { |
||
75 | return s(a); |
||
76 | }, |
||
77 | isSome: always, |
||
78 | isNone: never, |
||
79 | getOr: constant_a, |
||
80 | getOrThunk: constant_a, |
||
81 | getOrDie: constant_a, |
||
82 | getOrNull: constant_a, |
||
83 | getOrUndefined: constant_a, |
||
84 | or: self, |
||
85 | orThunk: self, |
||
86 | map: function (f) { |
||
87 | return some(f(a)); |
||
88 | }, |
||
89 | each: function (f) { |
||
90 | f(a); |
||
91 | }, |
||
92 | bind: bind, |
||
93 | exists: bind, |
||
94 | forall: bind, |
||
95 | filter: function (f) { |
||
96 | return f(a) ? me : NONE; |
||
97 | }, |
||
98 | toArray: function () { |
||
99 | return [a]; |
||
100 | }, |
||
101 | toString: function () { |
||
102 | return 'some(' + a + ')'; |
||
103 | } |
||
104 | }; |
||
105 | return me; |
||
106 | }; |
||
107 | var from = function (value) { |
||
108 | return value === null || value === undefined ? NONE : some(value); |
||
109 | }; |
||
110 | var Optional = { |
||
111 | some: some, |
||
112 | none: none, |
||
113 | from: from |
||
114 | }; |
||
115 | |||
637 | daniel-mar | 116 | var get$1 = function (xs, i) { |
597 | daniel-mar | 117 | return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none(); |
118 | }; |
||
119 | var head = function (xs) { |
||
637 | daniel-mar | 120 | return get$1(xs, 0); |
597 | daniel-mar | 121 | }; |
122 | |||
637 | daniel-mar | 123 | var someIf = function (b, a) { |
124 | return b ? Optional.some(a) : Optional.none(); |
||
125 | }; |
||
126 | |||
597 | daniel-mar | 127 | var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils'); |
128 | |||
129 | var isCodeSample = function (elm) { |
||
130 | return elm && elm.nodeName === 'PRE' && elm.className.indexOf('language-') !== -1; |
||
131 | }; |
||
132 | var trimArg = function (predicateFn) { |
||
133 | return function (arg1, arg2) { |
||
134 | return predicateFn(arg2); |
||
135 | }; |
||
136 | }; |
||
137 | |||
138 | var Global = typeof window !== 'undefined' ? window : Function('return this;')(); |
||
139 | |||
637 | daniel-mar | 140 | var exports$1 = {}, module = { exports: exports$1 }, global = {}; |
597 | daniel-mar | 141 | (function (define, exports, module, require) { |
142 | var oldprism = window.Prism; |
||
143 | window.Prism = { manual: true }; |
||
679 | daniel-mar | 144 | (function (global, factory) { |
145 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.EphoxContactWrapper = factory()); |
||
146 | }(this, function () { |
||
147 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; |
||
148 | var prismCore = { exports: {} }; |
||
149 | (function (module) { |
||
150 | var _self = typeof window !== 'undefined' ? window : typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : {}; |
||
151 | var Prism = function (_self) { |
||
1021 | daniel-mar | 152 | var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i; |
679 | daniel-mar | 153 | var uniqueId = 0; |
154 | var plainTextGrammar = {}; |
||
155 | var _ = { |
||
156 | manual: _self.Prism && _self.Prism.manual, |
||
157 | disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, |
||
158 | util: { |
||
159 | encode: function encode(tokens) { |
||
160 | if (tokens instanceof Token) { |
||
161 | return new Token(tokens.type, encode(tokens.content), tokens.alias); |
||
162 | } else if (Array.isArray(tokens)) { |
||
163 | return tokens.map(encode); |
||
164 | } else { |
||
165 | return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' '); |
||
166 | } |
||
597 | daniel-mar | 167 | }, |
679 | daniel-mar | 168 | type: function (o) { |
169 | return Object.prototype.toString.call(o).slice(8, -1); |
||
597 | daniel-mar | 170 | }, |
679 | daniel-mar | 171 | objId: function (obj) { |
172 | if (!obj['__id']) { |
||
173 | Object.defineProperty(obj, '__id', { value: ++uniqueId }); |
||
174 | } |
||
175 | return obj['__id']; |
||
176 | }, |
||
177 | clone: function deepClone(o, visited) { |
||
178 | visited = visited || {}; |
||
179 | var clone; |
||
180 | var id; |
||
181 | switch (_.util.type(o)) { |
||
182 | case 'Object': |
||
183 | id = _.util.objId(o); |
||
184 | if (visited[id]) { |
||
185 | return visited[id]; |
||
186 | } |
||
187 | clone = {}; |
||
188 | visited[id] = clone; |
||
189 | for (var key in o) { |
||
190 | if (o.hasOwnProperty(key)) { |
||
191 | clone[key] = deepClone(o[key], visited); |
||
597 | daniel-mar | 192 | } |
193 | } |
||
679 | daniel-mar | 194 | return clone; |
195 | case 'Array': |
||
196 | id = _.util.objId(o); |
||
197 | if (visited[id]) { |
||
198 | return visited[id]; |
||
199 | } |
||
200 | clone = []; |
||
201 | visited[id] = clone; |
||
202 | o.forEach(function (v, i) { |
||
203 | clone[i] = deepClone(v, visited); |
||
204 | }); |
||
205 | return clone; |
||
206 | default: |
||
207 | return o; |
||
597 | daniel-mar | 208 | } |
209 | }, |
||
679 | daniel-mar | 210 | getLanguage: function (element) { |
1021 | daniel-mar | 211 | while (element) { |
212 | var m = lang.exec(element.className); |
||
213 | if (m) { |
||
214 | return m[1].toLowerCase(); |
||
215 | } |
||
679 | daniel-mar | 216 | element = element.parentElement; |
597 | daniel-mar | 217 | } |
679 | daniel-mar | 218 | return 'none'; |
597 | daniel-mar | 219 | }, |
1021 | daniel-mar | 220 | setLanguage: function (element, language) { |
221 | element.className = element.className.replace(RegExp(lang.source, 'gi'), ''); |
||
222 | element.classList.add('language-' + language); |
||
223 | }, |
||
679 | daniel-mar | 224 | currentScript: function () { |
225 | if (typeof document === 'undefined') { |
||
226 | return null; |
||
227 | } |
||
228 | if ('currentScript' in document && 1 < 2) { |
||
229 | return document.currentScript; |
||
230 | } |
||
231 | try { |
||
232 | throw new Error(); |
||
233 | } catch (err) { |
||
234 | var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1]; |
||
235 | if (src) { |
||
236 | var scripts = document.getElementsByTagName('script'); |
||
237 | for (var i in scripts) { |
||
238 | if (scripts[i].src == src) { |
||
239 | return scripts[i]; |
||
597 | daniel-mar | 240 | } |
241 | } |
||
242 | } |
||
679 | daniel-mar | 243 | return null; |
244 | } |
||
245 | }, |
||
246 | isActive: function (element, className, defaultActivation) { |
||
247 | var no = 'no-' + className; |
||
248 | while (element) { |
||
249 | var classList = element.classList; |
||
250 | if (classList.contains(className)) { |
||
251 | return true; |
||
597 | daniel-mar | 252 | } |
679 | daniel-mar | 253 | if (classList.contains(no)) { |
254 | return false; |
||
597 | daniel-mar | 255 | } |
679 | daniel-mar | 256 | element = element.parentElement; |
257 | } |
||
258 | return !!defaultActivation; |
||
259 | } |
||
260 | }, |
||
261 | languages: { |
||
262 | plain: plainTextGrammar, |
||
263 | plaintext: plainTextGrammar, |
||
264 | text: plainTextGrammar, |
||
265 | txt: plainTextGrammar, |
||
266 | extend: function (id, redef) { |
||
267 | var lang = _.util.clone(_.languages[id]); |
||
268 | for (var key in redef) { |
||
269 | lang[key] = redef[key]; |
||
270 | } |
||
271 | return lang; |
||
272 | }, |
||
273 | insertBefore: function (inside, before, insert, root) { |
||
274 | root = root || _.languages; |
||
275 | var grammar = root[inside]; |
||
276 | var ret = {}; |
||
277 | for (var token in grammar) { |
||
278 | if (grammar.hasOwnProperty(token)) { |
||
279 | if (token == before) { |
||
280 | for (var newToken in insert) { |
||
281 | if (insert.hasOwnProperty(newToken)) { |
||
282 | ret[newToken] = insert[newToken]; |
||
597 | daniel-mar | 283 | } |
679 | daniel-mar | 284 | } |
597 | daniel-mar | 285 | } |
679 | daniel-mar | 286 | if (!insert.hasOwnProperty(token)) { |
287 | ret[token] = grammar[token]; |
||
597 | daniel-mar | 288 | } |
289 | } |
||
290 | } |
||
679 | daniel-mar | 291 | var old = root[inside]; |
292 | root[inside] = ret; |
||
293 | _.languages.DFS(_.languages, function (key, value) { |
||
294 | if (value === old && key != inside) { |
||
295 | this[key] = ret; |
||
637 | daniel-mar | 296 | } |
679 | daniel-mar | 297 | }); |
298 | return ret; |
||
299 | }, |
||
300 | DFS: function DFS(o, callback, type, visited) { |
||
301 | visited = visited || {}; |
||
302 | var objId = _.util.objId; |
||
303 | for (var i in o) { |
||
304 | if (o.hasOwnProperty(i)) { |
||
305 | callback.call(o, i, o[i], type || i); |
||
306 | var property = o[i]; |
||
307 | var propertyType = _.util.type(property); |
||
308 | if (propertyType === 'Object' && !visited[objId(property)]) { |
||
309 | visited[objId(property)] = true; |
||
310 | DFS(property, callback, null, visited); |
||
311 | } else if (propertyType === 'Array' && !visited[objId(property)]) { |
||
312 | visited[objId(property)] = true; |
||
313 | DFS(property, callback, i, visited); |
||
637 | daniel-mar | 314 | } |
315 | } |
||
316 | } |
||
597 | daniel-mar | 317 | } |
679 | daniel-mar | 318 | }, |
319 | plugins: {}, |
||
320 | highlightAll: function (async, callback) { |
||
321 | _.highlightAllUnder(document, async, callback); |
||
322 | }, |
||
323 | highlightAllUnder: function (container, async, callback) { |
||
324 | var env = { |
||
325 | callback: callback, |
||
326 | container: container, |
||
327 | selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code' |
||
328 | }; |
||
329 | _.hooks.run('before-highlightall', env); |
||
330 | env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector)); |
||
331 | _.hooks.run('before-all-elements-highlight', env); |
||
332 | for (var i = 0, element; element = env.elements[i++];) { |
||
333 | _.highlightElement(element, async === true, env.callback); |
||
597 | daniel-mar | 334 | } |
679 | daniel-mar | 335 | }, |
336 | highlightElement: function (element, async, callback) { |
||
337 | var language = _.util.getLanguage(element); |
||
338 | var grammar = _.languages[language]; |
||
1021 | daniel-mar | 339 | _.util.setLanguage(element, language); |
679 | daniel-mar | 340 | var parent = element.parentElement; |
341 | if (parent && parent.nodeName.toLowerCase() === 'pre') { |
||
1021 | daniel-mar | 342 | _.util.setLanguage(parent, language); |
597 | daniel-mar | 343 | } |
679 | daniel-mar | 344 | var code = element.textContent; |
345 | var env = { |
||
346 | element: element, |
||
347 | language: language, |
||
348 | grammar: grammar, |
||
349 | code: code |
||
597 | daniel-mar | 350 | }; |
679 | daniel-mar | 351 | function insertHighlightedCode(highlightedCode) { |
352 | env.highlightedCode = highlightedCode; |
||
353 | _.hooks.run('before-insert', env); |
||
354 | env.element.innerHTML = env.highlightedCode; |
||
355 | _.hooks.run('after-highlight', env); |
||
356 | _.hooks.run('complete', env); |
||
357 | callback && callback.call(env.element); |
||
597 | daniel-mar | 358 | } |
679 | daniel-mar | 359 | _.hooks.run('before-sanity-check', env); |
360 | parent = env.element.parentElement; |
||
361 | if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) { |
||
362 | parent.setAttribute('tabindex', '0'); |
||
363 | } |
||
364 | if (!env.code) { |
||
365 | _.hooks.run('complete', env); |
||
366 | callback && callback.call(env.element); |
||
367 | return; |
||
368 | } |
||
369 | _.hooks.run('before-highlight', env); |
||
370 | if (!env.grammar) { |
||
371 | insertHighlightedCode(_.util.encode(env.code)); |
||
372 | return; |
||
373 | } |
||
374 | if (async && _self.Worker) { |
||
375 | var worker = new Worker(_.filename); |
||
376 | worker.onmessage = function (evt) { |
||
377 | insertHighlightedCode(evt.data); |
||
378 | }; |
||
379 | worker.postMessage(JSON.stringify({ |
||
380 | language: env.language, |
||
381 | code: env.code, |
||
382 | immediateClose: true |
||
383 | })); |
||
384 | } else { |
||
385 | insertHighlightedCode(_.highlight(env.code, env.grammar, env.language)); |
||
386 | } |
||
387 | }, |
||
388 | highlight: function (text, grammar, language) { |
||
389 | var env = { |
||
390 | code: text, |
||
391 | grammar: grammar, |
||
392 | language: language |
||
597 | daniel-mar | 393 | }; |
679 | daniel-mar | 394 | _.hooks.run('before-tokenize', env); |
1021 | daniel-mar | 395 | if (!env.grammar) { |
396 | throw new Error('The language "' + env.language + '" has no grammar.'); |
||
397 | } |
||
679 | daniel-mar | 398 | env.tokens = _.tokenize(env.code, env.grammar); |
399 | _.hooks.run('after-tokenize', env); |
||
400 | return Token.stringify(_.util.encode(env.tokens), env.language); |
||
401 | }, |
||
402 | tokenize: function (text, grammar) { |
||
403 | var rest = grammar.rest; |
||
404 | if (rest) { |
||
405 | for (var token in rest) { |
||
406 | grammar[token] = rest[token]; |
||
597 | daniel-mar | 407 | } |
679 | daniel-mar | 408 | delete grammar.rest; |
409 | } |
||
410 | var tokenList = new LinkedList(); |
||
411 | addAfter(tokenList, tokenList.head, text); |
||
412 | matchGrammar(text, tokenList, grammar, tokenList.head, 0); |
||
413 | return toArray(tokenList); |
||
414 | }, |
||
415 | hooks: { |
||
416 | all: {}, |
||
417 | add: function (name, callback) { |
||
418 | var hooks = _.hooks.all; |
||
419 | hooks[name] = hooks[name] || []; |
||
420 | hooks[name].push(callback); |
||
421 | }, |
||
422 | run: function (name, env) { |
||
423 | var callbacks = _.hooks.all[name]; |
||
424 | if (!callbacks || !callbacks.length) { |
||
425 | return; |
||
426 | } |
||
427 | for (var i = 0, callback; callback = callbacks[i++];) { |
||
428 | callback(env); |
||
429 | } |
||
430 | } |
||
431 | }, |
||
432 | Token: Token |
||
433 | }; |
||
434 | _self.Prism = _; |
||
435 | function Token(type, content, alias, matchedStr) { |
||
436 | this.type = type; |
||
437 | this.content = content; |
||
438 | this.alias = alias; |
||
439 | this.length = (matchedStr || '').length | 0; |
||
440 | } |
||
441 | Token.stringify = function stringify(o, language) { |
||
442 | if (typeof o == 'string') { |
||
443 | return o; |
||
444 | } |
||
445 | if (Array.isArray(o)) { |
||
446 | var s = ''; |
||
447 | o.forEach(function (e) { |
||
448 | s += stringify(e, language); |
||
597 | daniel-mar | 449 | }); |
679 | daniel-mar | 450 | return s; |
451 | } |
||
452 | var env = { |
||
453 | type: o.type, |
||
454 | content: stringify(o.content, language), |
||
455 | tag: 'span', |
||
456 | classes: [ |
||
457 | 'token', |
||
458 | o.type |
||
459 | ], |
||
460 | attributes: {}, |
||
461 | language: language |
||
462 | }; |
||
463 | var aliases = o.alias; |
||
464 | if (aliases) { |
||
465 | if (Array.isArray(aliases)) { |
||
466 | Array.prototype.push.apply(env.classes, aliases); |
||
467 | } else { |
||
468 | env.classes.push(aliases); |
||
469 | } |
||
470 | } |
||
471 | _.hooks.run('wrap', env); |
||
472 | var attributes = ''; |
||
473 | for (var name in env.attributes) { |
||
474 | attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; |
||
475 | } |
||
476 | return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>'; |
||
477 | }; |
||
478 | function matchPattern(pattern, pos, text, lookbehind) { |
||
479 | pattern.lastIndex = pos; |
||
480 | var match = pattern.exec(text); |
||
481 | if (match && lookbehind && match[1]) { |
||
482 | var lookbehindLength = match[1].length; |
||
483 | match.index += lookbehindLength; |
||
484 | match[0] = match[0].slice(lookbehindLength); |
||
485 | } |
||
486 | return match; |
||
487 | } |
||
488 | function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) { |
||
489 | for (var token in grammar) { |
||
490 | if (!grammar.hasOwnProperty(token) || !grammar[token]) { |
||
491 | continue; |
||
492 | } |
||
493 | var patterns = grammar[token]; |
||
494 | patterns = Array.isArray(patterns) ? patterns : [patterns]; |
||
495 | for (var j = 0; j < patterns.length; ++j) { |
||
496 | if (rematch && rematch.cause == token + ',' + j) { |
||
497 | return; |
||
597 | daniel-mar | 498 | } |
679 | daniel-mar | 499 | var patternObj = patterns[j]; |
500 | var inside = patternObj.inside; |
||
501 | var lookbehind = !!patternObj.lookbehind; |
||
502 | var greedy = !!patternObj.greedy; |
||
503 | var alias = patternObj.alias; |
||
504 | if (greedy && !patternObj.pattern.global) { |
||
505 | var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0]; |
||
506 | patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g'); |
||
507 | } |
||
508 | var pattern = patternObj.pattern || patternObj; |
||
509 | for (var currentNode = startNode.next, pos = startPos; currentNode !== tokenList.tail; pos += currentNode.value.length, currentNode = currentNode.next) { |
||
510 | if (rematch && pos >= rematch.reach) { |
||
511 | break; |
||
597 | daniel-mar | 512 | } |
679 | daniel-mar | 513 | var str = currentNode.value; |
514 | if (tokenList.length > text.length) { |
||
515 | return; |
||
597 | daniel-mar | 516 | } |
679 | daniel-mar | 517 | if (str instanceof Token) { |
518 | continue; |
||
519 | } |
||
520 | var removeCount = 1; |
||
521 | var match; |
||
522 | if (greedy) { |
||
523 | match = matchPattern(pattern, pos, text, lookbehind); |
||
1021 | daniel-mar | 524 | if (!match || match.index >= text.length) { |
679 | daniel-mar | 525 | break; |
597 | daniel-mar | 526 | } |
679 | daniel-mar | 527 | var from = match.index; |
528 | var to = match.index + match[0].length; |
||
529 | var p = pos; |
||
530 | p += currentNode.value.length; |
||
531 | while (from >= p) { |
||
532 | currentNode = currentNode.next; |
||
533 | p += currentNode.value.length; |
||
534 | } |
||
535 | p -= currentNode.value.length; |
||
536 | pos = p; |
||
537 | if (currentNode.value instanceof Token) { |
||
538 | continue; |
||
539 | } |
||
540 | for (var k = currentNode; k !== tokenList.tail && (p < to || typeof k.value === 'string'); k = k.next) { |
||
541 | removeCount++; |
||
542 | p += k.value.length; |
||
543 | } |
||
544 | removeCount--; |
||
545 | str = text.slice(pos, p); |
||
546 | match.index -= pos; |
||
547 | } else { |
||
548 | match = matchPattern(pattern, 0, str, lookbehind); |
||
549 | if (!match) { |
||
550 | continue; |
||
551 | } |
||
597 | daniel-mar | 552 | } |
679 | daniel-mar | 553 | var from = match.index; |
554 | var matchStr = match[0]; |
||
555 | var before = str.slice(0, from); |
||
556 | var after = str.slice(from + matchStr.length); |
||
557 | var reach = pos + str.length; |
||
558 | if (rematch && reach > rematch.reach) { |
||
559 | rematch.reach = reach; |
||
597 | daniel-mar | 560 | } |
679 | daniel-mar | 561 | var removeFrom = currentNode.prev; |
562 | if (before) { |
||
563 | removeFrom = addAfter(tokenList, removeFrom, before); |
||
564 | pos += before.length; |
||
597 | daniel-mar | 565 | } |
679 | daniel-mar | 566 | removeRange(tokenList, removeFrom, removeCount); |
567 | var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr); |
||
568 | currentNode = addAfter(tokenList, removeFrom, wrapped); |
||
569 | if (after) { |
||
570 | addAfter(tokenList, currentNode, after); |
||
597 | daniel-mar | 571 | } |
679 | daniel-mar | 572 | if (removeCount > 1) { |
573 | var nestedRematch = { |
||
574 | cause: token + ',' + j, |
||
575 | reach: reach |
||
576 | }; |
||
577 | matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch); |
||
578 | if (rematch && nestedRematch.reach > rematch.reach) { |
||
579 | rematch.reach = nestedRematch.reach; |
||
597 | daniel-mar | 580 | } |
581 | } |
||
679 | daniel-mar | 582 | } |
597 | daniel-mar | 583 | } |
679 | daniel-mar | 584 | } |
585 | } |
||
586 | function LinkedList() { |
||
587 | var head = { |
||
588 | value: null, |
||
589 | prev: null, |
||
590 | next: null |
||
591 | }; |
||
592 | var tail = { |
||
593 | value: null, |
||
594 | prev: head, |
||
595 | next: null |
||
596 | }; |
||
597 | head.next = tail; |
||
598 | this.head = head; |
||
599 | this.tail = tail; |
||
600 | this.length = 0; |
||
601 | } |
||
602 | function addAfter(list, node, value) { |
||
603 | var next = node.next; |
||
604 | var newNode = { |
||
605 | value: value, |
||
606 | prev: node, |
||
607 | next: next |
||
608 | }; |
||
609 | node.next = newNode; |
||
610 | next.prev = newNode; |
||
611 | list.length++; |
||
612 | return newNode; |
||
613 | } |
||
614 | function removeRange(list, node, count) { |
||
615 | var next = node.next; |
||
616 | for (var i = 0; i < count && next !== list.tail; i++) { |
||
617 | next = next.next; |
||
618 | } |
||
619 | node.next = next; |
||
620 | next.prev = node; |
||
621 | list.length -= i; |
||
622 | } |
||
623 | function toArray(list) { |
||
624 | var array = []; |
||
625 | var node = list.head.next; |
||
626 | while (node !== list.tail) { |
||
627 | array.push(node.value); |
||
628 | node = node.next; |
||
629 | } |
||
630 | return array; |
||
631 | } |
||
632 | if (!_self.document) { |
||
633 | if (!_self.addEventListener) { |
||
634 | return _; |
||
635 | } |
||
636 | if (!_.disableWorkerMessageHandler) { |
||
637 | _self.addEventListener('message', function (evt) { |
||
638 | var message = JSON.parse(evt.data); |
||
639 | var lang = message.language; |
||
640 | var code = message.code; |
||
641 | var immediateClose = message.immediateClose; |
||
642 | _self.postMessage(_.highlight(code, _.languages[lang], lang)); |
||
643 | if (immediateClose) { |
||
644 | _self.close(); |
||
645 | } |
||
646 | }, false); |
||
647 | } |
||
648 | return _; |
||
649 | } |
||
650 | var script = _.util.currentScript(); |
||
651 | if (script) { |
||
652 | _.filename = script.src; |
||
653 | if (script.hasAttribute('data-manual')) { |
||
654 | _.manual = true; |
||
655 | } |
||
656 | } |
||
657 | function highlightAutomaticallyCallback() { |
||
658 | if (!_.manual) { |
||
659 | _.highlightAll(); |
||
660 | } |
||
661 | } |
||
662 | if (!_.manual) { |
||
663 | var readyState = document.readyState; |
||
664 | if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) { |
||
665 | document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback); |
||
666 | } else { |
||
667 | if (window.requestAnimationFrame) { |
||
668 | window.requestAnimationFrame(highlightAutomaticallyCallback); |
||
669 | } else { |
||
670 | window.setTimeout(highlightAutomaticallyCallback, 16); |
||
671 | } |
||
672 | } |
||
673 | } |
||
674 | return _; |
||
675 | }(_self); |
||
676 | if (module.exports) { |
||
677 | module.exports = Prism; |
||
678 | } |
||
679 | if (typeof commonjsGlobal !== 'undefined') { |
||
680 | commonjsGlobal.Prism = Prism; |
||
681 | } |
||
682 | }(prismCore)); |
||
683 | Prism.languages.clike = { |
||
684 | 'comment': [ |
||
685 | { |
||
686 | pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, |
||
687 | lookbehind: true, |
||
688 | greedy: true |
||
597 | daniel-mar | 689 | }, |
679 | daniel-mar | 690 | { |
691 | pattern: /(^|[^\\:])\/\/.*/, |
||
692 | lookbehind: true, |
||
693 | greedy: true |
||
694 | } |
||
597 | daniel-mar | 695 | ], |
679 | daniel-mar | 696 | 'string': { |
697 | pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, |
||
698 | greedy: true |
||
699 | }, |
||
700 | 'class-name': { |
||
1021 | daniel-mar | 701 | pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i, |
679 | daniel-mar | 702 | lookbehind: true, |
703 | inside: { 'punctuation': /[.\\]/ } |
||
704 | }, |
||
1021 | daniel-mar | 705 | 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/, |
706 | 'boolean': /\b(?:false|true)\b/, |
||
679 | daniel-mar | 707 | 'function': /\b\w+(?=\()/, |
708 | 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, |
||
709 | 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/, |
||
710 | 'punctuation': /[{}[\];(),.:]/ |
||
711 | }; |
||
712 | (function (Prism) { |
||
713 | function getPlaceholder(language, index) { |
||
714 | return '___' + language.toUpperCase() + index + '___'; |
||
715 | } |
||
716 | Object.defineProperties(Prism.languages['markup-templating'] = {}, { |
||
717 | buildPlaceholders: { |
||
718 | value: function (env, language, placeholderPattern, replaceFilter) { |
||
719 | if (env.language !== language) { |
||
720 | return; |
||
721 | } |
||
722 | var tokenStack = env.tokenStack = []; |
||
723 | env.code = env.code.replace(placeholderPattern, function (match) { |
||
724 | if (typeof replaceFilter === 'function' && !replaceFilter(match)) { |
||
725 | return match; |
||
597 | daniel-mar | 726 | } |
679 | daniel-mar | 727 | var i = tokenStack.length; |
728 | var placeholder; |
||
729 | while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1) { |
||
730 | ++i; |
||
597 | daniel-mar | 731 | } |
679 | daniel-mar | 732 | tokenStack[i] = match; |
733 | return placeholder; |
||
597 | daniel-mar | 734 | }); |
679 | daniel-mar | 735 | env.grammar = Prism.languages.markup; |
597 | daniel-mar | 736 | } |
737 | }, |
||
679 | daniel-mar | 738 | tokenizePlaceholders: { |
739 | value: function (env, language) { |
||
740 | if (env.language !== language || !env.tokenStack) { |
||
741 | return; |
||
597 | daniel-mar | 742 | } |
679 | daniel-mar | 743 | env.grammar = Prism.languages[language]; |
744 | var j = 0; |
||
745 | var keys = Object.keys(env.tokenStack); |
||
746 | function walkTokens(tokens) { |
||
747 | for (var i = 0; i < tokens.length; i++) { |
||
748 | if (j >= keys.length) { |
||
749 | break; |
||
750 | } |
||
751 | var token = tokens[i]; |
||
752 | if (typeof token === 'string' || token.content && typeof token.content === 'string') { |
||
753 | var k = keys[j]; |
||
754 | var t = env.tokenStack[k]; |
||
755 | var s = typeof token === 'string' ? token : token.content; |
||
756 | var placeholder = getPlaceholder(language, k); |
||
757 | var index = s.indexOf(placeholder); |
||
758 | if (index > -1) { |
||
759 | ++j; |
||
760 | var before = s.substring(0, index); |
||
761 | var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t); |
||
762 | var after = s.substring(index + placeholder.length); |
||
763 | var replacement = []; |
||
764 | if (before) { |
||
765 | replacement.push.apply(replacement, walkTokens([before])); |
||
597 | daniel-mar | 766 | } |
679 | daniel-mar | 767 | replacement.push(middle); |
768 | if (after) { |
||
769 | replacement.push.apply(replacement, walkTokens([after])); |
||
637 | daniel-mar | 770 | } |
679 | daniel-mar | 771 | if (typeof token === 'string') { |
772 | tokens.splice.apply(tokens, [ |
||
773 | i, |
||
774 | 1 |
||
775 | ].concat(replacement)); |
||
776 | } else { |
||
777 | token.content = replacement; |
||
597 | daniel-mar | 778 | } |
779 | } |
||
679 | daniel-mar | 780 | } else if (token.content) { |
781 | walkTokens(token.content); |
||
597 | daniel-mar | 782 | } |
783 | } |
||
679 | daniel-mar | 784 | return tokens; |
785 | } |
||
786 | walkTokens(env.tokens); |
||
787 | } |
||
788 | } |
||
789 | }); |
||
790 | }(Prism)); |
||
791 | Prism.languages.c = Prism.languages.extend('clike', { |
||
792 | 'comment': { |
||
793 | pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/, |
||
794 | greedy: true |
||
795 | }, |
||
1021 | daniel-mar | 796 | 'string': { |
797 | pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/, |
||
798 | greedy: true |
||
799 | }, |
||
679 | daniel-mar | 800 | 'class-name': { |
801 | pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/, |
||
802 | lookbehind: true |
||
803 | }, |
||
1021 | daniel-mar | 804 | 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/, |
679 | daniel-mar | 805 | 'function': /\b[a-z_]\w*(?=\s*\()/i, |
806 | 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i, |
||
807 | 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/ |
||
808 | }); |
||
809 | Prism.languages.insertBefore('c', 'string', { |
||
1021 | daniel-mar | 810 | 'char': { |
811 | pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/, |
||
812 | greedy: true |
||
813 | } |
||
814 | }); |
||
815 | Prism.languages.insertBefore('c', 'string', { |
||
679 | daniel-mar | 816 | 'macro': { |
817 | pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im, |
||
818 | lookbehind: true, |
||
819 | greedy: true, |
||
820 | alias: 'property', |
||
821 | inside: { |
||
822 | 'string': [ |
||
823 | { |
||
824 | pattern: /^(#\s*include\s*)<[^>]+>/, |
||
825 | lookbehind: true |
||
826 | }, |
||
827 | Prism.languages.c['string'] |
||
828 | ], |
||
1021 | daniel-mar | 829 | 'char': Prism.languages.c['char'], |
679 | daniel-mar | 830 | 'comment': Prism.languages.c['comment'], |
831 | 'macro-name': [ |
||
832 | { |
||
833 | pattern: /(^#\s*define\s+)\w+\b(?!\()/i, |
||
834 | lookbehind: true |
||
835 | }, |
||
836 | { |
||
837 | pattern: /(^#\s*define\s+)\w+\b(?=\()/i, |
||
838 | lookbehind: true, |
||
839 | alias: 'function' |
||
840 | } |
||
841 | ], |
||
842 | 'directive': { |
||
843 | pattern: /^(#\s*)[a-z]+/, |
||
844 | lookbehind: true, |
||
845 | alias: 'keyword' |
||
846 | }, |
||
847 | 'directive-hash': /^#/, |
||
848 | 'punctuation': /##|\\(?=[\r\n])/, |
||
849 | 'expression': { |
||
850 | pattern: /\S[\s\S]*/, |
||
851 | inside: Prism.languages.c |
||
852 | } |
||
853 | } |
||
1021 | daniel-mar | 854 | } |
679 | daniel-mar | 855 | }); |
1021 | daniel-mar | 856 | Prism.languages.insertBefore('c', 'function', { 'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/ }); |
679 | daniel-mar | 857 | delete Prism.languages.c['boolean']; |
858 | (function (Prism) { |
||
1021 | daniel-mar | 859 | var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_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|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/; |
679 | daniel-mar | 860 | var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { |
861 | return keyword.source; |
||
862 | }); |
||
863 | Prism.languages.cpp = Prism.languages.extend('c', { |
||
864 | 'class-name': [ |
||
865 | { |
||
866 | pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source.replace(/<keyword>/g, function () { |
||
867 | return keyword.source; |
||
868 | })), |
||
869 | lookbehind: true |
||
870 | }, |
||
871 | /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/, |
||
872 | /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i, |
||
873 | /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/ |
||
874 | ], |
||
875 | 'keyword': keyword, |
||
876 | 'number': { |
||
877 | pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i, |
||
878 | greedy: true |
||
597 | daniel-mar | 879 | }, |
679 | daniel-mar | 880 | 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/, |
1021 | daniel-mar | 881 | 'boolean': /\b(?:false|true)\b/ |
679 | daniel-mar | 882 | }); |
883 | Prism.languages.insertBefore('cpp', 'string', { |
||
884 | 'module': { |
||
1021 | daniel-mar | 885 | pattern: RegExp(/(\b(?:import|module)\s+)/.source + '(?:' + /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source + '|' + /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { |
679 | daniel-mar | 886 | return modName; |
887 | }) + ')'), |
||
888 | lookbehind: true, |
||
889 | greedy: true, |
||
890 | inside: { |
||
891 | 'string': /^[<"][\s\S]+/, |
||
892 | 'operator': /:/, |
||
893 | 'punctuation': /\./ |
||
894 | } |
||
895 | }, |
||
896 | 'raw-string': { |
||
897 | pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/, |
||
898 | alias: 'string', |
||
899 | greedy: true |
||
900 | } |
||
901 | }); |
||
902 | Prism.languages.insertBefore('cpp', 'keyword', { |
||
903 | 'generic-function': { |
||
904 | pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i, |
||
905 | inside: { |
||
906 | 'function': /^\w+/, |
||
907 | 'generic': { |
||
908 | pattern: /<[\s\S]+/, |
||
909 | alias: 'class-name', |
||
910 | inside: Prism.languages.cpp |
||
911 | } |
||
912 | } |
||
913 | } |
||
914 | }); |
||
915 | Prism.languages.insertBefore('cpp', 'operator', { |
||
916 | 'double-colon': { |
||
917 | pattern: /::/, |
||
918 | alias: 'punctuation' |
||
919 | } |
||
920 | }); |
||
921 | Prism.languages.insertBefore('cpp', 'class-name', { |
||
922 | 'base-clause': { |
||
923 | pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/, |
||
924 | lookbehind: true, |
||
925 | greedy: true, |
||
926 | inside: Prism.languages.extend('cpp', {}) |
||
927 | } |
||
928 | }); |
||
929 | Prism.languages.insertBefore('inside', 'double-colon', { 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i }, Prism.languages.cpp['base-clause']); |
||
930 | }(Prism)); |
||
931 | (function (Prism) { |
||
932 | function replace(pattern, replacements) { |
||
933 | return pattern.replace(/<<(\d+)>>/g, function (m, index) { |
||
934 | return '(?:' + replacements[+index] + ')'; |
||
935 | }); |
||
936 | } |
||
937 | function re(pattern, replacements, flags) { |
||
938 | return RegExp(replace(pattern, replacements), flags || ''); |
||
939 | } |
||
940 | function nested(pattern, depthLog2) { |
||
941 | for (var i = 0; i < depthLog2; i++) { |
||
942 | pattern = pattern.replace(/<<self>>/g, function () { |
||
943 | return '(?:' + pattern + ')'; |
||
944 | }); |
||
945 | } |
||
946 | return pattern.replace(/<<self>>/g, '[^\\s\\S]'); |
||
947 | } |
||
948 | var keywordKinds = { |
||
949 | type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void', |
||
950 | typeDeclaration: 'class enum interface record struct', |
||
951 | 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*{)', |
||
952 | 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' |
||
953 | }; |
||
954 | function keywordsToPattern(words) { |
||
955 | return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b'; |
||
956 | } |
||
957 | var typeDeclarationKeywords = keywordsToPattern(keywordKinds.typeDeclaration); |
||
958 | var keywords = RegExp(keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other)); |
||
959 | var nonTypeKeywords = keywordsToPattern(keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other); |
||
960 | var nonContextualKeywords = keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.other); |
||
961 | var generic = nested(/<(?:[^<>;=+\-*/%&|^]|<<self>>)*>/.source, 2); |
||
962 | var nestedRound = nested(/\((?:[^()]|<<self>>)*\)/.source, 2); |
||
963 | var name = /@?\b[A-Za-z_]\w*\b/.source; |
||
964 | var genericName = replace(/<<0>>(?:\s*<<1>>)?/.source, [ |
||
965 | name, |
||
966 | generic |
||
967 | ]); |
||
968 | var identifier = replace(/(?!<<0>>)<<1>>(?:\s*\.\s*<<1>>)*/.source, [ |
||
969 | nonTypeKeywords, |
||
970 | genericName |
||
971 | ]); |
||
972 | var array = /\[\s*(?:,\s*)*\]/.source; |
||
973 | var typeExpressionWithoutTuple = replace(/<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, [ |
||
974 | identifier, |
||
975 | array |
||
976 | ]); |
||
977 | var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [ |
||
978 | generic, |
||
979 | nestedRound, |
||
980 | array |
||
981 | ]); |
||
982 | var tuple = replace(/\(<<0>>+(?:,<<0>>+)+\)/.source, [tupleElement]); |
||
983 | var typeExpression = replace(/(?:<<0>>|<<1>>)(?:\s*(?:\?\s*)?<<2>>)*(?:\s*\?)?/.source, [ |
||
984 | tuple, |
||
985 | identifier, |
||
986 | array |
||
987 | ]); |
||
988 | var typeInside = { |
||
989 | 'keyword': keywords, |
||
990 | 'punctuation': /[<>()?,.:[\]]/ |
||
991 | }; |
||
992 | var character = /'(?:[^\r\n'\\]|\\.|\\[Uux][\da-fA-F]{1,8})'/.source; |
||
993 | var regularString = /"(?:\\.|[^\\"\r\n])*"/.source; |
||
994 | var verbatimString = /@"(?:""|\\[\s\S]|[^\\"])*"(?!")/.source; |
||
995 | Prism.languages.csharp = Prism.languages.extend('clike', { |
||
996 | 'string': [ |
||
997 | { |
||
998 | pattern: re(/(^|[^$\\])<<0>>/.source, [verbatimString]), |
||
999 | lookbehind: true, |
||
1000 | greedy: true |
||
1001 | }, |
||
1002 | { |
||
1003 | pattern: re(/(^|[^@$\\])<<0>>/.source, [regularString]), |
||
1004 | lookbehind: true, |
||
1005 | greedy: true |
||
1006 | } |
||
1007 | ], |
||
1008 | 'class-name': [ |
||
1009 | { |
||
1010 | pattern: re(/(\busing\s+static\s+)<<0>>(?=\s*;)/.source, [identifier]), |
||
1011 | lookbehind: true, |
||
1012 | inside: typeInside |
||
1013 | }, |
||
1014 | { |
||
1015 | pattern: re(/(\busing\s+<<0>>\s*=\s*)<<1>>(?=\s*;)/.source, [ |
||
1016 | name, |
||
1017 | typeExpression |
||
1018 | ]), |
||
1019 | lookbehind: true, |
||
1020 | inside: typeInside |
||
1021 | }, |
||
1022 | { |
||
1023 | pattern: re(/(\busing\s+)<<0>>(?=\s*=)/.source, [name]), |
||
1024 | lookbehind: true |
||
1025 | }, |
||
1026 | { |
||
1027 | pattern: re(/(\b<<0>>\s+)<<1>>/.source, [ |
||
1028 | typeDeclarationKeywords, |
||
1029 | genericName |
||
1030 | ]), |
||
1031 | lookbehind: true, |
||
1032 | inside: typeInside |
||
1033 | }, |
||
1034 | { |
||
1035 | pattern: re(/(\bcatch\s*\(\s*)<<0>>/.source, [identifier]), |
||
1036 | lookbehind: true, |
||
1037 | inside: typeInside |
||
1038 | }, |
||
1039 | { |
||
1040 | pattern: re(/(\bwhere\s+)<<0>>/.source, [name]), |
||
1041 | lookbehind: true |
||
1042 | }, |
||
1043 | { |
||
1044 | pattern: re(/(\b(?:is(?:\s+not)?|as)\s+)<<0>>/.source, [typeExpressionWithoutTuple]), |
||
1045 | lookbehind: true, |
||
1046 | inside: typeInside |
||
1047 | }, |
||
1048 | { |
||
1049 | pattern: re(/\b<<0>>(?=\s+(?!<<1>>|with\s*\{)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [ |
||
1050 | typeExpression, |
||
1051 | nonContextualKeywords, |
||
1052 | name |
||
1053 | ]), |
||
1054 | inside: typeInside |
||
1055 | } |
||
1056 | ], |
||
1057 | 'keyword': keywords, |
||
1021 | daniel-mar | 1058 | 'number': /(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:[dflmu]|lu|ul)?\b/i, |
679 | daniel-mar | 1059 | 'operator': />>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/, |
1060 | 'punctuation': /\?\.?|::|[{}[\];(),.:]/ |
||
1061 | }); |
||
1062 | Prism.languages.insertBefore('csharp', 'number', { |
||
1063 | 'range': { |
||
1064 | pattern: /\.\./, |
||
1065 | alias: 'operator' |
||
1066 | } |
||
1067 | }); |
||
1068 | Prism.languages.insertBefore('csharp', 'punctuation', { |
||
1069 | 'named-parameter': { |
||
1070 | pattern: re(/([(,]\s*)<<0>>(?=\s*:)/.source, [name]), |
||
1071 | lookbehind: true, |
||
1072 | alias: 'punctuation' |
||
1073 | } |
||
1074 | }); |
||
1075 | Prism.languages.insertBefore('csharp', 'class-name', { |
||
1076 | 'namespace': { |
||
1077 | pattern: re(/(\b(?:namespace|using)\s+)<<0>>(?:\s*\.\s*<<0>>)*(?=\s*[;{])/.source, [name]), |
||
1078 | lookbehind: true, |
||
1079 | inside: { 'punctuation': /\./ } |
||
1080 | }, |
||
1081 | 'type-expression': { |
||
1021 | daniel-mar | 1082 | pattern: re(/(\b(?:default|sizeof|typeof)\s*\(\s*(?!\s))(?:[^()\s]|\s(?!\s)|<<0>>)*(?=\s*\))/.source, [nestedRound]), |
679 | daniel-mar | 1083 | lookbehind: true, |
1084 | alias: 'class-name', |
||
1085 | inside: typeInside |
||
1086 | }, |
||
1087 | 'return-type': { |
||
1088 | pattern: re(/<<0>>(?=\s+(?:<<1>>\s*(?:=>|[({]|\.\s*this\s*\[)|this\s*\[))/.source, [ |
||
1089 | typeExpression, |
||
1090 | identifier |
||
1091 | ]), |
||
1092 | inside: typeInside, |
||
1093 | alias: 'class-name' |
||
1094 | }, |
||
1095 | 'constructor-invocation': { |
||
1096 | pattern: re(/(\bnew\s+)<<0>>(?=\s*[[({])/.source, [typeExpression]), |
||
1097 | lookbehind: true, |
||
1098 | inside: typeInside, |
||
1099 | alias: 'class-name' |
||
1100 | }, |
||
1101 | 'generic-method': { |
||
1102 | pattern: re(/<<0>>\s*<<1>>(?=\s*\()/.source, [ |
||
1103 | name, |
||
1104 | generic |
||
1105 | ]), |
||
1106 | inside: { |
||
1107 | 'function': re(/^<<0>>/.source, [name]), |
||
1108 | 'generic': { |
||
1109 | pattern: RegExp(generic), |
||
1110 | alias: 'class-name', |
||
1111 | inside: typeInside |
||
1112 | } |
||
1113 | } |
||
1114 | }, |
||
1115 | 'type-list': { |
||
1116 | pattern: re(/\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, [ |
||
1117 | typeDeclarationKeywords, |
||
1118 | genericName, |
||
1119 | name, |
||
1120 | typeExpression, |
||
1121 | keywords.source, |
||
1122 | nestedRound, |
||
1123 | /\bnew\s*\(\s*\)/.source |
||
1124 | ]), |
||
1125 | lookbehind: true, |
||
1126 | inside: { |
||
1127 | 'record-arguments': { |
||
1128 | pattern: re(/(^(?!new\s*\()<<0>>\s*)<<1>>/.source, [ |
||
1129 | genericName, |
||
1130 | nestedRound |
||
1131 | ]), |
||
1132 | lookbehind: true, |
||
597 | daniel-mar | 1133 | greedy: true, |
679 | daniel-mar | 1134 | inside: Prism.languages.csharp |
597 | daniel-mar | 1135 | }, |
679 | daniel-mar | 1136 | 'keyword': keywords, |
1137 | 'class-name': { |
||
1138 | pattern: RegExp(typeExpression), |
||
597 | daniel-mar | 1139 | greedy: true, |
679 | daniel-mar | 1140 | inside: typeInside |
597 | daniel-mar | 1141 | }, |
679 | daniel-mar | 1142 | 'punctuation': /[,()]/ |
1143 | } |
||
1144 | }, |
||
1145 | 'preprocessor': { |
||
1146 | pattern: /(^[\t ]*)#.*/m, |
||
1147 | lookbehind: true, |
||
1148 | alias: 'property', |
||
1149 | inside: { |
||
1150 | 'directive': { |
||
1151 | pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/, |
||
1152 | lookbehind: true, |
||
1153 | alias: 'keyword' |
||
597 | daniel-mar | 1154 | } |
679 | daniel-mar | 1155 | } |
1156 | } |
||
1157 | }); |
||
1158 | var regularStringOrCharacter = regularString + '|' + character; |
||
1159 | var regularStringCharacterOrComment = replace(/\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>/.source, [regularStringOrCharacter]); |
||
1160 | var roundExpression = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2); |
||
1161 | var attrTarget = /\b(?:assembly|event|field|method|module|param|property|return|type)\b/.source; |
||
1162 | var attr = replace(/<<0>>(?:\s*\(<<1>>*\))?/.source, [ |
||
1163 | identifier, |
||
1164 | roundExpression |
||
1165 | ]); |
||
1166 | Prism.languages.insertBefore('csharp', 'class-name', { |
||
1167 | 'attribute': { |
||
1168 | pattern: re(/((?:^|[^\s\w>)?])\s*\[\s*)(?:<<0>>\s*:\s*)?<<1>>(?:\s*,\s*<<1>>)*(?=\s*\])/.source, [ |
||
1169 | attrTarget, |
||
1170 | attr |
||
1171 | ]), |
||
1172 | lookbehind: true, |
||
1173 | greedy: true, |
||
1174 | inside: { |
||
1175 | 'target': { |
||
1176 | pattern: re(/^<<0>>(?=\s*:)/.source, [attrTarget]), |
||
1177 | alias: 'keyword' |
||
1178 | }, |
||
1179 | 'attribute-arguments': { |
||
1180 | pattern: re(/\(<<0>>*\)/.source, [roundExpression]), |
||
1181 | inside: Prism.languages.csharp |
||
1182 | }, |
||
1183 | 'class-name': { |
||
1184 | pattern: RegExp(identifier), |
||
1185 | inside: { 'punctuation': /\./ } |
||
1186 | }, |
||
1187 | 'punctuation': /[:,]/ |
||
1188 | } |
||
1189 | } |
||
1190 | }); |
||
1191 | var formatString = /:[^}\r\n]+/.source; |
||
1192 | var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2); |
||
1193 | var mInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [ |
||
1194 | mInterpolationRound, |
||
1195 | formatString |
||
1196 | ]); |
||
1197 | var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<<self>>*\)/.source, [regularStringOrCharacter]), 2); |
||
1198 | var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [ |
||
1199 | sInterpolationRound, |
||
1200 | formatString |
||
1201 | ]); |
||
1202 | function createInterpolationInside(interpolation, interpolationRound) { |
||
1203 | return { |
||
1204 | 'interpolation': { |
||
1205 | pattern: re(/((?:^|[^{])(?:\{\{)*)<<0>>/.source, [interpolation]), |
||
1206 | lookbehind: true, |
||
1207 | inside: { |
||
1208 | 'format-string': { |
||
1209 | pattern: re(/(^\{(?:(?![}:])<<0>>)*)<<1>>(?=\}$)/.source, [ |
||
1210 | interpolationRound, |
||
1211 | formatString |
||
1212 | ]), |
||
597 | daniel-mar | 1213 | lookbehind: true, |
679 | daniel-mar | 1214 | inside: { 'punctuation': /^:/ } |
1215 | }, |
||
1216 | 'punctuation': /^\{|\}$/, |
||
1217 | 'expression': { |
||
597 | daniel-mar | 1218 | pattern: /[\s\S]+/, |
679 | daniel-mar | 1219 | alias: 'language-csharp', |
1220 | inside: Prism.languages.csharp |
||
1221 | } |
||
597 | daniel-mar | 1222 | } |
679 | daniel-mar | 1223 | }, |
1224 | 'string': /[\s\S]+/ |
||
1225 | }; |
||
1226 | } |
||
1227 | Prism.languages.insertBefore('csharp', 'string', { |
||
1228 | 'interpolation-string': [ |
||
1229 | { |
||
1230 | pattern: re(/(^|[^\\])(?:\$@|@\$)"(?:""|\\[\s\S]|\{\{|<<0>>|[^\\{"])*"/.source, [mInterpolation]), |
||
1231 | lookbehind: true, |
||
1232 | greedy: true, |
||
1233 | inside: createInterpolationInside(mInterpolation, mInterpolationRound) |
||
1234 | }, |
||
1235 | { |
||
1236 | pattern: re(/(^|[^@\\])\$"(?:\\.|\{\{|<<0>>|[^\\"{])*"/.source, [sInterpolation]), |
||
1237 | lookbehind: true, |
||
1238 | greedy: true, |
||
1239 | inside: createInterpolationInside(sInterpolation, sInterpolationRound) |
||
1240 | } |
||
1021 | daniel-mar | 1241 | ], |
1242 | 'char': { |
||
1243 | pattern: RegExp(character), |
||
1244 | greedy: true |
||
1245 | } |
||
679 | daniel-mar | 1246 | }); |
1021 | daniel-mar | 1247 | Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp; |
679 | daniel-mar | 1248 | }(Prism)); |
1249 | (function (Prism) { |
||
1250 | var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/; |
||
1251 | Prism.languages.css = { |
||
1252 | 'comment': /\/\*[\s\S]*?\*\//, |
||
1253 | 'atrule': { |
||
1021 | daniel-mar | 1254 | pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source), |
679 | daniel-mar | 1255 | inside: { |
1256 | 'rule': /^@[\w-]+/, |
||
1257 | 'selector-function-argument': { |
||
1258 | pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/, |
||
1259 | lookbehind: true, |
||
1260 | alias: 'selector' |
||
1261 | }, |
||
1262 | 'keyword': { |
||
1263 | pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/, |
||
1264 | lookbehind: true |
||
637 | daniel-mar | 1265 | } |
679 | daniel-mar | 1266 | } |
597 | daniel-mar | 1267 | }, |
679 | daniel-mar | 1268 | 'url': { |
1269 | pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'), |
||
1270 | greedy: true, |
||
1271 | inside: { |
||
1272 | 'function': /^url/i, |
||
1273 | 'punctuation': /^\(|\)$/, |
||
1274 | 'string': { |
||
1275 | pattern: RegExp('^' + string.source + '$'), |
||
1276 | alias: 'url' |
||
1277 | } |
||
1278 | } |
||
1279 | }, |
||
1280 | 'selector': { |
||
1281 | pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'), |
||
1282 | lookbehind: true |
||
1283 | }, |
||
1284 | 'string': { |
||
1285 | pattern: string, |
||
1286 | greedy: true |
||
1287 | }, |
||
1288 | 'property': { |
||
1289 | pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i, |
||
1290 | lookbehind: true |
||
1291 | }, |
||
1292 | 'important': /!important\b/i, |
||
1293 | 'function': { |
||
1294 | pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i, |
||
1295 | lookbehind: true |
||
1296 | }, |
||
1297 | 'punctuation': /[(){};:,]/ |
||
1298 | }; |
||
1299 | Prism.languages.css['atrule'].inside.rest = Prism.languages.css; |
||
1300 | var markup = Prism.languages.markup; |
||
1301 | if (markup) { |
||
1302 | markup.tag.addInlined('style', 'css'); |
||
1303 | markup.tag.addAttribute('style', 'css'); |
||
1304 | } |
||
1305 | }(Prism)); |
||
1306 | (function (Prism) { |
||
1021 | daniel-mar | 1307 | 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(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/; |
1308 | var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source; |
||
679 | daniel-mar | 1309 | var className = { |
1021 | daniel-mar | 1310 | pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source), |
679 | daniel-mar | 1311 | lookbehind: true, |
1312 | inside: { |
||
1313 | 'namespace': { |
||
1314 | pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/, |
||
1315 | inside: { 'punctuation': /\./ } |
||
1316 | }, |
||
1317 | 'punctuation': /\./ |
||
1318 | } |
||
1319 | }; |
||
1320 | Prism.languages.java = Prism.languages.extend('clike', { |
||
1021 | daniel-mar | 1321 | 'string': { |
1322 | pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/, |
||
1323 | lookbehind: true, |
||
1324 | greedy: true |
||
1325 | }, |
||
679 | daniel-mar | 1326 | 'class-name': [ |
1327 | className, |
||
1328 | { |
||
1021 | daniel-mar | 1329 | pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source), |
679 | daniel-mar | 1330 | lookbehind: true, |
1331 | inside: className.inside |
||
1021 | daniel-mar | 1332 | }, |
1333 | { |
||
1334 | pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source), |
||
1335 | lookbehind: true, |
||
1336 | inside: className.inside |
||
679 | daniel-mar | 1337 | } |
1338 | ], |
||
1339 | 'keyword': keywords, |
||
1340 | 'function': [ |
||
1341 | Prism.languages.clike.function, |
||
1342 | { |
||
1343 | pattern: /(::\s*)[a-z_]\w*/, |
||
1344 | lookbehind: true |
||
1345 | } |
||
1346 | ], |
||
1347 | '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, |
||
1348 | 'operator': { |
||
1349 | pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m, |
||
1350 | lookbehind: true |
||
1021 | daniel-mar | 1351 | }, |
1352 | 'constant': /\b[A-Z][A-Z_\d]+\b/ |
||
679 | daniel-mar | 1353 | }); |
1354 | Prism.languages.insertBefore('java', 'string', { |
||
1355 | 'triple-quoted-string': { |
||
1356 | pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/, |
||
1357 | greedy: true, |
||
1358 | alias: 'string' |
||
1021 | daniel-mar | 1359 | }, |
1360 | 'char': { |
||
1361 | pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/, |
||
1362 | greedy: true |
||
679 | daniel-mar | 1363 | } |
1364 | }); |
||
1365 | Prism.languages.insertBefore('java', 'class-name', { |
||
1366 | 'annotation': { |
||
1367 | pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/, |
||
1368 | lookbehind: true, |
||
1369 | alias: 'punctuation' |
||
1370 | }, |
||
1371 | 'generics': { |
||
1372 | pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/, |
||
1373 | inside: { |
||
1374 | 'class-name': className, |
||
1375 | 'keyword': keywords, |
||
1376 | 'punctuation': /[<>(),.:]/, |
||
1377 | 'operator': /[?&|]/ |
||
1378 | } |
||
1379 | }, |
||
1021 | daniel-mar | 1380 | 'import': [ |
1381 | { |
||
1382 | pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source), |
||
1383 | lookbehind: true, |
||
1384 | inside: { |
||
1385 | 'namespace': className.inside.namespace, |
||
1386 | 'punctuation': /\./, |
||
1387 | 'operator': /\*/, |
||
1388 | 'class-name': /\w+/ |
||
1389 | } |
||
1390 | }, |
||
1391 | { |
||
1392 | pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source), |
||
1393 | lookbehind: true, |
||
1394 | alias: 'static', |
||
1395 | inside: { |
||
1396 | 'namespace': className.inside.namespace, |
||
1397 | 'static': /\b\w+$/, |
||
1398 | 'punctuation': /\./, |
||
1399 | 'operator': /\*/, |
||
1400 | 'class-name': /\w+/ |
||
1401 | } |
||
1402 | } |
||
1403 | ], |
||
679 | daniel-mar | 1404 | 'namespace': { |
1405 | pattern: RegExp(/(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/.source.replace(/<keyword>/g, function () { |
||
1406 | return keywords.source; |
||
1407 | })), |
||
1408 | lookbehind: true, |
||
1409 | inside: { 'punctuation': /\./ } |
||
1410 | } |
||
1411 | }); |
||
1412 | }(Prism)); |
||
1413 | Prism.languages.javascript = Prism.languages.extend('clike', { |
||
1414 | 'class-name': [ |
||
1415 | Prism.languages.clike['class-name'], |
||
1416 | { |
||
1021 | daniel-mar | 1417 | pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/, |
679 | daniel-mar | 1418 | lookbehind: true |
1419 | } |
||
597 | daniel-mar | 1420 | ], |
679 | daniel-mar | 1421 | 'keyword': [ |
1422 | { |
||
1423 | pattern: /((?:^|\})\s*)catch\b/, |
||
1424 | lookbehind: true |
||
1425 | }, |
||
1426 | { |
||
1427 | 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/, |
||
1428 | lookbehind: true |
||
1429 | } |
||
1430 | ], |
||
1431 | 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/, |
||
1021 | daniel-mar | 1432 | 'number': { |
1433 | pattern: RegExp(/(^|[^\w$])/.source + '(?:' + (/NaN|Infinity/.source + '|' + /0[bB][01]+(?:_[01]+)*n?/.source + '|' + /0[oO][0-7]+(?:_[0-7]+)*n?/.source + '|' + /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + '|' + /\d+(?:_\d+)*n/.source + '|' + /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ')' + /(?![\w$])/.source), |
||
1434 | lookbehind: true |
||
1435 | }, |
||
679 | daniel-mar | 1436 | 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/ |
1437 | }); |
||
1021 | daniel-mar | 1438 | Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/; |
679 | daniel-mar | 1439 | Prism.languages.insertBefore('javascript', 'keyword', { |
1440 | 'regex': { |
||
1021 | daniel-mar | 1441 | pattern: RegExp(/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + /\//.source + '(?:' + /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source + '|' + /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ')' + /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source), |
679 | daniel-mar | 1442 | lookbehind: true, |
1443 | greedy: true, |
||
1444 | inside: { |
||
1445 | 'regex-source': { |
||
1446 | pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/, |
||
1447 | lookbehind: true, |
||
1448 | alias: 'language-regex', |
||
1449 | inside: Prism.languages.regex |
||
1450 | }, |
||
1451 | 'regex-delimiter': /^\/|\/$/, |
||
1452 | 'regex-flags': /^[a-z]+$/ |
||
1453 | } |
||
1454 | }, |
||
1455 | 'function-variable': { |
||
1456 | 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*=>))/, |
||
1457 | alias: 'function' |
||
1458 | }, |
||
1459 | 'parameter': [ |
||
1460 | { |
||
1461 | pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/, |
||
1462 | lookbehind: true, |
||
1463 | inside: Prism.languages.javascript |
||
1464 | }, |
||
1465 | { |
||
1466 | pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i, |
||
1467 | lookbehind: true, |
||
1468 | inside: Prism.languages.javascript |
||
1469 | }, |
||
1470 | { |
||
1471 | pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/, |
||
1472 | lookbehind: true, |
||
1473 | inside: Prism.languages.javascript |
||
1474 | }, |
||
1475 | { |
||
1476 | 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*\{)/, |
||
1477 | lookbehind: true, |
||
1478 | inside: Prism.languages.javascript |
||
1479 | } |
||
1480 | ], |
||
1481 | 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/ |
||
1482 | }); |
||
1483 | Prism.languages.insertBefore('javascript', 'string', { |
||
1484 | 'hashbang': { |
||
1485 | pattern: /^#!.*/, |
||
1486 | greedy: true, |
||
1487 | alias: 'comment' |
||
1488 | }, |
||
1489 | 'template-string': { |
||
1490 | pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/, |
||
1491 | greedy: true, |
||
1492 | inside: { |
||
1493 | 'template-punctuation': { |
||
1494 | pattern: /^`|`$/, |
||
1495 | alias: 'string' |
||
1496 | }, |
||
1497 | 'interpolation': { |
||
1498 | pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/, |
||
1499 | lookbehind: true, |
||
1500 | inside: { |
||
1501 | 'interpolation-punctuation': { |
||
1502 | pattern: /^\$\{|\}$/, |
||
1503 | alias: 'punctuation' |
||
597 | daniel-mar | 1504 | }, |
679 | daniel-mar | 1505 | rest: Prism.languages.javascript |
1506 | } |
||
1507 | }, |
||
1508 | 'string': /[\s\S]+/ |
||
1509 | } |
||
1021 | daniel-mar | 1510 | }, |
1511 | 'string-property': { |
||
1512 | pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m, |
||
1513 | lookbehind: true, |
||
1514 | greedy: true, |
||
1515 | alias: 'property' |
||
679 | daniel-mar | 1516 | } |
1517 | }); |
||
1021 | daniel-mar | 1518 | Prism.languages.insertBefore('javascript', 'operator', { |
1519 | 'literal-property': { |
||
1520 | pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m, |
||
1521 | lookbehind: true, |
||
1522 | alias: 'property' |
||
1523 | } |
||
1524 | }); |
||
679 | daniel-mar | 1525 | if (Prism.languages.markup) { |
1526 | Prism.languages.markup.tag.addInlined('script', 'javascript'); |
||
1527 | Prism.languages.markup.tag.addAttribute(/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, 'javascript'); |
||
1528 | } |
||
1529 | Prism.languages.js = Prism.languages.javascript; |
||
1530 | Prism.languages.markup = { |
||
1531 | 'comment': { |
||
1532 | pattern: /<!--(?:(?!<!--)[\s\S])*?-->/, |
||
1533 | greedy: true |
||
1534 | }, |
||
1535 | 'prolog': { |
||
1536 | pattern: /<\?[\s\S]+?\?>/, |
||
1537 | greedy: true |
||
1538 | }, |
||
1539 | 'doctype': { |
||
1540 | pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i, |
||
1541 | greedy: true, |
||
1542 | inside: { |
||
1543 | 'internal-subset': { |
||
1544 | pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/, |
||
1545 | lookbehind: true, |
||
1546 | greedy: true, |
||
1547 | inside: null |
||
1548 | }, |
||
1549 | 'string': { |
||
1550 | pattern: /"[^"]*"|'[^']*'/, |
||
1551 | greedy: true |
||
1552 | }, |
||
1553 | 'punctuation': /^<!|>$|[[\]]/, |
||
1554 | 'doctype-tag': /^DOCTYPE/i, |
||
1555 | 'name': /[^\s<>'"]+/ |
||
1556 | } |
||
1557 | }, |
||
1558 | 'cdata': { |
||
1559 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i, |
||
1560 | greedy: true |
||
1561 | }, |
||
1562 | 'tag': { |
||
1563 | pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/, |
||
1564 | greedy: true, |
||
1565 | inside: { |
||
1566 | 'tag': { |
||
1567 | pattern: /^<\/?[^\s>\/]+/, |
||
1568 | inside: { |
||
1569 | 'punctuation': /^<\/?/, |
||
1570 | 'namespace': /^[^\s>\/:]+:/ |
||
1571 | } |
||
1572 | }, |
||
1573 | 'special-attr': [], |
||
1574 | 'attr-value': { |
||
1575 | pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/, |
||
1576 | inside: { |
||
1577 | 'punctuation': [ |
||
597 | daniel-mar | 1578 | { |
679 | daniel-mar | 1579 | pattern: /^=/, |
1580 | alias: 'attr-equals' |
||
597 | daniel-mar | 1581 | }, |
1021 | daniel-mar | 1582 | { |
1583 | pattern: /^(\s*)["']|["']$/, |
||
1584 | lookbehind: true |
||
1585 | } |
||
679 | daniel-mar | 1586 | ] |
1587 | } |
||
1588 | }, |
||
1589 | 'punctuation': /\/?>/, |
||
1590 | 'attr-name': { |
||
1591 | pattern: /[^\s>\/]+/, |
||
1592 | inside: { 'namespace': /^[^\s>\/:]+:/ } |
||
1593 | } |
||
1594 | } |
||
1595 | }, |
||
1596 | 'entity': [ |
||
1597 | { |
||
1598 | pattern: /&[\da-z]{1,8};/i, |
||
1599 | alias: 'named-entity' |
||
1600 | }, |
||
1601 | /&#x?[\da-f]{1,8};/i |
||
1602 | ] |
||
1603 | }; |
||
1604 | Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = Prism.languages.markup['entity']; |
||
1605 | Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup; |
||
1606 | Prism.hooks.add('wrap', function (env) { |
||
1607 | if (env.type === 'entity') { |
||
1608 | env.attributes['title'] = env.content.replace(/&/, '&'); |
||
1609 | } |
||
1610 | }); |
||
1611 | Object.defineProperty(Prism.languages.markup.tag, 'addInlined', { |
||
1612 | value: function addInlined(tagName, lang) { |
||
1613 | var includedCdataInside = {}; |
||
1614 | includedCdataInside['language-' + lang] = { |
||
1615 | pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i, |
||
1616 | lookbehind: true, |
||
1617 | inside: Prism.languages[lang] |
||
1618 | }; |
||
1619 | includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i; |
||
1620 | var inside = { |
||
1621 | 'included-cdata': { |
||
1622 | pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i, |
||
1623 | inside: includedCdataInside |
||
1624 | } |
||
1625 | }; |
||
1626 | inside['language-' + lang] = { |
||
1627 | pattern: /[\s\S]+/, |
||
1628 | inside: Prism.languages[lang] |
||
1629 | }; |
||
1630 | var def = {}; |
||
1631 | def[tagName] = { |
||
1632 | pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { |
||
1633 | return tagName; |
||
1634 | }), 'i'), |
||
1635 | lookbehind: true, |
||
1636 | greedy: true, |
||
1637 | inside: inside |
||
1638 | }; |
||
1639 | Prism.languages.insertBefore('markup', 'cdata', def); |
||
1640 | } |
||
1641 | }); |
||
1642 | Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', { |
||
1643 | value: function (attrName, lang) { |
||
1644 | Prism.languages.markup.tag.inside['special-attr'].push({ |
||
1645 | pattern: RegExp(/(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source, 'i'), |
||
1646 | lookbehind: true, |
||
1647 | inside: { |
||
1648 | 'attr-name': /^[^\s=]+/, |
||
1649 | 'attr-value': { |
||
1650 | pattern: /=[\s\S]+/, |
||
1651 | inside: { |
||
1652 | 'value': { |
||
1653 | pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/, |
||
597 | daniel-mar | 1654 | lookbehind: true, |
1655 | alias: [ |
||
679 | daniel-mar | 1656 | lang, |
1657 | 'language-' + lang |
||
597 | daniel-mar | 1658 | ], |
679 | daniel-mar | 1659 | inside: Prism.languages[lang] |
597 | daniel-mar | 1660 | }, |
679 | daniel-mar | 1661 | 'punctuation': [ |
1662 | { |
||
1663 | pattern: /^=/, |
||
1664 | alias: 'attr-equals' |
||
597 | daniel-mar | 1665 | }, |
679 | daniel-mar | 1666 | /"|'/ |
1667 | ] |
||
597 | daniel-mar | 1668 | } |
679 | daniel-mar | 1669 | } |
1670 | } |
||
1671 | }); |
||
1672 | } |
||
1673 | }); |
||
1674 | Prism.languages.html = Prism.languages.markup; |
||
1675 | Prism.languages.mathml = Prism.languages.markup; |
||
1676 | Prism.languages.svg = Prism.languages.markup; |
||
1677 | Prism.languages.xml = Prism.languages.extend('markup', {}); |
||
1678 | Prism.languages.ssml = Prism.languages.xml; |
||
1679 | Prism.languages.atom = Prism.languages.xml; |
||
1680 | Prism.languages.rss = Prism.languages.xml; |
||
1681 | (function (Prism) { |
||
1682 | var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/; |
||
1683 | var constant = [ |
||
1684 | { |
||
1685 | pattern: /\b(?:false|true)\b/i, |
||
1686 | alias: 'boolean' |
||
597 | daniel-mar | 1687 | }, |
679 | daniel-mar | 1688 | { |
1689 | pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i, |
||
1690 | greedy: true, |
||
1691 | lookbehind: true |
||
1692 | }, |
||
1693 | { |
||
1694 | pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i, |
||
1695 | greedy: true, |
||
1696 | lookbehind: true |
||
1697 | }, |
||
1698 | /\b(?:null)\b/i, |
||
1699 | /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/ |
||
1700 | ]; |
||
1701 | 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; |
||
1702 | var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/; |
||
1703 | var punctuation = /[{}\[\](),:;]/; |
||
1704 | Prism.languages.php = { |
||
1705 | 'delimiter': { |
||
1706 | pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i, |
||
1707 | alias: 'important' |
||
1708 | }, |
||
1709 | 'comment': comment, |
||
1021 | daniel-mar | 1710 | 'variable': /\$+(?:\w+\b|(?=\{))/, |
679 | daniel-mar | 1711 | 'package': { |
1712 | pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, |
||
1713 | lookbehind: true, |
||
1714 | inside: { 'punctuation': /\\/ } |
||
1715 | }, |
||
1716 | 'class-name-definition': { |
||
1717 | pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i, |
||
1718 | lookbehind: true, |
||
1719 | alias: 'class-name' |
||
1720 | }, |
||
1721 | 'function-definition': { |
||
1722 | pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i, |
||
1723 | lookbehind: true, |
||
1724 | alias: 'function' |
||
1725 | }, |
||
1726 | 'keyword': [ |
||
1727 | { |
||
1021 | daniel-mar | 1728 | pattern: /(\(\s*)\b(?:array|bool|boolean|float|int|integer|object|string)\b(?=\s*\))/i, |
679 | daniel-mar | 1729 | alias: 'type-casting', |
1730 | greedy: true, |
||
1731 | lookbehind: true |
||
1732 | }, |
||
1733 | { |
||
1021 | daniel-mar | 1734 | pattern: /([(,?]\s*)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string)\b(?=\s*\$)/i, |
679 | daniel-mar | 1735 | alias: 'type-hint', |
1736 | greedy: true, |
||
1737 | lookbehind: true |
||
1738 | }, |
||
1739 | { |
||
1021 | daniel-mar | 1740 | pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i, |
679 | daniel-mar | 1741 | alias: 'return-type', |
1742 | greedy: true, |
||
1743 | lookbehind: true |
||
1744 | }, |
||
1745 | { |
||
1021 | daniel-mar | 1746 | pattern: /\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i, |
679 | daniel-mar | 1747 | alias: 'type-declaration', |
1748 | greedy: true |
||
1749 | }, |
||
1750 | { |
||
1021 | daniel-mar | 1751 | pattern: /(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i, |
679 | daniel-mar | 1752 | alias: 'type-declaration', |
1753 | greedy: true, |
||
1754 | lookbehind: true |
||
1755 | }, |
||
1756 | { |
||
1757 | pattern: /\b(?:parent|self|static)(?=\s*::)/i, |
||
1758 | alias: 'static-context', |
||
1759 | greedy: true |
||
1760 | }, |
||
1761 | { |
||
1762 | pattern: /(\byield\s+)from\b/i, |
||
1763 | lookbehind: true |
||
1764 | }, |
||
1765 | /\bclass\b/i, |
||
1766 | { |
||
1021 | daniel-mar | 1767 | pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?: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|match|namespace|never|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i, |
679 | daniel-mar | 1768 | lookbehind: true |
1769 | } |
||
1770 | ], |
||
1771 | 'argument-name': { |
||
1021 | daniel-mar | 1772 | pattern: /([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i, |
679 | daniel-mar | 1773 | lookbehind: true |
1774 | }, |
||
1775 | 'class-name': [ |
||
1776 | { |
||
1777 | pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i, |
||
1778 | greedy: true, |
||
1779 | lookbehind: true |
||
1780 | }, |
||
1781 | { |
||
1782 | pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i, |
||
1783 | greedy: true, |
||
1784 | lookbehind: true |
||
1785 | }, |
||
1786 | { |
||
1787 | pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i, |
||
1788 | greedy: true |
||
1789 | }, |
||
1790 | { |
||
1791 | pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i, |
||
1792 | alias: 'class-name-fully-qualified', |
||
1793 | greedy: true, |
||
1794 | lookbehind: true, |
||
1795 | inside: { 'punctuation': /\\/ } |
||
1796 | }, |
||
1797 | { |
||
1798 | pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i, |
||
1799 | alias: 'class-name-fully-qualified', |
||
1800 | greedy: true, |
||
1801 | inside: { 'punctuation': /\\/ } |
||
1802 | }, |
||
1803 | { |
||
1804 | pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, |
||
1805 | alias: 'class-name-fully-qualified', |
||
1806 | greedy: true, |
||
1807 | lookbehind: true, |
||
1808 | inside: { 'punctuation': /\\/ } |
||
1809 | }, |
||
1810 | { |
||
1811 | pattern: /\b[a-z_]\w*(?=\s*\$)/i, |
||
1812 | alias: 'type-declaration', |
||
1813 | greedy: true |
||
1814 | }, |
||
1815 | { |
||
1816 | pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i, |
||
1817 | alias: [ |
||
1818 | 'class-name-fully-qualified', |
||
1819 | 'type-declaration' |
||
1820 | ], |
||
1821 | greedy: true, |
||
1822 | inside: { 'punctuation': /\\/ } |
||
1823 | }, |
||
1824 | { |
||
1825 | pattern: /\b[a-z_]\w*(?=\s*::)/i, |
||
1826 | alias: 'static-context', |
||
1827 | greedy: true |
||
1828 | }, |
||
1829 | { |
||
1830 | pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i, |
||
1831 | alias: [ |
||
1832 | 'class-name-fully-qualified', |
||
1833 | 'static-context' |
||
1834 | ], |
||
1835 | greedy: true, |
||
1836 | inside: { 'punctuation': /\\/ } |
||
1837 | }, |
||
1838 | { |
||
1839 | pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i, |
||
1840 | alias: 'type-hint', |
||
1841 | greedy: true, |
||
1842 | lookbehind: true |
||
1843 | }, |
||
1844 | { |
||
1845 | pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i, |
||
1846 | alias: [ |
||
1847 | 'class-name-fully-qualified', |
||
1848 | 'type-hint' |
||
1849 | ], |
||
1850 | greedy: true, |
||
1851 | lookbehind: true, |
||
1852 | inside: { 'punctuation': /\\/ } |
||
1853 | }, |
||
1854 | { |
||
1855 | pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i, |
||
1856 | alias: 'return-type', |
||
1857 | greedy: true, |
||
1858 | lookbehind: true |
||
1859 | }, |
||
1860 | { |
||
1861 | pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, |
||
1862 | alias: [ |
||
1863 | 'class-name-fully-qualified', |
||
1864 | 'return-type' |
||
1865 | ], |
||
1866 | greedy: true, |
||
1867 | lookbehind: true, |
||
1868 | inside: { 'punctuation': /\\/ } |
||
1869 | } |
||
1870 | ], |
||
1871 | 'constant': constant, |
||
1872 | 'function': { |
||
1873 | pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i, |
||
1874 | lookbehind: true, |
||
1875 | inside: { 'punctuation': /\\/ } |
||
1876 | }, |
||
1877 | 'property': { |
||
1878 | pattern: /(->\s*)\w+/, |
||
1879 | lookbehind: true |
||
1880 | }, |
||
1881 | 'number': number, |
||
1882 | 'operator': operator, |
||
1883 | 'punctuation': punctuation |
||
1884 | }; |
||
1885 | var string_interpolation = { |
||
1886 | pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/, |
||
1887 | lookbehind: true, |
||
1888 | inside: Prism.languages.php |
||
1889 | }; |
||
1890 | var string = [ |
||
1891 | { |
||
1892 | pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/, |
||
1893 | alias: 'nowdoc-string', |
||
1894 | greedy: true, |
||
1895 | inside: { |
||
1896 | 'delimiter': { |
||
1897 | pattern: /^<<<'[^']+'|[a-z_]\w*;$/i, |
||
1898 | alias: 'symbol', |
||
1899 | inside: { 'punctuation': /^<<<'?|[';]$/ } |
||
1900 | } |
||
1901 | } |
||
1902 | }, |
||
1903 | { |
||
1904 | pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i, |
||
1905 | alias: 'heredoc-string', |
||
1906 | greedy: true, |
||
1907 | inside: { |
||
1908 | 'delimiter': { |
||
1909 | pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i, |
||
1910 | alias: 'symbol', |
||
1911 | inside: { 'punctuation': /^<<<"?|[";]$/ } |
||
597 | daniel-mar | 1912 | }, |
679 | daniel-mar | 1913 | 'interpolation': string_interpolation |
1914 | } |
||
1915 | }, |
||
1916 | { |
||
1917 | pattern: /`(?:\\[\s\S]|[^\\`])*`/, |
||
1918 | alias: 'backtick-quoted-string', |
||
1919 | greedy: true |
||
1920 | }, |
||
1921 | { |
||
1922 | pattern: /'(?:\\[\s\S]|[^\\'])*'/, |
||
1923 | alias: 'single-quoted-string', |
||
1924 | greedy: true |
||
1925 | }, |
||
1926 | { |
||
1927 | pattern: /"(?:\\[\s\S]|[^\\"])*"/, |
||
1928 | alias: 'double-quoted-string', |
||
1929 | greedy: true, |
||
1930 | inside: { 'interpolation': string_interpolation } |
||
1931 | } |
||
1932 | ]; |
||
1933 | Prism.languages.insertBefore('php', 'variable', { |
||
1934 | 'string': string, |
||
1935 | 'attribute': { |
||
1936 | pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im, |
||
1937 | greedy: true, |
||
1938 | inside: { |
||
1939 | 'attribute-content': { |
||
1940 | pattern: /^(#\[)[\s\S]+(?=\]$)/, |
||
1941 | lookbehind: true, |
||
597 | daniel-mar | 1942 | inside: { |
679 | daniel-mar | 1943 | 'comment': comment, |
1944 | 'string': string, |
||
1945 | 'attribute-class-name': [ |
||
1946 | { |
||
1947 | pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i, |
||
1948 | alias: 'class-name', |
||
1949 | greedy: true, |
||
1950 | lookbehind: true |
||
1951 | }, |
||
1952 | { |
||
1953 | pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i, |
||
1954 | alias: [ |
||
1955 | 'class-name', |
||
1956 | 'class-name-fully-qualified' |
||
1957 | ], |
||
1958 | greedy: true, |
||
1959 | lookbehind: true, |
||
1960 | inside: { 'punctuation': /\\/ } |
||
597 | daniel-mar | 1961 | } |
679 | daniel-mar | 1962 | ], |
1963 | 'constant': constant, |
||
1964 | 'number': number, |
||
1965 | 'operator': operator, |
||
1966 | 'punctuation': punctuation |
||
597 | daniel-mar | 1967 | } |
1968 | }, |
||
679 | daniel-mar | 1969 | 'delimiter': { |
1970 | pattern: /^#\[|\]$/, |
||
1971 | alias: 'punctuation' |
||
1972 | } |
||
1973 | } |
||
1974 | } |
||
1975 | }); |
||
1976 | Prism.hooks.add('before-tokenize', function (env) { |
||
1977 | if (!/<\?/.test(env.code)) { |
||
1978 | return; |
||
1979 | } |
||
1021 | daniel-mar | 1980 | var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g; |
679 | daniel-mar | 1981 | Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern); |
1982 | }); |
||
1983 | Prism.hooks.add('after-tokenize', function (env) { |
||
1984 | Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php'); |
||
1985 | }); |
||
1986 | }(Prism)); |
||
1987 | Prism.languages.python = { |
||
1988 | 'comment': { |
||
1989 | pattern: /(^|[^\\])#.*/, |
||
1021 | daniel-mar | 1990 | lookbehind: true, |
1991 | greedy: true |
||
679 | daniel-mar | 1992 | }, |
1993 | 'string-interpolation': { |
||
1021 | daniel-mar | 1994 | pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i, |
679 | daniel-mar | 1995 | greedy: true, |
1996 | inside: { |
||
1997 | 'interpolation': { |
||
1998 | pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/, |
||
1999 | lookbehind: true, |
||
2000 | inside: { |
||
2001 | 'format-spec': { |
||
2002 | pattern: /(:)[^:(){}]+(?=\}$)/, |
||
597 | daniel-mar | 2003 | lookbehind: true |
2004 | }, |
||
679 | daniel-mar | 2005 | 'conversion-option': { |
2006 | pattern: /![sra](?=[:}]$)/, |
||
2007 | alias: 'punctuation' |
||
597 | daniel-mar | 2008 | }, |
679 | daniel-mar | 2009 | rest: null |
2010 | } |
||
2011 | }, |
||
2012 | 'string': /[\s\S]+/ |
||
2013 | } |
||
2014 | }, |
||
2015 | 'triple-quoted-string': { |
||
1021 | daniel-mar | 2016 | pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i, |
679 | daniel-mar | 2017 | greedy: true, |
2018 | alias: 'string' |
||
2019 | }, |
||
2020 | 'string': { |
||
1021 | daniel-mar | 2021 | pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i, |
679 | daniel-mar | 2022 | greedy: true |
2023 | }, |
||
2024 | 'function': { |
||
2025 | pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g, |
||
2026 | lookbehind: true |
||
2027 | }, |
||
2028 | 'class-name': { |
||
2029 | pattern: /(\bclass\s+)\w+/i, |
||
2030 | lookbehind: true |
||
2031 | }, |
||
2032 | 'decorator': { |
||
1021 | daniel-mar | 2033 | pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m, |
679 | daniel-mar | 2034 | lookbehind: true, |
2035 | alias: [ |
||
2036 | 'annotation', |
||
2037 | 'punctuation' |
||
2038 | ], |
||
2039 | inside: { 'punctuation': /\./ } |
||
2040 | }, |
||
1021 | daniel-mar | 2041 | 'keyword': /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/, |
679 | daniel-mar | 2042 | '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/, |
1021 | daniel-mar | 2043 | 'boolean': /\b(?:False|None|True)\b/, |
2044 | 'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i, |
||
2045 | 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/, |
||
679 | daniel-mar | 2046 | 'punctuation': /[{}[\];(),.:]/ |
2047 | }; |
||
2048 | Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python; |
||
2049 | Prism.languages.py = Prism.languages.python; |
||
2050 | (function (Prism) { |
||
2051 | Prism.languages.ruby = Prism.languages.extend('clike', { |
||
1021 | daniel-mar | 2052 | 'comment': { |
2053 | pattern: /#.*|^=begin\s[\s\S]*?^=end/m, |
||
2054 | greedy: true |
||
2055 | }, |
||
679 | daniel-mar | 2056 | 'class-name': { |
1021 | daniel-mar | 2057 | pattern: /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/, |
679 | daniel-mar | 2058 | lookbehind: true, |
2059 | inside: { 'punctuation': /[.\\]/ } |
||
597 | daniel-mar | 2060 | }, |
1021 | daniel-mar | 2061 | 'keyword': /\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/, |
2062 | 'operator': /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/, |
||
2063 | 'punctuation': /[(){}[\].,;]/ |
||
679 | daniel-mar | 2064 | }); |
1021 | daniel-mar | 2065 | Prism.languages.insertBefore('ruby', 'operator', { |
2066 | 'double-colon': { |
||
2067 | pattern: /::/, |
||
2068 | alias: 'punctuation' |
||
2069 | } |
||
2070 | }); |
||
679 | daniel-mar | 2071 | var interpolation = { |
1021 | daniel-mar | 2072 | pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/, |
2073 | lookbehind: true, |
||
679 | daniel-mar | 2074 | inside: { |
1021 | daniel-mar | 2075 | 'content': { |
2076 | pattern: /^(#\{)[\s\S]+(?=\}$)/, |
||
2077 | lookbehind: true, |
||
2078 | inside: Prism.languages.ruby |
||
2079 | }, |
||
679 | daniel-mar | 2080 | 'delimiter': { |
2081 | pattern: /^#\{|\}$/, |
||
1021 | daniel-mar | 2082 | alias: 'punctuation' |
2083 | } |
||
679 | daniel-mar | 2084 | } |
2085 | }; |
||
2086 | delete Prism.languages.ruby.function; |
||
1021 | daniel-mar | 2087 | var percentExpression = '(?:' + [ |
2088 | /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source, |
||
2089 | /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source, |
||
2090 | /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source, |
||
2091 | /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source, |
||
2092 | /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source |
||
2093 | ].join('|') + ')'; |
||
2094 | var symbolName = /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source; |
||
679 | daniel-mar | 2095 | Prism.languages.insertBefore('ruby', 'keyword', { |
1021 | daniel-mar | 2096 | 'regex-literal': [ |
679 | daniel-mar | 2097 | { |
1021 | daniel-mar | 2098 | pattern: RegExp(/%r/.source + percentExpression + /[egimnosux]{0,6}/.source), |
679 | daniel-mar | 2099 | greedy: true, |
1021 | daniel-mar | 2100 | inside: { |
2101 | 'interpolation': interpolation, |
||
2102 | 'regex': /[\s\S]+/ |
||
2103 | } |
||
679 | daniel-mar | 2104 | }, |
2105 | { |
||
2106 | pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/, |
||
2107 | lookbehind: true, |
||
2108 | greedy: true, |
||
1021 | daniel-mar | 2109 | inside: { |
2110 | 'interpolation': interpolation, |
||
2111 | 'regex': /[\s\S]+/ |
||
2112 | } |
||
679 | daniel-mar | 2113 | } |
2114 | ], |
||
2115 | 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/, |
||
1021 | daniel-mar | 2116 | 'symbol': [ |
2117 | { |
||
2118 | pattern: RegExp(/(^|[^:]):/.source + symbolName), |
||
2119 | lookbehind: true, |
||
2120 | greedy: true |
||
2121 | }, |
||
2122 | { |
||
2123 | pattern: RegExp(/([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source), |
||
2124 | lookbehind: true, |
||
2125 | greedy: true |
||
2126 | } |
||
2127 | ], |
||
679 | daniel-mar | 2128 | 'method-definition': { |
1021 | daniel-mar | 2129 | pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/, |
679 | daniel-mar | 2130 | lookbehind: true, |
2131 | inside: { |
||
1021 | daniel-mar | 2132 | 'function': /\b\w+$/, |
2133 | 'keyword': /^self\b/, |
||
2134 | 'class-name': /^\w+/, |
||
2135 | 'punctuation': /\./ |
||
679 | daniel-mar | 2136 | } |
2137 | } |
||
2138 | }); |
||
1021 | daniel-mar | 2139 | Prism.languages.insertBefore('ruby', 'string', { |
2140 | 'string-literal': [ |
||
2141 | { |
||
2142 | pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression), |
||
2143 | greedy: true, |
||
2144 | inside: { |
||
2145 | 'interpolation': interpolation, |
||
2146 | 'string': /[\s\S]+/ |
||
2147 | } |
||
2148 | }, |
||
2149 | { |
||
2150 | pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/, |
||
2151 | greedy: true, |
||
2152 | inside: { |
||
2153 | 'interpolation': interpolation, |
||
2154 | 'string': /[\s\S]+/ |
||
2155 | } |
||
2156 | }, |
||
2157 | { |
||
2158 | pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i, |
||
2159 | alias: 'heredoc-string', |
||
2160 | greedy: true, |
||
2161 | inside: { |
||
2162 | 'delimiter': { |
||
2163 | pattern: /^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i, |
||
2164 | inside: { |
||
2165 | 'symbol': /\b\w+/, |
||
2166 | 'punctuation': /^<<[-~]?/ |
||
2167 | } |
||
2168 | }, |
||
2169 | 'interpolation': interpolation, |
||
2170 | 'string': /[\s\S]+/ |
||
2171 | } |
||
2172 | }, |
||
2173 | { |
||
2174 | pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i, |
||
2175 | alias: 'heredoc-string', |
||
2176 | greedy: true, |
||
2177 | inside: { |
||
2178 | 'delimiter': { |
||
2179 | pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i, |
||
2180 | inside: { |
||
2181 | 'symbol': /\b\w+/, |
||
2182 | 'punctuation': /^<<[-~]?'|'$/ |
||
2183 | } |
||
2184 | }, |
||
2185 | 'string': /[\s\S]+/ |
||
2186 | } |
||
679 | daniel-mar | 2187 | } |
1021 | daniel-mar | 2188 | ], |
2189 | 'command-literal': [ |
||
2190 | { |
||
2191 | pattern: RegExp(/%x/.source + percentExpression), |
||
2192 | greedy: true, |
||
2193 | inside: { |
||
2194 | 'interpolation': interpolation, |
||
2195 | 'command': { |
||
2196 | pattern: /[\s\S]+/, |
||
2197 | alias: 'string' |
||
2198 | } |
||
679 | daniel-mar | 2199 | } |
1021 | daniel-mar | 2200 | }, |
2201 | { |
||
2202 | pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/, |
||
2203 | greedy: true, |
||
2204 | inside: { |
||
2205 | 'interpolation': interpolation, |
||
2206 | 'command': { |
||
2207 | pattern: /[\s\S]+/, |
||
2208 | alias: 'string' |
||
2209 | } |
||
2210 | } |
||
679 | daniel-mar | 2211 | } |
1021 | daniel-mar | 2212 | ] |
2213 | }); |
||
2214 | delete Prism.languages.ruby.string; |
||
2215 | Prism.languages.insertBefore('ruby', 'number', { |
||
2216 | 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/, |
||
2217 | 'constant': /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/ |
||
2218 | }); |
||
679 | daniel-mar | 2219 | Prism.languages.rb = Prism.languages.ruby; |
2220 | }(Prism)); |
||
2221 | var Prism$1 = prismCore.exports; |
||
2222 | var prismjs = { boltExport: Prism$1 }; |
||
2223 | return prismjs; |
||
597 | daniel-mar | 2224 | })); |
2225 | var prism = window.Prism; |
||
2226 | window.Prism = oldprism; |
||
2227 | return prism; |
||
679 | daniel-mar | 2228 | }(undefined, exports$1, module)); |
597 | daniel-mar | 2229 | var Prism$1 = module.exports.boltExport; |
2230 | |||
637 | daniel-mar | 2231 | var getLanguages$1 = function (editor) { |
597 | daniel-mar | 2232 | return editor.getParam('codesample_languages'); |
2233 | }; |
||
2234 | var useGlobalPrismJS = function (editor) { |
||
2235 | return editor.getParam('codesample_global_prismjs', false, 'boolean'); |
||
2236 | }; |
||
2237 | |||
637 | daniel-mar | 2238 | var get = function (editor) { |
597 | daniel-mar | 2239 | return Global.Prism && useGlobalPrismJS(editor) ? Global.Prism : Prism$1; |
2240 | }; |
||
2241 | |||
2242 | var getSelectedCodeSample = function (editor) { |
||
2243 | var node = editor.selection ? editor.selection.getNode() : null; |
||
637 | daniel-mar | 2244 | return someIf(isCodeSample(node), node); |
597 | daniel-mar | 2245 | }; |
2246 | var insertCodeSample = function (editor, language, code) { |
||
2247 | editor.undoManager.transact(function () { |
||
2248 | var node = getSelectedCodeSample(editor); |
||
2249 | code = global$1.DOM.encode(code); |
||
2250 | return node.fold(function () { |
||
2251 | editor.insertContent('<pre id="__new" class="language-' + language + '">' + code + '</pre>'); |
||
2252 | editor.selection.select(editor.$('#__new').removeAttr('id')[0]); |
||
2253 | }, function (n) { |
||
2254 | editor.dom.setAttrib(n, 'class', 'language-' + language); |
||
2255 | n.innerHTML = code; |
||
637 | daniel-mar | 2256 | get(editor).highlightElement(n); |
597 | daniel-mar | 2257 | editor.selection.select(n); |
2258 | }); |
||
2259 | }); |
||
2260 | }; |
||
2261 | var getCurrentCode = function (editor) { |
||
2262 | var node = getSelectedCodeSample(editor); |
||
637 | daniel-mar | 2263 | return node.fold(constant(''), function (n) { |
597 | daniel-mar | 2264 | return n.textContent; |
2265 | }); |
||
2266 | }; |
||
2267 | |||
637 | daniel-mar | 2268 | var getLanguages = function (editor) { |
597 | daniel-mar | 2269 | var defaultLanguages = [ |
2270 | { |
||
2271 | text: 'HTML/XML', |
||
2272 | value: 'markup' |
||
2273 | }, |
||
2274 | { |
||
2275 | text: 'JavaScript', |
||
2276 | value: 'javascript' |
||
2277 | }, |
||
2278 | { |
||
2279 | text: 'CSS', |
||
2280 | value: 'css' |
||
2281 | }, |
||
2282 | { |
||
2283 | text: 'PHP', |
||
2284 | value: 'php' |
||
2285 | }, |
||
2286 | { |
||
2287 | text: 'Ruby', |
||
2288 | value: 'ruby' |
||
2289 | }, |
||
2290 | { |
||
2291 | text: 'Python', |
||
2292 | value: 'python' |
||
2293 | }, |
||
2294 | { |
||
2295 | text: 'Java', |
||
2296 | value: 'java' |
||
2297 | }, |
||
2298 | { |
||
2299 | text: 'C', |
||
2300 | value: 'c' |
||
2301 | }, |
||
2302 | { |
||
2303 | text: 'C#', |
||
2304 | value: 'csharp' |
||
2305 | }, |
||
2306 | { |
||
2307 | text: 'C++', |
||
2308 | value: 'cpp' |
||
2309 | } |
||
2310 | ]; |
||
637 | daniel-mar | 2311 | var customLanguages = getLanguages$1(editor); |
597 | daniel-mar | 2312 | return customLanguages ? customLanguages : defaultLanguages; |
2313 | }; |
||
2314 | var getCurrentLanguage = function (editor, fallback) { |
||
2315 | var node = getSelectedCodeSample(editor); |
||
2316 | return node.fold(function () { |
||
2317 | return fallback; |
||
2318 | }, function (n) { |
||
2319 | var matches = n.className.match(/language-(\w+)/); |
||
2320 | return matches ? matches[1] : fallback; |
||
2321 | }); |
||
2322 | }; |
||
2323 | |||
2324 | var open = function (editor) { |
||
637 | daniel-mar | 2325 | var languages = getLanguages(editor); |
2326 | var defaultLanguage = head(languages).fold(constant(''), function (l) { |
||
597 | daniel-mar | 2327 | return l.value; |
2328 | }); |
||
2329 | var currentLanguage = getCurrentLanguage(editor, defaultLanguage); |
||
2330 | var currentCode = getCurrentCode(editor); |
||
2331 | editor.windowManager.open({ |
||
2332 | title: 'Insert/Edit Code Sample', |
||
2333 | size: 'large', |
||
2334 | body: { |
||
2335 | type: 'panel', |
||
2336 | items: [ |
||
2337 | { |
||
2338 | type: 'selectbox', |
||
2339 | name: 'language', |
||
2340 | label: 'Language', |
||
2341 | items: languages |
||
2342 | }, |
||
2343 | { |
||
2344 | type: 'textarea', |
||
2345 | name: 'code', |
||
2346 | label: 'Code view' |
||
2347 | } |
||
2348 | ] |
||
2349 | }, |
||
2350 | buttons: [ |
||
2351 | { |
||
2352 | type: 'cancel', |
||
2353 | name: 'cancel', |
||
2354 | text: 'Cancel' |
||
2355 | }, |
||
2356 | { |
||
2357 | type: 'submit', |
||
2358 | name: 'save', |
||
2359 | text: 'Save', |
||
2360 | primary: true |
||
2361 | } |
||
2362 | ], |
||
2363 | initialData: { |
||
2364 | language: currentLanguage, |
||
2365 | code: currentCode |
||
2366 | }, |
||
2367 | onSubmit: function (api) { |
||
2368 | var data = api.getData(); |
||
2369 | insertCodeSample(editor, data.language, data.code); |
||
2370 | api.close(); |
||
2371 | } |
||
2372 | }); |
||
2373 | }; |
||
2374 | |||
637 | daniel-mar | 2375 | var register$1 = function (editor) { |
597 | daniel-mar | 2376 | editor.addCommand('codesample', function () { |
2377 | var node = editor.selection.getNode(); |
||
2378 | if (editor.selection.isCollapsed() || isCodeSample(node)) { |
||
2379 | open(editor); |
||
2380 | } else { |
||
2381 | editor.formatter.toggle('code'); |
||
2382 | } |
||
2383 | }); |
||
2384 | }; |
||
2385 | |||
2386 | var setup = function (editor) { |
||
2387 | var $ = editor.$; |
||
2388 | editor.on('PreProcess', function (e) { |
||
2389 | $('pre[contenteditable=false]', e.node).filter(trimArg(isCodeSample)).each(function (idx, elm) { |
||
2390 | var $elm = $(elm), code = elm.textContent; |
||
2391 | $elm.attr('class', $.trim($elm.attr('class'))); |
||
2392 | $elm.removeAttr('contentEditable'); |
||
2393 | $elm.empty().append($('<code></code>').each(function () { |
||
2394 | this.textContent = code; |
||
2395 | })); |
||
2396 | }); |
||
2397 | }); |
||
2398 | editor.on('SetContent', function () { |
||
2399 | var unprocessedCodeSamples = $('pre').filter(trimArg(isCodeSample)).filter(function (idx, elm) { |
||
2400 | return elm.contentEditable !== 'false'; |
||
2401 | }); |
||
2402 | if (unprocessedCodeSamples.length) { |
||
2403 | editor.undoManager.transact(function () { |
||
2404 | unprocessedCodeSamples.each(function (idx, elm) { |
||
2405 | $(elm).find('br').each(function (idx, elm) { |
||
2406 | elm.parentNode.replaceChild(editor.getDoc().createTextNode('\n'), elm); |
||
2407 | }); |
||
2408 | elm.contentEditable = 'false'; |
||
2409 | elm.innerHTML = editor.dom.encode(elm.textContent); |
||
637 | daniel-mar | 2410 | get(editor).highlightElement(elm); |
597 | daniel-mar | 2411 | elm.className = $.trim(elm.className); |
2412 | }); |
||
2413 | }); |
||
2414 | } |
||
2415 | }); |
||
2416 | }; |
||
2417 | |||
2418 | var isCodeSampleSelection = function (editor) { |
||
2419 | var node = editor.selection.getStart(); |
||
2420 | return editor.dom.is(node, 'pre[class*="language-"]'); |
||
2421 | }; |
||
637 | daniel-mar | 2422 | var register = function (editor) { |
2423 | var onAction = function () { |
||
2424 | return editor.execCommand('codesample'); |
||
2425 | }; |
||
597 | daniel-mar | 2426 | editor.ui.registry.addToggleButton('codesample', { |
2427 | icon: 'code-sample', |
||
2428 | tooltip: 'Insert/edit code sample', |
||
637 | daniel-mar | 2429 | onAction: onAction, |
597 | daniel-mar | 2430 | onSetup: function (api) { |
2431 | var nodeChangeHandler = function () { |
||
2432 | api.setActive(isCodeSampleSelection(editor)); |
||
2433 | }; |
||
2434 | editor.on('NodeChange', nodeChangeHandler); |
||
2435 | return function () { |
||
2436 | return editor.off('NodeChange', nodeChangeHandler); |
||
2437 | }; |
||
2438 | } |
||
2439 | }); |
||
2440 | editor.ui.registry.addMenuItem('codesample', { |
||
2441 | text: 'Code sample...', |
||
2442 | icon: 'code-sample', |
||
637 | daniel-mar | 2443 | onAction: onAction |
597 | daniel-mar | 2444 | }); |
2445 | }; |
||
2446 | |||
2447 | function Plugin () { |
||
637 | daniel-mar | 2448 | global$2.add('codesample', function (editor) { |
597 | daniel-mar | 2449 | setup(editor); |
637 | daniel-mar | 2450 | register(editor); |
597 | daniel-mar | 2451 | register$1(editor); |
2452 | editor.on('dblclick', function (ev) { |
||
2453 | if (isCodeSample(ev.target)) { |
||
2454 | open(editor); |
||
2455 | } |
||
2456 | }); |
||
2457 | }); |
||
2458 | } |
||
2459 | |||
2460 | Plugin(); |
||
2461 | |||
2462 | }()); |