plugin.js 92 KB

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