plugin.js 92 KB

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