prism.js 58 KB

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