prism.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. /* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+d+elixir+erlang+go+java+json+kotlin+lua+nginx+nim+perl+php+python+jsx+crystal+rust+scss+sql+typescript */
  2. var _self = (typeof window !== 'undefined')
  3. ? window // if in browser
  4. : (
  5. (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
  6. ? self // if in worker
  7. : {} // if in node js
  8. );
  9. /**
  10. * Prism: Lightweight, robust, elegant syntax highlighting
  11. * MIT license http://www.opensource.org/licenses/mit-license.php/
  12. * @author Lea Verou http://lea.verou.me
  13. */
  14. var Prism = (function(){
  15. // Private helper vars
  16. var lang = /\blang(?:uage)?-(\w+)\b/i;
  17. var uniqueId = 0;
  18. var _ = _self.Prism = {
  19. manual: _self.Prism && _self.Prism.manual,
  20. util: {
  21. encode: function (tokens) {
  22. if (tokens instanceof Token) {
  23. return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
  24. } else if (_.util.type(tokens) === 'Array') {
  25. return tokens.map(_.util.encode);
  26. } else {
  27. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  28. }
  29. },
  30. type: function (o) {
  31. return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
  32. },
  33. objId: function (obj) {
  34. if (!obj['__id']) {
  35. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  36. }
  37. return obj['__id'];
  38. },
  39. // Deep clone a language definition (e.g. to extend it)
  40. clone: function (o) {
  41. var type = _.util.type(o);
  42. switch (type) {
  43. case 'Object':
  44. var clone = {};
  45. for (var key in o) {
  46. if (o.hasOwnProperty(key)) {
  47. clone[key] = _.util.clone(o[key]);
  48. }
  49. }
  50. return clone;
  51. case 'Array':
  52. return o.map(function(v) { return _.util.clone(v); });
  53. }
  54. return o;
  55. }
  56. },
  57. languages: {
  58. extend: function (id, redef) {
  59. var lang = _.util.clone(_.languages[id]);
  60. for (var key in redef) {
  61. lang[key] = redef[key];
  62. }
  63. return lang;
  64. },
  65. /**
  66. * Insert a token before another token in a language literal
  67. * As this needs to recreate the object (we cannot actually insert before keys in object literals),
  68. * we cannot just provide an object, we need anobject and a key.
  69. * @param inside The key (or language id) of the parent
  70. * @param before The key to insert before. If not provided, the function appends instead.
  71. * @param insert Object with the key/value pairs to insert
  72. * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
  73. */
  74. insertBefore: function (inside, before, insert, root) {
  75. root = root || _.languages;
  76. var grammar = root[inside];
  77. if (arguments.length == 2) {
  78. insert = arguments[1];
  79. for (var newToken in insert) {
  80. if (insert.hasOwnProperty(newToken)) {
  81. grammar[newToken] = insert[newToken];
  82. }
  83. }
  84. return grammar;
  85. }
  86. var ret = {};
  87. for (var token in grammar) {
  88. if (grammar.hasOwnProperty(token)) {
  89. if (token == before) {
  90. for (var newToken in insert) {
  91. if (insert.hasOwnProperty(newToken)) {
  92. ret[newToken] = insert[newToken];
  93. }
  94. }
  95. }
  96. ret[token] = grammar[token];
  97. }
  98. }
  99. // Update references in other language definitions
  100. _.languages.DFS(_.languages, function(key, value) {
  101. if (value === root[inside] && key != inside) {
  102. this[key] = ret;
  103. }
  104. });
  105. return root[inside] = ret;
  106. },
  107. // Traverse a language definition with Depth First Search
  108. DFS: function(o, callback, type, visited) {
  109. visited = visited || {};
  110. for (var i in o) {
  111. if (o.hasOwnProperty(i)) {
  112. callback.call(o, i, o[i], type || i);
  113. if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
  114. visited[_.util.objId(o[i])] = true;
  115. _.languages.DFS(o[i], callback, null, visited);
  116. }
  117. else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
  118. visited[_.util.objId(o[i])] = true;
  119. _.languages.DFS(o[i], callback, i, visited);
  120. }
  121. }
  122. }
  123. }
  124. },
  125. plugins: {},
  126. highlightAll: function(async, callback) {
  127. var env = {
  128. callback: callback,
  129. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  130. };
  131. _.hooks.run("before-highlightall", env);
  132. var elements = env.elements || document.querySelectorAll(env.selector);
  133. for (var i=0, element; element = elements[i++];) {
  134. _.highlightElement(element, async === true, env.callback);
  135. }
  136. },
  137. highlightElement: function(element, async, callback) {
  138. // Find language
  139. var language, grammar, parent = element;
  140. while (parent && !lang.test(parent.className)) {
  141. parent = parent.parentNode;
  142. }
  143. if (parent) {
  144. language = (parent.className.match(lang) || [,''])[1].toLowerCase();
  145. grammar = _.languages[language];
  146. }
  147. // Set language on the element, if not present
  148. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  149. // Set language on the parent, for styling
  150. parent = element.parentNode;
  151. if (/pre/i.test(parent.nodeName)) {
  152. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  153. }
  154. var code = element.textContent;
  155. var env = {
  156. element: element,
  157. language: language,
  158. grammar: grammar,
  159. code: code
  160. };
  161. _.hooks.run('before-sanity-check', env);
  162. if (!env.code || !env.grammar) {
  163. if (env.code) {
  164. _.hooks.run('before-highlight', env);
  165. env.element.textContent = env.code;
  166. _.hooks.run('after-highlight', env);
  167. }
  168. _.hooks.run('complete', env);
  169. return;
  170. }
  171. _.hooks.run('before-highlight', env);
  172. // if (async && _self.Worker) {
  173. // var worker = new Worker(_.filename);
  174. // worker.onmessage = function(evt) {
  175. // env.highlightedCode = evt.data;
  176. // _.hooks.run('before-insert', env);
  177. // env.element.innerHTML = env.highlightedCode;
  178. // callback && callback.call(env.element);
  179. // _.hooks.run('after-highlight', env);
  180. // _.hooks.run('complete', env);
  181. // };
  182. // worker.postMessage(JSON.stringify({
  183. // language: env.language,
  184. // code: env.code,
  185. // immediateClose: true
  186. // }));
  187. // }
  188. // else {
  189. env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
  190. _.hooks.run('before-insert', env);
  191. env.element.innerHTML = env.highlightedCode;
  192. callback && callback.call(element);
  193. _.hooks.run('after-highlight', env);
  194. _.hooks.run('complete', env);
  195. // }
  196. },
  197. highlight: function (text, grammar, language) {
  198. var tokens = _.tokenize(text, grammar);
  199. return Token.stringify(_.util.encode(tokens), language);
  200. },
  201. matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
  202. var Token = _.Token;
  203. for (var token in grammar) {
  204. if(!grammar.hasOwnProperty(token) || !grammar[token]) {
  205. continue;
  206. }
  207. if (token == target) {
  208. return;
  209. }
  210. var patterns = grammar[token];
  211. patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
  212. for (var j = 0; j < patterns.length; ++j) {
  213. var pattern = patterns[j],
  214. inside = pattern.inside,
  215. lookbehind = !!pattern.lookbehind,
  216. greedy = !!pattern.greedy,
  217. lookbehindLength = 0,
  218. alias = pattern.alias;
  219. if (greedy && !pattern.pattern.global) {
  220. // Without the global flag, lastIndex won't work
  221. var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
  222. pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
  223. }
  224. pattern = pattern.pattern || pattern;
  225. // Don’t cache length as it changes during the loop
  226. for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) {
  227. var str = strarr[i];
  228. if (strarr.length > text.length) {
  229. // Something went terribly wrong, ABORT, ABORT!
  230. return;
  231. }
  232. if (str instanceof Token) {
  233. continue;
  234. }
  235. pattern.lastIndex = 0;
  236. var match = pattern.exec(str),
  237. delNum = 1;
  238. // Greedy patterns can override/remove up to two previously matched tokens
  239. if (!match && greedy && i != strarr.length - 1) {
  240. pattern.lastIndex = pos;
  241. match = pattern.exec(text);
  242. if (!match) {
  243. break;
  244. }
  245. var from = match.index + (lookbehind ? match[1].length : 0),
  246. to = match.index + match[0].length,
  247. k = i,
  248. p = pos;
  249. for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) {
  250. p += strarr[k].length;
  251. // Move the index i to the element in strarr that is closest to from
  252. if (from >= p) {
  253. ++i;
  254. pos = p;
  255. }
  256. }
  257. /*
  258. * If strarr[i] is a Token, then the match starts inside another Token, which is invalid
  259. * If strarr[k - 1] is greedy we are in conflict with another greedy pattern
  260. */
  261. if (strarr[i] instanceof Token || strarr[k - 1].greedy) {
  262. continue;
  263. }
  264. // Number of tokens to delete and replace with the new match
  265. delNum = k - i;
  266. str = text.slice(pos, p);
  267. match.index -= pos;
  268. }
  269. if (!match) {
  270. if (oneshot) {
  271. break;
  272. }
  273. continue;
  274. }
  275. if(lookbehind) {
  276. lookbehindLength = match[1].length;
  277. }
  278. var from = match.index + lookbehindLength,
  279. match = match[0].slice(lookbehindLength),
  280. to = from + match.length,
  281. before = str.slice(0, from),
  282. after = str.slice(to);
  283. var args = [i, delNum];
  284. if (before) {
  285. ++i;
  286. pos += before.length;
  287. args.push(before);
  288. }
  289. var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
  290. args.push(wrapped);
  291. if (after) {
  292. args.push(after);
  293. }
  294. Array.prototype.splice.apply(strarr, args);
  295. if (delNum != 1)
  296. _.matchGrammar(text, strarr, grammar, i, pos, true, token);
  297. if (oneshot)
  298. break;
  299. }
  300. }
  301. }
  302. },
  303. tokenize: function(text, grammar, language) {
  304. var strarr = [text];
  305. var rest = grammar.rest;
  306. if (rest) {
  307. for (var token in rest) {
  308. grammar[token] = rest[token];
  309. }
  310. delete grammar.rest;
  311. }
  312. _.matchGrammar(text, strarr, grammar, 0, 0, false);
  313. return strarr;
  314. },
  315. hooks: {
  316. all: {},
  317. add: function (name, callback) {
  318. var hooks = _.hooks.all;
  319. hooks[name] = hooks[name] || [];
  320. hooks[name].push(callback);
  321. },
  322. run: function (name, env) {
  323. var callbacks = _.hooks.all[name];
  324. if (!callbacks || !callbacks.length) {
  325. return;
  326. }
  327. for (var i=0, callback; callback = callbacks[i++];) {
  328. callback(env);
  329. }
  330. }
  331. }
  332. };
  333. var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
  334. this.type = type;
  335. this.content = content;
  336. this.alias = alias;
  337. // Copy of the full string this token was created from
  338. this.length = (matchedStr || "").length|0;
  339. this.greedy = !!greedy;
  340. };
  341. Token.stringify = function(o, language, parent) {
  342. if (typeof o == 'string') {
  343. return o;
  344. }
  345. if (_.util.type(o) === 'Array') {
  346. return o.map(function(element) {
  347. return Token.stringify(element, language, o);
  348. }).join('');
  349. }
  350. var env = {
  351. type: o.type,
  352. content: Token.stringify(o.content, language, parent),
  353. tag: 'span',
  354. classes: ['token', o.type],
  355. attributes: {},
  356. language: language,
  357. parent: parent
  358. };
  359. if (env.type == 'comment') {
  360. env.attributes['spellcheck'] = 'true';
  361. }
  362. if (o.alias) {
  363. var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
  364. Array.prototype.push.apply(env.classes, aliases);
  365. }
  366. _.hooks.run('wrap', env);
  367. var attributes = Object.keys(env.attributes).map(function(name) {
  368. return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  369. }).join(' ');
  370. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
  371. };
  372. // if (!_self.document) {
  373. // if (!_self.addEventListener) {
  374. // // in Node.js
  375. // return _self.Prism;
  376. // }
  377. // // In worker
  378. // _self.addEventListener('message', function(evt) {
  379. // var message = JSON.parse(evt.data),
  380. // lang = message.language,
  381. // code = message.code,
  382. // immediateClose = message.immediateClose;
  383. // _self.postMessage(_.highlight(code, _.languages[lang], lang));
  384. // if (immediateClose) {
  385. // _self.close();
  386. // }
  387. // }, false);
  388. // return _self.Prism;
  389. // }
  390. // //Get current script and highlight
  391. // var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
  392. // if (script) {
  393. // _.filename = script.src;
  394. // if (!_.manual && !script.hasAttribute('data-manual')) {
  395. // if(document.readyState !== "loading") {
  396. // if (window.requestAnimationFrame) {
  397. // window.requestAnimationFrame(_.highlightAll);
  398. // } else {
  399. // window.setTimeout(_.highlightAll, 16);
  400. // }
  401. // }
  402. // else {
  403. // document.addEventListener('DOMContentLoaded', _.highlightAll);
  404. // }
  405. // }
  406. // }
  407. return _self.Prism;
  408. })();
  409. if (typeof module !== 'undefined' && module.exports) {
  410. module.exports = Prism;
  411. }
  412. // hack for components to work correctly in node.js
  413. if (typeof global !== 'undefined') {
  414. global.Prism = Prism;
  415. }
  416. ;
  417. Prism.languages.markup = {
  418. 'comment': /<!--[\s\S]*?-->/,
  419. 'prolog': /<\?[\s\S]+?\?>/,
  420. 'doctype': /<!DOCTYPE[\s\S]+?>/i,
  421. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  422. 'tag': {
  423. pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\s\S])*\1|[^\s'">=]+))?)*\s*\/?>/i,
  424. inside: {
  425. 'tag': {
  426. pattern: /^<\/?[^\s>\/]+/i,
  427. inside: {
  428. 'punctuation': /^<\/?/,
  429. 'namespace': /^[^\s>\/:]+:/
  430. }
  431. },
  432. 'attr-value': {
  433. pattern: /=(?:('|")[\s\S]*?(\1)|[^\s>]+)/i,
  434. inside: {
  435. 'punctuation': /[=>"']/
  436. }
  437. },
  438. 'punctuation': /\/?>/,
  439. 'attr-name': {
  440. pattern: /[^\s>\/]+/,
  441. inside: {
  442. 'namespace': /^[^\s>\/:]+:/
  443. }
  444. }
  445. }
  446. },
  447. 'entity': /&#?[\da-z]{1,8};/i
  448. };
  449. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
  450. Prism.languages.markup['entity'];
  451. // Plugin to make entity title show the real entity, idea by Roman Komarov
  452. Prism.hooks.add('wrap', function(env) {
  453. if (env.type === 'entity') {
  454. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  455. }
  456. });
  457. Prism.languages.xml = Prism.languages.markup;
  458. Prism.languages.html = Prism.languages.markup;
  459. Prism.languages.mathml = Prism.languages.markup;
  460. Prism.languages.svg = Prism.languages.markup;
  461. Prism.languages.css = {
  462. 'comment': /\/\*[\s\S]*?\*\//,
  463. 'atrule': {
  464. pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
  465. inside: {
  466. 'rule': /@[\w-]+/
  467. // See rest below
  468. }
  469. },
  470. 'url': /url\((?:(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
  471. 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
  472. 'string': {
  473. pattern: /("|')(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  474. greedy: true
  475. },
  476. 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
  477. 'important': /\B!important\b/i,
  478. 'function': /[-a-z0-9]+(?=\()/i,
  479. 'punctuation': /[(){};:]/
  480. };
  481. Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
  482. if (Prism.languages.markup) {
  483. Prism.languages.insertBefore('markup', 'tag', {
  484. 'style': {
  485. pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i,
  486. lookbehind: true,
  487. inside: Prism.languages.css,
  488. alias: 'language-css'
  489. }
  490. });
  491. Prism.languages.insertBefore('inside', 'attr-value', {
  492. 'style-attr': {
  493. pattern: /\s*style=("|').*?\1/i,
  494. inside: {
  495. 'attr-name': {
  496. pattern: /^\s*style/i,
  497. inside: Prism.languages.markup.tag.inside
  498. },
  499. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  500. 'attr-value': {
  501. pattern: /.+/i,
  502. inside: Prism.languages.css
  503. }
  504. },
  505. alias: 'language-css'
  506. }
  507. }, Prism.languages.markup.tag);
  508. };
  509. Prism.languages.clike = {
  510. 'comment': [
  511. {
  512. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  513. lookbehind: true
  514. },
  515. {
  516. pattern: /(^|[^\\:])\/\/.*/,
  517. lookbehind: true
  518. }
  519. ],
  520. 'string': {
  521. pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  522. greedy: true
  523. },
  524. 'class-name': {
  525. pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
  526. lookbehind: true,
  527. inside: {
  528. punctuation: /(\.|\\)/
  529. }
  530. },
  531. 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  532. 'boolean': /\b(true|false)\b/,
  533. 'function': /[a-z0-9_]+(?=\()/i,
  534. 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
  535. 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
  536. 'punctuation': /[{}[\];(),.:]/
  537. };
  538. Prism.languages.javascript = Prism.languages.extend('clike', {
  539. '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/,
  540. 'number': /\b-?(0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
  541. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  542. 'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,
  543. 'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
  544. });
  545. Prism.languages.insertBefore('javascript', 'keyword', {
  546. 'regex': {
  547. pattern: /(^|[^/])\/(?!\/)(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
  548. lookbehind: true,
  549. greedy: true
  550. }
  551. });
  552. Prism.languages.insertBefore('javascript', 'string', {
  553. 'template-string': {
  554. pattern: /`(?:\\\\|\\?[^\\])*?`/,
  555. greedy: true,
  556. inside: {
  557. 'interpolation': {
  558. pattern: /\$\{[^}]+\}/,
  559. inside: {
  560. 'interpolation-punctuation': {
  561. pattern: /^\$\{|\}$/,
  562. alias: 'punctuation'
  563. },
  564. rest: Prism.languages.javascript
  565. }
  566. },
  567. 'string': /[\s\S]+/
  568. }
  569. }
  570. });
  571. if (Prism.languages.markup) {
  572. Prism.languages.insertBefore('markup', 'tag', {
  573. 'script': {
  574. pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
  575. lookbehind: true,
  576. inside: Prism.languages.javascript,
  577. alias: 'language-javascript'
  578. }
  579. });
  580. }
  581. Prism.languages.js = Prism.languages.javascript;
  582. Prism.languages.c = Prism.languages.extend('clike', {
  583. '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/,
  584. 'operator': /\-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*\/]/,
  585. 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*\b/i
  586. });
  587. Prism.languages.insertBefore('c', 'string', {
  588. 'macro': {
  589. // allow for multiline macro definitions
  590. // spaces after the # character compile fine with gcc
  591. pattern: /(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,
  592. lookbehind: true,
  593. alias: 'property',
  594. inside: {
  595. // highlight the path of the include statement as a string
  596. 'string': {
  597. pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
  598. lookbehind: true
  599. },
  600. // highlight macro directives as keywords
  601. 'directive': {
  602. pattern: /(#\s*)\b(define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
  603. lookbehind: true,
  604. alias: 'keyword'
  605. }
  606. }
  607. },
  608. // highlight predefined macros as constants
  609. 'constant': /\b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
  610. });
  611. delete Prism.languages.c['class-name'];
  612. delete Prism.languages.c['boolean'];
  613. Prism.languages.cpp = Prism.languages.extend('c', {
  614. '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|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/,
  615. 'boolean': /\b(true|false)\b/,
  616. 'operator': /[-+]{1,2}|!=?|<{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/
  617. });
  618. Prism.languages.insertBefore('cpp', 'keyword', {
  619. 'class-name': {
  620. pattern: /(class\s+)[a-z0-9_]+/i,
  621. lookbehind: true
  622. }
  623. });
  624. (function(Prism) {
  625. // Ignore comments starting with { to privilege string interpolation highlighting
  626. var comment = /#(?!\{).+/,
  627. interpolation = {
  628. pattern: /#\{[^}]+\}/,
  629. alias: 'variable'
  630. };
  631. Prism.languages.coffeescript = Prism.languages.extend('javascript', {
  632. 'comment': comment,
  633. 'string': [
  634. // Strings are multiline
  635. {
  636. pattern: /'(?:\\?[^\\])*?'/,
  637. greedy: true
  638. },
  639. {
  640. // Strings are multiline
  641. pattern: /"(?:\\?[^\\])*?"/,
  642. greedy: true,
  643. inside: {
  644. 'interpolation': interpolation
  645. }
  646. }
  647. ],
  648. '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/,
  649. 'class-member': {
  650. pattern: /@(?!\d)\w+/,
  651. alias: 'variable'
  652. }
  653. });
  654. Prism.languages.insertBefore('coffeescript', 'comment', {
  655. 'multiline-comment': {
  656. pattern: /###[\s\S]+?###/,
  657. alias: 'comment'
  658. },
  659. // Block regexp can contain comments and interpolation
  660. 'block-regex': {
  661. pattern: /\/{3}[\s\S]*?\/{3}/,
  662. alias: 'regex',
  663. inside: {
  664. 'comment': comment,
  665. 'interpolation': interpolation
  666. }
  667. }
  668. });
  669. Prism.languages.insertBefore('coffeescript', 'string', {
  670. 'inline-javascript': {
  671. pattern: /`(?:\\?[\s\S])*?`/,
  672. inside: {
  673. 'delimiter': {
  674. pattern: /^`|`$/,
  675. alias: 'punctuation'
  676. },
  677. rest: Prism.languages.javascript
  678. }
  679. },
  680. // Block strings
  681. 'multiline-string': [
  682. {
  683. pattern: /'''[\s\S]*?'''/,
  684. greedy: true,
  685. alias: 'string'
  686. },
  687. {
  688. pattern: /"""[\s\S]*?"""/,
  689. greedy: true,
  690. alias: 'string',
  691. inside: {
  692. interpolation: interpolation
  693. }
  694. }
  695. ]
  696. });
  697. Prism.languages.insertBefore('coffeescript', 'keyword', {
  698. // Object property
  699. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  700. });
  701. delete Prism.languages.coffeescript['template-string'];
  702. }(Prism));
  703. /**
  704. * Original by Samuel Flores
  705. *
  706. * Adds the following new token classes:
  707. * constant, builtin, variable, symbol, regex
  708. */
  709. (function(Prism) {
  710. Prism.languages.ruby = Prism.languages.extend('clike', {
  711. 'comment': [
  712. /#(?!\{[^\r\n]*?\}).*/,
  713. /^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m
  714. ],
  715. '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|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/
  716. });
  717. var interpolation = {
  718. pattern: /#\{[^}]+\}/,
  719. inside: {
  720. 'delimiter': {
  721. pattern: /^#\{|\}$/,
  722. alias: 'tag'
  723. },
  724. rest: Prism.util.clone(Prism.languages.ruby)
  725. }
  726. };
  727. Prism.languages.insertBefore('ruby', 'keyword', {
  728. 'regex': [
  729. {
  730. pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,
  731. greedy: true,
  732. inside: {
  733. 'interpolation': interpolation
  734. }
  735. },
  736. {
  737. pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
  738. greedy: true,
  739. inside: {
  740. 'interpolation': interpolation
  741. }
  742. },
  743. {
  744. // Here we need to specifically allow interpolation
  745. pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
  746. greedy: true,
  747. inside: {
  748. 'interpolation': interpolation
  749. }
  750. },
  751. {
  752. pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
  753. greedy: true,
  754. inside: {
  755. 'interpolation': interpolation
  756. }
  757. },
  758. {
  759. pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
  760. greedy: true,
  761. inside: {
  762. 'interpolation': interpolation
  763. }
  764. },
  765. {
  766. pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
  767. lookbehind: true,
  768. greedy: true
  769. }
  770. ],
  771. 'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,
  772. 'symbol': /:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/
  773. });
  774. Prism.languages.insertBefore('ruby', 'number', {
  775. 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
  776. 'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/
  777. });
  778. Prism.languages.ruby.string = [
  779. {
  780. pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
  781. greedy: true,
  782. inside: {
  783. 'interpolation': interpolation
  784. }
  785. },
  786. {
  787. pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
  788. greedy: true,
  789. inside: {
  790. 'interpolation': interpolation
  791. }
  792. },
  793. {
  794. // Here we need to specifically allow interpolation
  795. pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
  796. greedy: true,
  797. inside: {
  798. 'interpolation': interpolation
  799. }
  800. },
  801. {
  802. pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
  803. greedy: true,
  804. inside: {
  805. 'interpolation': interpolation
  806. }
  807. },
  808. {
  809. pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
  810. greedy: true,
  811. inside: {
  812. 'interpolation': interpolation
  813. }
  814. },
  815. {
  816. pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
  817. greedy: true,
  818. inside: {
  819. 'interpolation': interpolation
  820. }
  821. }
  822. ];
  823. }(Prism));
  824. Prism.languages.d = Prism.languages.extend('clike', {
  825. 'string': [
  826. // r"", x""
  827. /\b[rx]"(\\.|[^\\"])*"[cwd]?/,
  828. // q"[]", q"()", q"<>", q"{}"
  829. /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/,
  830. // q"IDENT
  831. // ...
  832. // IDENT"
  833. /\bq"([_a-zA-Z][_a-zA-Z\d]*)(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\1"/,
  834. // q"//", q"||", etc.
  835. /\bq"(.)[\s\S]*?\1"/,
  836. // Characters
  837. /'(?:\\'|\\?[^']+)'/,
  838. /(["`])(\\.|(?!\1)[^\\])*\1[cwd]?/
  839. ],
  840. 'number': [
  841. // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
  842. // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
  843. /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]*/i,
  844. {
  845. pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]*/i,
  846. lookbehind: true
  847. }
  848. ],
  849. // In order: $, keywords and special tokens, globally defined symbols
  850. '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/,
  851. 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
  852. });
  853. Prism.languages.d.comment = [
  854. // Shebang
  855. /^\s*#!.+/,
  856. // /+ +/
  857. {
  858. // Allow one level of nesting
  859. pattern: /(^|[^\\])\/\+(?:\/\+[\s\S]*?\+\/|[\s\S])*?\+\//,
  860. lookbehind: true
  861. }
  862. ].concat(Prism.languages.d.comment);
  863. Prism.languages.insertBefore('d', 'comment', {
  864. 'token-string': {
  865. // Allow one level of nesting
  866. pattern: /\bq\{(?:|\{[^}]*\}|[^}])*\}/,
  867. alias: 'string'
  868. }
  869. });
  870. Prism.languages.insertBefore('d', 'keyword', {
  871. 'property': /\B@\w*/
  872. });
  873. Prism.languages.insertBefore('d', 'function', {
  874. 'register': {
  875. // Iasm registers
  876. 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)/,
  877. alias: 'variable'
  878. }
  879. });
  880. Prism.languages.elixir = {
  881. // Negative look-ahead is needed for string interpolation
  882. // Negative look-behind is needed to avoid highlighting markdown headers in
  883. // multi-line doc strings
  884. 'comment': {
  885. pattern: /(^|[^#])#(?![{#]).*/m,
  886. lookbehind: true
  887. },
  888. // ~r"""foo""", ~r'''foo''', ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  889. 'regex': /~[rR](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|[^}])+\}|<(?:\\>|[^>])+>)[uismxfr]*/,
  890. 'string': [
  891. {
  892. // ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>
  893. pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/,
  894. greedy: true,
  895. inside: {
  896. // See interpolation below
  897. }
  898. },
  899. {
  900. pattern: /("""|''')[\s\S]*?\1/,
  901. greedy: true,
  902. inside: {
  903. // See interpolation below
  904. }
  905. },
  906. {
  907. // Multi-line strings are allowed
  908. pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
  909. greedy: true,
  910. inside: {
  911. // See interpolation below
  912. }
  913. }
  914. ],
  915. 'atom': {
  916. // Look-behind prevents bad highlighting of the :: operator
  917. pattern: /(^|[^:]):\w+/,
  918. lookbehind: true,
  919. alias: 'symbol'
  920. },
  921. // Look-ahead prevents bad highlighting of the :: operator
  922. 'attr-name': /\w+:(?!:)/,
  923. 'capture': {
  924. // Look-behind prevents bad highlighting of the && operator
  925. pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
  926. lookbehind: true,
  927. alias: 'function'
  928. },
  929. 'argument': {
  930. // Look-behind prevents bad highlighting of the && operator
  931. pattern: /(^|[^&])&\d+/,
  932. lookbehind: true,
  933. alias: 'variable'
  934. },
  935. 'attribute': {
  936. pattern: /@[\S]+/,
  937. alias: 'variable'
  938. },
  939. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  940. '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/,
  941. 'boolean': /\b(?:true|false|nil)\b/,
  942. 'operator': [
  943. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  944. {
  945. // We don't want to match <<
  946. pattern: /([^<])<(?!<)/,
  947. lookbehind: true
  948. },
  949. {
  950. // We don't want to match >>
  951. pattern: /([^>])>(?!>)/,
  952. lookbehind: true
  953. }
  954. ],
  955. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  956. };
  957. Prism.languages.elixir.string.forEach(function(o) {
  958. o.inside = {
  959. 'interpolation': {
  960. pattern: /#\{[^}]+\}/,
  961. inside: {
  962. 'delimiter': {
  963. pattern: /^#\{|\}$/,
  964. alias: 'punctuation'
  965. },
  966. rest: Prism.util.clone(Prism.languages.elixir)
  967. }
  968. }
  969. };
  970. });
  971. Prism.languages.erlang = {
  972. 'comment': /%.+/,
  973. 'string': {
  974. pattern: /"(?:\\?.)*?"/,
  975. greedy: true
  976. },
  977. 'quoted-function': {
  978. pattern: /'(?:\\.|[^'\\])+'(?=\()/,
  979. alias: 'function'
  980. },
  981. 'quoted-atom': {
  982. pattern: /'(?:\\.|[^'\\])+'/,
  983. alias: 'atom'
  984. },
  985. 'boolean': /\b(?:true|false)\b/,
  986. 'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
  987. 'number': [
  988. /\$\\?./,
  989. /\d+#[a-z0-9]+/i,
  990. /(?:\b|-)\d*\.?\d+([Ee][+-]?\d+)?\b/
  991. ],
  992. 'function': /\b[a-z][\w@]*(?=\()/,
  993. 'variable': {
  994. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  995. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  996. lookbehind: true
  997. },
  998. 'operator': [
  999. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,
  1000. {
  1001. // We don't want to match <<
  1002. pattern: /(^|[^<])<(?!<)/,
  1003. lookbehind: true
  1004. },
  1005. {
  1006. // We don't want to match >>
  1007. pattern: /(^|[^>])>(?!>)/,
  1008. lookbehind: true
  1009. }
  1010. ],
  1011. 'atom': /\b[a-z][\w@]*/,
  1012. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  1013. };
  1014. Prism.languages.go = Prism.languages.extend('clike', {
  1015. '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/,
  1016. '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/,
  1017. 'boolean': /\b(_|iota|nil|true|false)\b/,
  1018. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  1019. 'number': /\b(-?(0x[a-f\d]+|(\d+\.?\d*|\.\d+)(e[-+]?\d+)?)i?)\b/i,
  1020. 'string': {
  1021. pattern: /("|'|`)(\\?.|\r|\n)*?\1/,
  1022. greedy: true
  1023. }
  1024. });
  1025. delete Prism.languages.go['class-name'];
  1026. Prism.languages.java = Prism.languages.extend('clike', {
  1027. '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/,
  1028. 'number': /\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,
  1029. 'operator': {
  1030. pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,
  1031. lookbehind: true
  1032. }
  1033. });
  1034. Prism.languages.insertBefore('java','function', {
  1035. 'annotation': {
  1036. alias: 'punctuation',
  1037. pattern: /(^|[^.])@\w+/,
  1038. lookbehind: true
  1039. }
  1040. });
  1041. Prism.languages.json = {
  1042. 'property': /"(?:\\.|[^\\"])*"(?=\s*:)/ig,
  1043. 'string': /"(?!:)(?:\\.|[^\\"])*"(?!:)/g,
  1044. 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?)\b/g,
  1045. 'punctuation': /[{}[\]);,]/g,
  1046. 'operator': /:/g,
  1047. 'boolean': /\b(true|false)\b/gi,
  1048. 'null': /\bnull\b/gi
  1049. };
  1050. Prism.languages.jsonp = Prism.languages.json;
  1051. (function (Prism) {
  1052. Prism.languages.kotlin = Prism.languages.extend('clike', {
  1053. 'keyword': {
  1054. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  1055. pattern: /(^|[^.])\b(?:abstract|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|else|enum|final|finally|for|fun|get|if|import|in|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|out|override|package|private|protected|public|reified|return|sealed|set|super|tailrec|this|throw|to|try|val|var|when|where|while)\b/,
  1056. lookbehind: true
  1057. },
  1058. 'function': [
  1059. /\w+(?=\s*\()/,
  1060. {
  1061. pattern: /(\.)\w+(?=\s*\{)/,
  1062. lookbehind: true
  1063. }
  1064. ],
  1065. 'number': /\b(?:0[bx][\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?[fFL]?)\b/,
  1066. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  1067. });
  1068. delete Prism.languages.kotlin["class-name"];
  1069. Prism.languages.insertBefore('kotlin', 'string', {
  1070. 'raw-string': {
  1071. pattern: /(["'])\1\1[\s\S]*?\1{3}/,
  1072. alias: 'string'
  1073. // See interpolation below
  1074. }
  1075. });
  1076. Prism.languages.insertBefore('kotlin', 'keyword', {
  1077. 'annotation': {
  1078. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  1079. alias: 'builtin'
  1080. }
  1081. });
  1082. Prism.languages.insertBefore('kotlin', 'function', {
  1083. 'label': {
  1084. pattern: /\w+@|@\w+/,
  1085. alias: 'symbol'
  1086. }
  1087. });
  1088. var interpolation = [
  1089. {
  1090. pattern: /\$\{[^}]+\}/,
  1091. inside: {
  1092. delimiter: {
  1093. pattern: /^\$\{|\}$/,
  1094. alias: 'variable'
  1095. },
  1096. rest: Prism.util.clone(Prism.languages.kotlin)
  1097. }
  1098. },
  1099. {
  1100. pattern: /\$\w+/,
  1101. alias: 'variable'
  1102. }
  1103. ];
  1104. Prism.languages.kotlin['string'].inside = Prism.languages.kotlin['raw-string'].inside = {
  1105. interpolation: interpolation
  1106. };
  1107. }(Prism));
  1108. Prism.languages.lua = {
  1109. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  1110. // \z may be used to skip the following space
  1111. 'string': {
  1112. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[\s\S]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  1113. greedy: true
  1114. },
  1115. 'number': /\b0x[a-f\d]+\.?[a-f\d]*(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|\.?\d*(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  1116. '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/,
  1117. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  1118. 'operator': [
  1119. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  1120. {
  1121. // Match ".." but don't break "..."
  1122. pattern: /(^|[^.])\.\.(?!\.)/,
  1123. lookbehind: true
  1124. }
  1125. ],
  1126. 'punctuation': /[\[\](){},;]|\.+|:+/
  1127. };
  1128. Prism.languages.nginx = Prism.languages.extend('clike', {
  1129. 'comment': {
  1130. pattern: /(^|[^"{\\])#.*/,
  1131. lookbehind: true
  1132. },
  1133. 'keyword': /\b(?:CONTENT_|DOCUMENT_|GATEWAY_|HTTP_|HTTPS|if_not_empty|PATH_|QUERY_|REDIRECT_|REMOTE_|REQUEST_|SCGI|SCRIPT_|SERVER_|http|server|events|location|include|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,
  1134. });
  1135. Prism.languages.insertBefore('nginx', 'keyword', {
  1136. 'variable': /\$[a-z_]+/i
  1137. });
  1138. Prism.languages.nim = {
  1139. 'comment': /#.*/,
  1140. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  1141. // Character literals are handled specifically to prevent issues with numeric type suffixes
  1142. 'string': {
  1143. pattern: /(?:(?:\b(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")|'(?:\\(?:\d+|x[\da-fA-F]{2}|.)|[^'])')/,
  1144. greedy: true
  1145. },
  1146. // The negative look ahead prevents wrong highlighting of the .. operator
  1147. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  1148. '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/,
  1149. 'function': {
  1150. pattern: /(?:(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  1151. inside: {
  1152. 'operator': /\*$/
  1153. }
  1154. },
  1155. // We don't want to highlight operators inside backticks
  1156. 'ignore': {
  1157. pattern: /`[^`\r\n]+`/,
  1158. inside: {
  1159. 'punctuation': /`/
  1160. }
  1161. },
  1162. 'operator': {
  1163. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  1164. // but allow the slice operator .. to take precedence over them
  1165. // One can define his own operators in Nim so all combination of operators might be an operator.
  1166. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|of|or|in|is|isnot|mod|not|notin|shl|shr|xor)\b)/m,
  1167. lookbehind: true
  1168. },
  1169. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  1170. };
  1171. Prism.languages.perl = {
  1172. 'comment': [
  1173. {
  1174. // POD
  1175. pattern: /(^\s*)=\w+[\s\S]*?=cut.*/m,
  1176. lookbehind: true
  1177. },
  1178. {
  1179. pattern: /(^|[^\\$])#.*/,
  1180. lookbehind: true
  1181. }
  1182. ],
  1183. // TODO Could be nice to handle Heredoc too.
  1184. 'string': [
  1185. // q/.../
  1186. {
  1187. pattern: /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
  1188. greedy: true
  1189. },
  1190. // q a...a
  1191. {
  1192. pattern: /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\1/,
  1193. greedy: true
  1194. },
  1195. // q(...)
  1196. {
  1197. pattern: /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,
  1198. greedy: true
  1199. },
  1200. // q{...}
  1201. {
  1202. pattern: /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,
  1203. greedy: true
  1204. },
  1205. // q[...]
  1206. {
  1207. pattern: /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,
  1208. greedy: true
  1209. },
  1210. // q<...>
  1211. {
  1212. pattern: /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,
  1213. greedy: true
  1214. },
  1215. // "...", `...`
  1216. {
  1217. pattern: /("|`)(?:[^\\]|\\[\s\S])*?\1/,
  1218. greedy: true
  1219. },
  1220. // '...'
  1221. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  1222. {
  1223. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  1224. greedy: true
  1225. }
  1226. ],
  1227. 'regex': [
  1228. // m/.../
  1229. {
  1230. pattern: /\b(?:m|qr)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[msixpodualngc]*/,
  1231. greedy: true
  1232. },
  1233. // m a...a
  1234. {
  1235. pattern: /\b(?:m|qr)\s+([a-zA-Z0-9])(?:[^\\]|\\.)*?\1[msixpodualngc]*/,
  1236. greedy: true
  1237. },
  1238. // m(...)
  1239. {
  1240. pattern: /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,
  1241. greedy: true
  1242. },
  1243. // m{...}
  1244. {
  1245. pattern: /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,
  1246. greedy: true
  1247. },
  1248. // m[...]
  1249. {
  1250. pattern: /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,
  1251. greedy: true
  1252. },
  1253. // m<...>
  1254. {
  1255. pattern: /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,
  1256. greedy: true
  1257. },
  1258. // The lookbehinds prevent -s from breaking
  1259. // FIXME We don't handle change of separator like s(...)[...]
  1260. // s/.../.../
  1261. {
  1262. pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
  1263. lookbehind: true,
  1264. greedy: true
  1265. },
  1266. // s a...a...a
  1267. {
  1268. pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
  1269. lookbehind: true,
  1270. greedy: true
  1271. },
  1272. // s(...)(...)
  1273. {
  1274. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,
  1275. lookbehind: true,
  1276. greedy: true
  1277. },
  1278. // s{...}{...}
  1279. {
  1280. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,
  1281. lookbehind: true,
  1282. greedy: true
  1283. },
  1284. // s[...][...]
  1285. {
  1286. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,
  1287. lookbehind: true,
  1288. greedy: true
  1289. },
  1290. // s<...><...>
  1291. {
  1292. pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,
  1293. lookbehind: true,
  1294. greedy: true
  1295. },
  1296. // /.../
  1297. // The look-ahead tries to prevent two divisions on
  1298. // the same line from being highlighted as regex.
  1299. // This does not support multi-line regex.
  1300. {
  1301. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/,
  1302. greedy: true
  1303. }
  1304. ],
  1305. // FIXME Not sure about the handling of ::, ', and #
  1306. 'variable': [
  1307. // ${^POSTMATCH}
  1308. /[&*$@%]\{\^[A-Z]+\}/,
  1309. // $^V
  1310. /[&*$@%]\^[A-Z_]/,
  1311. // ${...}
  1312. /[&*$@%]#?(?=\{)/,
  1313. // $foo
  1314. /[&*$@%]#?((::)*'?(?!\d)[\w$]+)+(::)*/i,
  1315. // $1
  1316. /[&*$@%]\d+/,
  1317. // $_, @_, %!
  1318. // The negative lookahead prevents from breaking the %= operator
  1319. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  1320. ],
  1321. 'filehandle': {
  1322. // <>, <FOO>, _
  1323. pattern: /<(?![<=])\S*>|\b_\b/,
  1324. alias: 'symbol'
  1325. },
  1326. 'vstring': {
  1327. // v1.2, 1.2.3
  1328. pattern: /v\d+(\.\d+)*|\d+(\.\d+){2,}/,
  1329. alias: 'string'
  1330. },
  1331. 'function': {
  1332. pattern: /sub [a-z0-9_]+/i,
  1333. inside: {
  1334. keyword: /sub/
  1335. }
  1336. },
  1337. '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/,
  1338. 'number': /\b-?(0x[\dA-Fa-f](_?[\dA-Fa-f])*|0b[01](_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)\b/,
  1339. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor)\b/,
  1340. 'punctuation': /[{}[\];(),:]/
  1341. };
  1342. /**
  1343. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  1344. * Modified by Miles Johnson: http://milesj.me
  1345. *
  1346. * Supports the following:
  1347. * - Extends clike syntax
  1348. * - Support for PHP 5.3+ (namespaces, traits, generators, etc)
  1349. * - Smarter constant and function matching
  1350. *
  1351. * Adds the following new token classes:
  1352. * constant, delimiter, variable, function, package
  1353. */
  1354. Prism.languages.php = Prism.languages.extend('clike', {
  1355. '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,
  1356. 'constant': /\b[A-Z0-9_]{2,}\b/,
  1357. 'comment': {
  1358. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1359. lookbehind: true
  1360. }
  1361. });
  1362. // Shell-like comments are matched after strings, because they are less
  1363. // common than strings containing hashes...
  1364. Prism.languages.insertBefore('php', 'class-name', {
  1365. 'shell-comment': {
  1366. pattern: /(^|[^\\])#.*/,
  1367. lookbehind: true,
  1368. alias: 'comment'
  1369. }
  1370. });
  1371. Prism.languages.insertBefore('php', 'keyword', {
  1372. 'delimiter': {
  1373. pattern: /\?>|<\?(?:php|=)?/i,
  1374. alias: 'important'
  1375. },
  1376. 'variable': /\$\w+\b/i,
  1377. 'package': {
  1378. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  1379. lookbehind: true,
  1380. inside: {
  1381. punctuation: /\\/
  1382. }
  1383. }
  1384. });
  1385. // Must be defined after the function pattern
  1386. Prism.languages.insertBefore('php', 'operator', {
  1387. 'property': {
  1388. pattern: /(->)[\w]+/,
  1389. lookbehind: true
  1390. }
  1391. });
  1392. // Add HTML support if the markup language exists
  1393. if (Prism.languages.markup) {
  1394. // Tokenize all inline PHP blocks that are wrapped in <?php ?>
  1395. // This allows for easy PHP + markup highlighting
  1396. Prism.hooks.add('before-highlight', function(env) {
  1397. if (env.language !== 'php' || !/(?:<\?php|<\?)/ig.test(env.code)) {
  1398. return;
  1399. }
  1400. env.tokenStack = [];
  1401. env.backupCode = env.code;
  1402. env.code = env.code.replace(/(?:<\?php|<\?)[\s\S]*?(?:\?>|$)/ig, function(match) {
  1403. var i = env.tokenStack.length;
  1404. // Check for existing strings
  1405. while (env.backupCode.indexOf('___PHP' + i + '___') !== -1)
  1406. ++i;
  1407. // Create a sparse array
  1408. env.tokenStack[i] = match;
  1409. return '___PHP' + i + '___';
  1410. });
  1411. // Switch the grammar to markup
  1412. env.grammar = Prism.languages.markup;
  1413. });
  1414. // Restore env.code for other plugins (e.g. line-numbers)
  1415. Prism.hooks.add('before-insert', function(env) {
  1416. if (env.language === 'php' && env.backupCode) {
  1417. env.code = env.backupCode;
  1418. delete env.backupCode;
  1419. }
  1420. });
  1421. // Re-insert the tokens after highlighting
  1422. Prism.hooks.add('after-highlight', function(env) {
  1423. if (env.language !== 'php' || !env.tokenStack) {
  1424. return;
  1425. }
  1426. // Switch the grammar back
  1427. env.grammar = Prism.languages.php;
  1428. for (var i = 0, keys = Object.keys(env.tokenStack); i < keys.length; ++i) {
  1429. var k = keys[i];
  1430. var t = env.tokenStack[k];
  1431. // The replace prevents $$, $&, $`, $', $n, $nn from being interpreted as special patterns
  1432. env.highlightedCode = env.highlightedCode.replace('___PHP' + k + '___',
  1433. "<span class=\"token php language-php\">" +
  1434. Prism.highlight(t, env.grammar, 'php').replace(/\$/g, '$$$$') +
  1435. "</span>");
  1436. }
  1437. env.element.innerHTML = env.highlightedCode;
  1438. });
  1439. }
  1440. ;
  1441. Prism.languages.python= {
  1442. 'triple-quoted-string': {
  1443. pattern: /"""[\s\S]+?"""|'''[\s\S]+?'''/,
  1444. alias: 'string'
  1445. },
  1446. 'comment': {
  1447. pattern: /(^|[^\\])#.*/,
  1448. lookbehind: true
  1449. },
  1450. 'string': {
  1451. pattern: /("|')(?:\\\\|\\?[^\\\r\n])*?\1/,
  1452. greedy: true
  1453. },
  1454. 'function' : {
  1455. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\()/g,
  1456. lookbehind: true
  1457. },
  1458. 'class-name': {
  1459. pattern: /(\bclass\s+)[a-z0-9_]+/i,
  1460. lookbehind: true
  1461. },
  1462. 'keyword' : /\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/,
  1463. 'boolean' : /\b(?:True|False)\b/,
  1464. 'number' : /\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  1465. 'operator' : /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
  1466. 'punctuation' : /[{}[\];(),.:]/
  1467. };
  1468. (function(Prism) {
  1469. var javascript = Prism.util.clone(Prism.languages.javascript);
  1470. Prism.languages.jsx = Prism.languages.extend('markup', javascript);
  1471. Prism.languages.jsx.tag.pattern= /<\/?[\w\.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(\\?[\s\S])*?\1|[^\s'">=]+|(\{[\s\S]*?\})))?|\{\.{3}\w+\}))*\s*\/?>/i;
  1472. Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:('|")[\s\S]*?(\1)|[^\s>]+)/i;
  1473. Prism.languages.insertBefore('inside', 'attr-name', {
  1474. 'spread': {
  1475. pattern: /\{\.{3}\w+\}/,
  1476. inside: {
  1477. 'punctuation': /\{|\}|\./,
  1478. 'attr-value': /\w+/
  1479. }
  1480. }
  1481. }, Prism.languages.jsx.tag);
  1482. var jsxExpression = Prism.util.clone(Prism.languages.jsx);
  1483. delete jsxExpression.punctuation
  1484. jsxExpression = Prism.languages.insertBefore('jsx', 'operator', {
  1485. 'punctuation': /=(?={)|[{}[\];(),.:]/
  1486. }, { jsx: jsxExpression });
  1487. Prism.languages.insertBefore('inside', 'attr-value',{
  1488. 'script': {
  1489. // Allow for one level of nesting
  1490. pattern: /=(\{(?:\{[^}]*\}|[^}])+\})/i,
  1491. inside: jsxExpression,
  1492. 'alias': 'language-javascript'
  1493. }
  1494. }, Prism.languages.jsx.tag);
  1495. }(Prism));
  1496. (function(Prism) {
  1497. Prism.languages.crystal = Prism.languages.extend('ruby', {
  1498. keyword: [
  1499. /\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/,
  1500. {
  1501. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  1502. lookbehind: true
  1503. }
  1504. ],
  1505. number: /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[0-9a-fA-F_]*[0-9a-fA-F]|(?:\d(?:[0-9_]*\d)?)(?:\.[0-9_]*\d)?(?:[eE][+-]?[0-9_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/,
  1506. });
  1507. var rest = Prism.util.clone(Prism.languages.crystal);
  1508. Prism.languages.insertBefore('crystal', 'string', {
  1509. attribute: {
  1510. pattern: /@\[.+?\]/,
  1511. alias: 'attr-name',
  1512. inside: {
  1513. delimiter: {
  1514. pattern: /^@\[|\]$/,
  1515. alias: 'tag'
  1516. },
  1517. rest: rest
  1518. }
  1519. },
  1520. expansion: [
  1521. {
  1522. pattern: /\{\{.+?\}\}/,
  1523. inside: {
  1524. delimiter: {
  1525. pattern: /^\{\{|\}\}$/,
  1526. alias: 'tag'
  1527. },
  1528. rest: rest
  1529. }
  1530. },
  1531. {
  1532. pattern: /\{%.+?%\}/,
  1533. inside: {
  1534. delimiter: {
  1535. pattern: /^\{%|%\}$/,
  1536. alias: 'tag'
  1537. },
  1538. rest: rest
  1539. }
  1540. }
  1541. ]
  1542. });
  1543. }(Prism));
  1544. /* TODO
  1545. Add support for Markdown notation inside doc comments
  1546. Add support for nested block comments...
  1547. Match closure params even when not followed by dash or brace
  1548. Add better support for macro definition
  1549. */
  1550. Prism.languages.rust = {
  1551. 'comment': [
  1552. {
  1553. pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
  1554. lookbehind: true
  1555. },
  1556. {
  1557. pattern: /(^|[^\\:])\/\/.*/,
  1558. lookbehind: true
  1559. }
  1560. ],
  1561. 'string': [
  1562. {
  1563. pattern: /b?r(#*)"(?:\\?.)*?"\1/,
  1564. greedy: true
  1565. },
  1566. {
  1567. pattern: /b?("|')(?:\\?.)*?\1/,
  1568. greedy: true
  1569. }
  1570. ],
  1571. '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/,
  1572. 'attribute': {
  1573. pattern: /#!?\[.+?\]/,
  1574. greedy: true,
  1575. alias: 'attr-name'
  1576. },
  1577. 'function': [
  1578. /[a-z0-9_]+(?=\s*\()/i,
  1579. // Macros can use parens or brackets
  1580. /[a-z0-9_]+!(?=\s*\(|\[)/i
  1581. ],
  1582. 'macro-rules': {
  1583. pattern: /[a-z0-9_]+!/i,
  1584. alias: 'function'
  1585. },
  1586. // Hex, oct, bin, dec numbers with visual separators and type suffix
  1587. '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/,
  1588. // Closure params should not be confused with bitwise OR |
  1589. 'closure-params': {
  1590. pattern: /\|[^|]*\|(?=\s*[{-])/,
  1591. inside: {
  1592. 'punctuation': /[\|:,]/,
  1593. 'operator': /[&*]/
  1594. }
  1595. },
  1596. 'punctuation': /[{}[\];(),:]|\.+|->/,
  1597. 'operator': /[-+*\/%!^=]=?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
  1598. };
  1599. Prism.languages.scss = Prism.languages.extend('css', {
  1600. 'comment': {
  1601. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1602. lookbehind: true
  1603. },
  1604. 'atrule': {
  1605. pattern: /@[\w-]+(?:\([^()]+\)|[^(])*?(?=\s+[{;])/,
  1606. inside: {
  1607. 'rule': /@[\w-]+/
  1608. // See rest below
  1609. }
  1610. },
  1611. // url, compassified
  1612. 'url': /(?:[-a-z]+-)*url(?=\()/i,
  1613. // CSS selector regex is not appropriate for Sass
  1614. // since there can be lot more things (var, @ directive, nesting..)
  1615. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  1616. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  1617. // 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
  1618. // can "pass" as a selector- e.g: proper#{$erty})
  1619. // this one was hard to do, so please be careful if you edit this one :)
  1620. 'selector': {
  1621. // Initial look-ahead is used to prevent matching of blank selectors
  1622. pattern: /(?=\S)[^@;\{\}\(\)]?([^@;\{\}\(\)]|&|#\{\$[-_\w]+\})+(?=\s*\{(\}|\s|[^\}]+(:|\{)[^\}]+))/m,
  1623. inside: {
  1624. 'parent': {
  1625. pattern: /&/,
  1626. alias: 'important'
  1627. },
  1628. 'placeholder': /%[-_\w]+/,
  1629. 'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
  1630. }
  1631. }
  1632. });
  1633. Prism.languages.insertBefore('scss', 'atrule', {
  1634. 'keyword': [
  1635. /@(?:if|else(?: if)?|for|each|while|import|extend|debug|warn|mixin|include|function|return|content)/i,
  1636. {
  1637. pattern: /( +)(?:from|through)(?= )/,
  1638. lookbehind: true
  1639. }
  1640. ]
  1641. });
  1642. Prism.languages.scss.property = {
  1643. pattern: /(?:[\w-]|\$[-_\w]+|#\{\$[-_\w]+\})+(?=\s*:)/i,
  1644. inside: {
  1645. 'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
  1646. }
  1647. };
  1648. Prism.languages.insertBefore('scss', 'important', {
  1649. // var and interpolated vars
  1650. 'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
  1651. });
  1652. Prism.languages.insertBefore('scss', 'function', {
  1653. 'placeholder': {
  1654. pattern: /%[-_\w]+/,
  1655. alias: 'selector'
  1656. },
  1657. 'statement': {
  1658. pattern: /\B!(?:default|optional)\b/i,
  1659. alias: 'keyword'
  1660. },
  1661. 'boolean': /\b(?:true|false)\b/,
  1662. 'null': /\bnull\b/,
  1663. 'operator': {
  1664. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|or|not)(?=\s)/,
  1665. lookbehind: true
  1666. }
  1667. });
  1668. Prism.languages.scss['atrule'].inside.rest = Prism.util.clone(Prism.languages.scss);
  1669. Prism.languages.sql= {
  1670. 'comment': {
  1671. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  1672. lookbehind: true
  1673. },
  1674. 'string' : {
  1675. pattern: /(^|[^@\\])("|')(?:\\?[\s\S])*?\2/,
  1676. greedy: true,
  1677. lookbehind: true
  1678. },
  1679. 'variable': /@[\w.$]+|@("|'|`)(?:\\?[\s\S])+?\1/,
  1680. 'function': /\b(?:COUNT|SUM|AVG|MIN|MAX|FIRST|LAST|UCASE|LCASE|MID|LEN|ROUND|NOW|FORMAT)(?=\s*\()/i, // Should we highlight user defined functions too?
  1681. '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 VARYING|CHARACTER (?:SET|VARYING)|CHARSET|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMN|COLUMNS|COMMENT|COMMIT|COMMITTED|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|DATA(?:BASES?)?|DATE(?:TIME)?|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITER(?:S)?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE(?: PRECISION)?|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE KEY|ELSE|ENABLE|ENCLOSED BY|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPE(?:D BY)?|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|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTO|INVOKER|ISOLATION LEVEL|JOIN|KEYS?|KILL|LANGUAGE SQL|LAST|LEFT|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MODIFIES SQL DATA|MODIFY|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL(?: CHAR VARYING| CHARACTER(?: VARYING)?| VARCHAR)?|NATURAL|NCHAR(?: VARCHAR)?|NEXT|NO(?: SQL|CHECK|CYCLE)?|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|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READ(?:S SQL DATA|TEXT)?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEATABLE|REPLICATION|REQUIRE|RESTORE|RESTRICT|RETURNS?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE MODE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|START(?:ING BY)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED BY|TEXT(?:SIZE)?|THEN|TIMESTAMP|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNPIVOT|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?)\b/i,
  1682. 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
  1683. 'number': /\b-?(?:0x)?\d*\.?[\da-f]+\b/,
  1684. 'operator': /[-+*\/=%^~]|&&?|\|?\||!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|IN|LIKE|NOT|OR|IS|DIV|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  1685. 'punctuation': /[;[\]()`,.]/
  1686. };
  1687. Prism.languages.typescript = Prism.languages.extend('javascript', {
  1688. // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
  1689. '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|false|true|module|declare|constructor|string|Function|any|number|boolean|Array|enum|symbol|namespace|abstract|require|type)\b/
  1690. });
  1691. Prism.languages.ts = Prism.languages.typescript;