prism.js 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396
  1. /* PrismJS 1.15.0
  2. https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+c+bash+cpp+coffeescript+ruby+d+dart+django+elixir+markup-templating+erlang+go+java+json+kotlin+lua+crystal+nginx+nim+perl+php+sql+scss+python+jsx+typescript+rust+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(){
  16. // Private helper vars
  17. var lang = /\blang(?:uage)?-([\w-]+)\b/i;
  18. var uniqueId = 0;
  19. var _ = _self.Prism = {
  20. manual: _self.Prism && _self.Prism.manual,
  21. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  22. util: {
  23. encode: function (tokens) {
  24. if (tokens instanceof Token) {
  25. return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
  26. } else if (_.util.type(tokens) === 'Array') {
  27. return tokens.map(_.util.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).match(/\[object (\w+)\]/)[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 (o, visited) {
  43. var type = _.util.type(o);
  44. visited = visited || {};
  45. switch (type) {
  46. case 'Object':
  47. if (visited[_.util.objId(o)]) {
  48. return visited[_.util.objId(o)];
  49. }
  50. var clone = {};
  51. visited[_.util.objId(o)] = clone;
  52. for (var key in o) {
  53. if (o.hasOwnProperty(key)) {
  54. clone[key] = _.util.clone(o[key], visited);
  55. }
  56. }
  57. return clone;
  58. case 'Array':
  59. if (visited[_.util.objId(o)]) {
  60. return visited[_.util.objId(o)];
  61. }
  62. var clone = [];
  63. visited[_.util.objId(o)] = clone;
  64. o.forEach(function (v, i) {
  65. clone[i] = _.util.clone(v, visited);
  66. });
  67. return clone;
  68. }
  69. return o;
  70. }
  71. },
  72. languages: {
  73. extend: function (id, redef) {
  74. var lang = _.util.clone(_.languages[id]);
  75. for (var key in redef) {
  76. lang[key] = redef[key];
  77. }
  78. return lang;
  79. },
  80. /**
  81. * Insert a token before another token in a language literal
  82. * As this needs to recreate the object (we cannot actually insert before keys in object literals),
  83. * we cannot just provide an object, we need anobject and a key.
  84. * @param inside The key (or language id) of the parent
  85. * @param before The key to insert before. If not provided, the function appends instead.
  86. * @param insert Object with the key/value pairs to insert
  87. * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
  88. */
  89. insertBefore: function (inside, before, insert, root) {
  90. root = root || _.languages;
  91. var grammar = root[inside];
  92. if (arguments.length == 2) {
  93. insert = arguments[1];
  94. for (var newToken in insert) {
  95. if (insert.hasOwnProperty(newToken)) {
  96. grammar[newToken] = insert[newToken];
  97. }
  98. }
  99. return grammar;
  100. }
  101. var ret = {};
  102. for (var token in grammar) {
  103. if (grammar.hasOwnProperty(token)) {
  104. if (token == before) {
  105. for (var newToken in insert) {
  106. if (insert.hasOwnProperty(newToken)) {
  107. ret[newToken] = insert[newToken];
  108. }
  109. }
  110. }
  111. ret[token] = grammar[token];
  112. }
  113. }
  114. // Update references in other language definitions
  115. _.languages.DFS(_.languages, function(key, value) {
  116. if (value === root[inside] && key != inside) {
  117. this[key] = ret;
  118. }
  119. });
  120. return root[inside] = ret;
  121. },
  122. // Traverse a language definition with Depth First Search
  123. DFS: function(o, callback, type, visited) {
  124. visited = visited || {};
  125. for (var i in o) {
  126. if (o.hasOwnProperty(i)) {
  127. callback.call(o, i, o[i], type || i);
  128. if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
  129. visited[_.util.objId(o[i])] = true;
  130. _.languages.DFS(o[i], callback, null, visited);
  131. }
  132. else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
  133. visited[_.util.objId(o[i])] = true;
  134. _.languages.DFS(o[i], callback, i, visited);
  135. }
  136. }
  137. }
  138. }
  139. },
  140. plugins: {},
  141. highlightAll: function(async, callback) {
  142. _.highlightAllUnder(document, async, callback);
  143. },
  144. highlightAllUnder: function(container, async, callback) {
  145. var env = {
  146. callback: callback,
  147. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  148. };
  149. _.hooks.run("before-highlightall", env);
  150. var elements = env.elements || container.querySelectorAll(env.selector);
  151. for (var i=0, element; element = elements[i++];) {
  152. _.highlightElement(element, async === true, env.callback);
  153. }
  154. },
  155. highlightElement: function(element, async, callback) {
  156. // Find language
  157. var language, grammar, parent = element;
  158. while (parent && !lang.test(parent.className)) {
  159. parent = parent.parentNode;
  160. }
  161. if (parent) {
  162. language = (parent.className.match(lang) || [,''])[1].toLowerCase();
  163. grammar = _.languages[language];
  164. }
  165. // Set language on the element, if not present
  166. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  167. if (element.parentNode) {
  168. // Set language on the parent, for styling
  169. parent = element.parentNode;
  170. if (/pre/i.test(parent.nodeName)) {
  171. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  172. }
  173. }
  174. var code = element.textContent;
  175. var env = {
  176. element: element,
  177. language: language,
  178. grammar: grammar,
  179. code: code
  180. };
  181. _.hooks.run('before-sanity-check', env);
  182. if (!env.code || !env.grammar) {
  183. if (env.code) {
  184. _.hooks.run('before-highlight', env);
  185. env.element.textContent = env.code;
  186. _.hooks.run('after-highlight', env);
  187. }
  188. _.hooks.run('complete', env);
  189. return;
  190. }
  191. _.hooks.run('before-highlight', env);
  192. // if (async && _self.Worker) {
  193. // var worker = new Worker(_.filename);
  194. // worker.onmessage = function(evt) {
  195. // env.highlightedCode = evt.data;
  196. // _.hooks.run('before-insert', env);
  197. // env.element.innerHTML = env.highlightedCode;
  198. // callback && callback.call(env.element);
  199. // _.hooks.run('after-highlight', env);
  200. // _.hooks.run('complete', env);
  201. // };
  202. // worker.postMessage(JSON.stringify({
  203. // language: env.language,
  204. // code: env.code,
  205. // immediateClose: true
  206. // }));
  207. // }
  208. // else {
  209. env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
  210. _.hooks.run('before-insert', env);
  211. env.element.innerHTML = env.highlightedCode;
  212. callback && callback.call(element);
  213. _.hooks.run('after-highlight', env);
  214. _.hooks.run('complete', env);
  215. // }
  216. },
  217. highlight: function (text, grammar, language) {
  218. var env = {
  219. code: text,
  220. grammar: grammar,
  221. language: language
  222. };
  223. _.hooks.run('before-tokenize', env);
  224. env.tokens = _.tokenize(env.code, env.grammar);
  225. _.hooks.run('after-tokenize', env);
  226. return Token.stringify(_.util.encode(env.tokens), env.language);
  227. },
  228. matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
  229. var Token = _.Token;
  230. for (var token in grammar) {
  231. if(!grammar.hasOwnProperty(token) || !grammar[token]) {
  232. continue;
  233. }
  234. if (token == target) {
  235. return;
  236. }
  237. var patterns = grammar[token];
  238. patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
  239. for (var j = 0; j < patterns.length; ++j) {
  240. var pattern = patterns[j],
  241. inside = pattern.inside,
  242. lookbehind = !!pattern.lookbehind,
  243. greedy = !!pattern.greedy,
  244. lookbehindLength = 0,
  245. alias = pattern.alias;
  246. if (greedy && !pattern.pattern.global) {
  247. // Without the global flag, lastIndex won't work
  248. var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
  249. pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
  250. }
  251. pattern = pattern.pattern || pattern;
  252. // Don’t cache length as it changes during the loop
  253. for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) {
  254. var str = strarr[i];
  255. if (strarr.length > text.length) {
  256. // Something went terribly wrong, ABORT, ABORT!
  257. return;
  258. }
  259. if (str instanceof Token) {
  260. continue;
  261. }
  262. if (greedy && i != strarr.length - 1) {
  263. pattern.lastIndex = pos;
  264. var match = pattern.exec(text);
  265. if (!match) {
  266. break;
  267. }
  268. var from = match.index + (lookbehind ? match[1].length : 0),
  269. to = match.index + match[0].length,
  270. k = i,
  271. p = pos;
  272. for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) {
  273. p += strarr[k].length;
  274. // Move the index i to the element in strarr that is closest to from
  275. if (from >= p) {
  276. ++i;
  277. pos = p;
  278. }
  279. }
  280. // If strarr[i] is a Token, then the match starts inside another Token, which is invalid
  281. if (strarr[i] instanceof Token) {
  282. continue;
  283. }
  284. // Number of tokens to delete and replace with the new match
  285. delNum = k - i;
  286. str = text.slice(pos, p);
  287. match.index -= pos;
  288. } else {
  289. pattern.lastIndex = 0;
  290. var match = pattern.exec(str),
  291. delNum = 1;
  292. }
  293. if (!match) {
  294. if (oneshot) {
  295. break;
  296. }
  297. continue;
  298. }
  299. if(lookbehind) {
  300. lookbehindLength = match[1] ? match[1].length : 0;
  301. }
  302. var from = match.index + lookbehindLength,
  303. match = match[0].slice(lookbehindLength),
  304. to = from + match.length,
  305. before = str.slice(0, from),
  306. after = str.slice(to);
  307. var args = [i, delNum];
  308. if (before) {
  309. ++i;
  310. pos += before.length;
  311. args.push(before);
  312. }
  313. var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
  314. args.push(wrapped);
  315. if (after) {
  316. args.push(after);
  317. }
  318. Array.prototype.splice.apply(strarr, args);
  319. if (delNum != 1)
  320. _.matchGrammar(text, strarr, grammar, i, pos, true, token);
  321. if (oneshot)
  322. break;
  323. }
  324. }
  325. }
  326. },
  327. tokenize: function(text, grammar, language) {
  328. var strarr = [text];
  329. var rest = grammar.rest;
  330. if (rest) {
  331. for (var token in rest) {
  332. grammar[token] = rest[token];
  333. }
  334. delete grammar.rest;
  335. }
  336. _.matchGrammar(text, strarr, grammar, 0, 0, false);
  337. return strarr;
  338. },
  339. hooks: {
  340. all: {},
  341. add: function (name, callback) {
  342. var hooks = _.hooks.all;
  343. hooks[name] = hooks[name] || [];
  344. hooks[name].push(callback);
  345. },
  346. run: function (name, env) {
  347. var callbacks = _.hooks.all[name];
  348. if (!callbacks || !callbacks.length) {
  349. return;
  350. }
  351. for (var i=0, callback; callback = callbacks[i++];) {
  352. callback(env);
  353. }
  354. }
  355. }
  356. };
  357. var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
  358. this.type = type;
  359. this.content = content;
  360. this.alias = alias;
  361. // Copy of the full string this token was created from
  362. this.length = (matchedStr || "").length|0;
  363. this.greedy = !!greedy;
  364. };
  365. Token.stringify = function(o, language, parent) {
  366. if (typeof o == 'string') {
  367. return o;
  368. }
  369. if (_.util.type(o) === 'Array') {
  370. return o.map(function(element) {
  371. return Token.stringify(element, language, o);
  372. }).join('');
  373. }
  374. var env = {
  375. type: o.type,
  376. content: Token.stringify(o.content, language, parent),
  377. tag: 'span',
  378. classes: ['token', o.type],
  379. attributes: {},
  380. language: language,
  381. parent: parent
  382. };
  383. if (o.alias) {
  384. var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
  385. Array.prototype.push.apply(env.classes, aliases);
  386. }
  387. _.hooks.run('wrap', env);
  388. var attributes = Object.keys(env.attributes).map(function(name) {
  389. return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  390. }).join(' ');
  391. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
  392. };
  393. // if (!_self.document) {
  394. // if (!_self.addEventListener) {
  395. // // in Node.js
  396. // return _self.Prism;
  397. // }
  398. // if (!_.disableWorkerMessageHandler) {
  399. // // In worker
  400. // _self.addEventListener('message', function (evt) {
  401. // var message = JSON.parse(evt.data),
  402. // lang = message.language,
  403. // code = message.code,
  404. // immediateClose = message.immediateClose;
  405. // _self.postMessage(_.highlight(code, _.languages[lang], lang));
  406. // if (immediateClose) {
  407. // _self.close();
  408. // }
  409. // }, false);
  410. // }
  411. // return _self.Prism;
  412. // }
  413. // //Get current script and highlight
  414. // var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
  415. // if (script) {
  416. // _.filename = script.src;
  417. // if (!_.manual && !script.hasAttribute('data-manual')) {
  418. // if(document.readyState !== "loading") {
  419. // if (window.requestAnimationFrame) {
  420. // window.requestAnimationFrame(_.highlightAll);
  421. // } else {
  422. // window.setTimeout(_.highlightAll, 16);
  423. // }
  424. // }
  425. // else {
  426. // document.addEventListener('DOMContentLoaded', _.highlightAll);
  427. // }
  428. // }
  429. // }
  430. return _self.Prism;
  431. })();
  432. if (typeof module !== 'undefined' && module.exports) {
  433. module.exports = Prism;
  434. }
  435. // hack for components to work correctly in node.js
  436. if (typeof global !== 'undefined') {
  437. global.Prism = Prism;
  438. }
  439. ;
  440. Prism.languages.markup = {
  441. 'comment': /<!--[\s\S]*?-->/,
  442. 'prolog': /<\?[\s\S]+?\?>/,
  443. 'doctype': /<!DOCTYPE[\s\S]+?>/i,
  444. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  445. 'tag': {
  446. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i,
  447. greedy: true,
  448. inside: {
  449. 'tag': {
  450. pattern: /^<\/?[^\s>\/]+/i,
  451. inside: {
  452. 'punctuation': /^<\/?/,
  453. 'namespace': /^[^\s>\/:]+:/
  454. }
  455. },
  456. 'attr-value': {
  457. pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i,
  458. inside: {
  459. 'punctuation': [
  460. /^=/,
  461. {
  462. pattern: /(^|[^\\])["']/,
  463. lookbehind: true
  464. }
  465. ]
  466. }
  467. },
  468. 'punctuation': /\/?>/,
  469. 'attr-name': {
  470. pattern: /[^\s>\/]+/,
  471. inside: {
  472. 'namespace': /^[^\s>\/:]+:/
  473. }
  474. }
  475. }
  476. },
  477. 'entity': /&#?[\da-z]{1,8};/i
  478. };
  479. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
  480. Prism.languages.markup['entity'];
  481. // Plugin to make entity title show the real entity, idea by Roman Komarov
  482. Prism.hooks.add('wrap', function(env) {
  483. if (env.type === 'entity') {
  484. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  485. }
  486. });
  487. Prism.languages.xml = Prism.languages.markup;
  488. Prism.languages.html = Prism.languages.markup;
  489. Prism.languages.mathml = Prism.languages.markup;
  490. Prism.languages.svg = Prism.languages.markup;
  491. Prism.languages.css = {
  492. 'comment': /\/\*[\s\S]*?\*\//,
  493. 'atrule': {
  494. pattern: /@[\w-]+?.*?(?:;|(?=\s*\{))/i,
  495. inside: {
  496. 'rule': /@[\w-]+/
  497. // See rest below
  498. }
  499. },
  500. 'url': /url\((?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
  501. 'selector': /[^{}\s][^{};]*?(?=\s*\{)/,
  502. 'string': {
  503. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  504. greedy: true
  505. },
  506. 'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
  507. 'important': /\B!important\b/i,
  508. 'function': /[-a-z0-9]+(?=\()/i,
  509. 'punctuation': /[(){};:]/
  510. };
  511. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  512. if (Prism.languages.markup) {
  513. Prism.languages.insertBefore('markup', 'tag', {
  514. 'style': {
  515. pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i,
  516. lookbehind: true,
  517. inside: Prism.languages.css,
  518. alias: 'language-css',
  519. greedy: true
  520. }
  521. });
  522. Prism.languages.insertBefore('inside', 'attr-value', {
  523. 'style-attr': {
  524. pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,
  525. inside: {
  526. 'attr-name': {
  527. pattern: /^\s*style/i,
  528. inside: Prism.languages.markup.tag.inside
  529. },
  530. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  531. 'attr-value': {
  532. pattern: /.+/i,
  533. inside: Prism.languages.css
  534. }
  535. },
  536. alias: 'language-css'
  537. }
  538. }, Prism.languages.markup.tag);
  539. };
  540. Prism.languages.clike = {
  541. 'comment': [
  542. {
  543. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  544. lookbehind: true
  545. },
  546. {
  547. pattern: /(^|[^\\:])\/\/.*/,
  548. lookbehind: true,
  549. greedy: true
  550. }
  551. ],
  552. 'string': {
  553. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  554. greedy: true
  555. },
  556. 'class-name': {
  557. pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[\w.\\]+/i,
  558. lookbehind: true,
  559. inside: {
  560. punctuation: /[.\\]/
  561. }
  562. },
  563. 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  564. 'boolean': /\b(?:true|false)\b/,
  565. 'function': /[a-z0-9_]+(?=\()/i,
  566. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
  567. 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
  568. 'punctuation': /[{}[\];(),.:]/
  569. };
  570. Prism.languages.javascript = Prism.languages.extend('clike', {
  571. 'keyword': /\b(?: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|var|void|while|with|yield)\b/,
  572. 'number': /\b(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
  573. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  574. 'function': /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/i,
  575. 'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
  576. });
  577. Prism.languages.insertBefore('javascript', 'keyword', {
  578. 'regex': {
  579. pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})\]]))/,
  580. lookbehind: true,
  581. greedy: true
  582. },
  583. // This must be declared before keyword because we use "function" inside the look-forward
  584. 'function-variable': {
  585. pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
  586. alias: 'function'
  587. },
  588. 'constant': /\b[A-Z][A-Z\d_]*\b/
  589. });
  590. Prism.languages.insertBefore('javascript', 'string', {
  591. 'template-string': {
  592. pattern: /`(?:\\[\s\S]|\${[^}]+}|[^\\`])*`/,
  593. greedy: true,
  594. inside: {
  595. 'interpolation': {
  596. pattern: /\${[^}]+}/,
  597. inside: {
  598. 'interpolation-punctuation': {
  599. pattern: /^\${|}$/,
  600. alias: 'punctuation'
  601. },
  602. rest: null // See below
  603. }
  604. },
  605. 'string': /[\s\S]+/
  606. }
  607. }
  608. });
  609. Prism.languages.javascript['template-string'].inside['interpolation'].inside.rest = Prism.languages.javascript;
  610. if (Prism.languages.markup) {
  611. Prism.languages.insertBefore('markup', 'tag', {
  612. 'script': {
  613. pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
  614. lookbehind: true,
  615. inside: Prism.languages.javascript,
  616. alias: 'language-javascript',
  617. greedy: true
  618. }
  619. });
  620. }
  621. Prism.languages.js = Prism.languages.javascript;
  622. Prism.languages.c = Prism.languages.extend('clike', {
  623. 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
  624. 'operator': /-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/]/,
  625. 'number': /(?:\b0x[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i
  626. });
  627. Prism.languages.insertBefore('c', 'string', {
  628. 'macro': {
  629. // allow for multiline macro definitions
  630. // spaces after the # character compile fine with gcc
  631. pattern: /(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im,
  632. lookbehind: true,
  633. alias: 'property',
  634. inside: {
  635. // highlight the path of the include statement as a string
  636. 'string': {
  637. pattern: /(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/,
  638. lookbehind: true
  639. },
  640. // highlight macro directives as keywords
  641. 'directive': {
  642. pattern: /(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
  643. lookbehind: true,
  644. alias: 'keyword'
  645. }
  646. }
  647. },
  648. // highlight predefined macros as constants
  649. 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
  650. });
  651. delete Prism.languages.c['class-name'];
  652. delete Prism.languages.c['boolean'];
  653. (function(Prism) {
  654. var insideString = {
  655. variable: [
  656. // Arithmetic Environment
  657. {
  658. pattern: /\$?\(\([\s\S]+?\)\)/,
  659. inside: {
  660. // If there is a $ sign at the beginning highlight $(( and )) as variable
  661. variable: [{
  662. pattern: /(^\$\(\([\s\S]+)\)\)/,
  663. lookbehind: true
  664. },
  665. /^\$\(\(/
  666. ],
  667. number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee]-?\d+)?/,
  668. // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
  669. operator: /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
  670. // If there is no $ sign at the beginning highlight (( and )) as punctuation
  671. punctuation: /\(\(?|\)\)?|,|;/
  672. }
  673. },
  674. // Command Substitution
  675. {
  676. pattern: /\$\([^)]+\)|`[^`]+`/,
  677. greedy: true,
  678. inside: {
  679. variable: /^\$\(|^`|\)$|`$/
  680. }
  681. },
  682. /\$(?:[\w#?*!@]+|\{[^}]+\})/i
  683. ]
  684. };
  685. Prism.languages.bash = {
  686. 'shebang': {
  687. pattern: /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/,
  688. alias: 'important'
  689. },
  690. 'comment': {
  691. pattern: /(^|[^"{\\])#.*/,
  692. lookbehind: true
  693. },
  694. 'string': [
  695. //Support for Here-Documents https://en.wikipedia.org/wiki/Here_document
  696. {
  697. pattern: /((?:^|[^<])<<\s*)["']?(\w+?)["']?\s*\r?\n(?:[\s\S])*?\r?\n\2/,
  698. lookbehind: true,
  699. greedy: true,
  700. inside: insideString
  701. },
  702. {
  703. pattern: /(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\1)[^\\])*\1/,
  704. greedy: true,
  705. inside: insideString
  706. }
  707. ],
  708. 'variable': insideString.variable,
  709. // Originally based on http://ss64.com/bash/
  710. 'function': {
  711. pattern: /(^|[\s;|&])(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chown|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|enable|env|ethtool|eval|exec|expand|expect|export|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logname|logout|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|make|man|mkdir|mkfifo|mkisofs|mknod|more|most|mount|mtools|mtr|mv|mmv|nano|netstat|nice|nl|nohup|notify-send|npm|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printenv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|renice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|seq|service|sftp|shift|shopt|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|traceroute|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|units|unrar|unshar|uptime|useradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)(?=$|[\s;|&])/,
  712. lookbehind: true
  713. },
  714. 'keyword': {
  715. pattern: /(^|[\s;|&])(?:let|:|\.|if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)(?=$|[\s;|&])/,
  716. lookbehind: true
  717. },
  718. 'boolean': {
  719. pattern: /(^|[\s;|&])(?:true|false)(?=$|[\s;|&])/,
  720. lookbehind: true
  721. },
  722. 'operator': /&&?|\|\|?|==?|!=?|<<<?|>>|<=?|>=?|=~/,
  723. 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];]/
  724. };
  725. var inside = insideString.variable[1].inside;
  726. inside.string = Prism.languages.bash.string;
  727. inside['function'] = Prism.languages.bash['function'];
  728. inside.keyword = Prism.languages.bash.keyword;
  729. inside['boolean'] = Prism.languages.bash['boolean'];
  730. inside.operator = Prism.languages.bash.operator;
  731. inside.punctuation = Prism.languages.bash.punctuation;
  732. Prism.languages.shell = Prism.languages.bash;
  733. })(Prism);
  734. Prism.languages.cpp = Prism.languages.extend('c', {
  735. 'keyword': /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,
  736. 'boolean': /\b(?:true|false)\b/,
  737. 'operator': /--?|\+\+?|!=?|<{1,2}=?|>{1,2}=?|->|:{1,2}|={1,2}|\^|~|%|&{1,2}|\|\|?|\?|\*|\/|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/
  738. });
  739. Prism.languages.insertBefore('cpp', 'keyword', {
  740. 'class-name': {
  741. pattern: /(class\s+)\w+/i,
  742. lookbehind: true
  743. }
  744. });
  745. Prism.languages.insertBefore('cpp', 'string', {
  746. 'raw-string': {
  747. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  748. alias: 'string',
  749. greedy: true
  750. }
  751. });
  752. (function(Prism) {
  753. // Ignore comments starting with { to privilege string interpolation highlighting
  754. var comment = /#(?!\{).+/,
  755. interpolation = {
  756. pattern: /#\{[^}]+\}/,
  757. alias: 'variable'
  758. };
  759. Prism.languages.coffeescript = Prism.languages.extend('javascript', {
  760. 'comment': comment,
  761. 'string': [
  762. // Strings are multiline
  763. {
  764. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  765. greedy: true
  766. },
  767. {
  768. // Strings are multiline
  769. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  770. greedy: true,
  771. inside: {
  772. 'interpolation': interpolation
  773. }
  774. }
  775. ],
  776. 'keyword': /\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,
  777. 'class-member': {
  778. pattern: /@(?!\d)\w+/,
  779. alias: 'variable'
  780. }
  781. });
  782. Prism.languages.insertBefore('coffeescript', 'comment', {
  783. 'multiline-comment': {
  784. pattern: /###[\s\S]+?###/,
  785. alias: 'comment'
  786. },
  787. // Block regexp can contain comments and interpolation
  788. 'block-regex': {
  789. pattern: /\/{3}[\s\S]*?\/{3}/,
  790. alias: 'regex',
  791. inside: {
  792. 'comment': comment,
  793. 'interpolation': interpolation
  794. }
  795. }
  796. });
  797. Prism.languages.insertBefore('coffeescript', 'string', {
  798. 'inline-javascript': {
  799. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  800. inside: {
  801. 'delimiter': {
  802. pattern: /^`|`$/,
  803. alias: 'punctuation'
  804. },
  805. rest: Prism.languages.javascript
  806. }
  807. },
  808. // Block strings
  809. 'multiline-string': [
  810. {
  811. pattern: /'''[\s\S]*?'''/,
  812. greedy: true,
  813. alias: 'string'
  814. },
  815. {
  816. pattern: /"""[\s\S]*?"""/,
  817. greedy: true,
  818. alias: 'string',
  819. inside: {
  820. interpolation: interpolation
  821. }
  822. }
  823. ]
  824. });
  825. Prism.languages.insertBefore('coffeescript', 'keyword', {
  826. // Object property
  827. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  828. });
  829. delete Prism.languages.coffeescript['template-string'];
  830. }(Prism));
  831. /**
  832. * Original by Samuel Flores
  833. *
  834. * Adds the following new token classes:
  835. * constant, builtin, variable, symbol, regex
  836. */
  837. (function(Prism) {
  838. Prism.languages.ruby = Prism.languages.extend('clike', {
  839. 'comment': [
  840. /#.*/,
  841. {
  842. pattern: /^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m,
  843. greedy: true
  844. }
  845. ],
  846. 'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/
  847. });
  848. var interpolation = {
  849. pattern: /#\{[^}]+\}/,
  850. inside: {
  851. 'delimiter': {
  852. pattern: /^#\{|\}$/,
  853. alias: 'tag'
  854. },
  855. rest: Prism.languages.ruby
  856. }
  857. };
  858. Prism.languages.insertBefore('ruby', 'keyword', {
  859. 'regex': [
  860. {
  861. pattern: /%r([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/,
  862. greedy: true,
  863. inside: {
  864. 'interpolation': interpolation
  865. }
  866. },
  867. {
  868. pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
  869. greedy: true,
  870. inside: {
  871. 'interpolation': interpolation
  872. }
  873. },
  874. {
  875. // Here we need to specifically allow interpolation
  876. pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
  877. greedy: true,
  878. inside: {
  879. 'interpolation': interpolation
  880. }
  881. },
  882. {
  883. pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
  884. greedy: true,
  885. inside: {
  886. 'interpolation': interpolation
  887. }
  888. },
  889. {
  890. pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
  891. greedy: true,
  892. inside: {
  893. 'interpolation': interpolation
  894. }
  895. },
  896. {
  897. pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
  898. lookbehind: true,
  899. greedy: true
  900. }
  901. ],
  902. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  903. 'symbol': {
  904. pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
  905. lookbehind: true
  906. }
  907. });
  908. Prism.languages.insertBefore('ruby', 'number', {
  909. '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/,
  910. 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
  911. });
  912. Prism.languages.ruby.string = [
  913. {
  914. pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  915. greedy: true,
  916. inside: {
  917. 'interpolation': interpolation
  918. }
  919. },
  920. {
  921. pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
  922. greedy: true,
  923. inside: {
  924. 'interpolation': interpolation
  925. }
  926. },
  927. {
  928. // Here we need to specifically allow interpolation
  929. pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
  930. greedy: true,
  931. inside: {
  932. 'interpolation': interpolation
  933. }
  934. },
  935. {
  936. pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
  937. greedy: true,
  938. inside: {
  939. 'interpolation': interpolation
  940. }
  941. },
  942. {
  943. pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
  944. greedy: true,
  945. inside: {
  946. 'interpolation': interpolation
  947. }
  948. },
  949. {
  950. pattern: /("|')(?:#\{[^}]+\}|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  951. greedy: true,
  952. inside: {
  953. 'interpolation': interpolation
  954. }
  955. }
  956. ];
  957. }(Prism));
  958. Prism.languages.d = Prism.languages.extend('clike', {
  959. 'string': [
  960. // r"", x""
  961. /\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/,
  962. // q"[]", q"()", q"<>", q"{}"
  963. /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/,
  964. // q"IDENT
  965. // ...
  966. // IDENT"
  967. /\bq"([_a-zA-Z][_a-zA-Z\d]*)(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\1"/,
  968. // q"//", q"||", etc.
  969. /\bq"(.)[\s\S]*?\1"/,
  970. // Characters
  971. /'(?:\\'|\\?[^']+)'/,
  972. /(["`])(?:\\[\s\S]|(?!\1)[^\\])*\1[cwd]?/
  973. ],
  974. 'number': [
  975. // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
  976. // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
  977. /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]*/i,
  978. {
  979. pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]*/i,
  980. lookbehind: true
  981. }
  982. ],
  983. // In order: $, keywords and special tokens, globally defined symbols
  984. 'keyword': /\$|\b(?:abstract|alias|align|asm|assert|auto|body|bool|break|byte|case|cast|catch|cdouble|cent|cfloat|char|class|const|continue|creal|dchar|debug|default|delegate|delete|deprecated|do|double|else|enum|export|extern|false|final|finally|float|for|foreach|foreach_reverse|function|goto|idouble|if|ifloat|immutable|import|inout|int|interface|invariant|ireal|lazy|long|macro|mixin|module|new|nothrow|null|out|override|package|pragma|private|protected|public|pure|real|ref|return|scope|shared|short|static|struct|super|switch|synchronized|template|this|throw|true|try|typedef|typeid|typeof|ubyte|ucent|uint|ulong|union|unittest|ushort|version|void|volatile|wchar|while|with|__(?:(?:FILE|MODULE|LINE|FUNCTION|PRETTY_FUNCTION|DATE|EOF|TIME|TIMESTAMP|VENDOR|VERSION)__|gshared|traits|vector|parameters)|string|wstring|dstring|size_t|ptrdiff_t)\b/,
  985. 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
  986. });
  987. Prism.languages.d.comment = [
  988. // Shebang
  989. /^\s*#!.+/,
  990. // /+ +/
  991. {
  992. // Allow one level of nesting
  993. pattern: /(^|[^\\])\/\+(?:\/\+[\s\S]*?\+\/|[\s\S])*?\+\//,
  994. lookbehind: true
  995. }
  996. ].concat(Prism.languages.d.comment);
  997. Prism.languages.insertBefore('d', 'comment', {
  998. 'token-string': {
  999. // Allow one level of nesting
  1000. pattern: /\bq\{(?:\{[^}]*\}|[^}])*\}/,
  1001. alias: 'string'
  1002. }
  1003. });
  1004. Prism.languages.insertBefore('d', 'keyword', {
  1005. 'property': /\B@\w*/
  1006. });
  1007. Prism.languages.insertBefore('d', 'function', {
  1008. 'register': {
  1009. // Iasm registers
  1010. pattern: /\b(?:[ABCD][LHX]|E[ABCD]X|E?(?:BP|SP|DI|SI)|[ECSDGF]S|CR[0234]|DR[012367]|TR[3-7]|X?MM[0-7]|R[ABCD]X|[BS]PL|R[BS]P|[DS]IL|R[DS]I|R(?:[89]|1[0-5])[BWD]?|XMM(?:[89]|1[0-5])|YMM(?:1[0-5]|\d))\b|\bST(?:\([0-7]\)|\b)/,
  1011. alias: 'variable'
  1012. }
  1013. });
  1014. Prism.languages.dart = Prism.languages.extend('clike', {
  1015. 'string': [
  1016. {
  1017. pattern: /r?("""|''')[\s\S]*?\1/,
  1018. greedy: true
  1019. },
  1020. {
  1021. pattern: /r?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  1022. greedy: true
  1023. }
  1024. ],
  1025. 'keyword': [
  1026. /\b(?:async|sync|yield)\*/,
  1027. /\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|default|deferred|do|dynamic|else|enum|export|external|extends|factory|final|finally|for|get|if|implements|import|in|library|new|null|operator|part|rethrow|return|set|static|super|switch|this|throw|try|typedef|var|void|while|with|yield)\b/
  1028. ],
  1029. 'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
  1030. });
  1031. Prism.languages.insertBefore('dart','function',{
  1032. 'metadata': {
  1033. pattern: /@\w+/,
  1034. alias: 'symbol'
  1035. }
  1036. });
  1037. // Django/Jinja2 syntax definition for Prism.js <http://prismjs.com> syntax highlighter.
  1038. // Mostly it works OK but can paint code incorrectly on complex html/template tag combinations.
  1039. var _django_template = {
  1040. 'property': {
  1041. pattern: /(?:{{|{%)[\s\S]*?(?:%}|}})/g,
  1042. greedy: true,
  1043. inside: {
  1044. 'string': {
  1045. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  1046. greedy: true
  1047. },
  1048. 'keyword': /\b(?:\||load|verbatim|widthratio|ssi|firstof|for|url|ifchanged|csrf_token|lorem|ifnotequal|autoescape|now|templatetag|debug|cycle|ifequal|regroup|comment|filter|endfilter|if|spaceless|with|extends|block|include|else|empty|endif|endfor|as|endblock|endautoescape|endverbatim|trans|endtrans|[Tt]rue|[Ff]alse|[Nn]one|in|is|static|macro|endmacro|call|endcall|set|endset|raw|endraw)\b/,
  1049. 'operator' : /[-+=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
  1050. 'function': /\b(?:_|abs|add|addslashes|attr|batch|callable|capfirst|capitalize|center|count|cut|d|date|default|default_if_none|defined|dictsort|dictsortreversed|divisibleby|e|equalto|escape|escaped|escapejs|even|filesizeformat|first|float|floatformat|force_escape|forceescape|format|get_digit|groupby|indent|int|iriencode|iterable|join|last|length|length_is|linebreaks|linebreaksbr|linenumbers|list|ljust|lower|make_list|map|mapping|number|odd|phone2numeric|pluralize|pprint|random|reject|rejectattr|removetags|replace|reverse|rjust|round|safe|safeseq|sameas|select|selectattr|sequence|slice|slugify|sort|string|stringformat|striptags|sum|time|timesince|timeuntil|title|trim|truncate|truncatechars|truncatechars_html|truncatewords|truncatewords_html|undefined|unordered_list|upper|urlencode|urlize|urlizetrunc|wordcount|wordwrap|xmlattr|yesno)\b/,
  1051. 'important': /\b-?\d+(?:\.\d+)?\b/,
  1052. 'variable': /\b\w+?\b/,
  1053. 'punctuation' : /[[\];(),.:]/
  1054. }
  1055. }
  1056. };
  1057. Prism.languages.django = Prism.languages.extend('markup', {'comment': /(?:<!--|{#)[\s\S]*?(?:#}|-->)/});
  1058. // Updated html tag pattern to allow template tags inside html tags
  1059. Prism.languages.django.tag.pattern = /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^>=]+))?)*\s*\/?>/i;
  1060. Prism.languages.insertBefore('django', 'entity', _django_template);
  1061. Prism.languages.insertBefore('inside', 'tag', _django_template, Prism.languages.django.tag);
  1062. if (Prism.languages.javascript) {
  1063. // Combine js code and template tags painting inside <script> blocks
  1064. Prism.languages.insertBefore('inside', 'string', _django_template, Prism.languages.django.script);
  1065. Prism.languages.django.script.inside.string.inside = _django_template;
  1066. }
  1067. if (Prism.languages.css) {
  1068. // Combine css code and template tags painting inside <style> blocks
  1069. Prism.languages.insertBefore('inside', 'atrule', {'tag': _django_template.property}, Prism.languages.django.style);
  1070. Prism.languages.django.style.inside.string.inside = _django_template;
  1071. }
  1072. // Add an Jinja2 alias
  1073. Prism.languages.jinja2 = Prism.languages.django;
  1074. Prism.languages.elixir = {
  1075. 'comment': {
  1076. pattern: /#.*/m,
  1077. lookbehind: true
  1078. },
  1079. // ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  1080. 'regex': {
  1081. pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
  1082. greedy: true
  1083. },
  1084. 'string': [
  1085. {
  1086. // ~s"""foo""" (multi-line), ~s'''foo''' (multi-line), ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo} (with interpolation care), ~s<foo>
  1087. pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/,
  1088. greedy: true,
  1089. inside: {
  1090. // See interpolation below
  1091. }
  1092. },
  1093. {
  1094. pattern: /("""|''')[\s\S]*?\1/,
  1095. greedy: true,
  1096. inside: {
  1097. // See interpolation below
  1098. }
  1099. },
  1100. {
  1101. // Multi-line strings are allowed
  1102. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  1103. greedy: true,
  1104. inside: {
  1105. // See interpolation below
  1106. }
  1107. }
  1108. ],
  1109. 'atom': {
  1110. // Look-behind prevents bad highlighting of the :: operator
  1111. pattern: /(^|[^:]):\w+/,
  1112. lookbehind: true,
  1113. alias: 'symbol'
  1114. },
  1115. // Look-ahead prevents bad highlighting of the :: operator
  1116. 'attr-name': /\w+:(?!:)/,
  1117. 'capture': {
  1118. // Look-behind prevents bad highlighting of the && operator
  1119. pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
  1120. lookbehind: true,
  1121. alias: 'function'
  1122. },
  1123. 'argument': {
  1124. // Look-behind prevents bad highlighting of the && operator
  1125. pattern: /(^|[^&])&\d+/,
  1126. lookbehind: true,
  1127. alias: 'variable'
  1128. },
  1129. 'attribute': {
  1130. pattern: /@\w+/,
  1131. alias: 'variable'
  1132. },
  1133. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  1134. 'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct)?|do|else|end|fn|for|if|import|not|or|require|rescue|try|unless|use|when)\b/,
  1135. 'boolean': /\b(?:true|false|nil)\b/,
  1136. 'operator': [
  1137. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  1138. {
  1139. // We don't want to match <<
  1140. pattern: /([^<])<(?!<)/,
  1141. lookbehind: true
  1142. },
  1143. {
  1144. // We don't want to match >>
  1145. pattern: /([^>])>(?!>)/,
  1146. lookbehind: true
  1147. }
  1148. ],
  1149. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  1150. };
  1151. Prism.languages.elixir.string.forEach(function(o) {
  1152. o.inside = {
  1153. 'interpolation': {
  1154. pattern: /#\{[^}]+\}/,
  1155. inside: {
  1156. 'delimiter': {
  1157. pattern: /^#\{|\}$/,
  1158. alias: 'punctuation'
  1159. },
  1160. rest: Prism.languages.elixir
  1161. }
  1162. }
  1163. };
  1164. });
  1165. Prism.languages['markup-templating'] = {};
  1166. Object.defineProperties(Prism.languages['markup-templating'], {
  1167. buildPlaceholders: {
  1168. // Tokenize all inline templating expressions matching placeholderPattern
  1169. // If the replaceFilter function is provided, it will be called with every match.
  1170. // If it returns false, the match will not be replaced.
  1171. value: function (env, language, placeholderPattern, replaceFilter) {
  1172. if (env.language !== language) {
  1173. return;
  1174. }
  1175. env.tokenStack = [];
  1176. env.code = env.code.replace(placeholderPattern, function(match) {
  1177. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  1178. return match;
  1179. }
  1180. var i = env.tokenStack.length;
  1181. // Check for existing strings
  1182. while (env.code.indexOf('___' + language.toUpperCase() + i + '___') !== -1)
  1183. ++i;
  1184. // Create a sparse array
  1185. env.tokenStack[i] = match;
  1186. return '___' + language.toUpperCase() + i + '___';
  1187. });
  1188. // Switch the grammar to markup
  1189. env.grammar = Prism.languages.markup;
  1190. }
  1191. },
  1192. tokenizePlaceholders: {
  1193. // Replace placeholders with proper tokens after tokenizing
  1194. value: function (env, language) {
  1195. if (env.language !== language || !env.tokenStack) {
  1196. return;
  1197. }
  1198. // Switch the grammar back
  1199. env.grammar = Prism.languages[language];
  1200. var j = 0;
  1201. var keys = Object.keys(env.tokenStack);
  1202. var walkTokens = function (tokens) {
  1203. if (j >= keys.length) {
  1204. return;
  1205. }
  1206. for (var i = 0; i < tokens.length; i++) {
  1207. var token = tokens[i];
  1208. if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
  1209. var k = keys[j];
  1210. var t = env.tokenStack[k];
  1211. var s = typeof token === 'string' ? token : token.content;
  1212. var index = s.indexOf('___' + language.toUpperCase() + k + '___');
  1213. if (index > -1) {
  1214. ++j;
  1215. var before = s.substring(0, index);
  1216. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar, language), 'language-' + language, t);
  1217. var after = s.substring(index + ('___' + language.toUpperCase() + k + '___').length);
  1218. var replacement;
  1219. if (before || after) {
  1220. replacement = [before, middle, after].filter(function (v) { return !!v; });
  1221. walkTokens(replacement);
  1222. } else {
  1223. replacement = middle;
  1224. }
  1225. if (typeof token === 'string') {
  1226. Array.prototype.splice.apply(tokens, [i, 1].concat(replacement));
  1227. } else {
  1228. token.content = replacement;
  1229. }
  1230. if (j >= keys.length) {
  1231. break;
  1232. }
  1233. }
  1234. } else if (token.content && typeof token.content !== 'string') {
  1235. walkTokens(token.content);
  1236. }
  1237. }
  1238. };
  1239. walkTokens(env.tokens);
  1240. }
  1241. }
  1242. });
  1243. Prism.languages.erlang = {
  1244. 'comment': /%.+/,
  1245. 'string': {
  1246. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  1247. greedy: true
  1248. },
  1249. 'quoted-function': {
  1250. pattern: /'(?:\\.|[^\\'\r\n])+'(?=\()/,
  1251. alias: 'function'
  1252. },
  1253. 'quoted-atom': {
  1254. pattern: /'(?:\\.|[^\\'\r\n])+'/,
  1255. alias: 'atom'
  1256. },
  1257. 'boolean': /\b(?:true|false)\b/,
  1258. 'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
  1259. 'number': [
  1260. /\$\\?./,
  1261. /\d+#[a-z0-9]+/i,
  1262. /(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i
  1263. ],
  1264. 'function': /\b[a-z][\w@]*(?=\()/,
  1265. 'variable': {
  1266. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  1267. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  1268. lookbehind: true
  1269. },
  1270. 'operator': [
  1271. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,
  1272. {
  1273. // We don't want to match <<
  1274. pattern: /(^|[^<])<(?!<)/,
  1275. lookbehind: true
  1276. },
  1277. {
  1278. // We don't want to match >>
  1279. pattern: /(^|[^>])>(?!>)/,
  1280. lookbehind: true
  1281. }
  1282. ],
  1283. 'atom': /\b[a-z][\w@]*/,
  1284. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  1285. };
  1286. Prism.languages.go = Prism.languages.extend('clike', {
  1287. 'keyword': /\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
  1288. 'builtin': /\b(?:bool|byte|complex(?:64|128)|error|float(?:32|64)|rune|string|u?int(?:8|16|32|64)?|uintptr|append|cap|close|complex|copy|delete|imag|len|make|new|panic|print(?:ln)?|real|recover)\b/,
  1289. 'boolean': /\b(?:_|iota|nil|true|false)\b/,
  1290. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  1291. 'number': /(?:\b0x[a-f\d]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[-+]?\d+)?)i?/i,
  1292. 'string': {
  1293. pattern: /(["'`])(\\[\s\S]|(?!\1)[^\\])*\1/,
  1294. greedy: true
  1295. }
  1296. });
  1297. delete Prism.languages.go['class-name'];
  1298. Prism.languages.java = Prism.languages.extend('clike', {
  1299. 'keyword': /\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,
  1300. 'number': /\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp-]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?[df]?/i,
  1301. 'operator': {
  1302. pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,
  1303. lookbehind: true
  1304. }
  1305. });
  1306. Prism.languages.insertBefore('java','function', {
  1307. 'annotation': {
  1308. alias: 'punctuation',
  1309. pattern: /(^|[^.])@\w+/,
  1310. lookbehind: true
  1311. }
  1312. });
  1313. Prism.languages.insertBefore('java', 'class-name', {
  1314. 'generics': {
  1315. pattern: /<\s*\w+(?:\.\w+)?(?:\s*,\s*\w+(?:\.\w+)?)*>/i,
  1316. alias: 'function',
  1317. inside: {
  1318. keyword: Prism.languages.java.keyword,
  1319. punctuation: /[<>(),.:]/
  1320. }
  1321. }
  1322. });
  1323. Prism.languages.json = {
  1324. 'property': /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
  1325. 'string': {
  1326. pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  1327. greedy: true
  1328. },
  1329. 'number': /-?\d+\.?\d*([Ee][+-]?\d+)?/,
  1330. 'punctuation': /[{}[\],]/,
  1331. 'operator': /:/g,
  1332. 'boolean': /\b(?:true|false)\b/i,
  1333. 'null': /\bnull\b/i
  1334. };
  1335. Prism.languages.jsonp = Prism.languages.json;
  1336. (function (Prism) {
  1337. Prism.languages.kotlin = Prism.languages.extend('clike', {
  1338. 'keyword': {
  1339. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  1340. pattern: /(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,
  1341. lookbehind: true
  1342. },
  1343. 'function': [
  1344. /\w+(?=\s*\()/,
  1345. {
  1346. pattern: /(\.)\w+(?=\s*\{)/,
  1347. lookbehind: true
  1348. }
  1349. ],
  1350. 'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
  1351. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  1352. });
  1353. delete Prism.languages.kotlin["class-name"];
  1354. Prism.languages.insertBefore('kotlin', 'string', {
  1355. 'raw-string': {
  1356. pattern: /("""|''')[\s\S]*?\1/,
  1357. alias: 'string'
  1358. // See interpolation below
  1359. }
  1360. });
  1361. Prism.languages.insertBefore('kotlin', 'keyword', {
  1362. 'annotation': {
  1363. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  1364. alias: 'builtin'
  1365. }
  1366. });
  1367. Prism.languages.insertBefore('kotlin', 'function', {
  1368. 'label': {
  1369. pattern: /\w+@|@\w+/,
  1370. alias: 'symbol'
  1371. }
  1372. });
  1373. var interpolation = [
  1374. {
  1375. pattern: /\$\{[^}]+\}/,
  1376. inside: {
  1377. delimiter: {
  1378. pattern: /^\$\{|\}$/,
  1379. alias: 'variable'
  1380. },
  1381. rest: Prism.languages.kotlin
  1382. }
  1383. },
  1384. {
  1385. pattern: /\$\w+/,
  1386. alias: 'variable'
  1387. }
  1388. ];
  1389. Prism.languages.kotlin['string'].inside = Prism.languages.kotlin['raw-string'].inside = {
  1390. interpolation: interpolation
  1391. };
  1392. }(Prism));
  1393. Prism.languages.lua = {
  1394. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  1395. // \z may be used to skip the following space
  1396. 'string': {
  1397. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[\s\S]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  1398. greedy: true
  1399. },
  1400. 'number': /\b0x[a-f\d]+\.?[a-f\d]*(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|\.?\d*(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  1401. '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/,
  1402. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  1403. 'operator': [
  1404. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  1405. {
  1406. // Match ".." but don't break "..."
  1407. pattern: /(^|[^.])\.\.(?!\.)/,
  1408. lookbehind: true
  1409. }
  1410. ],
  1411. 'punctuation': /[\[\](){},;]|\.+|:+/
  1412. };
  1413. (function(Prism) {
  1414. Prism.languages.crystal = Prism.languages.extend('ruby', {
  1415. keyword: [
  1416. /\b(?:abstract|alias|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|rescue|return|require|select|self|sizeof|struct|super|then|type|typeof|uninitialized|union|unless|until|when|while|with|yield|__DIR__|__END_LINE__|__FILE__|__LINE__)\b/,
  1417. {
  1418. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  1419. lookbehind: true
  1420. }
  1421. ],
  1422. number: /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[\da-fA-F_]*[\da-fA-F]|(?:\d(?:[\d_]*\d)?)(?:\.[\d_]*\d)?(?:[eE][+-]?[\d_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/
  1423. });
  1424. Prism.languages.insertBefore('crystal', 'string', {
  1425. attribute: {
  1426. pattern: /@\[.+?\]/,
  1427. alias: 'attr-name',
  1428. inside: {
  1429. delimiter: {
  1430. pattern: /^@\[|\]$/,
  1431. alias: 'tag'
  1432. },
  1433. rest: Prism.languages.crystal
  1434. }
  1435. },
  1436. expansion: [
  1437. {
  1438. pattern: /\{\{.+?\}\}/,
  1439. inside: {
  1440. delimiter: {
  1441. pattern: /^\{\{|\}\}$/,
  1442. alias: 'tag'
  1443. },
  1444. rest: Prism.languages.crystal
  1445. }
  1446. },
  1447. {
  1448. pattern: /\{%.+?%\}/,
  1449. inside: {
  1450. delimiter: {
  1451. pattern: /^\{%|%\}$/,
  1452. alias: 'tag'
  1453. },
  1454. rest: Prism.languages.crystal
  1455. }
  1456. }
  1457. ]
  1458. });
  1459. }(Prism));
  1460. Prism.languages.nginx = Prism.languages.extend('clike', {
  1461. 'comment': {
  1462. pattern: /(^|[^"{\\])#.*/,
  1463. lookbehind: true
  1464. },
  1465. 'keyword': /\b(?:CONTENT_|DOCUMENT_|GATEWAY_|HTTP_|HTTPS|if_not_empty|PATH_|QUERY_|REDIRECT_|REMOTE_|REQUEST_|SCGI|SCRIPT_|SERVER_|http|events|accept_mutex|accept_mutex_delay|access_log|add_after_body|add_before_body|add_header|addition_types|aio|alias|allow|ancient_browser|ancient_browser_value|auth|auth_basic|auth_basic_user_file|auth_http|auth_http_header|auth_http_timeout|autoindex|autoindex_exact_size|autoindex_localtime|break|charset|charset_map|charset_types|chunked_transfer_encoding|client_body_buffer_size|client_body_in_file_only|client_body_in_single_buffer|client_body_temp_path|client_body_timeout|client_header_buffer_size|client_header_timeout|client_max_body_size|connection_pool_size|create_full_put_path|daemon|dav_access|dav_methods|debug_connection|debug_points|default_type|deny|devpoll_changes|devpoll_events|directio|directio_alignment|disable_symlinks|empty_gif|env|epoll_events|error_log|error_page|expires|fastcgi_buffer_size|fastcgi_buffers|fastcgi_busy_buffers_size|fastcgi_cache|fastcgi_cache_bypass|fastcgi_cache_key|fastcgi_cache_lock|fastcgi_cache_lock_timeout|fastcgi_cache_methods|fastcgi_cache_min_uses|fastcgi_cache_path|fastcgi_cache_purge|fastcgi_cache_use_stale|fastcgi_cache_valid|fastcgi_connect_timeout|fastcgi_hide_header|fastcgi_ignore_client_abort|fastcgi_ignore_headers|fastcgi_index|fastcgi_intercept_errors|fastcgi_keep_conn|fastcgi_max_temp_file_size|fastcgi_next_upstream|fastcgi_no_cache|fastcgi_param|fastcgi_pass|fastcgi_pass_header|fastcgi_read_timeout|fastcgi_redirect_errors|fastcgi_send_timeout|fastcgi_split_path_info|fastcgi_store|fastcgi_store_access|fastcgi_temp_file_write_size|fastcgi_temp_path|flv|geo|geoip_city|geoip_country|google_perftools_profiles|gzip|gzip_buffers|gzip_comp_level|gzip_disable|gzip_http_version|gzip_min_length|gzip_proxied|gzip_static|gzip_types|gzip_vary|if|if_modified_since|ignore_invalid_headers|image_filter|image_filter_buffer|image_filter_jpeg_quality|image_filter_sharpen|image_filter_transparency|imap_capabilities|imap_client_buffer|include|index|internal|ip_hash|keepalive|keepalive_disable|keepalive_requests|keepalive_timeout|kqueue_changes|kqueue_events|large_client_header_buffers|limit_conn|limit_conn_log_level|limit_conn_zone|limit_except|limit_rate|limit_rate_after|limit_req|limit_req_log_level|limit_req_zone|limit_zone|lingering_close|lingering_time|lingering_timeout|listen|location|lock_file|log_format|log_format_combined|log_not_found|log_subrequest|map|map_hash_bucket_size|map_hash_max_size|master_process|max_ranges|memcached_buffer_size|memcached_connect_timeout|memcached_next_upstream|memcached_pass|memcached_read_timeout|memcached_send_timeout|merge_slashes|min_delete_depth|modern_browser|modern_browser_value|mp4|mp4_buffer_size|mp4_max_buffer_size|msie_padding|msie_refresh|multi_accept|open_file_cache|open_file_cache_errors|open_file_cache_min_uses|open_file_cache_valid|open_log_file_cache|optimize_server_names|override_charset|pcre_jit|perl|perl_modules|perl_require|perl_set|pid|pop3_auth|pop3_capabilities|port_in_redirect|post_action|postpone_output|protocol|proxy|proxy_buffer|proxy_buffer_size|proxy_buffering|proxy_buffers|proxy_busy_buffers_size|proxy_cache|proxy_cache_bypass|proxy_cache_key|proxy_cache_lock|proxy_cache_lock_timeout|proxy_cache_methods|proxy_cache_min_uses|proxy_cache_path|proxy_cache_use_stale|proxy_cache_valid|proxy_connect_timeout|proxy_cookie_domain|proxy_cookie_path|proxy_headers_hash_bucket_size|proxy_headers_hash_max_size|proxy_hide_header|proxy_http_version|proxy_ignore_client_abort|proxy_ignore_headers|proxy_intercept_errors|proxy_max_temp_file_size|proxy_method|proxy_next_upstream|proxy_no_cache|proxy_pass|proxy_pass_error_message|proxy_pass_header|proxy_pass_request_body|proxy_pass_request_headers|proxy_read_timeout|proxy_redirect|proxy_redirect_errors|proxy_send_lowat|proxy_send_timeout|proxy_set_body|proxy_set_header|proxy_ssl_session_reuse|proxy_store|proxy_store_access|proxy_temp_file_write_size|proxy_temp_path|proxy_timeout|proxy_upstream_fail_timeout|proxy_upstream_max_fails|random_index|read_ahead|real_ip_header|recursive_error_pages|request_pool_size|reset_timedout_connection|resolver|resolver_timeout|return|rewrite|root|rtsig_overflow_events|rtsig_overflow_test|rtsig_overflow_threshold|rtsig_signo|satisfy|satisfy_any|secure_link_secret|send_lowat|send_timeout|sendfile|sendfile_max_chunk|server|server_name|server_name_in_redirect|server_names_hash_bucket_size|server_names_hash_max_size|server_tokens|set|set_real_ip_from|smtp_auth|smtp_capabilities|so_keepalive|source_charset|split_clients|ssi|ssi_silent_errors|ssi_types|ssi_value_length|ssl|ssl_certificate|ssl_certificate_key|ssl_ciphers|ssl_client_certificate|ssl_crl|ssl_dhparam|ssl_engine|ssl_prefer_server_ciphers|ssl_protocols|ssl_session_cache|ssl_session_timeout|ssl_verify_client|ssl_verify_depth|starttls|stub_status|sub_filter|sub_filter_once|sub_filter_types|tcp_nodelay|tcp_nopush|timeout|timer_resolution|try_files|types|types_hash_bucket_size|types_hash_max_size|underscores_in_headers|uninitialized_variable_warn|upstream|use|user|userid|userid_domain|userid_expires|userid_name|userid_p3p|userid_path|userid_service|valid_referers|variables_hash_bucket_size|variables_hash_max_size|worker_connections|worker_cpu_affinity|worker_priority|worker_processes|worker_rlimit_core|worker_rlimit_nofile|worker_rlimit_sigpending|working_directory|xclient|xml_entities|xslt_entities|xslt_stylesheet|xslt_types)\b/i
  1466. });
  1467. Prism.languages.insertBefore('nginx', 'keyword', {
  1468. 'variable': /\$[a-z_]+/i
  1469. });
  1470. Prism.languages.nim = {
  1471. 'comment': /#.*/,
  1472. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  1473. // Character literals are handled specifically to prevent issues with numeric type suffixes
  1474. 'string': {
  1475. pattern: /(?:(?:\b(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")|'(?:\\(?:\d+|x[\da-fA-F]{2}|.)|[^'])')/,
  1476. greedy: true
  1477. },
  1478. // The negative look ahead prevents wrong highlighting of the .. operator
  1479. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  1480. 'keyword': /\b(?:addr|as|asm|atomic|bind|block|break|case|cast|concept|const|continue|converter|defer|discard|distinct|do|elif|else|end|enum|except|export|finally|for|from|func|generic|if|import|include|interface|iterator|let|macro|method|mixin|nil|object|out|proc|ptr|raise|ref|return|static|template|try|tuple|type|using|var|when|while|with|without|yield)\b/,
  1481. 'function': {
  1482. pattern: /(?:(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  1483. inside: {
  1484. 'operator': /\*$/
  1485. }
  1486. },
  1487. // We don't want to highlight operators inside backticks
  1488. 'ignore': {
  1489. pattern: /`[^`\r\n]+`/,
  1490. inside: {
  1491. 'punctuation': /`/
  1492. }
  1493. },
  1494. 'operator': {
  1495. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  1496. // but allow the slice operator .. to take precedence over them
  1497. // One can define his own operators in Nim so all combination of operators might be an operator.
  1498. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|of|or|in|is|isnot|mod|not|notin|shl|shr|xor)\b)/m,
  1499. lookbehind: true
  1500. },
  1501. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  1502. };
  1503. Prism.languages.perl = {
  1504. 'comment': [
  1505. {
  1506. // POD
  1507. pattern: /(^\s*)=\w+[\s\S]*?=cut.*/m,
  1508. lookbehind: true
  1509. },
  1510. {
  1511. pattern: /(^|[^\\$])#.*/,
  1512. lookbehind: true
  1513. }
  1514. ],
  1515. // TODO Could be nice to handle Heredoc too.
  1516. 'string': [
  1517. // q/.../
  1518. {
  1519. pattern: /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  1520. greedy: true
  1521. },
  1522. // q a...a
  1523. {
  1524. pattern: /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  1525. greedy: true
  1526. },
  1527. // q(...)
  1528. {
  1529. pattern: /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,
  1530. greedy: true
  1531. },
  1532. // q{...}
  1533. {
  1534. pattern: /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,
  1535. greedy: true
  1536. },
  1537. // q[...]
  1538. {
  1539. pattern: /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,
  1540. greedy: true
  1541. },
  1542. // q<...>
  1543. {
  1544. pattern: /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,
  1545. greedy: true
  1546. },
  1547. // "...", `...`
  1548. {
  1549. pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  1550. greedy: true
  1551. },
  1552. // '...'
  1553. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  1554. {
  1555. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  1556. greedy: true
  1557. }
  1558. ],
  1559. 'regex': [
  1560. // m/.../
  1561. {
  1562. pattern: /\b(?:m|qr)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[msixpodualngc]*/,
  1563. greedy: true
  1564. },
  1565. // m a...a
  1566. {
  1567. pattern: /\b(?:m|qr)\s+([a-zA-Z0-9])(?:(?!\1)[^\\]|\\[\s\S])*\1[msixpodualngc]*/,
  1568. greedy: true
  1569. },
  1570. // m(...)
  1571. {
  1572. pattern: /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,
  1573. greedy: true
  1574. },
  1575. // m{...}
  1576. {
  1577. pattern: /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,
  1578. greedy: true
  1579. },
  1580. // m[...]
  1581. {
  1582. pattern: /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,
  1583. greedy: true
  1584. },
  1585. // m<...>
  1586. {
  1587. pattern: /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,
  1588. greedy: true
  1589. },
  1590. // The lookbehinds prevent -s from breaking
  1591. // FIXME We don't handle change of separator like s(...)[...]
  1592. // s/.../.../
  1593. {
  1594. pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2[msixpodualngcer]*/,
  1595. lookbehind: true,
  1596. greedy: true
  1597. },
  1598. // s a...a...a
  1599. {
  1600. pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2[msixpodualngcer]*/,
  1601. lookbehind: true,
  1602. greedy: true
  1603. },
  1604. // s(...)(...)
  1605. {
  1606. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,
  1607. lookbehind: true,
  1608. greedy: true
  1609. },
  1610. // s{...}{...}
  1611. {
  1612. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,
  1613. lookbehind: true,
  1614. greedy: true
  1615. },
  1616. // s[...][...]
  1617. {
  1618. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,
  1619. lookbehind: true,
  1620. greedy: true
  1621. },
  1622. // s<...><...>
  1623. {
  1624. pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,
  1625. lookbehind: true,
  1626. greedy: true
  1627. },
  1628. // /.../
  1629. // The look-ahead tries to prevent two divisions on
  1630. // the same line from being highlighted as regex.
  1631. // This does not support multi-line regex.
  1632. {
  1633. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/,
  1634. greedy: true
  1635. }
  1636. ],
  1637. // FIXME Not sure about the handling of ::, ', and #
  1638. 'variable': [
  1639. // ${^POSTMATCH}
  1640. /[&*$@%]\{\^[A-Z]+\}/,
  1641. // $^V
  1642. /[&*$@%]\^[A-Z_]/,
  1643. // ${...}
  1644. /[&*$@%]#?(?=\{)/,
  1645. // $foo
  1646. /[&*$@%]#?(?:(?:::)*'?(?!\d)[\w$]+)+(?:::)*/i,
  1647. // $1
  1648. /[&*$@%]\d+/,
  1649. // $_, @_, %!
  1650. // The negative lookahead prevents from breaking the %= operator
  1651. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  1652. ],
  1653. 'filehandle': {
  1654. // <>, <FOO>, _
  1655. pattern: /<(?![<=])\S*>|\b_\b/,
  1656. alias: 'symbol'
  1657. },
  1658. 'vstring': {
  1659. // v1.2, 1.2.3
  1660. pattern: /v\d+(?:\.\d+)*|\d+(?:\.\d+){2,}/,
  1661. alias: 'string'
  1662. },
  1663. 'function': {
  1664. pattern: /sub [a-z0-9_]+/i,
  1665. inside: {
  1666. keyword: /sub/
  1667. }
  1668. },
  1669. 'keyword': /\b(?:any|break|continue|default|delete|die|do|else|elsif|eval|for|foreach|given|goto|if|last|local|my|next|our|package|print|redo|require|say|state|sub|switch|undef|unless|until|use|when|while)\b/,
  1670. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)\b/,
  1671. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(?:lt|gt|le|ge|eq|ne|cmp|not|and|or|xor)\b/,
  1672. 'punctuation': /[{}[\];(),:]/
  1673. };
  1674. /**
  1675. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  1676. * Modified by Miles Johnson: http://milesj.me
  1677. *
  1678. * Supports the following:
  1679. * - Extends clike syntax
  1680. * - Support for PHP 5.3+ (namespaces, traits, generators, etc)
  1681. * - Smarter constant and function matching
  1682. *
  1683. * Adds the following new token classes:
  1684. * constant, delimiter, variable, function, package
  1685. */
  1686. (function (Prism) {
  1687. Prism.languages.php = Prism.languages.extend('clike', {
  1688. 'keyword': /\b(?:and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|private|protected|parent|throw|null|echo|print|trait|namespace|final|yield|goto|instanceof|finally|try|catch)\b/i,
  1689. 'constant': /\b[A-Z0-9_]{2,}\b/,
  1690. 'comment': {
  1691. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1692. lookbehind: true
  1693. }
  1694. });
  1695. Prism.languages.insertBefore('php', 'string', {
  1696. 'shell-comment': {
  1697. pattern: /(^|[^\\])#.*/,
  1698. lookbehind: true,
  1699. alias: 'comment'
  1700. }
  1701. });
  1702. Prism.languages.insertBefore('php', 'keyword', {
  1703. 'delimiter': {
  1704. pattern: /\?>|<\?(?:php|=)?/i,
  1705. alias: 'important'
  1706. },
  1707. 'variable': /\$+(?:\w+\b|(?={))/i,
  1708. 'package': {
  1709. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  1710. lookbehind: true,
  1711. inside: {
  1712. punctuation: /\\/
  1713. }
  1714. }
  1715. });
  1716. // Must be defined after the function pattern
  1717. Prism.languages.insertBefore('php', 'operator', {
  1718. 'property': {
  1719. pattern: /(->)[\w]+/,
  1720. lookbehind: true
  1721. }
  1722. });
  1723. Prism.languages.insertBefore('php', 'string', {
  1724. 'nowdoc-string': {
  1725. pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/,
  1726. greedy: true,
  1727. alias: 'string',
  1728. inside: {
  1729. 'delimiter': {
  1730. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  1731. alias: 'symbol',
  1732. inside: {
  1733. 'punctuation': /^<<<'?|[';]$/
  1734. }
  1735. }
  1736. }
  1737. },
  1738. 'heredoc-string': {
  1739. pattern: /<<<(?:"([^"]+)"(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;|([a-z_]\w*)(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\2;)/i,
  1740. greedy: true,
  1741. alias: 'string',
  1742. inside: {
  1743. 'delimiter': {
  1744. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  1745. alias: 'symbol',
  1746. inside: {
  1747. 'punctuation': /^<<<"?|[";]$/
  1748. }
  1749. },
  1750. 'interpolation': null // See below
  1751. }
  1752. },
  1753. 'single-quoted-string': {
  1754. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1755. greedy: true,
  1756. alias: 'string'
  1757. },
  1758. 'double-quoted-string': {
  1759. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1760. greedy: true,
  1761. alias: 'string',
  1762. inside: {
  1763. 'interpolation': null // See below
  1764. }
  1765. }
  1766. });
  1767. // The different types of PHP strings "replace" the C-like standard string
  1768. delete Prism.languages.php['string'];
  1769. var string_interpolation = {
  1770. pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
  1771. lookbehind: true,
  1772. inside: {
  1773. rest: Prism.languages.php
  1774. }
  1775. };
  1776. Prism.languages.php['heredoc-string'].inside['interpolation'] = string_interpolation;
  1777. Prism.languages.php['double-quoted-string'].inside['interpolation'] = string_interpolation;
  1778. Prism.hooks.add('before-tokenize', function(env) {
  1779. if (!/(?:<\?php|<\?)/ig.test(env.code)) {
  1780. return;
  1781. }
  1782. var phpPattern = /(?:<\?php|<\?)[\s\S]*?(?:\?>|$)/ig;
  1783. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  1784. });
  1785. Prism.hooks.add('after-tokenize', function(env) {
  1786. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  1787. });
  1788. }(Prism));
  1789. Prism.languages.sql= {
  1790. 'comment': {
  1791. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  1792. lookbehind: true
  1793. },
  1794. 'string' : {
  1795. pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\])*\2/,
  1796. greedy: true,
  1797. lookbehind: true
  1798. },
  1799. 'variable': /@[\w.$]+|@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
  1800. 'function': /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i, // Should we highlight user defined functions too?
  1801. 'keyword': /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURNS?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
  1802. 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
  1803. 'number': /\b0x[\da-f]+\b|\b\d+\.?\d*|\B\.\d+\b/i,
  1804. 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|IN|LIKE|NOT|OR|IS|DIV|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  1805. 'punctuation': /[;[\]()`,.]/
  1806. };
  1807. Prism.languages.scss = Prism.languages.extend('css', {
  1808. 'comment': {
  1809. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1810. lookbehind: true
  1811. },
  1812. 'atrule': {
  1813. pattern: /@[\w-]+(?:\([^()]+\)|[^(])*?(?=\s+[{;])/,
  1814. inside: {
  1815. 'rule': /@[\w-]+/
  1816. // See rest below
  1817. }
  1818. },
  1819. // url, compassified
  1820. 'url': /(?:[-a-z]+-)*url(?=\()/i,
  1821. // CSS selector regex is not appropriate for Sass
  1822. // since there can be lot more things (var, @ directive, nesting..)
  1823. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  1824. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  1825. // the end of a selector is found when there is no rules in it ( {} or {\s}) or if there is a property (because an interpolated var
  1826. // can "pass" as a selector- e.g: proper#{$erty})
  1827. // this one was hard to do, so please be careful if you edit this one :)
  1828. 'selector': {
  1829. // Initial look-ahead is used to prevent matching of blank selectors
  1830. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()]|&|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}]+[:{][^}]+))/m,
  1831. inside: {
  1832. 'parent': {
  1833. pattern: /&/,
  1834. alias: 'important'
  1835. },
  1836. 'placeholder': /%[-\w]+/,
  1837. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  1838. }
  1839. }
  1840. });
  1841. Prism.languages.insertBefore('scss', 'atrule', {
  1842. 'keyword': [
  1843. /@(?:if|else(?: if)?|for|each|while|import|extend|debug|warn|mixin|include|function|return|content)/i,
  1844. {
  1845. pattern: /( +)(?:from|through)(?= )/,
  1846. lookbehind: true
  1847. }
  1848. ]
  1849. });
  1850. Prism.languages.scss.property = {
  1851. pattern: /(?:[\w-]|\$[-\w]+|#\{\$[-\w]+\})+(?=\s*:)/i,
  1852. inside: {
  1853. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  1854. }
  1855. };
  1856. Prism.languages.insertBefore('scss', 'important', {
  1857. // var and interpolated vars
  1858. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  1859. });
  1860. Prism.languages.insertBefore('scss', 'function', {
  1861. 'placeholder': {
  1862. pattern: /%[-\w]+/,
  1863. alias: 'selector'
  1864. },
  1865. 'statement': {
  1866. pattern: /\B!(?:default|optional)\b/i,
  1867. alias: 'keyword'
  1868. },
  1869. 'boolean': /\b(?:true|false)\b/,
  1870. 'null': /\bnull\b/,
  1871. 'operator': {
  1872. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|or|not)(?=\s)/,
  1873. lookbehind: true
  1874. }
  1875. });
  1876. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;
  1877. Prism.languages.python = {
  1878. 'comment': {
  1879. pattern: /(^|[^\\])#.*/,
  1880. lookbehind: true
  1881. },
  1882. 'triple-quoted-string': {
  1883. pattern: /("""|''')[\s\S]+?\1/,
  1884. greedy: true,
  1885. alias: 'string'
  1886. },
  1887. 'string': {
  1888. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  1889. greedy: true
  1890. },
  1891. 'function': {
  1892. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  1893. lookbehind: true
  1894. },
  1895. 'class-name': {
  1896. pattern: /(\bclass\s+)\w+/i,
  1897. lookbehind: true
  1898. },
  1899. 'keyword': /\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|pass|print|raise|return|try|while|with|yield)\b/,
  1900. '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/,
  1901. 'boolean': /\b(?:True|False|None)\b/,
  1902. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  1903. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
  1904. 'punctuation': /[{}[\];(),.:]/
  1905. };
  1906. (function(Prism) {
  1907. var javascript = Prism.util.clone(Prism.languages.javascript);
  1908. Prism.languages.jsx = Prism.languages.extend('markup', javascript);
  1909. Prism.languages.jsx.tag.pattern= /<\/?(?:[\w.:-]+\s*(?:\s+(?:[\w.:-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s{'">=]+|\{(?:\{(?:\{[^}]*\}|[^{}])*\}|[^{}])+\}))?|\{\.{3}[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\}))*\s*\/?)?>/i;
  1910. Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/i;
  1911. Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">]+)/i;
  1912. Prism.languages.insertBefore('inside', 'attr-name', {
  1913. 'spread': {
  1914. pattern: /\{\.{3}[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\}/,
  1915. inside: {
  1916. 'punctuation': /\.{3}|[{}.]/,
  1917. 'attr-value': /\w+/
  1918. }
  1919. }
  1920. }, Prism.languages.jsx.tag);
  1921. Prism.languages.insertBefore('inside', 'attr-value',{
  1922. 'script': {
  1923. // Allow for two levels of nesting
  1924. pattern: /=(\{(?:\{(?:\{[^}]*\}|[^}])*\}|[^}])+\})/i,
  1925. inside: {
  1926. 'script-punctuation': {
  1927. pattern: /^=(?={)/,
  1928. alias: 'punctuation'
  1929. },
  1930. rest: Prism.languages.jsx
  1931. },
  1932. 'alias': 'language-javascript'
  1933. }
  1934. }, Prism.languages.jsx.tag);
  1935. // The following will handle plain text inside tags
  1936. var stringifyToken = function (token) {
  1937. if (!token) {
  1938. return '';
  1939. }
  1940. if (typeof token === 'string') {
  1941. return token;
  1942. }
  1943. if (typeof token.content === 'string') {
  1944. return token.content;
  1945. }
  1946. return token.content.map(stringifyToken).join('');
  1947. };
  1948. var walkTokens = function (tokens) {
  1949. var openedTags = [];
  1950. for (var i = 0; i < tokens.length; i++) {
  1951. var token = tokens[i];
  1952. var notTagNorBrace = false;
  1953. if (typeof token !== 'string') {
  1954. if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
  1955. // We found a tag, now find its kind
  1956. if (token.content[0].content[0].content === '</') {
  1957. // Closing tag
  1958. if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
  1959. // Pop matching opening tag
  1960. openedTags.pop();
  1961. }
  1962. } else {
  1963. if (token.content[token.content.length - 1].content === '/>') {
  1964. // Autoclosed tag, ignore
  1965. } else {
  1966. // Opening tag
  1967. openedTags.push({
  1968. tagName: stringifyToken(token.content[0].content[1]),
  1969. openedBraces: 0
  1970. });
  1971. }
  1972. }
  1973. } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
  1974. // Here we might have entered a JSX context inside a tag
  1975. openedTags[openedTags.length - 1].openedBraces++;
  1976. } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
  1977. // Here we might have left a JSX context inside a tag
  1978. openedTags[openedTags.length - 1].openedBraces--;
  1979. } else {
  1980. notTagNorBrace = true
  1981. }
  1982. }
  1983. if (notTagNorBrace || typeof token === 'string') {
  1984. if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
  1985. // Here we are inside a tag, and not inside a JSX context.
  1986. // That's plain text: drop any tokens matched.
  1987. var plainText = stringifyToken(token);
  1988. // And merge text with adjacent text
  1989. if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
  1990. plainText += stringifyToken(tokens[i + 1]);
  1991. tokens.splice(i + 1, 1);
  1992. }
  1993. if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
  1994. plainText = stringifyToken(tokens[i - 1]) + plainText;
  1995. tokens.splice(i - 1, 1);
  1996. i--;
  1997. }
  1998. tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
  1999. }
  2000. }
  2001. if (token.content && typeof token.content !== 'string') {
  2002. walkTokens(token.content);
  2003. }
  2004. }
  2005. };
  2006. Prism.hooks.add('after-tokenize', function (env) {
  2007. if (env.language !== 'jsx' && env.language !== 'tsx') {
  2008. return;
  2009. }
  2010. walkTokens(env.tokens);
  2011. });
  2012. }(Prism));
  2013. Prism.languages.typescript = Prism.languages.extend('javascript', {
  2014. // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
  2015. 'keyword': /\b(?: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|var|void|while|with|yield|module|declare|constructor|namespace|abstract|require|type)\b/,
  2016. 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console)\b/,
  2017. });
  2018. Prism.languages.ts = Prism.languages.typescript;
  2019. /* TODO
  2020. Add support for Markdown notation inside doc comments
  2021. Add support for nested block comments...
  2022. Match closure params even when not followed by dash or brace
  2023. Add better support for macro definition
  2024. */
  2025. Prism.languages.rust = {
  2026. 'comment': [
  2027. {
  2028. pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
  2029. lookbehind: true
  2030. },
  2031. {
  2032. pattern: /(^|[^\\:])\/\/.*/,
  2033. lookbehind: true
  2034. }
  2035. ],
  2036. 'string': [
  2037. {
  2038. pattern: /b?r(#*)"(?:\\.|(?!"\1)[^\\\r\n])*"\1/,
  2039. greedy: true
  2040. },
  2041. {
  2042. pattern: /b?"(?:\\.|[^\\\r\n"])*"/,
  2043. greedy: true
  2044. }
  2045. ],
  2046. 'char': {
  2047. pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/,
  2048. alias: 'string'
  2049. },
  2050. 'lifetime-annotation': {
  2051. pattern: /'[^\s>']+/,
  2052. alias: 'symbol'
  2053. },
  2054. 'keyword': /\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,
  2055. 'attribute': {
  2056. pattern: /#!?\[.+?\]/,
  2057. greedy: true,
  2058. alias: 'attr-name'
  2059. },
  2060. 'function': [
  2061. /\w+(?=\s*\()/,
  2062. // Macros can use parens or brackets
  2063. /\w+!(?=\s*\(|\[)/
  2064. ],
  2065. 'macro-rules': {
  2066. pattern: /\w+!/,
  2067. alias: 'function'
  2068. },
  2069. // Hex, oct, bin, dec numbers with visual separators and type suffix
  2070. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64)?|f32|f64))?\b/,
  2071. // Closure params should not be confused with bitwise OR |
  2072. 'closure-params': {
  2073. pattern: /\|[^|]*\|(?=\s*[{-])/,
  2074. inside: {
  2075. 'punctuation': /[|:,]/,
  2076. 'operator': /[&*]/
  2077. }
  2078. },
  2079. 'punctuation': /[{}[\];(),:]|\.+|->/,
  2080. 'operator': /[-+*\/%!^]=?|=[=>]?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
  2081. };
  2082. Prism.languages.yaml = {
  2083. 'scalar': {
  2084. pattern: /([\-:]\s*(?:![^\s]+)?[ \t]*[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)[^\r\n]+(?:\2[^\r\n]+)*)/,
  2085. lookbehind: true,
  2086. alias: 'string'
  2087. },
  2088. 'comment': /#.*/,
  2089. 'key': {
  2090. pattern: /(\s*(?:^|[:\-,[{\r\n?])[ \t]*(?:![^\s]+)?[ \t]*)[^\r\n{[\]},#\s]+?(?=\s*:\s)/,
  2091. lookbehind: true,
  2092. alias: 'atrule'
  2093. },
  2094. 'directive': {
  2095. pattern: /(^[ \t]*)%.+/m,
  2096. lookbehind: true,
  2097. alias: 'important'
  2098. },
  2099. 'datetime': {
  2100. pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)(?:\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*)?)?)(?=[ \t]*(?:$|,|]|}))/m,
  2101. lookbehind: true,
  2102. alias: 'number'
  2103. },
  2104. 'boolean': {
  2105. pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)(?:true|false)[ \t]*(?=$|,|]|})/im,
  2106. lookbehind: true,
  2107. alias: 'important'
  2108. },
  2109. 'null': {
  2110. pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)(?:null|~)[ \t]*(?=$|,|]|})/im,
  2111. lookbehind: true,
  2112. alias: 'important'
  2113. },
  2114. 'string': {
  2115. pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}))/m,
  2116. lookbehind: true,
  2117. greedy: true
  2118. },
  2119. 'number': {
  2120. pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+\.?\d*|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)[ \t]*(?=$|,|]|})/im,
  2121. lookbehind: true
  2122. },
  2123. 'tag': /![^\s]+/,
  2124. 'important': /[&*][\w]+/,
  2125. 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
  2126. };