prism.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  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+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. // Plugin to make entity title show the real entity, idea by Roman Komarov
  451. Prism.hooks.add('wrap', function(env) {
  452. if (env.type === 'entity') {
  453. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  454. }
  455. });
  456. Prism.languages.xml = Prism.languages.markup;
  457. Prism.languages.html = Prism.languages.markup;
  458. Prism.languages.mathml = Prism.languages.markup;
  459. Prism.languages.svg = Prism.languages.markup;
  460. Prism.languages.css = {
  461. 'comment': /\/\*[\s\S]*?\*\//,
  462. 'atrule': {
  463. pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
  464. inside: {
  465. 'rule': /@[\w-]+/
  466. // See rest below
  467. }
  468. },
  469. 'url': /url\((?:(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
  470. 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
  471. 'string': {
  472. pattern: /("|')(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  473. greedy: true
  474. },
  475. 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
  476. 'important': /\B!important\b/i,
  477. 'function': /[-a-z0-9]+(?=\()/i,
  478. 'punctuation': /[(){};:]/
  479. };
  480. Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
  481. if (Prism.languages.markup) {
  482. Prism.languages.insertBefore('markup', 'tag', {
  483. 'style': {
  484. pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i,
  485. lookbehind: true,
  486. inside: Prism.languages.css,
  487. alias: 'language-css'
  488. }
  489. });
  490. Prism.languages.insertBefore('inside', 'attr-value', {
  491. 'style-attr': {
  492. pattern: /\s*style=("|').*?\1/i,
  493. inside: {
  494. 'attr-name': {
  495. pattern: /^\s*style/i,
  496. inside: Prism.languages.markup.tag.inside
  497. },
  498. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  499. 'attr-value': {
  500. pattern: /.+/i,
  501. inside: Prism.languages.css
  502. }
  503. },
  504. alias: 'language-css'
  505. }
  506. }, Prism.languages.markup.tag);
  507. };
  508. Prism.languages.clike = {
  509. 'comment': [
  510. {
  511. pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
  512. lookbehind: true
  513. },
  514. {
  515. pattern: /(^|[^\\:])\/\/.*/,
  516. lookbehind: true
  517. }
  518. ],
  519. 'string': {
  520. pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  521. greedy: true
  522. },
  523. 'class-name': {
  524. pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
  525. lookbehind: true,
  526. inside: {
  527. punctuation: /(\.|\\)/
  528. }
  529. },
  530. 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  531. 'boolean': /\b(true|false)\b/,
  532. 'function': /[a-z0-9_]+(?=\()/i,
  533. 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
  534. 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
  535. 'punctuation': /[{}[\];(),.:]/
  536. };
  537. Prism.languages.javascript = Prism.languages.extend('clike', {
  538. '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/,
  539. 'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
  540. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  541. 'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,
  542. 'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
  543. });
  544. Prism.languages.insertBefore('javascript', 'keyword', {
  545. 'regex': {
  546. pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
  547. lookbehind: true,
  548. greedy: true
  549. }
  550. });
  551. Prism.languages.insertBefore('javascript', 'string', {
  552. 'template-string': {
  553. pattern: /`(?:\\\\|\\?[^\\])*?`/,
  554. greedy: true,
  555. inside: {
  556. 'interpolation': {
  557. pattern: /\$\{[^}]+\}/,
  558. inside: {
  559. 'interpolation-punctuation': {
  560. pattern: /^\$\{|\}$/,
  561. alias: 'punctuation'
  562. },
  563. rest: Prism.languages.javascript
  564. }
  565. },
  566. 'string': /[\s\S]+/
  567. }
  568. }
  569. });
  570. if (Prism.languages.markup) {
  571. Prism.languages.insertBefore('markup', 'tag', {
  572. 'script': {
  573. pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
  574. lookbehind: true,
  575. inside: Prism.languages.javascript,
  576. alias: 'language-javascript'
  577. }
  578. });
  579. }
  580. Prism.languages.js = Prism.languages.javascript;
  581. Prism.languages.c = Prism.languages.extend('clike', {
  582. '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/,
  583. 'operator': /\-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*\/]/,
  584. 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*\b/i
  585. });
  586. Prism.languages.insertBefore('c', 'string', {
  587. 'macro': {
  588. // allow for multiline macro definitions
  589. // spaces after the # character compile fine with gcc
  590. pattern: /(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,
  591. lookbehind: true,
  592. alias: 'property',
  593. inside: {
  594. // highlight the path of the include statement as a string
  595. 'string': {
  596. pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
  597. lookbehind: true
  598. },
  599. // highlight macro directives as keywords
  600. 'directive': {
  601. pattern: /(#\s*)\b(define|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
  602. lookbehind: true,
  603. alias: 'keyword'
  604. }
  605. }
  606. },
  607. // highlight predefined macros as constants
  608. 'constant': /\b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|stdin|stdout|stderr)\b/
  609. });
  610. delete Prism.languages.c['class-name'];
  611. delete Prism.languages.c['boolean'];
  612. Prism.languages.cpp = Prism.languages.extend('c', {
  613. '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/,
  614. 'boolean': /\b(true|false)\b/,
  615. '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/
  616. });
  617. Prism.languages.insertBefore('cpp', 'keyword', {
  618. 'class-name': {
  619. pattern: /(class\s+)[a-z0-9_]+/i,
  620. lookbehind: true
  621. }
  622. });
  623. (function(Prism) {
  624. // Ignore comments starting with { to privilege string interpolation highlighting
  625. var comment = /#(?!\{).+/,
  626. interpolation = {
  627. pattern: /#\{[^}]+\}/,
  628. alias: 'variable'
  629. };
  630. Prism.languages.coffeescript = Prism.languages.extend('javascript', {
  631. 'comment': comment,
  632. 'string': [
  633. // Strings are multiline
  634. {
  635. pattern: /'(?:\\?[^\\])*?'/,
  636. greedy: true
  637. },
  638. {
  639. // Strings are multiline
  640. pattern: /"(?:\\?[^\\])*?"/,
  641. greedy: true,
  642. inside: {
  643. 'interpolation': interpolation
  644. }
  645. }
  646. ],
  647. '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/,
  648. 'class-member': {
  649. pattern: /@(?!\d)\w+/,
  650. alias: 'variable'
  651. }
  652. });
  653. Prism.languages.insertBefore('coffeescript', 'comment', {
  654. 'multiline-comment': {
  655. pattern: /###[\s\S]+?###/,
  656. alias: 'comment'
  657. },
  658. // Block regexp can contain comments and interpolation
  659. 'block-regex': {
  660. pattern: /\/{3}[\s\S]*?\/{3}/,
  661. alias: 'regex',
  662. inside: {
  663. 'comment': comment,
  664. 'interpolation': interpolation
  665. }
  666. }
  667. });
  668. Prism.languages.insertBefore('coffeescript', 'string', {
  669. 'inline-javascript': {
  670. pattern: /`(?:\\?[\s\S])*?`/,
  671. inside: {
  672. 'delimiter': {
  673. pattern: /^`|`$/,
  674. alias: 'punctuation'
  675. },
  676. rest: Prism.languages.javascript
  677. }
  678. },
  679. // Block strings
  680. 'multiline-string': [
  681. {
  682. pattern: /'''[\s\S]*?'''/,
  683. greedy: true,
  684. alias: 'string'
  685. },
  686. {
  687. pattern: /"""[\s\S]*?"""/,
  688. greedy: true,
  689. alias: 'string',
  690. inside: {
  691. interpolation: interpolation
  692. }
  693. }
  694. ]
  695. });
  696. Prism.languages.insertBefore('coffeescript', 'keyword', {
  697. // Object property
  698. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  699. });
  700. delete Prism.languages.coffeescript['template-string'];
  701. }(Prism));
  702. /**
  703. * Original by Samuel Flores
  704. *
  705. * Adds the following new token classes:
  706. * constant, builtin, variable, symbol, regex
  707. */
  708. (function(Prism) {
  709. Prism.languages.ruby = Prism.languages.extend('clike', {
  710. 'comment': [
  711. /#(?!\{[^\r\n]*?\}).*/,
  712. /^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m
  713. ],
  714. '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/
  715. });
  716. var interpolation = {
  717. pattern: /#\{[^}]+\}/,
  718. inside: {
  719. 'delimiter': {
  720. pattern: /^#\{|\}$/,
  721. alias: 'tag'
  722. },
  723. rest: Prism.util.clone(Prism.languages.ruby)
  724. }
  725. };
  726. Prism.languages.insertBefore('ruby', 'keyword', {
  727. 'regex': [
  728. {
  729. pattern: /%r([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[gim]{0,3}/,
  730. greedy: true,
  731. inside: {
  732. 'interpolation': interpolation
  733. }
  734. },
  735. {
  736. pattern: /%r\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/,
  737. greedy: true,
  738. inside: {
  739. 'interpolation': interpolation
  740. }
  741. },
  742. {
  743. // Here we need to specifically allow interpolation
  744. pattern: /%r\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/,
  745. greedy: true,
  746. inside: {
  747. 'interpolation': interpolation
  748. }
  749. },
  750. {
  751. pattern: /%r\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/,
  752. greedy: true,
  753. inside: {
  754. 'interpolation': interpolation
  755. }
  756. },
  757. {
  758. pattern: /%r<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/,
  759. greedy: true,
  760. inside: {
  761. 'interpolation': interpolation
  762. }
  763. },
  764. {
  765. pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
  766. lookbehind: true,
  767. greedy: true
  768. }
  769. ],
  770. 'variable': /[@$]+[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/,
  771. 'symbol': /:[a-zA-Z_][a-zA-Z_0-9]*(?:[?!]|\b)/
  772. });
  773. Prism.languages.insertBefore('ruby', 'number', {
  774. '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/,
  775. 'constant': /\b[A-Z][a-zA-Z_0-9]*(?:[?!]|\b)/
  776. });
  777. Prism.languages.ruby.string = [
  778. {
  779. pattern: /%[qQiIwWxs]?([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
  780. greedy: true,
  781. inside: {
  782. 'interpolation': interpolation
  783. }
  784. },
  785. {
  786. pattern: /%[qQiIwWxs]?\((?:[^()\\]|\\[\s\S])*\)/,
  787. greedy: true,
  788. inside: {
  789. 'interpolation': interpolation
  790. }
  791. },
  792. {
  793. // Here we need to specifically allow interpolation
  794. pattern: /%[qQiIwWxs]?\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/,
  795. greedy: true,
  796. inside: {
  797. 'interpolation': interpolation
  798. }
  799. },
  800. {
  801. pattern: /%[qQiIwWxs]?\[(?:[^\[\]\\]|\\[\s\S])*\]/,
  802. greedy: true,
  803. inside: {
  804. 'interpolation': interpolation
  805. }
  806. },
  807. {
  808. pattern: /%[qQiIwWxs]?<(?:[^<>\\]|\\[\s\S])*>/,
  809. greedy: true,
  810. inside: {
  811. 'interpolation': interpolation
  812. }
  813. },
  814. {
  815. pattern: /("|')(#\{[^}]+\}|\\(?:\r?\n|\r)|\\?.)*?\1/,
  816. greedy: true,
  817. inside: {
  818. 'interpolation': interpolation
  819. }
  820. }
  821. ];
  822. }(Prism));
  823. Prism.languages.elixir = {
  824. // Negative look-ahead is needed for string interpolation
  825. // Negative look-behind is needed to avoid highlighting markdown headers in
  826. // multi-line doc strings
  827. 'comment': {
  828. pattern: /(^|[^#])#(?![{#]).*/m,
  829. lookbehind: true
  830. },
  831. // ~r"""foo""", ~r'''foo''', ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  832. 'regex': /~[rR](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|[^}])+\}|<(?:\\>|[^>])+>)[uismxfr]*/,
  833. 'string': [
  834. {
  835. // ~s"""foo""", ~s'''foo''', ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo}, ~s<foo>
  836. pattern: /~[cCsSwW](?:("""|'''|[\/|"'])(?:\\.|(?!\1)[^\\])+\1|\((?:\\\)|[^)])+\)|\[(?:\\\]|[^\]])+\]|\{(?:\\\}|#\{[^}]+\}|[^}])+\}|<(?:\\>|[^>])+>)[csa]?/,
  837. greedy: true,
  838. inside: {
  839. // See interpolation below
  840. }
  841. },
  842. {
  843. pattern: /("""|''')[\s\S]*?\1/,
  844. greedy: true,
  845. inside: {
  846. // See interpolation below
  847. }
  848. },
  849. {
  850. // Multi-line strings are allowed
  851. pattern: /("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
  852. greedy: true,
  853. inside: {
  854. // See interpolation below
  855. }
  856. }
  857. ],
  858. 'atom': {
  859. // Look-behind prevents bad highlighting of the :: operator
  860. pattern: /(^|[^:]):\w+/,
  861. lookbehind: true,
  862. alias: 'symbol'
  863. },
  864. // Look-ahead prevents bad highlighting of the :: operator
  865. 'attr-name': /\w+:(?!:)/,
  866. 'capture': {
  867. // Look-behind prevents bad highlighting of the && operator
  868. pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
  869. lookbehind: true,
  870. alias: 'function'
  871. },
  872. 'argument': {
  873. // Look-behind prevents bad highlighting of the && operator
  874. pattern: /(^|[^&])&\d+/,
  875. lookbehind: true,
  876. alias: 'variable'
  877. },
  878. 'attribute': {
  879. pattern: /@[\S]+/,
  880. alias: 'variable'
  881. },
  882. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  883. '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/,
  884. 'boolean': /\b(?:true|false|nil)\b/,
  885. 'operator': [
  886. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  887. {
  888. // We don't want to match <<
  889. pattern: /([^<])<(?!<)/,
  890. lookbehind: true
  891. },
  892. {
  893. // We don't want to match >>
  894. pattern: /([^>])>(?!>)/,
  895. lookbehind: true
  896. }
  897. ],
  898. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  899. };
  900. Prism.languages.elixir.string.forEach(function(o) {
  901. o.inside = {
  902. 'interpolation': {
  903. pattern: /#\{[^}]+\}/,
  904. inside: {
  905. 'delimiter': {
  906. pattern: /^#\{|\}$/,
  907. alias: 'punctuation'
  908. },
  909. rest: Prism.util.clone(Prism.languages.elixir)
  910. }
  911. }
  912. };
  913. });
  914. Prism.languages.erlang = {
  915. 'comment': /%.+/,
  916. 'string': {
  917. pattern: /"(?:\\?.)*?"/,
  918. greedy: true
  919. },
  920. 'quoted-function': {
  921. pattern: /'(?:\\.|[^'\\])+'(?=\()/,
  922. alias: 'function'
  923. },
  924. 'quoted-atom': {
  925. pattern: /'(?:\\.|[^'\\])+'/,
  926. alias: 'atom'
  927. },
  928. 'boolean': /\b(?:true|false)\b/,
  929. 'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
  930. 'number': [
  931. /\$\\?./,
  932. /\d+#[a-z0-9]+/i,
  933. /(?:\b|-)\d*\.?\d+([Ee][+-]?\d+)?\b/
  934. ],
  935. 'function': /\b[a-z][\w@]*(?=\()/,
  936. 'variable': {
  937. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  938. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  939. lookbehind: true
  940. },
  941. 'operator': [
  942. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,
  943. {
  944. // We don't want to match <<
  945. pattern: /(^|[^<])<(?!<)/,
  946. lookbehind: true
  947. },
  948. {
  949. // We don't want to match >>
  950. pattern: /(^|[^>])>(?!>)/,
  951. lookbehind: true
  952. }
  953. ],
  954. 'atom': /\b[a-z][\w@]*/,
  955. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  956. };
  957. Prism.languages.go = Prism.languages.extend('clike', {
  958. '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/,
  959. '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/,
  960. 'boolean': /\b(_|iota|nil|true|false)\b/,
  961. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  962. 'number': /\b(-?(0x[a-f\d]+|(\d+\.?\d*|\.\d+)(e[-+]?\d+)?)i?)\b/i,
  963. 'string': {
  964. pattern: /("|'|`)(\\?.|\r|\n)*?\1/,
  965. greedy: true
  966. }
  967. });
  968. delete Prism.languages.go['class-name'];
  969. Prism.languages.java = Prism.languages.extend('clike', {
  970. '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/,
  971. 'number': /\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,
  972. 'operator': {
  973. pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,
  974. lookbehind: true
  975. }
  976. });
  977. Prism.languages.insertBefore('java','function', {
  978. 'annotation': {
  979. alias: 'punctuation',
  980. pattern: /(^|[^.])@\w+/,
  981. lookbehind: true
  982. }
  983. });
  984. Prism.languages.json = {
  985. 'property': /"(?:\\.|[^\\"])*"(?=\s*:)/ig,
  986. 'string': /"(?!:)(?:\\.|[^\\"])*"(?!:)/g,
  987. 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?)\b/g,
  988. 'punctuation': /[{}[\]);,]/g,
  989. 'operator': /:/g,
  990. 'boolean': /\b(true|false)\b/gi,
  991. 'null': /\bnull\b/gi
  992. };
  993. Prism.languages.jsonp = Prism.languages.json;
  994. (function (Prism) {
  995. Prism.languages.kotlin = Prism.languages.extend('clike', {
  996. 'keyword': {
  997. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  998. 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/,
  999. lookbehind: true
  1000. },
  1001. 'function': [
  1002. /\w+(?=\s*\()/,
  1003. {
  1004. pattern: /(\.)\w+(?=\s*\{)/,
  1005. lookbehind: true
  1006. }
  1007. ],
  1008. 'number': /\b(?:0[bx][\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?[fFL]?)\b/,
  1009. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  1010. });
  1011. delete Prism.languages.kotlin["class-name"];
  1012. Prism.languages.insertBefore('kotlin', 'string', {
  1013. 'raw-string': {
  1014. pattern: /(["'])\1\1[\s\S]*?\1{3}/,
  1015. alias: 'string'
  1016. // See interpolation below
  1017. }
  1018. });
  1019. Prism.languages.insertBefore('kotlin', 'keyword', {
  1020. 'annotation': {
  1021. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  1022. alias: 'builtin'
  1023. }
  1024. });
  1025. Prism.languages.insertBefore('kotlin', 'function', {
  1026. 'label': {
  1027. pattern: /\w+@|@\w+/,
  1028. alias: 'symbol'
  1029. }
  1030. });
  1031. var interpolation = [
  1032. {
  1033. pattern: /\$\{[^}]+\}/,
  1034. inside: {
  1035. delimiter: {
  1036. pattern: /^\$\{|\}$/,
  1037. alias: 'variable'
  1038. },
  1039. rest: Prism.util.clone(Prism.languages.kotlin)
  1040. }
  1041. },
  1042. {
  1043. pattern: /\$\w+/,
  1044. alias: 'variable'
  1045. }
  1046. ];
  1047. Prism.languages.kotlin['string'].inside = Prism.languages.kotlin['raw-string'].inside = {
  1048. interpolation: interpolation
  1049. };
  1050. }(Prism));
  1051. Prism.languages.lua = {
  1052. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  1053. // \z may be used to skip the following space
  1054. 'string': {
  1055. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[\s\S]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  1056. greedy: true
  1057. },
  1058. 'number': /\b0x[a-f\d]+\.?[a-f\d]*(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|\.?\d*(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  1059. '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/,
  1060. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  1061. 'operator': [
  1062. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  1063. {
  1064. // Match ".." but don't break "..."
  1065. pattern: /(^|[^.])\.\.(?!\.)/,
  1066. lookbehind: true
  1067. }
  1068. ],
  1069. 'punctuation': /[\[\](){},;]|\.+|:+/
  1070. };
  1071. Prism.languages.nginx = Prism.languages.extend('clike', {
  1072. 'comment': {
  1073. pattern: /(^|[^"{\\])#.*/,
  1074. lookbehind: true
  1075. },
  1076. '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,
  1077. });
  1078. Prism.languages.insertBefore('nginx', 'keyword', {
  1079. 'variable': /\$[a-z_]+/i
  1080. });
  1081. Prism.languages.perl = {
  1082. 'comment': [
  1083. {
  1084. // POD
  1085. pattern: /(^\s*)=\w+[\s\S]*?=cut.*/m,
  1086. lookbehind: true
  1087. },
  1088. {
  1089. pattern: /(^|[^\\$])#.*/,
  1090. lookbehind: true
  1091. }
  1092. ],
  1093. // TODO Could be nice to handle Heredoc too.
  1094. 'string': [
  1095. // q/.../
  1096. {
  1097. pattern: /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1/,
  1098. greedy: true
  1099. },
  1100. // q a...a
  1101. {
  1102. pattern: /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\1/,
  1103. greedy: true
  1104. },
  1105. // q(...)
  1106. {
  1107. pattern: /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,
  1108. greedy: true
  1109. },
  1110. // q{...}
  1111. {
  1112. pattern: /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,
  1113. greedy: true
  1114. },
  1115. // q[...]
  1116. {
  1117. pattern: /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,
  1118. greedy: true
  1119. },
  1120. // q<...>
  1121. {
  1122. pattern: /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,
  1123. greedy: true
  1124. },
  1125. // "...", `...`
  1126. {
  1127. pattern: /("|`)(?:[^\\]|\\[\s\S])*?\1/,
  1128. greedy: true
  1129. },
  1130. // '...'
  1131. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  1132. {
  1133. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  1134. greedy: true
  1135. }
  1136. ],
  1137. 'regex': [
  1138. // m/.../
  1139. {
  1140. pattern: /\b(?:m|qr)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\1[msixpodualngc]*/,
  1141. greedy: true
  1142. },
  1143. // m a...a
  1144. {
  1145. pattern: /\b(?:m|qr)\s+([a-zA-Z0-9])(?:[^\\]|\\.)*?\1[msixpodualngc]*/,
  1146. greedy: true
  1147. },
  1148. // m(...)
  1149. {
  1150. pattern: /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,
  1151. greedy: true
  1152. },
  1153. // m{...}
  1154. {
  1155. pattern: /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,
  1156. greedy: true
  1157. },
  1158. // m[...]
  1159. {
  1160. pattern: /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,
  1161. greedy: true
  1162. },
  1163. // m<...>
  1164. {
  1165. pattern: /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,
  1166. greedy: true
  1167. },
  1168. // The lookbehinds prevent -s from breaking
  1169. // FIXME We don't handle change of separator like s(...)[...]
  1170. // s/.../.../
  1171. {
  1172. pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s\{\(\[<])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
  1173. lookbehind: true,
  1174. greedy: true
  1175. },
  1176. // s a...a...a
  1177. {
  1178. pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:[^\\]|\\[\s\S])*?\2(?:[^\\]|\\[\s\S])*?\2[msixpodualngcer]*/,
  1179. lookbehind: true,
  1180. greedy: true
  1181. },
  1182. // s(...)(...)
  1183. {
  1184. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,
  1185. lookbehind: true,
  1186. greedy: true
  1187. },
  1188. // s{...}{...}
  1189. {
  1190. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,
  1191. lookbehind: true,
  1192. greedy: true
  1193. },
  1194. // s[...][...]
  1195. {
  1196. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,
  1197. lookbehind: true,
  1198. greedy: true
  1199. },
  1200. // s<...><...>
  1201. {
  1202. pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,
  1203. lookbehind: true,
  1204. greedy: true
  1205. },
  1206. // /.../
  1207. // The look-ahead tries to prevent two divisions on
  1208. // the same line from being highlighted as regex.
  1209. // This does not support multi-line regex.
  1210. {
  1211. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/,
  1212. greedy: true
  1213. }
  1214. ],
  1215. // FIXME Not sure about the handling of ::, ', and #
  1216. 'variable': [
  1217. // ${^POSTMATCH}
  1218. /[&*$@%]\{\^[A-Z]+\}/,
  1219. // $^V
  1220. /[&*$@%]\^[A-Z_]/,
  1221. // ${...}
  1222. /[&*$@%]#?(?=\{)/,
  1223. // $foo
  1224. /[&*$@%]#?((::)*'?(?!\d)[\w$]+)+(::)*/i,
  1225. // $1
  1226. /[&*$@%]\d+/,
  1227. // $_, @_, %!
  1228. // The negative lookahead prevents from breaking the %= operator
  1229. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  1230. ],
  1231. 'filehandle': {
  1232. // <>, <FOO>, _
  1233. pattern: /<(?![<=])\S*>|\b_\b/,
  1234. alias: 'symbol'
  1235. },
  1236. 'vstring': {
  1237. // v1.2, 1.2.3
  1238. pattern: /v\d+(\.\d+)*|\d+(\.\d+){2,}/,
  1239. alias: 'string'
  1240. },
  1241. 'function': {
  1242. pattern: /sub [a-z0-9_]+/i,
  1243. inside: {
  1244. keyword: /sub/
  1245. }
  1246. },
  1247. '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/,
  1248. 'number': /\b-?(0x[\dA-Fa-f](_?[\dA-Fa-f])*|0b[01](_?[01])*|(\d(_?\d)*)?\.?\d(_?\d)*([Ee][+-]?\d+)?)\b/,
  1249. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor)\b/,
  1250. 'punctuation': /[{}[\];(),:]/
  1251. };
  1252. /**
  1253. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  1254. * Modified by Miles Johnson: http://milesj.me
  1255. *
  1256. * Supports the following:
  1257. * - Extends clike syntax
  1258. * - Support for PHP 5.3+ (namespaces, traits, generators, etc)
  1259. * - Smarter constant and function matching
  1260. *
  1261. * Adds the following new token classes:
  1262. * constant, delimiter, variable, function, package
  1263. */
  1264. Prism.languages.php = Prism.languages.extend('clike', {
  1265. '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,
  1266. 'constant': /\b[A-Z0-9_]{2,}\b/,
  1267. 'comment': {
  1268. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1269. lookbehind: true
  1270. }
  1271. });
  1272. // Shell-like comments are matched after strings, because they are less
  1273. // common than strings containing hashes...
  1274. Prism.languages.insertBefore('php', 'class-name', {
  1275. 'shell-comment': {
  1276. pattern: /(^|[^\\])#.*/,
  1277. lookbehind: true,
  1278. alias: 'comment'
  1279. }
  1280. });
  1281. Prism.languages.insertBefore('php', 'keyword', {
  1282. 'delimiter': {
  1283. pattern: /\?>|<\?(?:php|=)?/i,
  1284. alias: 'important'
  1285. },
  1286. 'variable': /\$\w+\b/i,
  1287. 'package': {
  1288. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  1289. lookbehind: true,
  1290. inside: {
  1291. punctuation: /\\/
  1292. }
  1293. }
  1294. });
  1295. // Must be defined after the function pattern
  1296. Prism.languages.insertBefore('php', 'operator', {
  1297. 'property': {
  1298. pattern: /(->)[\w]+/,
  1299. lookbehind: true
  1300. }
  1301. });
  1302. // Add HTML support if the markup language exists
  1303. if (Prism.languages.markup) {
  1304. // Tokenize all inline PHP blocks that are wrapped in <?php ?>
  1305. // This allows for easy PHP + markup highlighting
  1306. Prism.hooks.add('before-highlight', function(env) {
  1307. if (env.language !== 'php' || !/(?:<\?php|<\?)/ig.test(env.code)) {
  1308. return;
  1309. }
  1310. env.tokenStack = [];
  1311. env.backupCode = env.code;
  1312. env.code = env.code.replace(/(?:<\?php|<\?)[\s\S]*?(?:\?>|$)/ig, function(match) {
  1313. var i = env.tokenStack.length;
  1314. // Check for existing strings
  1315. while (env.backupCode.indexOf('___PHP' + i + '___') !== -1)
  1316. ++i;
  1317. // Create a sparse array
  1318. env.tokenStack[i] = match;
  1319. return '___PHP' + i + '___';
  1320. });
  1321. // Switch the grammar to markup
  1322. env.grammar = Prism.languages.markup;
  1323. });
  1324. // Restore env.code for other plugins (e.g. line-numbers)
  1325. Prism.hooks.add('before-insert', function(env) {
  1326. if (env.language === 'php' && env.backupCode) {
  1327. env.code = env.backupCode;
  1328. delete env.backupCode;
  1329. }
  1330. });
  1331. // Re-insert the tokens after highlighting
  1332. Prism.hooks.add('after-highlight', function(env) {
  1333. if (env.language !== 'php' || !env.tokenStack) {
  1334. return;
  1335. }
  1336. // Switch the grammar back
  1337. env.grammar = Prism.languages.php;
  1338. for (var i = 0, keys = Object.keys(env.tokenStack); i < keys.length; ++i) {
  1339. var k = keys[i];
  1340. var t = env.tokenStack[k];
  1341. // The replace prevents $$, $&, $`, $', $n, $nn from being interpreted as special patterns
  1342. env.highlightedCode = env.highlightedCode.replace('___PHP' + k + '___',
  1343. "<span class=\"token php language-php\">" +
  1344. Prism.highlight(t, env.grammar, 'php').replace(/\$/g, '$$$$') +
  1345. "</span>");
  1346. }
  1347. env.element.innerHTML = env.highlightedCode;
  1348. });
  1349. }
  1350. ;
  1351. Prism.languages.python= {
  1352. 'triple-quoted-string': {
  1353. pattern: /"""[\s\S]+?"""|'''[\s\S]+?'''/,
  1354. alias: 'string'
  1355. },
  1356. 'comment': {
  1357. pattern: /(^|[^\\])#.*/,
  1358. lookbehind: true
  1359. },
  1360. 'string': {
  1361. pattern: /("|')(?:\\\\|\\?[^\\\r\n])*?\1/,
  1362. greedy: true
  1363. },
  1364. 'function' : {
  1365. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\()/g,
  1366. lookbehind: true
  1367. },
  1368. 'class-name': {
  1369. pattern: /(\bclass\s+)[a-z0-9_]+/i,
  1370. lookbehind: true
  1371. },
  1372. '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/,
  1373. 'boolean' : /\b(?:True|False)\b/,
  1374. 'number' : /\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  1375. 'operator' : /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
  1376. 'punctuation' : /[{}[\];(),.:]/
  1377. };
  1378. (function(Prism) {
  1379. Prism.languages.crystal = Prism.languages.extend('ruby', {
  1380. keyword: [
  1381. /\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/,
  1382. {
  1383. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  1384. lookbehind: true
  1385. }
  1386. ],
  1387. 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/,
  1388. });
  1389. var rest = Prism.util.clone(Prism.languages.crystal);
  1390. Prism.languages.insertBefore('crystal', 'string', {
  1391. attribute: {
  1392. pattern: /@\[.+?\]/,
  1393. alias: 'attr-name',
  1394. inside: {
  1395. delimiter: {
  1396. pattern: /^@\[|\]$/,
  1397. alias: 'tag'
  1398. },
  1399. rest: rest
  1400. }
  1401. },
  1402. expansion: [
  1403. {
  1404. pattern: /\{\{.+?\}\}/,
  1405. inside: {
  1406. delimiter: {
  1407. pattern: /^\{\{|\}\}$/,
  1408. alias: 'tag'
  1409. },
  1410. rest: rest
  1411. }
  1412. },
  1413. {
  1414. pattern: /\{%.+?%\}/,
  1415. inside: {
  1416. delimiter: {
  1417. pattern: /^\{%|%\}$/,
  1418. alias: 'tag'
  1419. },
  1420. rest: rest
  1421. }
  1422. }
  1423. ]
  1424. });
  1425. }(Prism));
  1426. /* TODO
  1427. Add support for Markdown notation inside doc comments
  1428. Add support for nested block comments...
  1429. Match closure params even when not followed by dash or brace
  1430. Add better support for macro definition
  1431. */
  1432. Prism.languages.rust = {
  1433. 'comment': [
  1434. {
  1435. pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
  1436. lookbehind: true
  1437. },
  1438. {
  1439. pattern: /(^|[^\\:])\/\/.*/,
  1440. lookbehind: true
  1441. }
  1442. ],
  1443. 'string': [
  1444. {
  1445. pattern: /b?r(#*)"(?:\\?.)*?"\1/,
  1446. greedy: true
  1447. },
  1448. {
  1449. pattern: /b?("|')(?:\\?.)*?\1/,
  1450. greedy: true
  1451. }
  1452. ],
  1453. '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/,
  1454. 'attribute': {
  1455. pattern: /#!?\[.+?\]/,
  1456. greedy: true,
  1457. alias: 'attr-name'
  1458. },
  1459. 'function': [
  1460. /[a-z0-9_]+(?=\s*\()/i,
  1461. // Macros can use parens or brackets
  1462. /[a-z0-9_]+!(?=\s*\(|\[)/i
  1463. ],
  1464. 'macro-rules': {
  1465. pattern: /[a-z0-9_]+!/i,
  1466. alias: 'function'
  1467. },
  1468. // Hex, oct, bin, dec numbers with visual separators and type suffix
  1469. '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/,
  1470. // Closure params should not be confused with bitwise OR |
  1471. 'closure-params': {
  1472. pattern: /\|[^|]*\|(?=\s*[{-])/,
  1473. inside: {
  1474. 'punctuation': /[\|:,]/,
  1475. 'operator': /[&*]/
  1476. }
  1477. },
  1478. 'punctuation': /[{}[\];(),:]|\.+|->/,
  1479. 'operator': /[-+*\/%!^=]=?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
  1480. };
  1481. Prism.languages.scss = Prism.languages.extend('css', {
  1482. 'comment': {
  1483. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1484. lookbehind: true
  1485. },
  1486. 'atrule': {
  1487. pattern: /@[\w-]+(?:\([^()]+\)|[^(])*?(?=\s+[{;])/,
  1488. inside: {
  1489. 'rule': /@[\w-]+/
  1490. // See rest below
  1491. }
  1492. },
  1493. // url, compassified
  1494. 'url': /(?:[-a-z]+-)*url(?=\()/i,
  1495. // CSS selector regex is not appropriate for Sass
  1496. // since there can be lot more things (var, @ directive, nesting..)
  1497. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  1498. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  1499. // 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
  1500. // can "pass" as a selector- e.g: proper#{$erty})
  1501. // this one was hard to do, so please be careful if you edit this one :)
  1502. 'selector': {
  1503. // Initial look-ahead is used to prevent matching of blank selectors
  1504. pattern: /(?=\S)[^@;\{\}\(\)]?([^@;\{\}\(\)]|&|#\{\$[-_\w]+\})+(?=\s*\{(\}|\s|[^\}]+(:|\{)[^\}]+))/m,
  1505. inside: {
  1506. 'parent': {
  1507. pattern: /&/,
  1508. alias: 'important'
  1509. },
  1510. 'placeholder': /%[-_\w]+/,
  1511. 'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
  1512. }
  1513. }
  1514. });
  1515. Prism.languages.insertBefore('scss', 'atrule', {
  1516. 'keyword': [
  1517. /@(?:if|else(?: if)?|for|each|while|import|extend|debug|warn|mixin|include|function|return|content)/i,
  1518. {
  1519. pattern: /( +)(?:from|through)(?= )/,
  1520. lookbehind: true
  1521. }
  1522. ]
  1523. });
  1524. Prism.languages.scss.property = {
  1525. pattern: /(?:[\w-]|\$[-_\w]+|#\{\$[-_\w]+\})+(?=\s*:)/i,
  1526. inside: {
  1527. 'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
  1528. }
  1529. };
  1530. Prism.languages.insertBefore('scss', 'important', {
  1531. // var and interpolated vars
  1532. 'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
  1533. });
  1534. Prism.languages.insertBefore('scss', 'function', {
  1535. 'placeholder': {
  1536. pattern: /%[-_\w]+/,
  1537. alias: 'selector'
  1538. },
  1539. 'statement': {
  1540. pattern: /\B!(?:default|optional)\b/i,
  1541. alias: 'keyword'
  1542. },
  1543. 'boolean': /\b(?:true|false)\b/,
  1544. 'null': /\bnull\b/,
  1545. 'operator': {
  1546. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|or|not)(?=\s)/,
  1547. lookbehind: true
  1548. }
  1549. });
  1550. Prism.languages.scss['atrule'].inside.rest = Prism.util.clone(Prism.languages.scss);
  1551. Prism.languages.sql= {
  1552. 'comment': {
  1553. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  1554. lookbehind: true
  1555. },
  1556. 'string' : {
  1557. pattern: /(^|[^@\\])("|')(?:\\?[\s\S])*?\2/,
  1558. greedy: true,
  1559. lookbehind: true
  1560. },
  1561. 'variable': /@[\w.$]+|@("|'|`)(?:\\?[\s\S])+?\1/,
  1562. '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?
  1563. '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,
  1564. 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
  1565. 'number': /\b-?(?:0x)?\d*\.?[\da-f]+\b/,
  1566. 'operator': /[-+*\/=%^~]|&&?|\|?\||!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|IN|LIKE|NOT|OR|IS|DIV|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  1567. 'punctuation': /[;[\]()`,.]/
  1568. };
  1569. Prism.languages.typescript = Prism.languages.extend('javascript', {
  1570. // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
  1571. '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/
  1572. });
  1573. Prism.languages.ts = Prism.languages.typescript;