prism.js 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937
  1. /* PrismJS 1.20.0
  2. https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+bash+csharp+gcode+json+less+lua+markdown+markup-templating+php+processing+python+regex+ruby+sass+swift+typescript+unrealscript+xml-doc+yaml */
  3. var _self = (typeof window !== 'undefined')
  4. ? window // if in browser
  5. : (
  6. (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
  7. ? self // if in worker
  8. : {} // if in node js
  9. );
  10. /**
  11. * Prism: Lightweight, robust, elegant syntax highlighting
  12. * MIT license http://www.opensource.org/licenses/mit-license.php/
  13. * @author Lea Verou http://lea.verou.me
  14. */
  15. var Prism = (function (_self){
  16. // Private helper vars
  17. var lang = /\blang(?:uage)?-([\w-]+)\b/i;
  18. var uniqueId = 0;
  19. var _ = {
  20. manual: _self.Prism && _self.Prism.manual,
  21. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  22. util: {
  23. encode: function encode(tokens) {
  24. if (tokens instanceof Token) {
  25. return new Token(tokens.type, encode(tokens.content), tokens.alias);
  26. } else if (Array.isArray(tokens)) {
  27. return tokens.map(encode);
  28. } else {
  29. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  30. }
  31. },
  32. type: function (o) {
  33. return Object.prototype.toString.call(o).slice(8, -1);
  34. },
  35. objId: function (obj) {
  36. if (!obj['__id']) {
  37. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  38. }
  39. return obj['__id'];
  40. },
  41. // Deep clone a language definition (e.g. to extend it)
  42. clone: function deepClone(o, visited) {
  43. var clone, id, type = _.util.type(o);
  44. visited = visited || {};
  45. switch (type) {
  46. case 'Object':
  47. id = _.util.objId(o);
  48. if (visited[id]) {
  49. return visited[id];
  50. }
  51. clone = {};
  52. visited[id] = clone;
  53. for (var key in o) {
  54. if (o.hasOwnProperty(key)) {
  55. clone[key] = deepClone(o[key], visited);
  56. }
  57. }
  58. return clone;
  59. case 'Array':
  60. id = _.util.objId(o);
  61. if (visited[id]) {
  62. return visited[id];
  63. }
  64. clone = [];
  65. visited[id] = clone;
  66. o.forEach(function (v, i) {
  67. clone[i] = deepClone(v, visited);
  68. });
  69. return clone;
  70. default:
  71. return o;
  72. }
  73. },
  74. /**
  75. * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
  76. *
  77. * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
  78. *
  79. * @param {Element} element
  80. * @returns {string}
  81. */
  82. getLanguage: function (element) {
  83. while (element && !lang.test(element.className)) {
  84. element = element.parentElement;
  85. }
  86. if (element) {
  87. return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
  88. }
  89. return 'none';
  90. },
  91. /**
  92. * Returns the script element that is currently executing.
  93. *
  94. * This does __not__ work for line script element.
  95. *
  96. * @returns {HTMLScriptElement | null}
  97. */
  98. currentScript: function () {
  99. if (typeof document === 'undefined') {
  100. return null;
  101. }
  102. if ('currentScript' in document) {
  103. return document.currentScript;
  104. }
  105. // IE11 workaround
  106. // we'll get the src of the current script by parsing IE11's error stack trace
  107. // this will not work for inline scripts
  108. try {
  109. throw new Error();
  110. } catch (err) {
  111. // Get file src url from stack. Specifically works with the format of stack traces in IE.
  112. // A stack will look like this:
  113. //
  114. // Error
  115. // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
  116. // at Global code (http://localhost/components/prism-core.js:606:1)
  117. var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
  118. if (src) {
  119. var scripts = document.getElementsByTagName('script');
  120. for (var i in scripts) {
  121. if (scripts[i].src == src) {
  122. return scripts[i];
  123. }
  124. }
  125. }
  126. return null;
  127. }
  128. }
  129. },
  130. languages: {
  131. extend: function (id, redef) {
  132. var lang = _.util.clone(_.languages[id]);
  133. for (var key in redef) {
  134. lang[key] = redef[key];
  135. }
  136. return lang;
  137. },
  138. /**
  139. * Insert a token before another token in a language literal
  140. * As this needs to recreate the object (we cannot actually insert before keys in object literals),
  141. * we cannot just provide an object, we need an object and a key.
  142. * @param inside The key (or language id) of the parent
  143. * @param before The key to insert before.
  144. * @param insert Object with the key/value pairs to insert
  145. * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
  146. */
  147. insertBefore: function (inside, before, insert, root) {
  148. root = root || _.languages;
  149. var grammar = root[inside];
  150. var ret = {};
  151. for (var token in grammar) {
  152. if (grammar.hasOwnProperty(token)) {
  153. if (token == before) {
  154. for (var newToken in insert) {
  155. if (insert.hasOwnProperty(newToken)) {
  156. ret[newToken] = insert[newToken];
  157. }
  158. }
  159. }
  160. // Do not insert token which also occur in insert. See #1525
  161. if (!insert.hasOwnProperty(token)) {
  162. ret[token] = grammar[token];
  163. }
  164. }
  165. }
  166. var old = root[inside];
  167. root[inside] = ret;
  168. // Update references in other language definitions
  169. _.languages.DFS(_.languages, function(key, value) {
  170. if (value === old && key != inside) {
  171. this[key] = ret;
  172. }
  173. });
  174. return ret;
  175. },
  176. // Traverse a language definition with Depth First Search
  177. DFS: function DFS(o, callback, type, visited) {
  178. visited = visited || {};
  179. var objId = _.util.objId;
  180. for (var i in o) {
  181. if (o.hasOwnProperty(i)) {
  182. callback.call(o, i, o[i], type || i);
  183. var property = o[i],
  184. propertyType = _.util.type(property);
  185. if (propertyType === 'Object' && !visited[objId(property)]) {
  186. visited[objId(property)] = true;
  187. DFS(property, callback, null, visited);
  188. }
  189. else if (propertyType === 'Array' && !visited[objId(property)]) {
  190. visited[objId(property)] = true;
  191. DFS(property, callback, i, visited);
  192. }
  193. }
  194. }
  195. }
  196. },
  197. plugins: {},
  198. highlightAll: function(async, callback) {
  199. _.highlightAllUnder(document, async, callback);
  200. },
  201. highlightAllUnder: function(container, async, callback) {
  202. var env = {
  203. callback: callback,
  204. container: container,
  205. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  206. };
  207. _.hooks.run('before-highlightall', env);
  208. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  209. _.hooks.run('before-all-elements-highlight', env);
  210. for (var i = 0, element; element = env.elements[i++];) {
  211. _.highlightElement(element, async === true, env.callback);
  212. }
  213. },
  214. highlightElement: function(element, async, callback) {
  215. // Find language
  216. var language = _.util.getLanguage(element);
  217. var grammar = _.languages[language];
  218. // Set language on the element, if not present
  219. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  220. // Set language on the parent, for styling
  221. var parent = element.parentNode;
  222. if (parent && parent.nodeName.toLowerCase() === 'pre') {
  223. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  224. }
  225. var code = element.textContent;
  226. var env = {
  227. element: element,
  228. language: language,
  229. grammar: grammar,
  230. code: code
  231. };
  232. function insertHighlightedCode(highlightedCode) {
  233. env.highlightedCode = highlightedCode;
  234. _.hooks.run('before-insert', env);
  235. env.element.innerHTML = env.highlightedCode;
  236. _.hooks.run('after-highlight', env);
  237. _.hooks.run('complete', env);
  238. callback && callback.call(env.element);
  239. }
  240. _.hooks.run('before-sanity-check', env);
  241. if (!env.code) {
  242. _.hooks.run('complete', env);
  243. callback && callback.call(env.element);
  244. return;
  245. }
  246. _.hooks.run('before-highlight', env);
  247. if (!env.grammar) {
  248. insertHighlightedCode(_.util.encode(env.code));
  249. return;
  250. }
  251. if (async && _self.Worker) {
  252. var worker = new Worker(_.filename);
  253. worker.onmessage = function(evt) {
  254. insertHighlightedCode(evt.data);
  255. };
  256. worker.postMessage(JSON.stringify({
  257. language: env.language,
  258. code: env.code,
  259. immediateClose: true
  260. }));
  261. }
  262. else {
  263. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  264. }
  265. },
  266. highlight: function (text, grammar, language) {
  267. var env = {
  268. code: text,
  269. grammar: grammar,
  270. language: language
  271. };
  272. _.hooks.run('before-tokenize', env);
  273. env.tokens = _.tokenize(env.code, env.grammar);
  274. _.hooks.run('after-tokenize', env);
  275. return Token.stringify(_.util.encode(env.tokens), env.language);
  276. },
  277. tokenize: function(text, grammar) {
  278. var rest = grammar.rest;
  279. if (rest) {
  280. for (var token in rest) {
  281. grammar[token] = rest[token];
  282. }
  283. delete grammar.rest;
  284. }
  285. var tokenList = new LinkedList();
  286. addAfter(tokenList, tokenList.head, text);
  287. matchGrammar(text, tokenList, grammar, tokenList.head, 0);
  288. return toArray(tokenList);
  289. },
  290. hooks: {
  291. all: {},
  292. add: function (name, callback) {
  293. var hooks = _.hooks.all;
  294. hooks[name] = hooks[name] || [];
  295. hooks[name].push(callback);
  296. },
  297. run: function (name, env) {
  298. var callbacks = _.hooks.all[name];
  299. if (!callbacks || !callbacks.length) {
  300. return;
  301. }
  302. for (var i=0, callback; callback = callbacks[i++];) {
  303. callback(env);
  304. }
  305. }
  306. },
  307. Token: Token
  308. };
  309. _self.Prism = _;
  310. function Token(type, content, alias, matchedStr, greedy) {
  311. this.type = type;
  312. this.content = content;
  313. this.alias = alias;
  314. // Copy of the full string this token was created from
  315. this.length = (matchedStr || '').length|0;
  316. this.greedy = !!greedy;
  317. }
  318. Token.stringify = function stringify(o, language) {
  319. if (typeof o == 'string') {
  320. return o;
  321. }
  322. if (Array.isArray(o)) {
  323. var s = '';
  324. o.forEach(function (e) {
  325. s += stringify(e, language);
  326. });
  327. return s;
  328. }
  329. var env = {
  330. type: o.type,
  331. content: stringify(o.content, language),
  332. tag: 'span',
  333. classes: ['token', o.type],
  334. attributes: {},
  335. language: language
  336. };
  337. var aliases = o.alias;
  338. if (aliases) {
  339. if (Array.isArray(aliases)) {
  340. Array.prototype.push.apply(env.classes, aliases);
  341. } else {
  342. env.classes.push(aliases);
  343. }
  344. }
  345. _.hooks.run('wrap', env);
  346. var attributes = '';
  347. for (var name in env.attributes) {
  348. attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  349. }
  350. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
  351. };
  352. /**
  353. * @param {string} text
  354. * @param {LinkedList<string | Token>} tokenList
  355. * @param {any} grammar
  356. * @param {LinkedListNode<string | Token>} startNode
  357. * @param {number} startPos
  358. * @param {boolean} [oneshot=false]
  359. * @param {string} [target]
  360. */
  361. function matchGrammar(text, tokenList, grammar, startNode, startPos, oneshot, target) {
  362. for (var token in grammar) {
  363. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  364. continue;
  365. }
  366. var patterns = grammar[token];
  367. patterns = Array.isArray(patterns) ? patterns : [patterns];
  368. for (var j = 0; j < patterns.length; ++j) {
  369. if (target && target == token + ',' + j) {
  370. return;
  371. }
  372. var pattern = patterns[j],
  373. inside = pattern.inside,
  374. lookbehind = !!pattern.lookbehind,
  375. greedy = !!pattern.greedy,
  376. lookbehindLength = 0,
  377. alias = pattern.alias;
  378. if (greedy && !pattern.pattern.global) {
  379. // Without the global flag, lastIndex won't work
  380. var flags = pattern.pattern.toString().match(/[imsuy]*$/)[0];
  381. pattern.pattern = RegExp(pattern.pattern.source, flags + 'g');
  382. }
  383. pattern = pattern.pattern || pattern;
  384. for ( // iterate the token list and keep track of the current token/string position
  385. var currentNode = startNode.next, pos = startPos;
  386. currentNode !== tokenList.tail;
  387. pos += currentNode.value.length, currentNode = currentNode.next
  388. ) {
  389. var str = currentNode.value;
  390. if (tokenList.length > text.length) {
  391. // Something went terribly wrong, ABORT, ABORT!
  392. return;
  393. }
  394. if (str instanceof Token) {
  395. continue;
  396. }
  397. var removeCount = 1; // this is the to parameter of removeBetween
  398. if (greedy && currentNode != tokenList.tail.prev) {
  399. pattern.lastIndex = pos;
  400. var match = pattern.exec(text);
  401. if (!match) {
  402. break;
  403. }
  404. var from = match.index + (lookbehind && match[1] ? match[1].length : 0);
  405. var to = match.index + match[0].length;
  406. var p = pos;
  407. // find the node that contains the match
  408. p += currentNode.value.length;
  409. while (from >= p) {
  410. currentNode = currentNode.next;
  411. p += currentNode.value.length;
  412. }
  413. // adjust pos (and p)
  414. p -= currentNode.value.length;
  415. pos = p;
  416. // the current node is a Token, then the match starts inside another Token, which is invalid
  417. if (currentNode.value instanceof Token) {
  418. continue;
  419. }
  420. // find the last node which is affected by this match
  421. for (
  422. var k = currentNode;
  423. k !== tokenList.tail && (p < to || (typeof k.value === 'string' && !k.prev.value.greedy));
  424. k = k.next
  425. ) {
  426. removeCount++;
  427. p += k.value.length;
  428. }
  429. removeCount--;
  430. // replace with the new match
  431. str = text.slice(pos, p);
  432. match.index -= pos;
  433. } else {
  434. pattern.lastIndex = 0;
  435. var match = pattern.exec(str);
  436. }
  437. if (!match) {
  438. if (oneshot) {
  439. break;
  440. }
  441. continue;
  442. }
  443. if (lookbehind) {
  444. lookbehindLength = match[1] ? match[1].length : 0;
  445. }
  446. var from = match.index + lookbehindLength,
  447. match = match[0].slice(lookbehindLength),
  448. to = from + match.length,
  449. before = str.slice(0, from),
  450. after = str.slice(to);
  451. var removeFrom = currentNode.prev;
  452. if (before) {
  453. removeFrom = addAfter(tokenList, removeFrom, before);
  454. pos += before.length;
  455. }
  456. removeRange(tokenList, removeFrom, removeCount);
  457. var wrapped = new Token(token, inside ? _.tokenize(match, inside) : match, alias, match, greedy);
  458. currentNode = addAfter(tokenList, removeFrom, wrapped);
  459. if (after) {
  460. addAfter(tokenList, currentNode, after);
  461. }
  462. if (removeCount > 1)
  463. matchGrammar(text, tokenList, grammar, currentNode.prev, pos, true, token + ',' + j);
  464. if (oneshot)
  465. break;
  466. }
  467. }
  468. }
  469. }
  470. /**
  471. * @typedef LinkedListNode
  472. * @property {T} value
  473. * @property {LinkedListNode<T> | null} prev The previous node.
  474. * @property {LinkedListNode<T> | null} next The next node.
  475. * @template T
  476. */
  477. /**
  478. * @template T
  479. */
  480. function LinkedList() {
  481. /** @type {LinkedListNode<T>} */
  482. var head = { value: null, prev: null, next: null };
  483. /** @type {LinkedListNode<T>} */
  484. var tail = { value: null, prev: head, next: null };
  485. head.next = tail;
  486. /** @type {LinkedListNode<T>} */
  487. this.head = head;
  488. /** @type {LinkedListNode<T>} */
  489. this.tail = tail;
  490. this.length = 0;
  491. }
  492. /**
  493. * Adds a new node with the given value to the list.
  494. * @param {LinkedList<T>} list
  495. * @param {LinkedListNode<T>} node
  496. * @param {T} value
  497. * @returns {LinkedListNode<T>} The added node.
  498. * @template T
  499. */
  500. function addAfter(list, node, value) {
  501. // assumes that node != list.tail && values.length >= 0
  502. var next = node.next;
  503. var newNode = { value: value, prev: node, next: next };
  504. node.next = newNode;
  505. next.prev = newNode;
  506. list.length++;
  507. return newNode;
  508. }
  509. /**
  510. * Removes `count` nodes after the given node. The given node will not be removed.
  511. * @param {LinkedList<T>} list
  512. * @param {LinkedListNode<T>} node
  513. * @param {number} count
  514. * @template T
  515. */
  516. function removeRange(list, node, count) {
  517. var next = node.next;
  518. for (var i = 0; i < count && next !== list.tail; i++) {
  519. next = next.next;
  520. }
  521. node.next = next;
  522. next.prev = node;
  523. list.length -= i;
  524. }
  525. /**
  526. * @param {LinkedList<T>} list
  527. * @returns {T[]}
  528. * @template T
  529. */
  530. function toArray(list) {
  531. var array = [];
  532. var node = list.head.next;
  533. while (node !== list.tail) {
  534. array.push(node.value);
  535. node = node.next;
  536. }
  537. return array;
  538. }
  539. if (!_self.document) {
  540. if (!_self.addEventListener) {
  541. // in Node.js
  542. return _;
  543. }
  544. if (!_.disableWorkerMessageHandler) {
  545. // In worker
  546. _self.addEventListener('message', function (evt) {
  547. var message = JSON.parse(evt.data),
  548. lang = message.language,
  549. code = message.code,
  550. immediateClose = message.immediateClose;
  551. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  552. if (immediateClose) {
  553. _self.close();
  554. }
  555. }, false);
  556. }
  557. return _;
  558. }
  559. //Get current script and highlight
  560. var script = _.util.currentScript();
  561. if (script) {
  562. _.filename = script.src;
  563. if (script.hasAttribute('data-manual')) {
  564. _.manual = true;
  565. }
  566. }
  567. function highlightAutomaticallyCallback() {
  568. if (!_.manual) {
  569. _.highlightAll();
  570. }
  571. }
  572. if (!_.manual) {
  573. // If the document state is "loading", then we'll use DOMContentLoaded.
  574. // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
  575. // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
  576. // might take longer one animation frame to execute which can create a race condition where only some plugins have
  577. // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
  578. // See https://github.com/PrismJS/prism/issues/2102
  579. var readyState = document.readyState;
  580. if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
  581. document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
  582. } else {
  583. if (window.requestAnimationFrame) {
  584. window.requestAnimationFrame(highlightAutomaticallyCallback);
  585. } else {
  586. window.setTimeout(highlightAutomaticallyCallback, 16);
  587. }
  588. }
  589. }
  590. return _;
  591. })(_self);
  592. if (typeof module !== 'undefined' && module.exports) {
  593. module.exports = Prism;
  594. }
  595. // hack for components to work correctly in node.js
  596. if (typeof global !== 'undefined') {
  597. global.Prism = Prism;
  598. }
  599. ;
  600. Prism.languages.markup = {
  601. 'comment': /<!--[\s\S]*?-->/,
  602. 'prolog': /<\?[\s\S]+?\?>/,
  603. 'doctype': {
  604. // https://www.w3.org/TR/xml/#NT-doctypedecl
  605. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
  606. greedy: true,
  607. inside: {
  608. 'internal-subset': {
  609. pattern: /(\[)[\s\S]+(?=\]>$)/,
  610. lookbehind: true,
  611. greedy: true,
  612. inside: null // see below
  613. },
  614. 'string': {
  615. pattern: /"[^"]*"|'[^']*'/,
  616. greedy: true
  617. },
  618. 'punctuation': /^<!|>$|[[\]]/,
  619. 'doctype-tag': /^DOCTYPE/,
  620. 'name': /[^\s<>'"]+/
  621. }
  622. },
  623. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  624. 'tag': {
  625. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
  626. greedy: true,
  627. inside: {
  628. 'tag': {
  629. pattern: /^<\/?[^\s>\/]+/,
  630. inside: {
  631. 'punctuation': /^<\/?/,
  632. 'namespace': /^[^\s>\/:]+:/
  633. }
  634. },
  635. 'attr-value': {
  636. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
  637. inside: {
  638. 'punctuation': [
  639. {
  640. pattern: /^=/,
  641. alias: 'attr-equals'
  642. },
  643. /"|'/
  644. ]
  645. }
  646. },
  647. 'punctuation': /\/?>/,
  648. 'attr-name': {
  649. pattern: /[^\s>\/]+/,
  650. inside: {
  651. 'namespace': /^[^\s>\/:]+:/
  652. }
  653. }
  654. }
  655. },
  656. 'entity': [
  657. {
  658. pattern: /&[\da-z]{1,8};/i,
  659. alias: 'named-entity'
  660. },
  661. /&#x?[\da-f]{1,8};/i
  662. ]
  663. };
  664. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
  665. Prism.languages.markup['entity'];
  666. Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
  667. // Plugin to make entity title show the real entity, idea by Roman Komarov
  668. Prism.hooks.add('wrap', function (env) {
  669. if (env.type === 'entity') {
  670. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  671. }
  672. });
  673. Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
  674. /**
  675. * Adds an inlined language to markup.
  676. *
  677. * An example of an inlined language is CSS with `<style>` tags.
  678. *
  679. * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
  680. * case insensitive.
  681. * @param {string} lang The language key.
  682. * @example
  683. * addInlined('style', 'css');
  684. */
  685. value: function addInlined(tagName, lang) {
  686. var includedCdataInside = {};
  687. includedCdataInside['language-' + lang] = {
  688. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  689. lookbehind: true,
  690. inside: Prism.languages[lang]
  691. };
  692. includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
  693. var inside = {
  694. 'included-cdata': {
  695. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  696. inside: includedCdataInside
  697. }
  698. };
  699. inside['language-' + lang] = {
  700. pattern: /[\s\S]+/,
  701. inside: Prism.languages[lang]
  702. };
  703. var def = {};
  704. def[tagName] = {
  705. pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
  706. lookbehind: true,
  707. greedy: true,
  708. inside: inside
  709. };
  710. Prism.languages.insertBefore('markup', 'cdata', def);
  711. }
  712. });
  713. Prism.languages.html = Prism.languages.markup;
  714. Prism.languages.mathml = Prism.languages.markup;
  715. Prism.languages.svg = Prism.languages.markup;
  716. Prism.languages.xml = Prism.languages.extend('markup', {});
  717. Prism.languages.ssml = Prism.languages.xml;
  718. Prism.languages.atom = Prism.languages.xml;
  719. Prism.languages.rss = Prism.languages.xml;
  720. (function (Prism) {
  721. var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
  722. Prism.languages.css = {
  723. 'comment': /\/\*[\s\S]*?\*\//,
  724. 'atrule': {
  725. pattern: /@[\w-]+[\s\S]*?(?:;|(?=\s*\{))/,
  726. inside: {
  727. 'rule': /^@[\w-]+/,
  728. 'selector-function-argument': {
  729. pattern: /(\bselector\s*\((?!\s*\))\s*)(?:[^()]|\((?:[^()]|\([^()]*\))*\))+?(?=\s*\))/,
  730. lookbehind: true,
  731. alias: 'selector'
  732. }
  733. // See rest below
  734. }
  735. },
  736. 'url': {
  737. pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
  738. greedy: true,
  739. inside: {
  740. 'function': /^url/i,
  741. 'punctuation': /^\(|\)$/
  742. }
  743. },
  744. 'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
  745. 'string': {
  746. pattern: string,
  747. greedy: true
  748. },
  749. 'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
  750. 'important': /!important\b/i,
  751. 'function': /[-a-z0-9]+(?=\()/i,
  752. 'punctuation': /[(){};:,]/
  753. };
  754. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  755. var markup = Prism.languages.markup;
  756. if (markup) {
  757. markup.tag.addInlined('style', 'css');
  758. Prism.languages.insertBefore('inside', 'attr-value', {
  759. 'style-attr': {
  760. pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,
  761. inside: {
  762. 'attr-name': {
  763. pattern: /^\s*style/i,
  764. inside: markup.tag.inside
  765. },
  766. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  767. 'attr-value': {
  768. pattern: /.+/i,
  769. inside: Prism.languages.css
  770. }
  771. },
  772. alias: 'language-css'
  773. }
  774. }, markup.tag);
  775. }
  776. }(Prism));
  777. Prism.languages.clike = {
  778. 'comment': [
  779. {
  780. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  781. lookbehind: true
  782. },
  783. {
  784. pattern: /(^|[^\\:])\/\/.*/,
  785. lookbehind: true,
  786. greedy: true
  787. }
  788. ],
  789. 'string': {
  790. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  791. greedy: true
  792. },
  793. 'class-name': {
  794. pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
  795. lookbehind: true,
  796. inside: {
  797. 'punctuation': /[.\\]/
  798. }
  799. },
  800. 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  801. 'boolean': /\b(?:true|false)\b/,
  802. 'function': /\w+(?=\()/,
  803. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
  804. 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  805. 'punctuation': /[{}[\];(),.:]/
  806. };
  807. Prism.languages.javascript = Prism.languages.extend('clike', {
  808. 'class-name': [
  809. Prism.languages.clike['class-name'],
  810. {
  811. pattern: /(^|[^$\w\xA0-\uFFFF])[_$A-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\.(?:prototype|constructor))/,
  812. lookbehind: true
  813. }
  814. ],
  815. 'keyword': [
  816. {
  817. pattern: /((?:^|})\s*)(?:catch|finally)\b/,
  818. lookbehind: true
  819. },
  820. {
  821. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|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/,
  822. lookbehind: true
  823. },
  824. ],
  825. 'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
  826. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  827. 'function': /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  828. 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
  829. });
  830. Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
  831. Prism.languages.insertBefore('javascript', 'keyword', {
  832. 'regex': {
  833. pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
  834. lookbehind: true,
  835. greedy: true
  836. },
  837. // This must be declared before keyword because we use "function" inside the look-forward
  838. 'function-variable': {
  839. pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/,
  840. alias: 'function'
  841. },
  842. 'parameter': [
  843. {
  844. pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,
  845. lookbehind: true,
  846. inside: Prism.languages.javascript
  847. },
  848. {
  849. pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/i,
  850. inside: Prism.languages.javascript
  851. },
  852. {
  853. pattern: /(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,
  854. lookbehind: true,
  855. inside: Prism.languages.javascript
  856. },
  857. {
  858. 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]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/,
  859. lookbehind: true,
  860. inside: Prism.languages.javascript
  861. }
  862. ],
  863. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  864. });
  865. Prism.languages.insertBefore('javascript', 'string', {
  866. 'template-string': {
  867. pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
  868. greedy: true,
  869. inside: {
  870. 'template-punctuation': {
  871. pattern: /^`|`$/,
  872. alias: 'string'
  873. },
  874. 'interpolation': {
  875. pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
  876. lookbehind: true,
  877. inside: {
  878. 'interpolation-punctuation': {
  879. pattern: /^\${|}$/,
  880. alias: 'punctuation'
  881. },
  882. rest: Prism.languages.javascript
  883. }
  884. },
  885. 'string': /[\s\S]+/
  886. }
  887. }
  888. });
  889. if (Prism.languages.markup) {
  890. Prism.languages.markup.tag.addInlined('script', 'javascript');
  891. }
  892. Prism.languages.js = Prism.languages.javascript;
  893. (function(Prism) {
  894. // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
  895. // + LC_ALL, RANDOM, REPLY, SECONDS.
  896. // + make sure PS1..4 are here as they are not always set,
  897. // - some useless things.
  898. var envVars = '\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b';
  899. var insideString = {
  900. 'environment': {
  901. pattern: RegExp("\\$" + envVars),
  902. alias: 'constant'
  903. },
  904. 'variable': [
  905. // [0]: Arithmetic Environment
  906. {
  907. pattern: /\$?\(\([\s\S]+?\)\)/,
  908. greedy: true,
  909. inside: {
  910. // If there is a $ sign at the beginning highlight $(( and )) as variable
  911. 'variable': [
  912. {
  913. pattern: /(^\$\(\([\s\S]+)\)\)/,
  914. lookbehind: true
  915. },
  916. /^\$\(\(/
  917. ],
  918. 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee]-?\d+)?/,
  919. // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
  920. 'operator': /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
  921. // If there is no $ sign at the beginning highlight (( and )) as punctuation
  922. 'punctuation': /\(\(?|\)\)?|,|;/
  923. }
  924. },
  925. // [1]: Command Substitution
  926. {
  927. pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
  928. greedy: true,
  929. inside: {
  930. 'variable': /^\$\(|^`|\)$|`$/
  931. }
  932. },
  933. // [2]: Brace expansion
  934. {
  935. pattern: /\$\{[^}]+\}/,
  936. greedy: true,
  937. inside: {
  938. 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
  939. 'punctuation': /[\[\]]/,
  940. 'environment': {
  941. pattern: RegExp("(\\{)" + envVars),
  942. lookbehind: true,
  943. alias: 'constant'
  944. }
  945. }
  946. },
  947. /\$(?:\w+|[#?*!@$])/
  948. ],
  949. // Escape sequences from echo and printf's manuals, and escaped quotes.
  950. 'entity': /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})/
  951. };
  952. Prism.languages.bash = {
  953. 'shebang': {
  954. pattern: /^#!\s*\/.*/,
  955. alias: 'important'
  956. },
  957. 'comment': {
  958. pattern: /(^|[^"{\\$])#.*/,
  959. lookbehind: true
  960. },
  961. 'function-name': [
  962. // a) function foo {
  963. // b) foo() {
  964. // c) function foo() {
  965. // but not “foo {”
  966. {
  967. // a) and c)
  968. pattern: /(\bfunction\s+)\w+(?=(?:\s*\(?:\s*\))?\s*\{)/,
  969. lookbehind: true,
  970. alias: 'function'
  971. },
  972. {
  973. // b)
  974. pattern: /\b\w+(?=\s*\(\s*\)\s*\{)/,
  975. alias: 'function'
  976. }
  977. ],
  978. // Highlight variable names as variables in for and select beginnings.
  979. 'for-or-select': {
  980. pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
  981. alias: 'variable',
  982. lookbehind: true
  983. },
  984. // Highlight variable names as variables in the left-hand part
  985. // of assignments (“=” and “+=”).
  986. 'assign-left': {
  987. pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
  988. inside: {
  989. 'environment': {
  990. pattern: RegExp("(^|[\\s;|&]|[<>]\\()" + envVars),
  991. lookbehind: true,
  992. alias: 'constant'
  993. }
  994. },
  995. alias: 'variable',
  996. lookbehind: true
  997. },
  998. 'string': [
  999. // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
  1000. {
  1001. pattern: /((?:^|[^<])<<-?\s*)(\w+?)\s*(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\2/,
  1002. lookbehind: true,
  1003. greedy: true,
  1004. inside: insideString
  1005. },
  1006. // Here-document with quotes around the tag
  1007. // → No expansion (so no “inside”).
  1008. {
  1009. pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s*(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\3/,
  1010. lookbehind: true,
  1011. greedy: true
  1012. },
  1013. // “Normal” string
  1014. {
  1015. pattern: /(^|[^\\](?:\\\\)*)(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\2)[^\\])*\2/,
  1016. lookbehind: true,
  1017. greedy: true,
  1018. inside: insideString
  1019. }
  1020. ],
  1021. 'environment': {
  1022. pattern: RegExp("\\$?" + envVars),
  1023. alias: 'constant'
  1024. },
  1025. 'variable': insideString.variable,
  1026. 'function': {
  1027. pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|aptitude|apt-cache|apt-get|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,
  1028. lookbehind: true
  1029. },
  1030. 'keyword': {
  1031. pattern: /(^|[\s;|&]|[<>]\()(?:if|then|else|elif|fi|for|while|in|case|esac|function|select|do|done|until)(?=$|[)\s;|&])/,
  1032. lookbehind: true
  1033. },
  1034. // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
  1035. 'builtin': {
  1036. pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|break|cd|continue|eval|exec|exit|export|getopts|hash|pwd|readonly|return|shift|test|times|trap|umask|unset|alias|bind|builtin|caller|command|declare|echo|enable|help|let|local|logout|mapfile|printf|read|readarray|source|type|typeset|ulimit|unalias|set|shopt)(?=$|[)\s;|&])/,
  1037. lookbehind: true,
  1038. // Alias added to make those easier to distinguish from strings.
  1039. alias: 'class-name'
  1040. },
  1041. 'boolean': {
  1042. pattern: /(^|[\s;|&]|[<>]\()(?:true|false)(?=$|[)\s;|&])/,
  1043. lookbehind: true
  1044. },
  1045. 'file-descriptor': {
  1046. pattern: /\B&\d\b/,
  1047. alias: 'important'
  1048. },
  1049. 'operator': {
  1050. // Lots of redirections here, but not just that.
  1051. pattern: /\d?<>|>\||\+=|==?|!=?|=~|<<[<-]?|[&\d]?>>|\d?[<>]&?|&[>&]?|\|[&|]?|<=?|>=?/,
  1052. inside: {
  1053. 'file-descriptor': {
  1054. pattern: /^\d/,
  1055. alias: 'important'
  1056. }
  1057. }
  1058. },
  1059. 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
  1060. 'number': {
  1061. pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
  1062. lookbehind: true
  1063. }
  1064. };
  1065. /* Patterns in command substitution. */
  1066. var toBeCopied = [
  1067. 'comment',
  1068. 'function-name',
  1069. 'for-or-select',
  1070. 'assign-left',
  1071. 'string',
  1072. 'environment',
  1073. 'function',
  1074. 'keyword',
  1075. 'builtin',
  1076. 'boolean',
  1077. 'file-descriptor',
  1078. 'operator',
  1079. 'punctuation',
  1080. 'number'
  1081. ];
  1082. var inside = insideString.variable[1].inside;
  1083. for(var i = 0; i < toBeCopied.length; i++) {
  1084. inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
  1085. }
  1086. Prism.languages.shell = Prism.languages.bash;
  1087. })(Prism);
  1088. (function (Prism) {
  1089. /**
  1090. * Replaces all placeholders "<<n>>" of given pattern with the n-th replacement (zero based).
  1091. *
  1092. * Note: This is a simple text based replacement. Be careful when using backreferences!
  1093. *
  1094. * @param {string} pattern the given pattern.
  1095. * @param {string[]} replacements a list of replacement which can be inserted into the given pattern.
  1096. * @returns {string} the pattern with all placeholders replaced with their corresponding replacements.
  1097. * @example replace(/a<<0>>a/.source, [/b+/.source]) === /a(?:b+)a/.source
  1098. */
  1099. function replace(pattern, replacements) {
  1100. return pattern.replace(/<<(\d+)>>/g, function (m, index) {
  1101. return '(?:' + replacements[+index] + ')';
  1102. });
  1103. }
  1104. /**
  1105. * @param {string} pattern
  1106. * @param {string[]} replacements
  1107. * @param {string} [flags]
  1108. * @returns {RegExp}
  1109. */
  1110. function re(pattern, replacements, flags) {
  1111. return RegExp(replace(pattern, replacements), flags || '');
  1112. }
  1113. /**
  1114. * Creates a nested pattern where all occurrences of the string `<<self>>` are replaced with the pattern itself.
  1115. *
  1116. * @param {string} pattern
  1117. * @param {number} depthLog2
  1118. * @returns {string}
  1119. */
  1120. function nested(pattern, depthLog2) {
  1121. for (var i = 0; i < depthLog2; i++) {
  1122. pattern = pattern.replace(/<<self>>/g, function () { return '(?:' + pattern + ')'; });
  1123. }
  1124. return pattern.replace(/<<self>>/g, '[^\\s\\S]');
  1125. }
  1126. // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
  1127. var keywordKinds = {
  1128. // keywords which represent a return or variable type
  1129. type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void',
  1130. // keywords which are used to declare a type
  1131. typeDeclaration: 'class enum interface struct',
  1132. // contextual keywords
  1133. // ("var" and "dynamic" are missing because they are used like types)
  1134. contextual: 'add alias and ascending async await by descending from get global group into join let nameof not notnull on or orderby partial remove select set unmanaged value when where where',
  1135. // all other keywords
  1136. 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'
  1137. };
  1138. // keywords
  1139. function keywordsToPattern(words) {
  1140. return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b';
  1141. }
  1142. var typeDeclarationKeywords = keywordsToPattern(keywordKinds.typeDeclaration);
  1143. var keywords = RegExp(keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other));
  1144. var nonTypeKeywords = keywordsToPattern(keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other);
  1145. var nonContextualKeywords = keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.other);
  1146. // types
  1147. var generic = nested(/<(?:[^<>;=+\-*/%&|^]|<<self>>)*>/.source, 2); // the idea behind the other forbidden characters is to prevent false positives. Same for tupleElement.
  1148. var nestedRound = nested(/\((?:[^()]|<<self>>)*\)/.source, 2);
  1149. var name = /@?\b[A-Za-z_]\w*\b/.source;
  1150. var genericName = replace(/<<0>>(?:\s*<<1>>)?/.source, [name, generic]);
  1151. var identifier = replace(/(?!<<0>>)<<1>>(?:\s*\.\s*<<1>>)*/.source, [nonTypeKeywords, genericName]);
  1152. var array = /\[\s*(?:,\s*)*\]/.source;
  1153. var typeExpressionWithoutTuple = replace(/<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, [identifier, array]);
  1154. var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [generic, nestedRound, array])
  1155. var tuple = replace(/\(<<0>>+(?:,<<0>>+)+\)/.source, [tupleElement]);
  1156. var typeExpression = replace(/(?:<<0>>|<<1>>)(?:\s*(?:\?\s*)?<<2>>)*(?:\s*\?)?/.source, [tuple, identifier, array]);
  1157. var typeInside = {
  1158. 'keyword': keywords,
  1159. 'punctuation': /[<>()?,.:[\]]/
  1160. };
  1161. // strings & characters
  1162. // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#character-literals
  1163. // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#string-literals
  1164. var character = /'(?:[^\r\n'\\]|\\.|\\[Uux][\da-fA-F]{1,8})'/.source; // simplified pattern
  1165. var regularString = /"(?:\\.|[^\\"\r\n])*"/.source;
  1166. var verbatimString = /@"(?:""|\\[\s\S]|[^\\"])*"(?!")/.source;
  1167. Prism.languages.csharp = Prism.languages.extend('clike', {
  1168. 'string': [
  1169. {
  1170. pattern: re(/(^|[^$\\])<<0>>/.source, [verbatimString]),
  1171. lookbehind: true,
  1172. greedy: true
  1173. },
  1174. {
  1175. pattern: re(/(^|[^@$\\])<<0>>/.source, [regularString]),
  1176. lookbehind: true,
  1177. greedy: true
  1178. },
  1179. {
  1180. pattern: RegExp(character),
  1181. greedy: true,
  1182. alias: 'character'
  1183. }
  1184. ],
  1185. 'class-name': [
  1186. {
  1187. // Using static
  1188. // using static System.Math;
  1189. pattern: re(/(\busing\s+static\s+)<<0>>(?=\s*;)/.source, [identifier]),
  1190. lookbehind: true,
  1191. inside: typeInside
  1192. },
  1193. {
  1194. // Using alias (type)
  1195. // using Project = PC.MyCompany.Project;
  1196. pattern: re(/(\busing\s+<<0>>\s*=\s*)<<1>>(?=\s*;)/.source, [name, typeExpression]),
  1197. lookbehind: true,
  1198. inside: typeInside
  1199. },
  1200. {
  1201. // Using alias (alias)
  1202. // using Project = PC.MyCompany.Project;
  1203. pattern: re(/(\busing\s+)<<0>>(?=\s*=)/.source, [name]),
  1204. lookbehind: true
  1205. },
  1206. {
  1207. // Type declarations
  1208. // class Foo<A, B>
  1209. // interface Foo<out A, B>
  1210. pattern: re(/(\b<<0>>\s+)<<1>>/.source, [typeDeclarationKeywords, genericName]),
  1211. lookbehind: true,
  1212. inside: typeInside
  1213. },
  1214. {
  1215. // Single catch exception declaration
  1216. // catch(Foo)
  1217. // (things like catch(Foo e) is covered by variable declaration)
  1218. pattern: re(/(\bcatch\s*\(\s*)<<0>>/.source, [identifier]),
  1219. lookbehind: true,
  1220. inside: typeInside
  1221. },
  1222. {
  1223. // Name of the type parameter of generic constraints
  1224. // where Foo : class
  1225. pattern: re(/(\bwhere\s+)<<0>>/.source, [name]),
  1226. lookbehind: true
  1227. },
  1228. {
  1229. // Casts and checks via as and is.
  1230. // as Foo<A>, is Bar<B>
  1231. // (things like if(a is Foo b) is covered by variable declaration)
  1232. pattern: re(/(\b(?:is(?:\s+not)?|as)\s+)<<0>>/.source, [typeExpressionWithoutTuple]),
  1233. lookbehind: true,
  1234. inside: typeInside
  1235. },
  1236. {
  1237. // Variable, field and parameter declaration
  1238. // (Foo bar, Bar baz, Foo[,,] bay, Foo<Bar, FooBar<Bar>> bax)
  1239. pattern: re(/\b<<0>>(?=\s+(?!<<1>>)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [typeExpression, nonContextualKeywords, name]),
  1240. inside: typeInside
  1241. }
  1242. ],
  1243. 'keyword': keywords,
  1244. // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#literals
  1245. 'number': /(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:ul|lu|[dflmu])?\b/i,
  1246. 'operator': />>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,
  1247. 'punctuation': /\?\.?|::|[{}[\];(),.:]/
  1248. });
  1249. Prism.languages.insertBefore('csharp', 'number', {
  1250. 'range': {
  1251. pattern: /\.\./,
  1252. alias: 'operator'
  1253. }
  1254. });
  1255. Prism.languages.insertBefore('csharp', 'punctuation', {
  1256. 'named-parameter': {
  1257. pattern: re(/([(,]\s*)<<0>>(?=\s*:)/.source, [name]),
  1258. lookbehind: true,
  1259. alias: 'punctuation'
  1260. }
  1261. });
  1262. Prism.languages.insertBefore('csharp', 'class-name', {
  1263. 'namespace': {
  1264. // namespace Foo.Bar {}
  1265. // using Foo.Bar;
  1266. pattern: re(/(\b(?:namespace|using)\s+)<<0>>(?:\s*\.\s*<<0>>)*(?=\s*[;{])/.source, [name]),
  1267. lookbehind: true,
  1268. inside: {
  1269. 'punctuation': /\./
  1270. }
  1271. },
  1272. 'type-expression': {
  1273. // default(Foo), typeof(Foo<Bar>), sizeof(int)
  1274. pattern: re(/(\b(?:default|typeof|sizeof)\s*\(\s*)(?:[^()\s]|\s(?!\s*\))|<<0>>)*(?=\s*\))/.source, [nestedRound]),
  1275. lookbehind: true,
  1276. alias: 'class-name',
  1277. inside: typeInside
  1278. },
  1279. 'return-type': {
  1280. // Foo<Bar> ForBar(); Foo IFoo.Bar() => 0
  1281. // int this[int index] => 0; T IReadOnlyList<T>.this[int index] => this[index];
  1282. // int Foo => 0; int Foo { get; set } = 0;
  1283. pattern: re(/<<0>>(?=\s+(?:<<1>>\s*(?:=>|[({]|\.\s*this\s*\[)|this\s*\[))/.source, [typeExpression, identifier]),
  1284. inside: typeInside,
  1285. alias: 'class-name'
  1286. },
  1287. 'constructor-invocation': {
  1288. // new List<Foo<Bar[]>> { }
  1289. pattern: re(/(\bnew\s+)<<0>>(?=\s*[[({])/.source, [typeExpression]),
  1290. lookbehind: true,
  1291. inside: typeInside,
  1292. alias: 'class-name'
  1293. },
  1294. /*'explicit-implementation': {
  1295. // int IFoo<Foo>.Bar => 0; void IFoo<Foo<Foo>>.Foo<T>();
  1296. pattern: replace(/\b<<0>>(?=\.<<1>>)/, className, methodOrPropertyDeclaration),
  1297. inside: classNameInside,
  1298. alias: 'class-name'
  1299. },*/
  1300. 'generic-method': {
  1301. // foo<Bar>()
  1302. pattern: re(/<<0>>\s*<<1>>(?=\s*\()/.source, [name, generic]),
  1303. inside: {
  1304. 'function': re(/^<<0>>/.source, [name]),
  1305. 'generic': {
  1306. pattern: RegExp(generic),
  1307. alias: 'class-name',
  1308. inside: typeInside
  1309. }
  1310. }
  1311. },
  1312. 'type-list': {
  1313. // The list of types inherited or of generic constraints
  1314. // class Foo<F> : Bar, IList<FooBar>
  1315. // where F : Bar, IList<int>
  1316. pattern: re(
  1317. /\b((?:<<0>>\s+<<1>>|where\s+<<2>>)\s*:\s*)(?:<<3>>|<<4>>)(?:\s*,\s*(?:<<3>>|<<4>>))*(?=\s*(?:where|[{;]|=>|$))/.source,
  1318. [typeDeclarationKeywords, genericName, name, typeExpression, keywords.source]
  1319. ),
  1320. lookbehind: true,
  1321. inside: {
  1322. 'keyword': keywords,
  1323. 'class-name': {
  1324. pattern: RegExp(typeExpression),
  1325. greedy: true,
  1326. inside: typeInside
  1327. },
  1328. 'punctuation': /,/
  1329. }
  1330. },
  1331. 'preprocessor': {
  1332. pattern: /(^\s*)#.*/m,
  1333. lookbehind: true,
  1334. alias: 'property',
  1335. inside: {
  1336. // highlight preprocessor directives as keywords
  1337. 'directive': {
  1338. pattern: /(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
  1339. lookbehind: true,
  1340. alias: 'keyword'
  1341. }
  1342. }
  1343. }
  1344. });
  1345. // attributes
  1346. var regularStringOrCharacter = regularString + '|' + character;
  1347. var regularStringCharacterOrComment = replace(/\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>/.source, [regularStringOrCharacter]);
  1348. var roundExpression = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
  1349. // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/#attribute-targets
  1350. var attrTarget = /\b(?:assembly|event|field|method|module|param|property|return|type)\b/.source;
  1351. var attr = replace(/<<0>>(?:\s*\(<<1>>*\))?/.source, [identifier, roundExpression]);
  1352. Prism.languages.insertBefore('csharp', 'class-name', {
  1353. 'attribute': {
  1354. // Attributes
  1355. // [Foo], [Foo(1), Bar(2, Prop = "foo")], [return: Foo(1), Bar(2)], [assembly: Foo(Bar)]
  1356. pattern: re(/((?:^|[^\s\w>)?])\s*\[\s*)(?:<<0>>\s*:\s*)?<<1>>(?:\s*,\s*<<1>>)*(?=\s*\])/.source, [attrTarget, attr]),
  1357. lookbehind: true,
  1358. greedy: true,
  1359. inside: {
  1360. 'target': {
  1361. pattern: re(/^<<0>>(?=\s*:)/.source, [attrTarget]),
  1362. alias: 'keyword'
  1363. },
  1364. 'attribute-arguments': {
  1365. pattern: re(/\(<<0>>*\)/.source, [roundExpression]),
  1366. inside: Prism.languages.csharp
  1367. },
  1368. 'class-name': {
  1369. pattern: RegExp(identifier),
  1370. inside: {
  1371. 'punctuation': /\./
  1372. }
  1373. },
  1374. 'punctuation': /[:,]/
  1375. }
  1376. }
  1377. });
  1378. // string interpolation
  1379. var formatString = /:[^}\r\n]+/.source;
  1380. // multi line
  1381. var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2)
  1382. var mInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [mInterpolationRound, formatString]);
  1383. // single line
  1384. var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<<self>>*\)/.source, [regularStringOrCharacter]), 2)
  1385. var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [sInterpolationRound, formatString]);
  1386. function createInterpolationInside(interpolation, interpolationRound) {
  1387. return {
  1388. 'interpolation': {
  1389. pattern: re(/((?:^|[^{])(?:\{\{)*)<<0>>/.source, [interpolation]),
  1390. lookbehind: true,
  1391. inside: {
  1392. 'format-string': {
  1393. pattern: re(/(^\{(?:(?![}:])<<0>>)*)<<1>>(?=\}$)/.source, [interpolationRound, formatString]),
  1394. lookbehind: true,
  1395. inside: {
  1396. 'punctuation': /^:/
  1397. }
  1398. },
  1399. 'punctuation': /^\{|\}$/,
  1400. 'expression': {
  1401. pattern: /[\s\S]+/,
  1402. alias: 'language-csharp',
  1403. inside: Prism.languages.csharp
  1404. }
  1405. }
  1406. },
  1407. 'string': /[\s\S]+/
  1408. };
  1409. }
  1410. Prism.languages.insertBefore('csharp', 'string', {
  1411. 'interpolation-string': [
  1412. {
  1413. pattern: re(/(^|[^\\])(?:\$@|@\$)"(?:""|\\[\s\S]|\{\{|<<0>>|[^\\{"])*"/.source, [mInterpolation]),
  1414. lookbehind: true,
  1415. greedy: true,
  1416. inside: createInterpolationInside(mInterpolation, mInterpolationRound),
  1417. },
  1418. {
  1419. pattern: re(/(^|[^@\\])\$"(?:\\.|\{\{|<<0>>|[^\\"{])*"/.source, [sInterpolation]),
  1420. lookbehind: true,
  1421. greedy: true,
  1422. inside: createInterpolationInside(sInterpolation, sInterpolationRound),
  1423. }
  1424. ]
  1425. });
  1426. }(Prism));
  1427. Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp;
  1428. Prism.languages.gcode = {
  1429. 'comment': /;.*|\B\(.*?\)\B/,
  1430. 'string': {
  1431. pattern: /"(?:""|[^"])*"/,
  1432. greedy: true
  1433. },
  1434. 'keyword': /\b[GM]\d+(?:\.\d+)?\b/,
  1435. 'property': /\b[A-Z]/,
  1436. 'checksum': {
  1437. pattern: /\*\d+/,
  1438. alias: 'punctuation'
  1439. },
  1440. // T0:0:0
  1441. 'punctuation': /:/
  1442. };
  1443. // https://www.json.org/json-en.html
  1444. Prism.languages.json = {
  1445. 'property': {
  1446. pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
  1447. greedy: true
  1448. },
  1449. 'string': {
  1450. pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  1451. greedy: true
  1452. },
  1453. 'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
  1454. 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
  1455. 'punctuation': /[{}[\],]/,
  1456. 'operator': /:/,
  1457. 'boolean': /\b(?:true|false)\b/,
  1458. 'null': {
  1459. pattern: /\bnull\b/,
  1460. alias: 'keyword'
  1461. }
  1462. };
  1463. Prism.languages.webmanifest = Prism.languages.json;
  1464. /* FIXME :
  1465. :extend() is not handled specifically : its highlighting is buggy.
  1466. Mixin usage must be inside a ruleset to be highlighted.
  1467. At-rules (e.g. import) containing interpolations are buggy.
  1468. Detached rulesets are highlighted as at-rules.
  1469. A comment before a mixin usage prevents the latter to be properly highlighted.
  1470. */
  1471. Prism.languages.less = Prism.languages.extend('css', {
  1472. 'comment': [
  1473. /\/\*[\s\S]*?\*\//,
  1474. {
  1475. pattern: /(^|[^\\])\/\/.*/,
  1476. lookbehind: true
  1477. }
  1478. ],
  1479. 'atrule': {
  1480. pattern: /@[\w-]+?(?:\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};])*?(?=\s*\{)/,
  1481. inside: {
  1482. 'punctuation': /[:()]/
  1483. }
  1484. },
  1485. // selectors and mixins are considered the same
  1486. 'selector': {
  1487. pattern: /(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};@])*?(?=\s*\{)/,
  1488. inside: {
  1489. // mixin parameters
  1490. 'variable': /@+[\w-]+/
  1491. }
  1492. },
  1493. 'property': /(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/i,
  1494. 'operator': /[+\-*\/]/
  1495. });
  1496. Prism.languages.insertBefore('less', 'property', {
  1497. 'variable': [
  1498. // Variable declaration (the colon must be consumed!)
  1499. {
  1500. pattern: /@[\w-]+\s*:/,
  1501. inside: {
  1502. "punctuation": /:/
  1503. }
  1504. },
  1505. // Variable usage
  1506. /@@?[\w-]+/
  1507. ],
  1508. 'mixin-usage': {
  1509. pattern: /([{;]\s*)[.#](?!\d)[\w-]+.*?(?=[(;])/,
  1510. lookbehind: true,
  1511. alias: 'function'
  1512. }
  1513. });
  1514. Prism.languages.lua = {
  1515. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  1516. // \z may be used to skip the following space
  1517. 'string': {
  1518. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[\s\S]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  1519. greedy: true
  1520. },
  1521. 'number': /\b0x[a-f\d]+\.?[a-f\d]*(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|\.?\d*(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  1522. 'keyword': /\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/,
  1523. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  1524. 'operator': [
  1525. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  1526. {
  1527. // Match ".." but don't break "..."
  1528. pattern: /(^|[^.])\.\.(?!\.)/,
  1529. lookbehind: true
  1530. }
  1531. ],
  1532. 'punctuation': /[\[\](){},;]|\.+|:+/
  1533. };
  1534. (function (Prism) {
  1535. // Allow only one line break
  1536. var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?!\n|\r\n?))/.source;
  1537. /**
  1538. * This function is intended for the creation of the bold or italic pattern.
  1539. *
  1540. * This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
  1541. *
  1542. * _Note:_ Keep in mind that this adds a capturing group.
  1543. *
  1544. * @param {string} pattern
  1545. * @returns {RegExp}
  1546. */
  1547. function createInline(pattern) {
  1548. pattern = pattern.replace(/<inner>/g, function () { return inner; });
  1549. return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')');
  1550. }
  1551. var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
  1552. var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|$)/.source.replace(/__/g, function () { return tableCell; });
  1553. var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
  1554. Prism.languages.markdown = Prism.languages.extend('markup', {});
  1555. Prism.languages.insertBefore('markdown', 'prolog', {
  1556. 'blockquote': {
  1557. // > ...
  1558. pattern: /^>(?:[\t ]*>)*/m,
  1559. alias: 'punctuation'
  1560. },
  1561. 'table': {
  1562. pattern: RegExp('^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm'),
  1563. inside: {
  1564. 'table-data-rows': {
  1565. pattern: RegExp('^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$'),
  1566. lookbehind: true,
  1567. inside: {
  1568. 'table-data': {
  1569. pattern: RegExp(tableCell),
  1570. inside: Prism.languages.markdown
  1571. },
  1572. 'punctuation': /\|/
  1573. }
  1574. },
  1575. 'table-line': {
  1576. pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'),
  1577. lookbehind: true,
  1578. inside: {
  1579. 'punctuation': /\||:?-{3,}:?/
  1580. }
  1581. },
  1582. 'table-header-row': {
  1583. pattern: RegExp('^' + tableRow + '$'),
  1584. inside: {
  1585. 'table-header': {
  1586. pattern: RegExp(tableCell),
  1587. alias: 'important',
  1588. inside: Prism.languages.markdown
  1589. },
  1590. 'punctuation': /\|/
  1591. }
  1592. }
  1593. }
  1594. },
  1595. 'code': [
  1596. {
  1597. // Prefixed by 4 spaces or 1 tab and preceded by an empty line
  1598. pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
  1599. lookbehind: true,
  1600. alias: 'keyword'
  1601. },
  1602. {
  1603. // `code`
  1604. // ``code``
  1605. pattern: /``.+?``|`[^`\r\n]+`/,
  1606. alias: 'keyword'
  1607. },
  1608. {
  1609. // ```optional language
  1610. // code block
  1611. // ```
  1612. pattern: /^```[\s\S]*?^```$/m,
  1613. greedy: true,
  1614. inside: {
  1615. 'code-block': {
  1616. pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
  1617. lookbehind: true
  1618. },
  1619. 'code-language': {
  1620. pattern: /^(```).+/,
  1621. lookbehind: true
  1622. },
  1623. 'punctuation': /```/
  1624. }
  1625. }
  1626. ],
  1627. 'title': [
  1628. {
  1629. // title 1
  1630. // =======
  1631. // title 2
  1632. // -------
  1633. pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
  1634. alias: 'important',
  1635. inside: {
  1636. punctuation: /==+$|--+$/
  1637. }
  1638. },
  1639. {
  1640. // # title 1
  1641. // ###### title 6
  1642. pattern: /(^\s*)#+.+/m,
  1643. lookbehind: true,
  1644. alias: 'important',
  1645. inside: {
  1646. punctuation: /^#+|#+$/
  1647. }
  1648. }
  1649. ],
  1650. 'hr': {
  1651. // ***
  1652. // ---
  1653. // * * *
  1654. // -----------
  1655. pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
  1656. lookbehind: true,
  1657. alias: 'punctuation'
  1658. },
  1659. 'list': {
  1660. // * item
  1661. // + item
  1662. // - item
  1663. // 1. item
  1664. pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
  1665. lookbehind: true,
  1666. alias: 'punctuation'
  1667. },
  1668. 'url-reference': {
  1669. // [id]: http://example.com "Optional title"
  1670. // [id]: http://example.com 'Optional title'
  1671. // [id]: http://example.com (Optional title)
  1672. // [id]: <http://example.com> "Optional title"
  1673. pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
  1674. inside: {
  1675. 'variable': {
  1676. pattern: /^(!?\[)[^\]]+/,
  1677. lookbehind: true
  1678. },
  1679. 'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
  1680. 'punctuation': /^[\[\]!:]|[<>]/
  1681. },
  1682. alias: 'url'
  1683. },
  1684. 'bold': {
  1685. // **strong**
  1686. // __strong__
  1687. // allow one nested instance of italic text using the same delimiter
  1688. pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
  1689. lookbehind: true,
  1690. greedy: true,
  1691. inside: {
  1692. 'content': {
  1693. pattern: /(^..)[\s\S]+(?=..$)/,
  1694. lookbehind: true,
  1695. inside: {} // see below
  1696. },
  1697. 'punctuation': /\*\*|__/
  1698. }
  1699. },
  1700. 'italic': {
  1701. // *em*
  1702. // _em_
  1703. // allow one nested instance of bold text using the same delimiter
  1704. pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
  1705. lookbehind: true,
  1706. greedy: true,
  1707. inside: {
  1708. 'content': {
  1709. pattern: /(^.)[\s\S]+(?=.$)/,
  1710. lookbehind: true,
  1711. inside: {} // see below
  1712. },
  1713. 'punctuation': /[*_]/
  1714. }
  1715. },
  1716. 'strike': {
  1717. // ~~strike through~~
  1718. // ~strike~
  1719. pattern: createInline(/(~~?)(?:(?!~)<inner>)+?\2/.source),
  1720. lookbehind: true,
  1721. greedy: true,
  1722. inside: {
  1723. 'content': {
  1724. pattern: /(^~~?)[\s\S]+(?=\1$)/,
  1725. lookbehind: true,
  1726. inside: {} // see below
  1727. },
  1728. 'punctuation': /~~?/
  1729. }
  1730. },
  1731. 'url': {
  1732. // [example](http://example.com "Optional title")
  1733. // [example][id]
  1734. // [example] [id]
  1735. pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)| ?\[(?:(?!\])<inner>)+\])/.source),
  1736. lookbehind: true,
  1737. greedy: true,
  1738. inside: {
  1739. 'variable': {
  1740. pattern: /(\[)[^\]]+(?=\]$)/,
  1741. lookbehind: true
  1742. },
  1743. 'content': {
  1744. pattern: /(^!?\[)[^\]]+(?=\])/,
  1745. lookbehind: true,
  1746. inside: {} // see below
  1747. },
  1748. 'string': {
  1749. pattern: /"(?:\\.|[^"\\])*"(?=\)$)/
  1750. }
  1751. }
  1752. }
  1753. });
  1754. ['url', 'bold', 'italic', 'strike'].forEach(function (token) {
  1755. ['url', 'bold', 'italic', 'strike'].forEach(function (inside) {
  1756. if (token !== inside) {
  1757. Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
  1758. }
  1759. });
  1760. });
  1761. Prism.hooks.add('after-tokenize', function (env) {
  1762. if (env.language !== 'markdown' && env.language !== 'md') {
  1763. return;
  1764. }
  1765. function walkTokens(tokens) {
  1766. if (!tokens || typeof tokens === 'string') {
  1767. return;
  1768. }
  1769. for (var i = 0, l = tokens.length; i < l; i++) {
  1770. var token = tokens[i];
  1771. if (token.type !== 'code') {
  1772. walkTokens(token.content);
  1773. continue;
  1774. }
  1775. /*
  1776. * Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
  1777. * is optional. But the grammar is defined so that there is only one case we have to handle:
  1778. *
  1779. * token.content = [
  1780. * <span class="punctuation">```</span>,
  1781. * <span class="code-language">xxxx</span>,
  1782. * '\n', // exactly one new lines (\r or \n or \r\n)
  1783. * <span class="code-block">...</span>,
  1784. * '\n', // exactly one new lines again
  1785. * <span class="punctuation">```</span>
  1786. * ];
  1787. */
  1788. var codeLang = token.content[1];
  1789. var codeBlock = token.content[3];
  1790. if (codeLang && codeBlock &&
  1791. codeLang.type === 'code-language' && codeBlock.type === 'code-block' &&
  1792. typeof codeLang.content === 'string') {
  1793. // this might be a language that Prism does not support
  1794. // do some replacements to support C++, C#, and F#
  1795. var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp')
  1796. // only use the first word
  1797. lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase();
  1798. var alias = 'language-' + lang;
  1799. // add alias
  1800. if (!codeBlock.alias) {
  1801. codeBlock.alias = [alias];
  1802. } else if (typeof codeBlock.alias === 'string') {
  1803. codeBlock.alias = [codeBlock.alias, alias];
  1804. } else {
  1805. codeBlock.alias.push(alias);
  1806. }
  1807. }
  1808. }
  1809. }
  1810. walkTokens(env.tokens);
  1811. });
  1812. Prism.hooks.add('wrap', function (env) {
  1813. if (env.type !== 'code-block') {
  1814. return;
  1815. }
  1816. var codeLang = '';
  1817. for (var i = 0, l = env.classes.length; i < l; i++) {
  1818. var cls = env.classes[i];
  1819. var match = /language-(.+)/.exec(cls);
  1820. if (match) {
  1821. codeLang = match[1];
  1822. break;
  1823. }
  1824. }
  1825. var grammar = Prism.languages[codeLang];
  1826. if (!grammar) {
  1827. if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) {
  1828. var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16);
  1829. env.attributes['id'] = id;
  1830. Prism.plugins.autoloader.loadLanguages(codeLang, function () {
  1831. var ele = document.getElementById(id);
  1832. if (ele) {
  1833. ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
  1834. }
  1835. });
  1836. }
  1837. } else {
  1838. // reverse Prism.util.encode
  1839. var code = env.content.replace(/&lt;/g, '<').replace(/&amp;/g, '&');
  1840. env.content = Prism.highlight(code, grammar, codeLang);
  1841. }
  1842. });
  1843. Prism.languages.md = Prism.languages.markdown;
  1844. }(Prism));
  1845. (function (Prism) {
  1846. /**
  1847. * Returns the placeholder for the given language id and index.
  1848. *
  1849. * @param {string} language
  1850. * @param {string|number} index
  1851. * @returns {string}
  1852. */
  1853. function getPlaceholder(language, index) {
  1854. return '___' + language.toUpperCase() + index + '___';
  1855. }
  1856. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  1857. buildPlaceholders: {
  1858. /**
  1859. * Tokenize all inline templating expressions matching `placeholderPattern`.
  1860. *
  1861. * If `replaceFilter` is provided, only matches of `placeholderPattern` for which `replaceFilter` returns
  1862. * `true` will be replaced.
  1863. *
  1864. * @param {object} env The environment of the `before-tokenize` hook.
  1865. * @param {string} language The language id.
  1866. * @param {RegExp} placeholderPattern The matches of this pattern will be replaced by placeholders.
  1867. * @param {(match: string) => boolean} [replaceFilter]
  1868. */
  1869. value: function (env, language, placeholderPattern, replaceFilter) {
  1870. if (env.language !== language) {
  1871. return;
  1872. }
  1873. var tokenStack = env.tokenStack = [];
  1874. env.code = env.code.replace(placeholderPattern, function (match) {
  1875. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  1876. return match;
  1877. }
  1878. var i = tokenStack.length;
  1879. var placeholder;
  1880. // Check for existing strings
  1881. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1)
  1882. ++i;
  1883. // Create a sparse array
  1884. tokenStack[i] = match;
  1885. return placeholder;
  1886. });
  1887. // Switch the grammar to markup
  1888. env.grammar = Prism.languages.markup;
  1889. }
  1890. },
  1891. tokenizePlaceholders: {
  1892. /**
  1893. * Replace placeholders with proper tokens after tokenizing.
  1894. *
  1895. * @param {object} env The environment of the `after-tokenize` hook.
  1896. * @param {string} language The language id.
  1897. */
  1898. value: function (env, language) {
  1899. if (env.language !== language || !env.tokenStack) {
  1900. return;
  1901. }
  1902. // Switch the grammar back
  1903. env.grammar = Prism.languages[language];
  1904. var j = 0;
  1905. var keys = Object.keys(env.tokenStack);
  1906. function walkTokens(tokens) {
  1907. for (var i = 0; i < tokens.length; i++) {
  1908. // all placeholders are replaced already
  1909. if (j >= keys.length) {
  1910. break;
  1911. }
  1912. var token = tokens[i];
  1913. if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
  1914. var k = keys[j];
  1915. var t = env.tokenStack[k];
  1916. var s = typeof token === 'string' ? token : token.content;
  1917. var placeholder = getPlaceholder(language, k);
  1918. var index = s.indexOf(placeholder);
  1919. if (index > -1) {
  1920. ++j;
  1921. var before = s.substring(0, index);
  1922. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  1923. var after = s.substring(index + placeholder.length);
  1924. var replacement = [];
  1925. if (before) {
  1926. replacement.push.apply(replacement, walkTokens([before]));
  1927. }
  1928. replacement.push(middle);
  1929. if (after) {
  1930. replacement.push.apply(replacement, walkTokens([after]));
  1931. }
  1932. if (typeof token === 'string') {
  1933. tokens.splice.apply(tokens, [i, 1].concat(replacement));
  1934. } else {
  1935. token.content = replacement;
  1936. }
  1937. }
  1938. } else if (token.content /* && typeof token.content !== 'string' */) {
  1939. walkTokens(token.content);
  1940. }
  1941. }
  1942. return tokens;
  1943. }
  1944. walkTokens(env.tokens);
  1945. }
  1946. }
  1947. });
  1948. }(Prism));
  1949. /**
  1950. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  1951. * Modified by Miles Johnson: http://milesj.me
  1952. *
  1953. * Supports the following:
  1954. * - Extends clike syntax
  1955. * - Support for PHP 5.3+ (namespaces, traits, generators, etc)
  1956. * - Smarter constant and function matching
  1957. *
  1958. * Adds the following new token classes:
  1959. * constant, delimiter, variable, function, package
  1960. */
  1961. (function (Prism) {
  1962. Prism.languages.php = Prism.languages.extend('clike', {
  1963. 'keyword': /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,
  1964. 'boolean': {
  1965. pattern: /\b(?:false|true)\b/i,
  1966. alias: 'constant'
  1967. },
  1968. 'constant': [
  1969. /\b[A-Z_][A-Z0-9_]*\b/,
  1970. /\b(?:null)\b/i,
  1971. ],
  1972. 'comment': {
  1973. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1974. lookbehind: true
  1975. }
  1976. });
  1977. Prism.languages.insertBefore('php', 'string', {
  1978. 'shell-comment': {
  1979. pattern: /(^|[^\\])#.*/,
  1980. lookbehind: true,
  1981. alias: 'comment'
  1982. }
  1983. });
  1984. Prism.languages.insertBefore('php', 'comment', {
  1985. 'delimiter': {
  1986. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  1987. alias: 'important'
  1988. }
  1989. });
  1990. Prism.languages.insertBefore('php', 'keyword', {
  1991. 'variable': /\$+(?:\w+\b|(?={))/i,
  1992. 'package': {
  1993. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  1994. lookbehind: true,
  1995. inside: {
  1996. punctuation: /\\/
  1997. }
  1998. }
  1999. });
  2000. // Must be defined after the function pattern
  2001. Prism.languages.insertBefore('php', 'operator', {
  2002. 'property': {
  2003. pattern: /(->)[\w]+/,
  2004. lookbehind: true
  2005. }
  2006. });
  2007. var string_interpolation = {
  2008. pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,
  2009. lookbehind: true,
  2010. inside: Prism.languages.php
  2011. };
  2012. Prism.languages.insertBefore('php', 'string', {
  2013. 'nowdoc-string': {
  2014. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  2015. greedy: true,
  2016. alias: 'string',
  2017. inside: {
  2018. 'delimiter': {
  2019. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  2020. alias: 'symbol',
  2021. inside: {
  2022. 'punctuation': /^<<<'?|[';]$/
  2023. }
  2024. }
  2025. }
  2026. },
  2027. 'heredoc-string': {
  2028. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  2029. greedy: true,
  2030. alias: 'string',
  2031. inside: {
  2032. 'delimiter': {
  2033. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  2034. alias: 'symbol',
  2035. inside: {
  2036. 'punctuation': /^<<<"?|[";]$/
  2037. }
  2038. },
  2039. 'interpolation': string_interpolation // See below
  2040. }
  2041. },
  2042. 'single-quoted-string': {
  2043. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  2044. greedy: true,
  2045. alias: 'string'
  2046. },
  2047. 'double-quoted-string': {
  2048. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  2049. greedy: true,
  2050. alias: 'string',
  2051. inside: {
  2052. 'interpolation': string_interpolation // See below
  2053. }
  2054. }
  2055. });
  2056. // The different types of PHP strings "replace" the C-like standard string
  2057. delete Prism.languages.php['string'];
  2058. Prism.hooks.add('before-tokenize', function(env) {
  2059. if (!/<\?/.test(env.code)) {
  2060. return;
  2061. }
  2062. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig;
  2063. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  2064. });
  2065. Prism.hooks.add('after-tokenize', function(env) {
  2066. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  2067. });
  2068. }(Prism));
  2069. Prism.languages.processing = Prism.languages.extend('clike', {
  2070. 'keyword': /\b(?:break|catch|case|class|continue|default|else|extends|final|for|if|implements|import|new|null|private|public|return|static|super|switch|this|try|void|while)\b/,
  2071. 'operator': /<[<=]?|>[>=]?|&&?|\|\|?|[%?]|[!=+\-*\/]=?/
  2072. });
  2073. Prism.languages.insertBefore('processing', 'number', {
  2074. // Special case: XML is a type
  2075. 'constant': /\b(?!XML\b)[A-Z][A-Z\d_]+\b/,
  2076. 'type': {
  2077. pattern: /\b(?:boolean|byte|char|color|double|float|int|XML|[A-Z]\w*)\b/,
  2078. alias: 'variable'
  2079. }
  2080. });
  2081. // Spaces are allowed between function name and parenthesis
  2082. Prism.languages.processing['function'].pattern = /\w+(?=\s*\()/;
  2083. // Class-names is not styled by default
  2084. Prism.languages.processing['class-name'].alias = 'variable';
  2085. Prism.languages.python = {
  2086. 'comment': {
  2087. pattern: /(^|[^\\])#.*/,
  2088. lookbehind: true
  2089. },
  2090. 'string-interpolation': {
  2091. pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  2092. greedy: true,
  2093. inside: {
  2094. 'interpolation': {
  2095. // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
  2096. pattern: /((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,
  2097. lookbehind: true,
  2098. inside: {
  2099. 'format-spec': {
  2100. pattern: /(:)[^:(){}]+(?=}$)/,
  2101. lookbehind: true
  2102. },
  2103. 'conversion-option': {
  2104. pattern: /![sra](?=[:}]$)/,
  2105. alias: 'punctuation'
  2106. },
  2107. rest: null
  2108. }
  2109. },
  2110. 'string': /[\s\S]+/
  2111. }
  2112. },
  2113. 'triple-quoted-string': {
  2114. pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,
  2115. greedy: true,
  2116. alias: 'string'
  2117. },
  2118. 'string': {
  2119. pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  2120. greedy: true
  2121. },
  2122. 'function': {
  2123. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  2124. lookbehind: true
  2125. },
  2126. 'class-name': {
  2127. pattern: /(\bclass\s+)\w+/i,
  2128. lookbehind: true
  2129. },
  2130. 'decorator': {
  2131. pattern: /(^\s*)@\w+(?:\.\w+)*/im,
  2132. lookbehind: true,
  2133. alias: ['annotation', 'punctuation'],
  2134. inside: {
  2135. 'punctuation': /\./
  2136. }
  2137. },
  2138. 'keyword': /\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
  2139. '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/,
  2140. 'boolean': /\b(?:True|False|None)\b/,
  2141. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  2142. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  2143. 'punctuation': /[{}[\];(),.:]/
  2144. };
  2145. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  2146. Prism.languages.py = Prism.languages.python;
  2147. (function (Prism) {
  2148. Prism.languages.typescript = Prism.languages.extend('javascript', {
  2149. 'class-name': {
  2150. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
  2151. lookbehind: true,
  2152. greedy: true,
  2153. inside: null // see below
  2154. },
  2155. // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
  2156. 'keyword': /\b(?:abstract|as|asserts|async|await|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|null|of|package|private|protected|public|readonly|return|require|set|static|super|switch|this|throw|try|type|typeof|undefined|var|void|while|with|yield)\b/,
  2157. 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
  2158. });
  2159. // doesn't work with TS because TS is too complex
  2160. delete Prism.languages.typescript['parameter'];
  2161. // a version of typescript specifically for highlighting types
  2162. var typeInside = Prism.languages.extend('typescript', {});
  2163. delete typeInside['class-name'];
  2164. Prism.languages.typescript['class-name'].inside = typeInside;
  2165. Prism.languages.insertBefore('typescript', 'function', {
  2166. 'generic-function': {
  2167. // e.g. foo<T extends "bar" | "baz">( ...
  2168. pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
  2169. greedy: true,
  2170. inside: {
  2171. 'function': /^#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*/,
  2172. 'generic': {
  2173. pattern: /<[\s\S]+/, // everything after the first <
  2174. alias: 'class-name',
  2175. inside: typeInside
  2176. }
  2177. }
  2178. }
  2179. });
  2180. Prism.languages.ts = Prism.languages.typescript;
  2181. }(Prism));
  2182. (function (Prism) {
  2183. var specialEscape = {
  2184. pattern: /\\[\\(){}[\]^$+*?|.]/,
  2185. alias: 'escape'
  2186. };
  2187. var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|c[a-zA-Z]|0[0-7]{0,2}|[123][0-7]{2}|.)/;
  2188. var charClass = {
  2189. pattern: /\.|\\[wsd]|\\p{[^{}]+}/i,
  2190. alias: 'class-name'
  2191. };
  2192. var charClassWithoutDot = {
  2193. pattern: /\\[wsd]|\\p{[^{}]+}/i,
  2194. alias: 'class-name'
  2195. };
  2196. var rangeChar = '(?:[^\\\\-]|' + escape.source + ')';
  2197. var range = RegExp(rangeChar + '-' + rangeChar);
  2198. // the name of a capturing group
  2199. var groupName = {
  2200. pattern: /(<|')[^<>']+(?=[>']$)/,
  2201. lookbehind: true,
  2202. alias: 'variable'
  2203. };
  2204. Prism.languages.regex = {
  2205. 'charset': {
  2206. pattern: /((?:^|[^\\])(?:\\\\)*)\[(?:[^\\\]]|\\[\s\S])*\]/,
  2207. lookbehind: true,
  2208. inside: {
  2209. 'charset-negation': {
  2210. pattern: /(^\[)\^/,
  2211. lookbehind: true,
  2212. alias: 'operator'
  2213. },
  2214. 'charset-punctuation': {
  2215. pattern: /^\[|\]$/,
  2216. alias: 'punctuation'
  2217. },
  2218. 'range': {
  2219. pattern: range,
  2220. inside: {
  2221. 'escape': escape,
  2222. 'range-punctuation': {
  2223. pattern: /-/,
  2224. alias: 'operator'
  2225. }
  2226. }
  2227. },
  2228. 'special-escape': specialEscape,
  2229. 'charclass': charClassWithoutDot,
  2230. 'escape': escape
  2231. }
  2232. },
  2233. 'special-escape': specialEscape,
  2234. 'charclass': charClass,
  2235. 'backreference': [
  2236. {
  2237. // a backreference which is not an octal escape
  2238. pattern: /\\(?![123][0-7]{2})[1-9]/,
  2239. alias: 'keyword'
  2240. },
  2241. {
  2242. pattern: /\\k<[^<>']+>/,
  2243. alias: 'keyword',
  2244. inside: {
  2245. 'group-name': groupName
  2246. }
  2247. }
  2248. ],
  2249. 'anchor': {
  2250. pattern: /[$^]|\\[ABbGZz]/,
  2251. alias: 'function'
  2252. },
  2253. 'escape': escape,
  2254. 'group': [
  2255. {
  2256. // https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html
  2257. // https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference?view=netframework-4.7.2#grouping-constructs
  2258. // (), (?<name>), (?'name'), (?>), (?:), (?=), (?!), (?<=), (?<!), (?is-m), (?i-m:)
  2259. pattern: /\((?:\?(?:<[^<>']+>|'[^<>']+'|[>:]|<?[=!]|[idmnsuxU]+(?:-[idmnsuxU]+)?:?))?/,
  2260. alias: 'punctuation',
  2261. inside: {
  2262. 'group-name': groupName
  2263. }
  2264. },
  2265. {
  2266. pattern: /\)/,
  2267. alias: 'punctuation'
  2268. }
  2269. ],
  2270. 'quantifier': {
  2271. pattern: /(?:[+*?]|\{(?:\d+,?\d*)\})[?+]?/,
  2272. alias: 'number'
  2273. },
  2274. 'alternation': {
  2275. pattern: /\|/,
  2276. alias: 'keyword'
  2277. }
  2278. };
  2279. [
  2280. 'actionscript',
  2281. 'coffescript',
  2282. 'flow',
  2283. 'javascript',
  2284. 'typescript',
  2285. 'vala'
  2286. ].forEach(function (lang) {
  2287. var grammar = Prism.languages[lang];
  2288. if (grammar) {
  2289. grammar['regex'].inside = {
  2290. 'language-regex': {
  2291. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/i,
  2292. lookbehind: true,
  2293. inside: Prism.languages.regex
  2294. },
  2295. 'regex-flags': /[a-z]+$/i,
  2296. 'regex-delimiter': /^\/|\/$/,
  2297. };
  2298. }
  2299. });
  2300. }(Prism))
  2301. ;
  2302. /**
  2303. * Original by Samuel Flores
  2304. *
  2305. * Adds the following new token classes:
  2306. * constant, builtin, variable, symbol, regex
  2307. */
  2308. (function (Prism) {
  2309. Prism.languages.ruby = Prism.languages.extend('clike', {
  2310. 'comment': [
  2311. /#.*/,
  2312. {
  2313. pattern: /^=begin\s[\s\S]*?^=end/m,
  2314. greedy: true
  2315. }
  2316. ],
  2317. 'class-name': {
  2318. pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
  2319. lookbehind: true,
  2320. inside: {
  2321. 'punctuation': /[.\\]/
  2322. }
  2323. },
  2324. 'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/
  2325. });
  2326. var interpolation = {
  2327. pattern: /#\{[^}]+\}/,
  2328. inside: {
  2329. 'delimiter': {
  2330. pattern: /^#\{|\}$/,
  2331. alias: 'tag'
  2332. },
  2333. rest: Prism.languages.ruby
  2334. }
  2335. };
  2336. delete Prism.languages.ruby.function;
  2337. Prism.languages.insertBefore('ruby', 'keyword', {
  2338. 'regex': [
  2339. {
  2340. pattern: RegExp(/%r/.source + '(?:' + [
  2341. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/.source,
  2342. /\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/.source,
  2343. // Here we need to specifically allow interpolation
  2344. /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/.source,
  2345. /\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/.source,
  2346. /<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/.source
  2347. ].join('|') + ')'),
  2348. greedy: true,
  2349. inside: {
  2350. 'interpolation': interpolation
  2351. }
  2352. },
  2353. {
  2354. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[gim]{0,3}(?=\s*(?:$|[\r\n,.;})]))/,
  2355. lookbehind: true,
  2356. greedy: true
  2357. }
  2358. ],
  2359. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  2360. 'symbol': {
  2361. pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
  2362. lookbehind: true
  2363. },
  2364. 'method-definition': {
  2365. pattern: /(\bdef\s+)[\w.]+/,
  2366. lookbehind: true,
  2367. inside: {
  2368. 'function': /\w+$/,
  2369. rest: Prism.languages.ruby
  2370. }
  2371. }
  2372. });
  2373. Prism.languages.insertBefore('ruby', 'number', {
  2374. 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
  2375. 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
  2376. });
  2377. Prism.languages.ruby.string = [
  2378. {
  2379. pattern: RegExp(/%[qQiIwWxs]?/.source + '(?:' + [
  2380. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  2381. /\((?:[^()\\]|\\[\s\S])*\)/.source,
  2382. // Here we need to specifically allow interpolation
  2383. /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
  2384. /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
  2385. /<(?:[^<>\\]|\\[\s\S])*>/.source
  2386. ].join('|') + ')'),
  2387. greedy: true,
  2388. inside: {
  2389. 'interpolation': interpolation
  2390. }
  2391. },
  2392. {
  2393. pattern: /("|')(?:#\{[^}]+\}|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2394. greedy: true,
  2395. inside: {
  2396. 'interpolation': interpolation
  2397. }
  2398. }
  2399. ];
  2400. Prism.languages.rb = Prism.languages.ruby;
  2401. }(Prism));
  2402. (function(Prism) {
  2403. Prism.languages.sass = Prism.languages.extend('css', {
  2404. // Sass comments don't need to be closed, only indented
  2405. 'comment': {
  2406. pattern: /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t]+.+)*/m,
  2407. lookbehind: true
  2408. }
  2409. });
  2410. Prism.languages.insertBefore('sass', 'atrule', {
  2411. // We want to consume the whole line
  2412. 'atrule-line': {
  2413. // Includes support for = and + shortcuts
  2414. pattern: /^(?:[ \t]*)[@+=].+/m,
  2415. inside: {
  2416. 'atrule': /(?:@[\w-]+|[+=])/m
  2417. }
  2418. }
  2419. });
  2420. delete Prism.languages.sass.atrule;
  2421. var variable = /\$[-\w]+|#\{\$[-\w]+\}/;
  2422. var operator = [
  2423. /[+*\/%]|[=!]=|<=?|>=?|\b(?:and|or|not)\b/,
  2424. {
  2425. pattern: /(\s+)-(?=\s)/,
  2426. lookbehind: true
  2427. }
  2428. ];
  2429. Prism.languages.insertBefore('sass', 'property', {
  2430. // We want to consume the whole line
  2431. 'variable-line': {
  2432. pattern: /^[ \t]*\$.+/m,
  2433. inside: {
  2434. 'punctuation': /:/,
  2435. 'variable': variable,
  2436. 'operator': operator
  2437. }
  2438. },
  2439. // We want to consume the whole line
  2440. 'property-line': {
  2441. pattern: /^[ \t]*(?:[^:\s]+ *:.*|:[^:\s]+.*)/m,
  2442. inside: {
  2443. 'property': [
  2444. /[^:\s]+(?=\s*:)/,
  2445. {
  2446. pattern: /(:)[^:\s]+/,
  2447. lookbehind: true
  2448. }
  2449. ],
  2450. 'punctuation': /:/,
  2451. 'variable': variable,
  2452. 'operator': operator,
  2453. 'important': Prism.languages.sass.important
  2454. }
  2455. }
  2456. });
  2457. delete Prism.languages.sass.property;
  2458. delete Prism.languages.sass.important;
  2459. // Now that whole lines for other patterns are consumed,
  2460. // what's left should be selectors
  2461. Prism.languages.insertBefore('sass', 'punctuation', {
  2462. 'selector': {
  2463. pattern: /([ \t]*)\S(?:,?[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,?[^,\r\n]+)*)*/,
  2464. lookbehind: true
  2465. }
  2466. });
  2467. }(Prism));
  2468. // issues: nested multiline comments
  2469. Prism.languages.swift = Prism.languages.extend('clike', {
  2470. 'string': {
  2471. pattern: /("|')(?:\\(?:\((?:[^()]|\([^)]+\))+\)|\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2472. greedy: true,
  2473. inside: {
  2474. 'interpolation': {
  2475. pattern: /\\\((?:[^()]|\([^)]+\))+\)/,
  2476. inside: {
  2477. delimiter: {
  2478. pattern: /^\\\(|\)$/,
  2479. alias: 'variable'
  2480. }
  2481. // See rest below
  2482. }
  2483. }
  2484. }
  2485. },
  2486. 'keyword': /\b(?:as|associativity|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic(?:Type)?|else|enum|extension|fallthrough|final|for|func|get|guard|if|import|in|infix|init|inout|internal|is|lazy|left|let|mutating|new|none|nonmutating|operator|optional|override|postfix|precedence|prefix|private|protocol|public|repeat|required|rethrows|return|right|safe|self|Self|set|static|struct|subscript|super|switch|throws?|try|Type|typealias|unowned|unsafe|var|weak|where|while|willSet|__(?:COLUMN__|FILE__|FUNCTION__|LINE__))\b/,
  2487. 'number': /\b(?:[\d_]+(?:\.[\de_]+)?|0x[a-f0-9_]+(?:\.[a-f0-9p_]+)?|0b[01_]+|0o[0-7_]+)\b/i,
  2488. 'constant': /\b(?:nil|[A-Z_]{2,}|k[A-Z][A-Za-z_]+)\b/,
  2489. 'atrule': /@\b(?:IB(?:Outlet|Designable|Action|Inspectable)|class_protocol|exported|noreturn|NS(?:Copying|Managed)|objc|UIApplicationMain|auto_closure)\b/,
  2490. 'builtin': /\b(?:[A-Z]\S+|abs|advance|alignof(?:Value)?|assert|contains|count(?:Elements)?|debugPrint(?:ln)?|distance|drop(?:First|Last)|dump|enumerate|equal|filter|find|first|getVaList|indices|isEmpty|join|last|lexicographicalCompare|map|max(?:Element)?|min(?:Element)?|numericCast|overlaps|partition|print(?:ln)?|reduce|reflect|reverse|sizeof(?:Value)?|sort(?:ed)?|split|startsWith|stride(?:of(?:Value)?)?|suffix|swap|toDebugString|toString|transcode|underestimateCount|unsafeBitCast|with(?:ExtendedLifetime|Unsafe(?:MutablePointers?|Pointers?)|VaList))\b/
  2491. });
  2492. Prism.languages.swift['string'].inside['interpolation'].inside.rest = Prism.languages.swift;
  2493. Prism.languages.unrealscript = {
  2494. 'comment': /\/\/.*|\/\*[\s\S]*?\*\//,
  2495. 'string': {
  2496. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2497. greedy: true
  2498. },
  2499. 'category': {
  2500. pattern: /(\b(?:(?:autoexpand|hide|show)categories|var)\s*\()[^()]+(?=\))/,
  2501. lookbehind: true,
  2502. greedy: true,
  2503. alias: 'property'
  2504. },
  2505. 'metadata': {
  2506. pattern: /(\w\s*)<\s*\w+\s*=[^<>|=\r\n]+(?:\|\s*\w+\s*=[^<>|=\r\n]+)*>/,
  2507. lookbehind: true,
  2508. greedy: true,
  2509. inside: {
  2510. 'property': /\w+(?=\s*=)/,
  2511. 'operator': /=/,
  2512. 'punctuation': /[<>|]/
  2513. }
  2514. },
  2515. 'macro': {
  2516. pattern: /`\w+/,
  2517. alias: 'property'
  2518. },
  2519. 'class-name': {
  2520. pattern: /(\b(?:class|enum|extends|interface|state(?:\(\))?|struct|within)\s+)\w+/,
  2521. lookbehind: true
  2522. },
  2523. 'keyword': /\b(?:abstract|actor|array|auto|autoexpandcategories|bool|break|byte|case|class|classgroup|client|coerce|collapsecategories|config|const|continue|default|defaultproperties|delegate|dependson|deprecated|do|dontcollapsecategories|editconst|editinlinenew|else|enum|event|exec|export|extends|final|float|for|forcescriptorder|foreach|function|goto|guid|hidecategories|hidedropdown|if|ignores|implements|inherits|input|int|interface|iterator|latent|local|material|name|native|nativereplication|noexport|nontransient|noteditinlinenew|notplaceable|operator|optional|out|pawn|perobjectconfig|perobjectlocalized|placeable|postoperator|preoperator|private|protected|reliable|replication|return|server|showcategories|simulated|singular|state|static|string|struct|structdefault|structdefaultproperties|switch|texture|transient|travel|unreliable|until|var|vector|while|within)\b/,
  2524. 'function': /[a-z_]\w*(?=\s*\()/i,
  2525. 'boolean': /\b(?:false|true)\b/,
  2526. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
  2527. // https://docs.unrealengine.com/udk/Three/UnrealScriptExpressions.html
  2528. 'operator': />>|<<|--|\+\+|\*\*|[-+*/~!=<>$@]=?|&&?|\|\|?|\^\^?|[?:%]|\b(?:Cross|Dot|ClockwiseFrom)\b/,
  2529. 'punctuation': /[()[\]{};,.]/
  2530. };
  2531. Prism.languages.uc = Prism.languages.uscript = Prism.languages.unrealscript;
  2532. (function (Prism) {
  2533. /**
  2534. * If the given language is present, it will insert the given doc comment grammar token into it.
  2535. *
  2536. * @param {string} lang
  2537. * @param {any} docComment
  2538. */
  2539. function insertDocComment(lang, docComment) {
  2540. if (Prism.languages[lang]) {
  2541. Prism.languages.insertBefore(lang, 'comment', {
  2542. 'doc-comment': docComment
  2543. });
  2544. }
  2545. }
  2546. var tag = Prism.languages.markup.tag;
  2547. var slashDocComment = {
  2548. pattern: /\/\/\/.*/,
  2549. greedy: true,
  2550. alias: 'comment',
  2551. inside: {
  2552. 'tag': tag
  2553. }
  2554. };
  2555. var tickDocComment = {
  2556. pattern: /'''.*/,
  2557. greedy: true,
  2558. alias: 'comment',
  2559. inside: {
  2560. 'tag': tag
  2561. }
  2562. };
  2563. insertDocComment('csharp', slashDocComment);
  2564. insertDocComment('fsharp', slashDocComment);
  2565. insertDocComment('vbnet', tickDocComment);
  2566. }(Prism));
  2567. (function (Prism) {
  2568. // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
  2569. // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
  2570. var anchorOrAlias = /[*&][^\s[\]{},]+/;
  2571. // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
  2572. var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
  2573. // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
  2574. var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
  2575. + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
  2576. /**
  2577. *
  2578. * @param {string} value
  2579. * @param {string} [flags]
  2580. * @returns {RegExp}
  2581. */
  2582. function createValuePattern(value, flags) {
  2583. flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
  2584. var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|]|}|\s*#))/.source
  2585. .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
  2586. return RegExp(pattern, flags)
  2587. }
  2588. Prism.languages.yaml = {
  2589. 'scalar': {
  2590. pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)[^\r\n]+(?:\2[^\r\n]+)*)/.source
  2591. .replace(/<<prop>>/g, function () { return properties; })),
  2592. lookbehind: true,
  2593. alias: 'string'
  2594. },
  2595. 'comment': /#.*/,
  2596. 'key': {
  2597. pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)[^\r\n{[\]},#\s]+?(?=\s*:\s)/.source
  2598. .replace(/<<prop>>/g, function () { return properties; })),
  2599. lookbehind: true,
  2600. alias: 'atrule'
  2601. },
  2602. 'directive': {
  2603. pattern: /(^[ \t]*)%.+/m,
  2604. lookbehind: true,
  2605. alias: 'important'
  2606. },
  2607. 'datetime': {
  2608. pattern: createValuePattern(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?)?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),
  2609. lookbehind: true,
  2610. alias: 'number'
  2611. },
  2612. 'boolean': {
  2613. pattern: createValuePattern(/true|false/.source, 'i'),
  2614. lookbehind: true,
  2615. alias: 'important'
  2616. },
  2617. 'null': {
  2618. pattern: createValuePattern(/null|~/.source, 'i'),
  2619. lookbehind: true,
  2620. alias: 'important'
  2621. },
  2622. 'string': {
  2623. // \2 because of the lookbehind group
  2624. pattern: createValuePattern(/("|')(?:(?!\2)[^\\\r\n]|\\.)*\2/.source),
  2625. lookbehind: true,
  2626. greedy: true
  2627. },
  2628. 'number': {
  2629. pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+\.?\d*|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
  2630. lookbehind: true
  2631. },
  2632. 'tag': tag,
  2633. 'important': anchorOrAlias,
  2634. 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
  2635. };
  2636. Prism.languages.yml = Prism.languages.yaml;
  2637. }(Prism));