prism.js 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447
  1. /* PrismJS 1.14.0
  2. http://prismjs.com/download.html#themes=prism-okaidia&languages=markup+css+clike+javascript+c+bash+cpp+csharp+diff+markup-templating+git+go+graphql+http+hpkp+hsts+java+json+less+markdown+nginx+php+php-extras+sql+python+sass+scss+scala+plsql+vim&plugins=line-numbers+autolinker+wpd+command-line */
  3. var _self = (typeof window !== 'undefined')
  4. ? window // if in browser
  5. : (
  6. (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
  7. ? self // if in worker
  8. : {} // if in node js
  9. );
  10. /**
  11. * Prism: Lightweight, robust, elegant syntax highlighting
  12. * MIT license http://www.opensource.org/licenses/mit-license.php/
  13. * @author Lea Verou http://lea.verou.me
  14. */
  15. var Prism = (function(){
  16. // Private helper vars
  17. var lang = /\blang(?:uage)?-([\w-]+)\b/i;
  18. var uniqueId = 0;
  19. var _ = _self.Prism = {
  20. manual: _self.Prism && _self.Prism.manual,
  21. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  22. util: {
  23. encode: function (tokens) {
  24. if (tokens instanceof Token) {
  25. return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
  26. } else if (_.util.type(tokens) === 'Array') {
  27. return tokens.map(_.util.encode);
  28. } else {
  29. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  30. }
  31. },
  32. type: function (o) {
  33. return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
  34. },
  35. objId: function (obj) {
  36. if (!obj['__id']) {
  37. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  38. }
  39. return obj['__id'];
  40. },
  41. // Deep clone a language definition (e.g. to extend it)
  42. clone: function (o, visited) {
  43. var type = _.util.type(o);
  44. visited = visited || {};
  45. switch (type) {
  46. case 'Object':
  47. if (visited[_.util.objId(o)]) {
  48. return visited[_.util.objId(o)];
  49. }
  50. var clone = {};
  51. visited[_.util.objId(o)] = clone;
  52. for (var key in o) {
  53. if (o.hasOwnProperty(key)) {
  54. clone[key] = _.util.clone(o[key], visited);
  55. }
  56. }
  57. return clone;
  58. case 'Array':
  59. if (visited[_.util.objId(o)]) {
  60. return visited[_.util.objId(o)];
  61. }
  62. var clone = [];
  63. visited[_.util.objId(o)] = clone;
  64. o.forEach(function (v, i) {
  65. clone[i] = _.util.clone(v, visited);
  66. });
  67. return clone;
  68. }
  69. return o;
  70. }
  71. },
  72. languages: {
  73. extend: function (id, redef) {
  74. var lang = _.util.clone(_.languages[id]);
  75. for (var key in redef) {
  76. lang[key] = redef[key];
  77. }
  78. return lang;
  79. },
  80. /**
  81. * Insert a token before another token in a language literal
  82. * As this needs to recreate the object (we cannot actually insert before keys in object literals),
  83. * we cannot just provide an object, we need anobject and a key.
  84. * @param inside The key (or language id) of the parent
  85. * @param before The key to insert before. If not provided, the function appends instead.
  86. * @param insert Object with the key/value pairs to insert
  87. * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
  88. */
  89. insertBefore: function (inside, before, insert, root) {
  90. root = root || _.languages;
  91. var grammar = root[inside];
  92. if (arguments.length == 2) {
  93. insert = arguments[1];
  94. for (var newToken in insert) {
  95. if (insert.hasOwnProperty(newToken)) {
  96. grammar[newToken] = insert[newToken];
  97. }
  98. }
  99. return grammar;
  100. }
  101. var ret = {};
  102. for (var token in grammar) {
  103. if (grammar.hasOwnProperty(token)) {
  104. if (token == before) {
  105. for (var newToken in insert) {
  106. if (insert.hasOwnProperty(newToken)) {
  107. ret[newToken] = insert[newToken];
  108. }
  109. }
  110. }
  111. ret[token] = grammar[token];
  112. }
  113. }
  114. // Update references in other language definitions
  115. _.languages.DFS(_.languages, function(key, value) {
  116. if (value === root[inside] && key != inside) {
  117. this[key] = ret;
  118. }
  119. });
  120. return root[inside] = ret;
  121. },
  122. // Traverse a language definition with Depth First Search
  123. DFS: function(o, callback, type, visited) {
  124. visited = visited || {};
  125. for (var i in o) {
  126. if (o.hasOwnProperty(i)) {
  127. callback.call(o, i, o[i], type || i);
  128. if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
  129. visited[_.util.objId(o[i])] = true;
  130. _.languages.DFS(o[i], callback, null, visited);
  131. }
  132. else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
  133. visited[_.util.objId(o[i])] = true;
  134. _.languages.DFS(o[i], callback, i, visited);
  135. }
  136. }
  137. }
  138. }
  139. },
  140. plugins: {},
  141. highlightAll: function(async, callback) {
  142. _.highlightAllUnder(document, async, callback);
  143. },
  144. highlightAllUnder: function(container, async, callback) {
  145. var env = {
  146. callback: callback,
  147. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  148. };
  149. _.hooks.run("before-highlightall", env);
  150. var elements = env.elements || container.querySelectorAll(env.selector);
  151. for (var i=0, element; element = elements[i++];) {
  152. _.highlightElement(element, async === true, env.callback);
  153. }
  154. },
  155. highlightElement: function(element, async, callback) {
  156. // Find language
  157. var language, grammar, parent = element;
  158. while (parent && !lang.test(parent.className)) {
  159. parent = parent.parentNode;
  160. }
  161. if (parent) {
  162. language = (parent.className.match(lang) || [,''])[1].toLowerCase();
  163. grammar = _.languages[language];
  164. }
  165. // Set language on the element, if not present
  166. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  167. if (element.parentNode) {
  168. // Set language on the parent, for styling
  169. parent = element.parentNode;
  170. if (/pre/i.test(parent.nodeName)) {
  171. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  172. }
  173. }
  174. var code = element.textContent;
  175. var env = {
  176. element: element,
  177. language: language,
  178. grammar: grammar,
  179. code: code
  180. };
  181. _.hooks.run('before-sanity-check', env);
  182. if (!env.code || !env.grammar) {
  183. if (env.code) {
  184. _.hooks.run('before-highlight', env);
  185. env.element.textContent = env.code;
  186. _.hooks.run('after-highlight', env);
  187. }
  188. _.hooks.run('complete', env);
  189. return;
  190. }
  191. _.hooks.run('before-highlight', env);
  192. if (async && _self.Worker) {
  193. var worker = new Worker(_.filename);
  194. worker.onmessage = function(evt) {
  195. env.highlightedCode = evt.data;
  196. _.hooks.run('before-insert', env);
  197. env.element.innerHTML = env.highlightedCode;
  198. callback && callback.call(env.element);
  199. _.hooks.run('after-highlight', env);
  200. _.hooks.run('complete', env);
  201. };
  202. worker.postMessage(JSON.stringify({
  203. language: env.language,
  204. code: env.code,
  205. immediateClose: true
  206. }));
  207. }
  208. else {
  209. env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
  210. _.hooks.run('before-insert', env);
  211. env.element.innerHTML = env.highlightedCode;
  212. callback && callback.call(element);
  213. _.hooks.run('after-highlight', env);
  214. _.hooks.run('complete', env);
  215. }
  216. },
  217. highlight: function (text, grammar, language) {
  218. var env = {
  219. code: text,
  220. grammar: grammar,
  221. language: language
  222. };
  223. _.hooks.run('before-tokenize', env);
  224. env.tokens = _.tokenize(env.code, env.grammar);
  225. _.hooks.run('after-tokenize', env);
  226. return Token.stringify(_.util.encode(env.tokens), env.language);
  227. },
  228. matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
  229. var Token = _.Token;
  230. for (var token in grammar) {
  231. if(!grammar.hasOwnProperty(token) || !grammar[token]) {
  232. continue;
  233. }
  234. if (token == target) {
  235. return;
  236. }
  237. var patterns = grammar[token];
  238. patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
  239. for (var j = 0; j < patterns.length; ++j) {
  240. var pattern = patterns[j],
  241. inside = pattern.inside,
  242. lookbehind = !!pattern.lookbehind,
  243. greedy = !!pattern.greedy,
  244. lookbehindLength = 0,
  245. alias = pattern.alias;
  246. if (greedy && !pattern.pattern.global) {
  247. // Without the global flag, lastIndex won't work
  248. var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
  249. pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
  250. }
  251. pattern = pattern.pattern || pattern;
  252. // Don’t cache length as it changes during the loop
  253. for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) {
  254. var str = strarr[i];
  255. if (strarr.length > text.length) {
  256. // Something went terribly wrong, ABORT, ABORT!
  257. return;
  258. }
  259. if (str instanceof Token) {
  260. continue;
  261. }
  262. if (greedy && i != strarr.length - 1) {
  263. pattern.lastIndex = pos;
  264. var match = pattern.exec(text);
  265. if (!match) {
  266. break;
  267. }
  268. var from = match.index + (lookbehind ? match[1].length : 0),
  269. to = match.index + match[0].length,
  270. k = i,
  271. p = pos;
  272. for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) {
  273. p += strarr[k].length;
  274. // Move the index i to the element in strarr that is closest to from
  275. if (from >= p) {
  276. ++i;
  277. pos = p;
  278. }
  279. }
  280. // If strarr[i] is a Token, then the match starts inside another Token, which is invalid
  281. if (strarr[i] instanceof Token) {
  282. continue;
  283. }
  284. // Number of tokens to delete and replace with the new match
  285. delNum = k - i;
  286. str = text.slice(pos, p);
  287. match.index -= pos;
  288. } else {
  289. pattern.lastIndex = 0;
  290. var match = pattern.exec(str),
  291. delNum = 1;
  292. }
  293. if (!match) {
  294. if (oneshot) {
  295. break;
  296. }
  297. continue;
  298. }
  299. if(lookbehind) {
  300. lookbehindLength = match[1] ? match[1].length : 0;
  301. }
  302. var from = match.index + lookbehindLength,
  303. match = match[0].slice(lookbehindLength),
  304. to = from + match.length,
  305. before = str.slice(0, from),
  306. after = str.slice(to);
  307. var args = [i, delNum];
  308. if (before) {
  309. ++i;
  310. pos += before.length;
  311. args.push(before);
  312. }
  313. var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
  314. args.push(wrapped);
  315. if (after) {
  316. args.push(after);
  317. }
  318. Array.prototype.splice.apply(strarr, args);
  319. if (delNum != 1)
  320. _.matchGrammar(text, strarr, grammar, i, pos, true, token);
  321. if (oneshot)
  322. break;
  323. }
  324. }
  325. }
  326. },
  327. tokenize: function(text, grammar, language) {
  328. var strarr = [text];
  329. var rest = grammar.rest;
  330. if (rest) {
  331. for (var token in rest) {
  332. grammar[token] = rest[token];
  333. }
  334. delete grammar.rest;
  335. }
  336. _.matchGrammar(text, strarr, grammar, 0, 0, false);
  337. return strarr;
  338. },
  339. hooks: {
  340. all: {},
  341. add: function (name, callback) {
  342. var hooks = _.hooks.all;
  343. hooks[name] = hooks[name] || [];
  344. hooks[name].push(callback);
  345. },
  346. run: function (name, env) {
  347. var callbacks = _.hooks.all[name];
  348. if (!callbacks || !callbacks.length) {
  349. return;
  350. }
  351. for (var i=0, callback; callback = callbacks[i++];) {
  352. callback(env);
  353. }
  354. }
  355. }
  356. };
  357. var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
  358. this.type = type;
  359. this.content = content;
  360. this.alias = alias;
  361. // Copy of the full string this token was created from
  362. this.length = (matchedStr || "").length|0;
  363. this.greedy = !!greedy;
  364. };
  365. Token.stringify = function(o, language, parent) {
  366. if (typeof o == 'string') {
  367. return o;
  368. }
  369. if (_.util.type(o) === 'Array') {
  370. return o.map(function(element) {
  371. return Token.stringify(element, language, o);
  372. }).join('');
  373. }
  374. var env = {
  375. type: o.type,
  376. content: Token.stringify(o.content, language, parent),
  377. tag: 'span',
  378. classes: ['token', o.type],
  379. attributes: {},
  380. language: language,
  381. parent: parent
  382. };
  383. if (o.alias) {
  384. var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
  385. Array.prototype.push.apply(env.classes, aliases);
  386. }
  387. _.hooks.run('wrap', env);
  388. var attributes = Object.keys(env.attributes).map(function(name) {
  389. return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  390. }).join(' ');
  391. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
  392. };
  393. if (!_self.document) {
  394. if (!_self.addEventListener) {
  395. // in Node.js
  396. return _self.Prism;
  397. }
  398. if (!_.disableWorkerMessageHandler) {
  399. // In worker
  400. _self.addEventListener('message', function (evt) {
  401. var message = JSON.parse(evt.data),
  402. lang = message.language,
  403. code = message.code,
  404. immediateClose = message.immediateClose;
  405. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  406. if (immediateClose) {
  407. _self.close();
  408. }
  409. }, false);
  410. }
  411. return _self.Prism;
  412. }
  413. //Get current script and highlight
  414. var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
  415. if (script) {
  416. _.filename = script.src;
  417. if (!_.manual && !script.hasAttribute('data-manual')) {
  418. if(document.readyState !== "loading") {
  419. if (window.requestAnimationFrame) {
  420. window.requestAnimationFrame(_.highlightAll);
  421. } else {
  422. window.setTimeout(_.highlightAll, 16);
  423. }
  424. }
  425. else {
  426. document.addEventListener('DOMContentLoaded', _.highlightAll);
  427. }
  428. }
  429. }
  430. return _self.Prism;
  431. })();
  432. if (typeof module !== 'undefined' && module.exports) {
  433. module.exports = Prism;
  434. }
  435. // hack for components to work correctly in node.js
  436. if (typeof global !== 'undefined') {
  437. global.Prism = Prism;
  438. }
  439. ;
  440. Prism.languages.markup = {
  441. 'comment': /<!--[\s\S]*?-->/,
  442. 'prolog': /<\?[\s\S]+?\?>/,
  443. 'doctype': /<!DOCTYPE[\s\S]+?>/i,
  444. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  445. 'tag': {
  446. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i,
  447. greedy: true,
  448. inside: {
  449. 'tag': {
  450. pattern: /^<\/?[^\s>\/]+/i,
  451. inside: {
  452. 'punctuation': /^<\/?/,
  453. 'namespace': /^[^\s>\/:]+:/
  454. }
  455. },
  456. 'attr-value': {
  457. pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i,
  458. inside: {
  459. 'punctuation': [
  460. /^=/,
  461. {
  462. pattern: /(^|[^\\])["']/,
  463. lookbehind: true
  464. }
  465. ]
  466. }
  467. },
  468. 'punctuation': /\/?>/,
  469. 'attr-name': {
  470. pattern: /[^\s>\/]+/,
  471. inside: {
  472. 'namespace': /^[^\s>\/:]+:/
  473. }
  474. }
  475. }
  476. },
  477. 'entity': /&#?[\da-z]{1,8};/i
  478. };
  479. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
  480. Prism.languages.markup['entity'];
  481. // Plugin to make entity title show the real entity, idea by Roman Komarov
  482. Prism.hooks.add('wrap', function(env) {
  483. if (env.type === 'entity') {
  484. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  485. }
  486. });
  487. Prism.languages.xml = Prism.languages.markup;
  488. Prism.languages.html = Prism.languages.markup;
  489. Prism.languages.mathml = Prism.languages.markup;
  490. Prism.languages.svg = Prism.languages.markup;
  491. Prism.languages.css = {
  492. 'comment': /\/\*[\s\S]*?\*\//,
  493. 'atrule': {
  494. pattern: /@[\w-]+?.*?(?:;|(?=\s*\{))/i,
  495. inside: {
  496. 'rule': /@[\w-]+/
  497. // See rest below
  498. }
  499. },
  500. 'url': /url\((?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
  501. 'selector': /[^{}\s][^{};]*?(?=\s*\{)/,
  502. 'string': {
  503. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  504. greedy: true
  505. },
  506. 'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
  507. 'important': /\B!important\b/i,
  508. 'function': /[-a-z0-9]+(?=\()/i,
  509. 'punctuation': /[(){};:]/
  510. };
  511. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  512. if (Prism.languages.markup) {
  513. Prism.languages.insertBefore('markup', 'tag', {
  514. 'style': {
  515. pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i,
  516. lookbehind: true,
  517. inside: Prism.languages.css,
  518. alias: 'language-css',
  519. greedy: true
  520. }
  521. });
  522. Prism.languages.insertBefore('inside', 'attr-value', {
  523. 'style-attr': {
  524. pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,
  525. inside: {
  526. 'attr-name': {
  527. pattern: /^\s*style/i,
  528. inside: Prism.languages.markup.tag.inside
  529. },
  530. 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
  531. 'attr-value': {
  532. pattern: /.+/i,
  533. inside: Prism.languages.css
  534. }
  535. },
  536. alias: 'language-css'
  537. }
  538. }, Prism.languages.markup.tag);
  539. };
  540. Prism.languages.clike = {
  541. 'comment': [
  542. {
  543. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  544. lookbehind: true
  545. },
  546. {
  547. pattern: /(^|[^\\:])\/\/.*/,
  548. lookbehind: true,
  549. greedy: true
  550. }
  551. ],
  552. 'string': {
  553. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  554. greedy: true
  555. },
  556. 'class-name': {
  557. pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[\w.\\]+/i,
  558. lookbehind: true,
  559. inside: {
  560. punctuation: /[.\\]/
  561. }
  562. },
  563. 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  564. 'boolean': /\b(?:true|false)\b/,
  565. 'function': /[a-z0-9_]+(?=\()/i,
  566. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
  567. 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
  568. 'punctuation': /[{}[\];(),.:]/
  569. };
  570. Prism.languages.javascript = Prism.languages.extend('clike', {
  571. 'keyword': /\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
  572. 'number': /\b(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
  573. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  574. 'function': /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/i,
  575. 'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
  576. });
  577. Prism.languages.insertBefore('javascript', 'keyword', {
  578. 'regex': {
  579. pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})\]]))/,
  580. lookbehind: true,
  581. greedy: true
  582. },
  583. // This must be declared before keyword because we use "function" inside the look-forward
  584. 'function-variable': {
  585. pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i,
  586. alias: 'function'
  587. },
  588. 'constant': /\b[A-Z][A-Z\d_]*\b/
  589. });
  590. Prism.languages.insertBefore('javascript', 'string', {
  591. 'template-string': {
  592. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  593. greedy: true,
  594. inside: {
  595. 'interpolation': {
  596. pattern: /\$\{[^}]+\}/,
  597. inside: {
  598. 'interpolation-punctuation': {
  599. pattern: /^\$\{|\}$/,
  600. alias: 'punctuation'
  601. },
  602. rest: Prism.languages.javascript
  603. }
  604. },
  605. 'string': /[\s\S]+/
  606. }
  607. }
  608. });
  609. if (Prism.languages.markup) {
  610. Prism.languages.insertBefore('markup', 'tag', {
  611. 'script': {
  612. pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i,
  613. lookbehind: true,
  614. inside: Prism.languages.javascript,
  615. alias: 'language-javascript',
  616. greedy: true
  617. }
  618. });
  619. }
  620. Prism.languages.js = Prism.languages.javascript;
  621. Prism.languages.c = Prism.languages.extend('clike', {
  622. 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
  623. 'operator': /-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/]/,
  624. 'number': /(?:\b0x[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i
  625. });
  626. Prism.languages.insertBefore('c', 'string', {
  627. 'macro': {
  628. // allow for multiline macro definitions
  629. // spaces after the # character compile fine with gcc
  630. pattern: /(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im,
  631. lookbehind: true,
  632. alias: 'property',
  633. inside: {
  634. // highlight the path of the include statement as a string
  635. 'string': {
  636. pattern: /(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/,
  637. lookbehind: true
  638. },
  639. // highlight macro directives as keywords
  640. 'directive': {
  641. pattern: /(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
  642. lookbehind: true,
  643. alias: 'keyword'
  644. }
  645. }
  646. },
  647. // highlight predefined macros as constants
  648. 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
  649. });
  650. delete Prism.languages.c['class-name'];
  651. delete Prism.languages.c['boolean'];
  652. (function(Prism) {
  653. var insideString = {
  654. variable: [
  655. // Arithmetic Environment
  656. {
  657. pattern: /\$?\(\([\s\S]+?\)\)/,
  658. inside: {
  659. // If there is a $ sign at the beginning highlight $(( and )) as variable
  660. variable: [{
  661. pattern: /(^\$\(\([\s\S]+)\)\)/,
  662. lookbehind: true
  663. },
  664. /^\$\(\(/
  665. ],
  666. number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee]-?\d+)?/,
  667. // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
  668. operator: /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
  669. // If there is no $ sign at the beginning highlight (( and )) as punctuation
  670. punctuation: /\(\(?|\)\)?|,|;/
  671. }
  672. },
  673. // Command Substitution
  674. {
  675. pattern: /\$\([^)]+\)|`[^`]+`/,
  676. greedy: true,
  677. inside: {
  678. variable: /^\$\(|^`|\)$|`$/
  679. }
  680. },
  681. /\$(?:[\w#?*!@]+|\{[^}]+\})/i
  682. ]
  683. };
  684. Prism.languages.bash = {
  685. 'shebang': {
  686. pattern: /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/,
  687. alias: 'important'
  688. },
  689. 'comment': {
  690. pattern: /(^|[^"{\\])#.*/,
  691. lookbehind: true
  692. },
  693. 'string': [
  694. //Support for Here-Documents https://en.wikipedia.org/wiki/Here_document
  695. {
  696. pattern: /((?:^|[^<])<<\s*)["']?(\w+?)["']?\s*\r?\n(?:[\s\S])*?\r?\n\2/,
  697. lookbehind: true,
  698. greedy: true,
  699. inside: insideString
  700. },
  701. {
  702. pattern: /(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\1)[^\\])*\1/,
  703. greedy: true,
  704. inside: insideString
  705. }
  706. ],
  707. 'variable': insideString.variable,
  708. // Originally based on http://ss64.com/bash/
  709. 'function': {
  710. pattern: /(^|[\s;|&])(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chown|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|enable|env|ethtool|eval|exec|expand|expect|export|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logname|logout|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|make|man|mkdir|mkfifo|mkisofs|mknod|more|most|mount|mtools|mtr|mv|mmv|nano|netstat|nice|nl|nohup|notify-send|npm|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printenv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|renice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|seq|service|sftp|shift|shopt|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|traceroute|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|units|unrar|unshar|uptime|useradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)(?=$|[\s;|&])/,
  711. lookbehind: true
  712. },
  713. 'keyword': {
  714. pattern: /(^|[\s;|&])(?:let|:|\.|if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)(?=$|[\s;|&])/,
  715. lookbehind: true
  716. },
  717. 'boolean': {
  718. pattern: /(^|[\s;|&])(?:true|false)(?=$|[\s;|&])/,
  719. lookbehind: true
  720. },
  721. 'operator': /&&?|\|\|?|==?|!=?|<<<?|>>|<=?|>=?|=~/,
  722. 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];]/
  723. };
  724. var inside = insideString.variable[1].inside;
  725. inside.string = Prism.languages.bash.string;
  726. inside['function'] = Prism.languages.bash['function'];
  727. inside.keyword = Prism.languages.bash.keyword;
  728. inside['boolean'] = Prism.languages.bash['boolean'];
  729. inside.operator = Prism.languages.bash.operator;
  730. inside.punctuation = Prism.languages.bash.punctuation;
  731. Prism.languages.shell = Prism.languages.bash;
  732. })(Prism);
  733. Prism.languages.cpp = Prism.languages.extend('c', {
  734. 'keyword': /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,
  735. 'boolean': /\b(?:true|false)\b/,
  736. 'operator': /--?|\+\+?|!=?|<{1,2}=?|>{1,2}=?|->|:{1,2}|={1,2}|\^|~|%|&{1,2}|\|\|?|\?|\*|\/|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/
  737. });
  738. Prism.languages.insertBefore('cpp', 'keyword', {
  739. 'class-name': {
  740. pattern: /(class\s+)\w+/i,
  741. lookbehind: true
  742. }
  743. });
  744. Prism.languages.insertBefore('cpp', 'string', {
  745. 'raw-string': {
  746. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  747. alias: 'string',
  748. greedy: true
  749. }
  750. });
  751. Prism.languages.csharp = Prism.languages.extend('clike', {
  752. 'keyword': /\b(?:abstract|add|alias|as|ascending|async|await|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|global|goto|group|if|implicit|in|int|interface|internal|into|is|join|let|lock|long|namespace|new|null|object|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|remove|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|value|var|virtual|void|volatile|where|while|yield)\b/,
  753. 'string': [
  754. {
  755. pattern: /@("|')(?:\1\1|\\[\s\S]|(?!\1)[^\\])*\1/,
  756. greedy: true
  757. },
  758. {
  759. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*?\1/,
  760. greedy: true
  761. }
  762. ],
  763. 'class-name': [
  764. {
  765. // (Foo bar, Bar baz)
  766. pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?=\s+\w+)/,
  767. inside: {
  768. punctuation: /\./
  769. }
  770. },
  771. {
  772. // [Foo]
  773. pattern: /(\[)[A-Z]\w*(?:\.\w+)*\b/,
  774. lookbehind: true,
  775. inside: {
  776. punctuation: /\./
  777. }
  778. },
  779. {
  780. // class Foo : Bar
  781. pattern: /(\b(?:class|interface)\s+[A-Z]\w*(?:\.\w+)*\s*:\s*)[A-Z]\w*(?:\.\w+)*\b/,
  782. lookbehind: true,
  783. inside: {
  784. punctuation: /\./
  785. }
  786. },
  787. {
  788. // class Foo
  789. pattern: /((?:\b(?:class|interface|new)\s+)|(?:catch\s+\())[A-Z]\w*(?:\.\w+)*\b/,
  790. lookbehind: true,
  791. inside: {
  792. punctuation: /\./
  793. }
  794. }
  795. ],
  796. 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i
  797. });
  798. Prism.languages.insertBefore('csharp', 'class-name', {
  799. 'generic-method': {
  800. pattern: /\w+\s*<[^>\r\n]+?>\s*(?=\()/,
  801. inside: {
  802. function: /^\w+/,
  803. 'class-name': {
  804. pattern: /\b[A-Z]\w*(?:\.\w+)*\b/,
  805. inside: {
  806. punctuation: /\./
  807. }
  808. },
  809. keyword: Prism.languages.csharp.keyword,
  810. punctuation: /[<>(),.:]/
  811. }
  812. },
  813. 'preprocessor': {
  814. pattern: /(^\s*)#.*/m,
  815. lookbehind: true,
  816. alias: 'property',
  817. inside: {
  818. // highlight preprocessor directives as keywords
  819. 'directive': {
  820. pattern: /(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
  821. lookbehind: true,
  822. alias: 'keyword'
  823. }
  824. }
  825. }
  826. });
  827. Prism.languages.dotnet = Prism.languages.csharp;
  828. Prism.languages.diff = {
  829. 'coord': [
  830. // Match all kinds of coord lines (prefixed by "+++", "---" or "***").
  831. /^(?:\*{3}|-{3}|\+{3}).*$/m,
  832. // Match "@@ ... @@" coord lines in unified diff.
  833. /^@@.*@@$/m,
  834. // Match coord lines in normal diff (starts with a number).
  835. /^\d+.*$/m
  836. ],
  837. // Match inserted and deleted lines. Support both +/- and >/< styles.
  838. 'deleted': /^[-<].*$/m,
  839. 'inserted': /^[+>].*$/m,
  840. // Match "different" lines (prefixed with "!") in context diff.
  841. 'diff': {
  842. 'pattern': /^!(?!!).+$/m,
  843. 'alias': 'important'
  844. }
  845. };
  846. Prism.languages['markup-templating'] = {};
  847. Object.defineProperties(Prism.languages['markup-templating'], {
  848. buildPlaceholders: {
  849. // Tokenize all inline templating expressions matching placeholderPattern
  850. // If the replaceFilter function is provided, it will be called with every match.
  851. // If it returns false, the match will not be replaced.
  852. value: function (env, language, placeholderPattern, replaceFilter) {
  853. if (env.language !== language) {
  854. return;
  855. }
  856. env.tokenStack = [];
  857. env.code = env.code.replace(placeholderPattern, function(match) {
  858. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  859. return match;
  860. }
  861. var i = env.tokenStack.length;
  862. // Check for existing strings
  863. while (env.code.indexOf('___' + language.toUpperCase() + i + '___') !== -1)
  864. ++i;
  865. // Create a sparse array
  866. env.tokenStack[i] = match;
  867. return '___' + language.toUpperCase() + i + '___';
  868. });
  869. // Switch the grammar to markup
  870. env.grammar = Prism.languages.markup;
  871. }
  872. },
  873. tokenizePlaceholders: {
  874. // Replace placeholders with proper tokens after tokenizing
  875. value: function (env, language) {
  876. if (env.language !== language || !env.tokenStack) {
  877. return;
  878. }
  879. // Switch the grammar back
  880. env.grammar = Prism.languages[language];
  881. var j = 0;
  882. var keys = Object.keys(env.tokenStack);
  883. var walkTokens = function (tokens) {
  884. if (j >= keys.length) {
  885. return;
  886. }
  887. for (var i = 0; i < tokens.length; i++) {
  888. var token = tokens[i];
  889. if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
  890. var k = keys[j];
  891. var t = env.tokenStack[k];
  892. var s = typeof token === 'string' ? token : token.content;
  893. var index = s.indexOf('___' + language.toUpperCase() + k + '___');
  894. if (index > -1) {
  895. ++j;
  896. var before = s.substring(0, index);
  897. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar, language), 'language-' + language, t);
  898. var after = s.substring(index + ('___' + language.toUpperCase() + k + '___').length);
  899. var replacement;
  900. if (before || after) {
  901. replacement = [before, middle, after].filter(function (v) { return !!v; });
  902. walkTokens(replacement);
  903. } else {
  904. replacement = middle;
  905. }
  906. if (typeof token === 'string') {
  907. Array.prototype.splice.apply(tokens, [i, 1].concat(replacement));
  908. } else {
  909. token.content = replacement;
  910. }
  911. if (j >= keys.length) {
  912. break;
  913. }
  914. }
  915. } else if (token.content && typeof token.content !== 'string') {
  916. walkTokens(token.content);
  917. }
  918. }
  919. };
  920. walkTokens(env.tokens);
  921. }
  922. }
  923. });
  924. Prism.languages.git = {
  925. /*
  926. * A simple one line comment like in a git status command
  927. * For instance:
  928. * $ git status
  929. * # On branch infinite-scroll
  930. * # Your branch and 'origin/sharedBranches/frontendTeam/infinite-scroll' have diverged,
  931. * # and have 1 and 2 different commits each, respectively.
  932. * nothing to commit (working directory clean)
  933. */
  934. 'comment': /^#.*/m,
  935. /*
  936. * Regexp to match the changed lines in a git diff output. Check the example below.
  937. */
  938. 'deleted': /^[-–].*/m,
  939. 'inserted': /^\+.*/m,
  940. /*
  941. * a string (double and simple quote)
  942. */
  943. 'string': /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/m,
  944. /*
  945. * a git command. It starts with a random prompt finishing by a $, then "git" then some other parameters
  946. * For instance:
  947. * $ git add file.txt
  948. */
  949. 'command': {
  950. pattern: /^.*\$ git .*$/m,
  951. inside: {
  952. /*
  953. * A git command can contain a parameter starting by a single or a double dash followed by a string
  954. * For instance:
  955. * $ git diff --cached
  956. * $ git log -p
  957. */
  958. 'parameter': /\s--?\w+/m
  959. }
  960. },
  961. /*
  962. * Coordinates displayed in a git diff command
  963. * For instance:
  964. * $ git diff
  965. * diff --git file.txt file.txt
  966. * index 6214953..1d54a52 100644
  967. * --- file.txt
  968. * +++ file.txt
  969. * @@ -1 +1,2 @@
  970. * -Here's my tetx file
  971. * +Here's my text file
  972. * +And this is the second line
  973. */
  974. 'coord': /^@@.*@@$/m,
  975. /*
  976. * Match a "commit [SHA1]" line in a git log output.
  977. * For instance:
  978. * $ git log
  979. * commit a11a14ef7e26f2ca62d4b35eac455ce636d0dc09
  980. * Author: lgiraudel
  981. * Date: Mon Feb 17 11:18:34 2014 +0100
  982. *
  983. * Add of a new line
  984. */
  985. 'commit_sha1': /^commit \w{40}$/m
  986. };
  987. Prism.languages.go = Prism.languages.extend('clike', {
  988. '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/,
  989. '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/,
  990. 'boolean': /\b(?:_|iota|nil|true|false)\b/,
  991. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  992. 'number': /(?:\b0x[a-f\d]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[-+]?\d+)?)i?/i,
  993. 'string': {
  994. pattern: /(["'`])(\\[\s\S]|(?!\1)[^\\])*\1/,
  995. greedy: true
  996. }
  997. });
  998. delete Prism.languages.go['class-name'];
  999. Prism.languages.graphql = {
  1000. 'comment': /#.*/,
  1001. 'string': {
  1002. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  1003. greedy: true
  1004. },
  1005. 'number': /(?:\B-|\b)\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
  1006. 'boolean': /\b(?:true|false)\b/,
  1007. 'variable': /\$[a-z_]\w*/i,
  1008. 'directive': {
  1009. pattern: /@[a-z_]\w*/i,
  1010. alias: 'function'
  1011. },
  1012. 'attr-name': /[a-z_]\w*(?=\s*:)/i,
  1013. 'keyword': [
  1014. {
  1015. pattern: /(fragment\s+(?!on)[a-z_]\w*\s+|\.{3}\s*)on\b/,
  1016. lookbehind: true
  1017. },
  1018. /\b(?:query|fragment|mutation)\b/
  1019. ],
  1020. 'operator': /!|=|\.{3}/,
  1021. 'punctuation': /[!(){}\[\]:=,]/
  1022. };
  1023. Prism.languages.http = {
  1024. 'request-line': {
  1025. pattern: /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\s(?:https?:\/\/|\/)\S+\sHTTP\/[0-9.]+/m,
  1026. inside: {
  1027. // HTTP Verb
  1028. property: /^(?:POST|GET|PUT|DELETE|OPTIONS|PATCH|TRACE|CONNECT)\b/,
  1029. // Path or query argument
  1030. 'attr-name': /:\w+/
  1031. }
  1032. },
  1033. 'response-status': {
  1034. pattern: /^HTTP\/1.[01] \d+.*/m,
  1035. inside: {
  1036. // Status, e.g. 200 OK
  1037. property: {
  1038. pattern: /(^HTTP\/1.[01] )\d+.*/i,
  1039. lookbehind: true
  1040. }
  1041. }
  1042. },
  1043. // HTTP header name
  1044. 'header-name': {
  1045. pattern: /^[\w-]+:(?=.)/m,
  1046. alias: 'keyword'
  1047. }
  1048. };
  1049. // Create a mapping of Content-Type headers to language definitions
  1050. var httpLanguages = {
  1051. 'application/json': Prism.languages.javascript,
  1052. 'application/xml': Prism.languages.markup,
  1053. 'text/xml': Prism.languages.markup,
  1054. 'text/html': Prism.languages.markup
  1055. };
  1056. // Insert each content type parser that has its associated language
  1057. // currently loaded.
  1058. for (var contentType in httpLanguages) {
  1059. if (httpLanguages[contentType]) {
  1060. var options = {};
  1061. options[contentType] = {
  1062. pattern: new RegExp('(content-type:\\s*' + contentType + '[\\w\\W]*?)(?:\\r?\\n|\\r){2}[\\w\\W]*', 'i'),
  1063. lookbehind: true,
  1064. inside: {
  1065. rest: httpLanguages[contentType]
  1066. }
  1067. };
  1068. Prism.languages.insertBefore('http', 'header-name', options);
  1069. }
  1070. }
  1071. ;
  1072. /**
  1073. * Original by Scott Helme.
  1074. *
  1075. * Reference: https://scotthelme.co.uk/hpkp-cheat-sheet/
  1076. */
  1077. Prism.languages.hpkp = {
  1078. 'directive': {
  1079. pattern: /\b(?:(?:includeSubDomains|preload|strict)(?: |;)|pin-sha256="[a-zA-Z\d+=/]+"|(?:max-age|report-uri)=|report-to )/,
  1080. alias: 'keyword'
  1081. },
  1082. 'safe': {
  1083. pattern: /\d{7,}/,
  1084. alias: 'selector'
  1085. },
  1086. 'unsafe': {
  1087. pattern: /\d{0,6}/,
  1088. alias: 'function'
  1089. }
  1090. };
  1091. /**
  1092. * Original by Scott Helme.
  1093. *
  1094. * Reference: https://scotthelme.co.uk/hsts-cheat-sheet/
  1095. */
  1096. Prism.languages.hsts = {
  1097. 'directive': {
  1098. pattern: /\b(?:max-age=|includeSubDomains|preload)/,
  1099. alias: 'keyword'
  1100. },
  1101. 'safe': {
  1102. pattern: /\d{8,}/,
  1103. alias: 'selector'
  1104. },
  1105. 'unsafe': {
  1106. pattern: /\d{0,7}/,
  1107. alias: 'function'
  1108. }
  1109. };
  1110. Prism.languages.java = Prism.languages.extend('clike', {
  1111. '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/,
  1112. 'number': /\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp-]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?[df]?/i,
  1113. 'operator': {
  1114. pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,
  1115. lookbehind: true
  1116. }
  1117. });
  1118. Prism.languages.insertBefore('java','function', {
  1119. 'annotation': {
  1120. alias: 'punctuation',
  1121. pattern: /(^|[^.])@\w+/,
  1122. lookbehind: true
  1123. }
  1124. });
  1125. Prism.languages.insertBefore('java', 'class-name', {
  1126. 'generics': {
  1127. pattern: /<\s*\w+(?:\.\w+)?(?:\s*,\s*\w+(?:\.\w+)?)*>/i,
  1128. alias: 'function',
  1129. inside: {
  1130. keyword: Prism.languages.java.keyword,
  1131. punctuation: /[<>(),.:]/
  1132. }
  1133. }
  1134. });
  1135. Prism.languages.json = {
  1136. 'property': /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
  1137. 'string': {
  1138. pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  1139. greedy: true
  1140. },
  1141. 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
  1142. 'punctuation': /[{}[\]);,]/,
  1143. 'operator': /:/g,
  1144. 'boolean': /\b(?:true|false)\b/i,
  1145. 'null': /\bnull\b/i
  1146. };
  1147. Prism.languages.jsonp = Prism.languages.json;
  1148. /* FIXME :
  1149. :extend() is not handled specifically : its highlighting is buggy.
  1150. Mixin usage must be inside a ruleset to be highlighted.
  1151. At-rules (e.g. import) containing interpolations are buggy.
  1152. Detached rulesets are highlighted as at-rules.
  1153. A comment before a mixin usage prevents the latter to be properly highlighted.
  1154. */
  1155. Prism.languages.less = Prism.languages.extend('css', {
  1156. 'comment': [
  1157. /\/\*[\s\S]*?\*\//,
  1158. {
  1159. pattern: /(^|[^\\])\/\/.*/,
  1160. lookbehind: true
  1161. }
  1162. ],
  1163. 'atrule': {
  1164. pattern: /@[\w-]+?(?:\([^{}]+\)|[^(){};])*?(?=\s*\{)/i,
  1165. inside: {
  1166. 'punctuation': /[:()]/
  1167. }
  1168. },
  1169. // selectors and mixins are considered the same
  1170. 'selector': {
  1171. pattern: /(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\([^{}]*\)|[^{};@])*?(?=\s*\{)/,
  1172. inside: {
  1173. // mixin parameters
  1174. 'variable': /@+[\w-]+/
  1175. }
  1176. },
  1177. 'property': /(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/i,
  1178. 'punctuation': /[{}();:,]/,
  1179. 'operator': /[+\-*\/]/
  1180. });
  1181. // Invert function and punctuation positions
  1182. Prism.languages.insertBefore('less', 'punctuation', {
  1183. 'function': Prism.languages.less.function
  1184. });
  1185. Prism.languages.insertBefore('less', 'property', {
  1186. 'variable': [
  1187. // Variable declaration (the colon must be consumed!)
  1188. {
  1189. pattern: /@[\w-]+\s*:/,
  1190. inside: {
  1191. "punctuation": /:/
  1192. }
  1193. },
  1194. // Variable usage
  1195. /@@?[\w-]+/
  1196. ],
  1197. 'mixin-usage': {
  1198. pattern: /([{;]\s*)[.#](?!\d)[\w-]+.*?(?=[(;])/,
  1199. lookbehind: true,
  1200. alias: 'function'
  1201. }
  1202. });
  1203. Prism.languages.markdown = Prism.languages.extend('markup', {});
  1204. Prism.languages.insertBefore('markdown', 'prolog', {
  1205. 'blockquote': {
  1206. // > ...
  1207. pattern: /^>(?:[\t ]*>)*/m,
  1208. alias: 'punctuation'
  1209. },
  1210. 'code': [
  1211. {
  1212. // Prefixed by 4 spaces or 1 tab
  1213. pattern: /^(?: {4}|\t).+/m,
  1214. alias: 'keyword'
  1215. },
  1216. {
  1217. // `code`
  1218. // ``code``
  1219. pattern: /``.+?``|`[^`\n]+`/,
  1220. alias: 'keyword'
  1221. }
  1222. ],
  1223. 'title': [
  1224. {
  1225. // title 1
  1226. // =======
  1227. // title 2
  1228. // -------
  1229. pattern: /\w+.*(?:\r?\n|\r)(?:==+|--+)/,
  1230. alias: 'important',
  1231. inside: {
  1232. punctuation: /==+$|--+$/
  1233. }
  1234. },
  1235. {
  1236. // # title 1
  1237. // ###### title 6
  1238. pattern: /(^\s*)#+.+/m,
  1239. lookbehind: true,
  1240. alias: 'important',
  1241. inside: {
  1242. punctuation: /^#+|#+$/
  1243. }
  1244. }
  1245. ],
  1246. 'hr': {
  1247. // ***
  1248. // ---
  1249. // * * *
  1250. // -----------
  1251. pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
  1252. lookbehind: true,
  1253. alias: 'punctuation'
  1254. },
  1255. 'list': {
  1256. // * item
  1257. // + item
  1258. // - item
  1259. // 1. item
  1260. pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
  1261. lookbehind: true,
  1262. alias: 'punctuation'
  1263. },
  1264. 'url-reference': {
  1265. // [id]: http://example.com "Optional title"
  1266. // [id]: http://example.com 'Optional title'
  1267. // [id]: http://example.com (Optional title)
  1268. // [id]: <http://example.com> "Optional title"
  1269. pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
  1270. inside: {
  1271. 'variable': {
  1272. pattern: /^(!?\[)[^\]]+/,
  1273. lookbehind: true
  1274. },
  1275. 'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
  1276. 'punctuation': /^[\[\]!:]|[<>]/
  1277. },
  1278. alias: 'url'
  1279. },
  1280. 'bold': {
  1281. // **strong**
  1282. // __strong__
  1283. // Allow only one line break
  1284. pattern: /(^|[^\\])(\*\*|__)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,
  1285. lookbehind: true,
  1286. inside: {
  1287. 'punctuation': /^\*\*|^__|\*\*$|__$/
  1288. }
  1289. },
  1290. 'italic': {
  1291. // *em*
  1292. // _em_
  1293. // Allow only one line break
  1294. pattern: /(^|[^\\])([*_])(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,
  1295. lookbehind: true,
  1296. inside: {
  1297. 'punctuation': /^[*_]|[*_]$/
  1298. }
  1299. },
  1300. 'url': {
  1301. // [example](http://example.com "Optional title")
  1302. // [example] [id]
  1303. pattern: /!?\[[^\]]+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)| ?\[[^\]\n]*\])/,
  1304. inside: {
  1305. 'variable': {
  1306. pattern: /(!?\[)[^\]]+(?=\]$)/,
  1307. lookbehind: true
  1308. },
  1309. 'string': {
  1310. pattern: /"(?:\\.|[^"\\])*"(?=\)$)/
  1311. }
  1312. }
  1313. }
  1314. });
  1315. Prism.languages.markdown['bold'].inside['url'] = Prism.languages.markdown['url'];
  1316. Prism.languages.markdown['italic'].inside['url'] = Prism.languages.markdown['url'];
  1317. Prism.languages.markdown['bold'].inside['italic'] = Prism.languages.markdown['italic'];
  1318. Prism.languages.markdown['italic'].inside['bold'] = Prism.languages.markdown['bold'];
  1319. Prism.languages.nginx = Prism.languages.extend('clike', {
  1320. 'comment': {
  1321. pattern: /(^|[^"{\\])#.*/,
  1322. lookbehind: true
  1323. },
  1324. 'keyword': /\b(?:CONTENT_|DOCUMENT_|GATEWAY_|HTTP_|HTTPS|if_not_empty|PATH_|QUERY_|REDIRECT_|REMOTE_|REQUEST_|SCGI|SCRIPT_|SERVER_|http|events|accept_mutex|accept_mutex_delay|access_log|add_after_body|add_before_body|add_header|addition_types|aio|alias|allow|ancient_browser|ancient_browser_value|auth|auth_basic|auth_basic_user_file|auth_http|auth_http_header|auth_http_timeout|autoindex|autoindex_exact_size|autoindex_localtime|break|charset|charset_map|charset_types|chunked_transfer_encoding|client_body_buffer_size|client_body_in_file_only|client_body_in_single_buffer|client_body_temp_path|client_body_timeout|client_header_buffer_size|client_header_timeout|client_max_body_size|connection_pool_size|create_full_put_path|daemon|dav_access|dav_methods|debug_connection|debug_points|default_type|deny|devpoll_changes|devpoll_events|directio|directio_alignment|disable_symlinks|empty_gif|env|epoll_events|error_log|error_page|expires|fastcgi_buffer_size|fastcgi_buffers|fastcgi_busy_buffers_size|fastcgi_cache|fastcgi_cache_bypass|fastcgi_cache_key|fastcgi_cache_lock|fastcgi_cache_lock_timeout|fastcgi_cache_methods|fastcgi_cache_min_uses|fastcgi_cache_path|fastcgi_cache_purge|fastcgi_cache_use_stale|fastcgi_cache_valid|fastcgi_connect_timeout|fastcgi_hide_header|fastcgi_ignore_client_abort|fastcgi_ignore_headers|fastcgi_index|fastcgi_intercept_errors|fastcgi_keep_conn|fastcgi_max_temp_file_size|fastcgi_next_upstream|fastcgi_no_cache|fastcgi_param|fastcgi_pass|fastcgi_pass_header|fastcgi_read_timeout|fastcgi_redirect_errors|fastcgi_send_timeout|fastcgi_split_path_info|fastcgi_store|fastcgi_store_access|fastcgi_temp_file_write_size|fastcgi_temp_path|flv|geo|geoip_city|geoip_country|google_perftools_profiles|gzip|gzip_buffers|gzip_comp_level|gzip_disable|gzip_http_version|gzip_min_length|gzip_proxied|gzip_static|gzip_types|gzip_vary|if|if_modified_since|ignore_invalid_headers|image_filter|image_filter_buffer|image_filter_jpeg_quality|image_filter_sharpen|image_filter_transparency|imap_capabilities|imap_client_buffer|include|index|internal|ip_hash|keepalive|keepalive_disable|keepalive_requests|keepalive_timeout|kqueue_changes|kqueue_events|large_client_header_buffers|limit_conn|limit_conn_log_level|limit_conn_zone|limit_except|limit_rate|limit_rate_after|limit_req|limit_req_log_level|limit_req_zone|limit_zone|lingering_close|lingering_time|lingering_timeout|listen|location|lock_file|log_format|log_format_combined|log_not_found|log_subrequest|map|map_hash_bucket_size|map_hash_max_size|master_process|max_ranges|memcached_buffer_size|memcached_connect_timeout|memcached_next_upstream|memcached_pass|memcached_read_timeout|memcached_send_timeout|merge_slashes|min_delete_depth|modern_browser|modern_browser_value|mp4|mp4_buffer_size|mp4_max_buffer_size|msie_padding|msie_refresh|multi_accept|open_file_cache|open_file_cache_errors|open_file_cache_min_uses|open_file_cache_valid|open_log_file_cache|optimize_server_names|override_charset|pcre_jit|perl|perl_modules|perl_require|perl_set|pid|pop3_auth|pop3_capabilities|port_in_redirect|post_action|postpone_output|protocol|proxy|proxy_buffer|proxy_buffer_size|proxy_buffering|proxy_buffers|proxy_busy_buffers_size|proxy_cache|proxy_cache_bypass|proxy_cache_key|proxy_cache_lock|proxy_cache_lock_timeout|proxy_cache_methods|proxy_cache_min_uses|proxy_cache_path|proxy_cache_use_stale|proxy_cache_valid|proxy_connect_timeout|proxy_cookie_domain|proxy_cookie_path|proxy_headers_hash_bucket_size|proxy_headers_hash_max_size|proxy_hide_header|proxy_http_version|proxy_ignore_client_abort|proxy_ignore_headers|proxy_intercept_errors|proxy_max_temp_file_size|proxy_method|proxy_next_upstream|proxy_no_cache|proxy_pass|proxy_pass_error_message|proxy_pass_header|proxy_pass_request_body|proxy_pass_request_headers|proxy_read_timeout|proxy_redirect|proxy_redirect_errors|proxy_send_lowat|proxy_send_timeout|proxy_set_body|proxy_set_header|proxy_ssl_session_reuse|proxy_store|proxy_store_access|proxy_temp_file_write_size|proxy_temp_path|proxy_timeout|proxy_upstream_fail_timeout|proxy_upstream_max_fails|random_index|read_ahead|real_ip_header|recursive_error_pages|request_pool_size|reset_timedout_connection|resolver|resolver_timeout|return|rewrite|root|rtsig_overflow_events|rtsig_overflow_test|rtsig_overflow_threshold|rtsig_signo|satisfy|satisfy_any|secure_link_secret|send_lowat|send_timeout|sendfile|sendfile_max_chunk|server|server_name|server_name_in_redirect|server_names_hash_bucket_size|server_names_hash_max_size|server_tokens|set|set_real_ip_from|smtp_auth|smtp_capabilities|so_keepalive|source_charset|split_clients|ssi|ssi_silent_errors|ssi_types|ssi_value_length|ssl|ssl_certificate|ssl_certificate_key|ssl_ciphers|ssl_client_certificate|ssl_crl|ssl_dhparam|ssl_engine|ssl_prefer_server_ciphers|ssl_protocols|ssl_session_cache|ssl_session_timeout|ssl_verify_client|ssl_verify_depth|starttls|stub_status|sub_filter|sub_filter_once|sub_filter_types|tcp_nodelay|tcp_nopush|timeout|timer_resolution|try_files|types|types_hash_bucket_size|types_hash_max_size|underscores_in_headers|uninitialized_variable_warn|upstream|use|user|userid|userid_domain|userid_expires|userid_name|userid_p3p|userid_path|userid_service|valid_referers|variables_hash_bucket_size|variables_hash_max_size|worker_connections|worker_cpu_affinity|worker_priority|worker_processes|worker_rlimit_core|worker_rlimit_nofile|worker_rlimit_sigpending|working_directory|xclient|xml_entities|xslt_entities|xslt_stylesheet|xslt_types)\b/i
  1325. });
  1326. Prism.languages.insertBefore('nginx', 'keyword', {
  1327. 'variable': /\$[a-z_]+/i
  1328. });
  1329. /**
  1330. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  1331. * Modified by Miles Johnson: http://milesj.me
  1332. *
  1333. * Supports the following:
  1334. * - Extends clike syntax
  1335. * - Support for PHP 5.3+ (namespaces, traits, generators, etc)
  1336. * - Smarter constant and function matching
  1337. *
  1338. * Adds the following new token classes:
  1339. * constant, delimiter, variable, function, package
  1340. */
  1341. (function (Prism) {
  1342. Prism.languages.php = Prism.languages.extend('clike', {
  1343. '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,
  1344. 'constant': /\b[A-Z0-9_]{2,}\b/,
  1345. 'comment': {
  1346. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1347. lookbehind: true
  1348. }
  1349. });
  1350. Prism.languages.insertBefore('php', 'string', {
  1351. 'shell-comment': {
  1352. pattern: /(^|[^\\])#.*/,
  1353. lookbehind: true,
  1354. alias: 'comment'
  1355. }
  1356. });
  1357. Prism.languages.insertBefore('php', 'keyword', {
  1358. 'delimiter': {
  1359. pattern: /\?>|<\?(?:php|=)?/i,
  1360. alias: 'important'
  1361. },
  1362. 'variable': /\$+(?:\w+\b|(?={))/i,
  1363. 'package': {
  1364. pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
  1365. lookbehind: true,
  1366. inside: {
  1367. punctuation: /\\/
  1368. }
  1369. }
  1370. });
  1371. // Must be defined after the function pattern
  1372. Prism.languages.insertBefore('php', 'operator', {
  1373. 'property': {
  1374. pattern: /(->)[\w]+/,
  1375. lookbehind: true
  1376. }
  1377. });
  1378. Prism.languages.insertBefore('php', 'string', {
  1379. 'nowdoc-string': {
  1380. pattern: /<<<'([^']+)'(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;/,
  1381. greedy: true,
  1382. alias: 'string',
  1383. inside: {
  1384. 'delimiter': {
  1385. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  1386. alias: 'symbol',
  1387. inside: {
  1388. 'punctuation': /^<<<'?|[';]$/
  1389. }
  1390. }
  1391. }
  1392. },
  1393. 'heredoc-string': {
  1394. pattern: /<<<(?:"([^"]+)"(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\1;|([a-z_]\w*)(?:\r\n?|\n)(?:.*(?:\r\n?|\n))*?\2;)/i,
  1395. greedy: true,
  1396. alias: 'string',
  1397. inside: {
  1398. 'delimiter': {
  1399. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  1400. alias: 'symbol',
  1401. inside: {
  1402. 'punctuation': /^<<<"?|[";]$/
  1403. }
  1404. },
  1405. 'interpolation': null // See below
  1406. }
  1407. },
  1408. 'single-quoted-string': {
  1409. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1410. greedy: true,
  1411. alias: 'string'
  1412. },
  1413. 'double-quoted-string': {
  1414. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1415. greedy: true,
  1416. alias: 'string',
  1417. inside: {
  1418. 'interpolation': null // See below
  1419. }
  1420. }
  1421. });
  1422. // The different types of PHP strings "replace" the C-like standard string
  1423. delete Prism.languages.php['string'];
  1424. var string_interpolation = {
  1425. pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[.+?]|->\w+)*)/,
  1426. lookbehind: true,
  1427. inside: {
  1428. rest: Prism.languages.php
  1429. }
  1430. };
  1431. Prism.languages.php['heredoc-string'].inside['interpolation'] = string_interpolation;
  1432. Prism.languages.php['double-quoted-string'].inside['interpolation'] = string_interpolation;
  1433. Prism.hooks.add('before-tokenize', function(env) {
  1434. if (!/(?:<\?php|<\?)/ig.test(env.code)) {
  1435. return;
  1436. }
  1437. var phpPattern = /(?:<\?php|<\?)[\s\S]*?(?:\?>|$)/ig;
  1438. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  1439. });
  1440. Prism.hooks.add('after-tokenize', function(env) {
  1441. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  1442. });
  1443. }(Prism));
  1444. Prism.languages.insertBefore('php', 'variable', {
  1445. 'this': /\$this\b/,
  1446. 'global': /\$(?:_(?:SERVER|GET|POST|FILES|REQUEST|SESSION|ENV|COOKIE)|GLOBALS|HTTP_RAW_POST_DATA|argc|argv|php_errormsg|http_response_header)\b/,
  1447. 'scope': {
  1448. pattern: /\b[\w\\]+::/,
  1449. inside: {
  1450. keyword: /static|self|parent/,
  1451. punctuation: /::|\\/
  1452. }
  1453. }
  1454. });
  1455. Prism.languages.sql= {
  1456. 'comment': {
  1457. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  1458. lookbehind: true
  1459. },
  1460. 'string' : {
  1461. pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\])*\2/,
  1462. greedy: true,
  1463. lookbehind: true
  1464. },
  1465. 'variable': /@[\w.$]+|@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
  1466. 'function': /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i, // Should we highlight user defined functions too?
  1467. 'keyword': /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURNS?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
  1468. 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
  1469. 'number': /\b0x[\da-f]+\b|\b\d+\.?\d*|\B\.\d+\b/i,
  1470. 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|IN|LIKE|NOT|OR|IS|DIV|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  1471. 'punctuation': /[;[\]()`,.]/
  1472. };
  1473. Prism.languages.python = {
  1474. 'comment': {
  1475. pattern: /(^|[^\\])#.*/,
  1476. lookbehind: true
  1477. },
  1478. 'triple-quoted-string': {
  1479. pattern: /("""|''')[\s\S]+?\1/,
  1480. greedy: true,
  1481. alias: 'string'
  1482. },
  1483. 'string': {
  1484. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  1485. greedy: true
  1486. },
  1487. 'function': {
  1488. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  1489. lookbehind: true
  1490. },
  1491. 'class-name': {
  1492. pattern: /(\bclass\s+)\w+/i,
  1493. lookbehind: true
  1494. },
  1495. 'keyword': /\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|pass|print|raise|return|try|while|with|yield)\b/,
  1496. 'builtin':/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
  1497. 'boolean': /\b(?:True|False|None)\b/,
  1498. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  1499. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,
  1500. 'punctuation': /[{}[\];(),.:]/
  1501. };
  1502. (function(Prism) {
  1503. Prism.languages.sass = Prism.languages.extend('css', {
  1504. // Sass comments don't need to be closed, only indented
  1505. 'comment': {
  1506. pattern: /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t]+.+)*/m,
  1507. lookbehind: true
  1508. }
  1509. });
  1510. Prism.languages.insertBefore('sass', 'atrule', {
  1511. // We want to consume the whole line
  1512. 'atrule-line': {
  1513. // Includes support for = and + shortcuts
  1514. pattern: /^(?:[ \t]*)[@+=].+/m,
  1515. inside: {
  1516. 'atrule': /(?:@[\w-]+|[+=])/m
  1517. }
  1518. }
  1519. });
  1520. delete Prism.languages.sass.atrule;
  1521. var variable = /\$[-\w]+|#\{\$[-\w]+\}/;
  1522. var operator = [
  1523. /[+*\/%]|[=!]=|<=?|>=?|\b(?:and|or|not)\b/,
  1524. {
  1525. pattern: /(\s+)-(?=\s)/,
  1526. lookbehind: true
  1527. }
  1528. ];
  1529. Prism.languages.insertBefore('sass', 'property', {
  1530. // We want to consume the whole line
  1531. 'variable-line': {
  1532. pattern: /^[ \t]*\$.+/m,
  1533. inside: {
  1534. 'punctuation': /:/,
  1535. 'variable': variable,
  1536. 'operator': operator
  1537. }
  1538. },
  1539. // We want to consume the whole line
  1540. 'property-line': {
  1541. pattern: /^[ \t]*(?:[^:\s]+ *:.*|:[^:\s]+.*)/m,
  1542. inside: {
  1543. 'property': [
  1544. /[^:\s]+(?=\s*:)/,
  1545. {
  1546. pattern: /(:)[^:\s]+/,
  1547. lookbehind: true
  1548. }
  1549. ],
  1550. 'punctuation': /:/,
  1551. 'variable': variable,
  1552. 'operator': operator,
  1553. 'important': Prism.languages.sass.important
  1554. }
  1555. }
  1556. });
  1557. delete Prism.languages.sass.property;
  1558. delete Prism.languages.sass.important;
  1559. // Now that whole lines for other patterns are consumed,
  1560. // what's left should be selectors
  1561. delete Prism.languages.sass.selector;
  1562. Prism.languages.insertBefore('sass', 'punctuation', {
  1563. 'selector': {
  1564. pattern: /([ \t]*)\S(?:,?[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,?[^,\r\n]+)*)*/,
  1565. lookbehind: true
  1566. }
  1567. });
  1568. }(Prism));
  1569. Prism.languages.scss = Prism.languages.extend('css', {
  1570. 'comment': {
  1571. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  1572. lookbehind: true
  1573. },
  1574. 'atrule': {
  1575. pattern: /@[\w-]+(?:\([^()]+\)|[^(])*?(?=\s+[{;])/,
  1576. inside: {
  1577. 'rule': /@[\w-]+/
  1578. // See rest below
  1579. }
  1580. },
  1581. // url, compassified
  1582. 'url': /(?:[-a-z]+-)*url(?=\()/i,
  1583. // CSS selector regex is not appropriate for Sass
  1584. // since there can be lot more things (var, @ directive, nesting..)
  1585. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  1586. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  1587. // 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
  1588. // can "pass" as a selector- e.g: proper#{$erty})
  1589. // this one was hard to do, so please be careful if you edit this one :)
  1590. 'selector': {
  1591. // Initial look-ahead is used to prevent matching of blank selectors
  1592. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()]|&|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}]+[:{][^}]+))/m,
  1593. inside: {
  1594. 'parent': {
  1595. pattern: /&/,
  1596. alias: 'important'
  1597. },
  1598. 'placeholder': /%[-\w]+/,
  1599. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  1600. }
  1601. }
  1602. });
  1603. Prism.languages.insertBefore('scss', 'atrule', {
  1604. 'keyword': [
  1605. /@(?:if|else(?: if)?|for|each|while|import|extend|debug|warn|mixin|include|function|return|content)/i,
  1606. {
  1607. pattern: /( +)(?:from|through)(?= )/,
  1608. lookbehind: true
  1609. }
  1610. ]
  1611. });
  1612. Prism.languages.scss.property = {
  1613. pattern: /(?:[\w-]|\$[-\w]+|#\{\$[-\w]+\})+(?=\s*:)/i,
  1614. inside: {
  1615. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  1616. }
  1617. };
  1618. Prism.languages.insertBefore('scss', 'important', {
  1619. // var and interpolated vars
  1620. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  1621. });
  1622. Prism.languages.insertBefore('scss', 'function', {
  1623. 'placeholder': {
  1624. pattern: /%[-\w]+/,
  1625. alias: 'selector'
  1626. },
  1627. 'statement': {
  1628. pattern: /\B!(?:default|optional)\b/i,
  1629. alias: 'keyword'
  1630. },
  1631. 'boolean': /\b(?:true|false)\b/,
  1632. 'null': /\bnull\b/,
  1633. 'operator': {
  1634. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|or|not)(?=\s)/,
  1635. lookbehind: true
  1636. }
  1637. });
  1638. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;
  1639. Prism.languages.scala = Prism.languages.extend('java', {
  1640. 'keyword': /<-|=>|\b(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|null|object|override|package|private|protected|return|sealed|self|super|this|throw|trait|try|type|val|var|while|with|yield)\b/,
  1641. 'string': [
  1642. {
  1643. pattern: /"""[\s\S]*?"""/,
  1644. greedy: true
  1645. },
  1646. {
  1647. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  1648. greedy: true
  1649. }
  1650. ],
  1651. 'builtin': /\b(?:String|Int|Long|Short|Byte|Boolean|Double|Float|Char|Any|AnyRef|AnyVal|Unit|Nothing)\b/,
  1652. 'number': /\b0x[\da-f]*\.?[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e\d+)?[dfl]?/i,
  1653. 'symbol': /'[^\d\s\\]\w*/
  1654. });
  1655. delete Prism.languages.scala['class-name'];
  1656. delete Prism.languages.scala['function'];
  1657. Prism.languages.plsql = Prism.languages.extend('sql', {
  1658. 'comment': [
  1659. /\/\*[\s\S]*?\*\//,
  1660. /--.*/
  1661. ]
  1662. });
  1663. if (Prism.util.type(Prism.languages.plsql['keyword']) !== 'Array') {
  1664. Prism.languages.plsql['keyword'] = [Prism.languages.plsql['keyword']];
  1665. }
  1666. Prism.languages.plsql['keyword'].unshift(
  1667. /\b(?:ACCESS|AGENT|AGGREGATE|ARRAY|ARROW|AT|ATTRIBUTE|AUDIT|AUTHID|BFILE_BASE|BLOB_BASE|BLOCK|BODY|BOTH|BOUND|BYTE|CALLING|CHAR_BASE|CHARSET(?:FORM|ID)|CLOB_BASE|COLAUTH|COLLECT|CLUSTERS?|COMPILED|COMPRESS|CONSTANT|CONSTRUCTOR|CONTEXT|CRASH|CUSTOMDATUM|DANGLING|DATE_BASE|DEFINE|DETERMINISTIC|DURATION|ELEMENT|EMPTY|EXCEPTIONS?|EXCLUSIVE|EXTERNAL|FINAL|FORALL|FORM|FOUND|GENERAL|HEAP|HIDDEN|IDENTIFIED|IMMEDIATE|INCLUDING|INCREMENT|INDICATOR|INDEXES|INDICES|INFINITE|INITIAL|ISOPEN|INSTANTIABLE|INTERFACE|INVALIDATE|JAVA|LARGE|LEADING|LENGTH|LIBRARY|LIKE[24C]|LIMITED|LONG|LOOP|MAP|MAXEXTENTS|MAXLEN|MEMBER|MINUS|MLSLABEL|MULTISET|NAME|NAN|NATIVE|NEW|NOAUDIT|NOCOMPRESS|NOCOPY|NOTFOUND|NOWAIT|NUMBER(?:_BASE)?|OBJECT|OCI(?:COLL|DATE|DATETIME|DURATION|INTERVAL|LOBLOCATOR|NUMBER|RAW|REF|REFCURSOR|ROWID|STRING|TYPE)|OFFLINE|ONLINE|ONLY|OPAQUE|OPERATOR|ORACLE|ORADATA|ORGANIZATION|ORL(?:ANY|VARY)|OTHERS|OVERLAPS|OVERRIDING|PACKAGE|PARALLEL_ENABLE|PARAMETERS?|PASCAL|PCTFREE|PIPE(?:LINED)?|PRAGMA|PRIOR|PRIVATE|RAISE|RANGE|RAW|RECORD|REF|REFERENCE|REM|REMAINDER|RESULT|RESOURCE|RETURNING|REVERSE|ROW(?:ID|NUM|TYPE)|SAMPLE|SB[124]|SEGMENT|SELF|SEPARATE|SEQUENCE|SHORT|SIZE(?:_T)?|SPARSE|SQL(?:CODE|DATA|NAME|STATE)|STANDARD|STATIC|STDDEV|STORED|STRING|STRUCT|STYLE|SUBMULTISET|SUBPARTITION|SUBSTITUTABLE|SUBTYPE|SUCCESSFUL|SYNONYM|SYSDATE|TABAUTH|TDO|THE|TIMEZONE_(?:ABBR|HOUR|MINUTE|REGION)|TRAILING|TRANSAC(?:TIONAL)?|TRUSTED|UB[124]|UID|UNDER|UNTRUSTED|VALIDATE|VALIST|VARCHAR2|VARIABLE|VARIANCE|VARRAY|VIEWS|VOID|WHENEVER|WRAPPED|ZONE)\b/i
  1668. );
  1669. if (Prism.util.type(Prism.languages.plsql['operator']) !== 'Array') {
  1670. Prism.languages.plsql['operator'] = [Prism.languages.plsql['operator']];
  1671. }
  1672. Prism.languages.plsql['operator'].unshift(
  1673. /:=/
  1674. );
  1675. Prism.languages.vim = {
  1676. 'string': /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\r\n]|'')*'/,
  1677. 'comment': /".*/,
  1678. 'function': /\w+(?=\()/,
  1679. 'keyword': /\b(?:ab|abbreviate|abc|abclear|abo|aboveleft|al|all|arga|argadd|argd|argdelete|argdo|arge|argedit|argg|argglobal|argl|arglocal|ar|args|argu|argument|as|ascii|bad|badd|ba|ball|bd|bdelete|be|bel|belowright|bf|bfirst|bl|blast|bm|bmodified|bn|bnext|bN|bNext|bo|botright|bp|bprevious|brea|break|breaka|breakadd|breakd|breakdel|breakl|breaklist|br|brewind|bro|browse|bufdo|b|buffer|buffers|bun|bunload|bw|bwipeout|ca|cabbrev|cabc|cabclear|caddb|caddbuffer|cad|caddexpr|caddf|caddfile|cal|call|cat|catch|cb|cbuffer|cc|ccl|cclose|cd|ce|center|cex|cexpr|cf|cfile|cfir|cfirst|cgetb|cgetbuffer|cgete|cgetexpr|cg|cgetfile|c|change|changes|chd|chdir|che|checkpath|checkt|checktime|cla|clast|cl|clist|clo|close|cmapc|cmapclear|cnew|cnewer|cn|cnext|cN|cNext|cnf|cnfile|cNfcNfile|cnorea|cnoreabbrev|col|colder|colo|colorscheme|comc|comclear|comp|compiler|conf|confirm|con|continue|cope|copen|co|copy|cpf|cpfile|cp|cprevious|cq|cquit|cr|crewind|cuna|cunabbrev|cu|cunmap|cw|cwindow|debugg|debuggreedy|delc|delcommand|d|delete|delf|delfunction|delm|delmarks|diffg|diffget|diffoff|diffpatch|diffpu|diffput|diffsplit|diffthis|diffu|diffupdate|dig|digraphs|di|display|dj|djump|dl|dlist|dr|drop|ds|dsearch|dsp|dsplit|earlier|echoe|echoerr|echom|echomsg|echon|e|edit|el|else|elsei|elseif|em|emenu|endfo|endfor|endf|endfunction|endfun|en|endif|endt|endtry|endw|endwhile|ene|enew|ex|exi|exit|exu|exusage|f|file|files|filetype|fina|finally|fin|find|fini|finish|fir|first|fix|fixdel|fo|fold|foldc|foldclose|folddoc|folddoclosed|foldd|folddoopen|foldo|foldopen|for|fu|fun|function|go|goto|gr|grep|grepa|grepadd|ha|hardcopy|h|help|helpf|helpfind|helpg|helpgrep|helpt|helptags|hid|hide|his|history|ia|iabbrev|iabc|iabclear|if|ij|ijump|il|ilist|imapc|imapclear|in|inorea|inoreabbrev|isearch|isp|isplit|iuna|iunabbrev|iu|iunmap|j|join|ju|jumps|k|keepalt|keepj|keepjumps|kee|keepmarks|laddb|laddbuffer|lad|laddexpr|laddf|laddfile|lan|language|la|last|later|lb|lbuffer|lc|lcd|lch|lchdir|lcl|lclose|let|left|lefta|leftabove|lex|lexpr|lf|lfile|lfir|lfirst|lgetb|lgetbuffer|lgete|lgetexpr|lg|lgetfile|lgr|lgrep|lgrepa|lgrepadd|lh|lhelpgrep|l|list|ll|lla|llast|lli|llist|lmak|lmake|lm|lmap|lmapc|lmapclear|lnew|lnewer|lne|lnext|lN|lNext|lnf|lnfile|lNf|lNfile|ln|lnoremap|lo|loadview|loc|lockmarks|lockv|lockvar|lol|lolder|lop|lopen|lpf|lpfile|lp|lprevious|lr|lrewind|ls|lt|ltag|lu|lunmap|lv|lvimgrep|lvimgrepa|lvimgrepadd|lw|lwindow|mak|make|ma|mark|marks|mat|match|menut|menutranslate|mk|mkexrc|mks|mksession|mksp|mkspell|mkvie|mkview|mkv|mkvimrc|mod|mode|m|move|mzf|mzfile|mz|mzscheme|nbkey|new|n|next|N|Next|nmapc|nmapclear|noh|nohlsearch|norea|noreabbrev|nu|number|nun|nunmap|omapc|omapclear|on|only|o|open|opt|options|ou|ounmap|pc|pclose|ped|pedit|pe|perl|perld|perldo|po|pop|popu|popup|pp|ppop|pre|preserve|prev|previous|p|print|P|Print|profd|profdel|prof|profile|promptf|promptfind|promptr|promptrepl|ps|psearch|pta|ptag|ptf|ptfirst|ptj|ptjump|ptl|ptlast|ptn|ptnext|ptN|ptNext|ptp|ptprevious|ptr|ptrewind|pts|ptselect|pu|put|pw|pwd|pyf|pyfile|py|python|qa|qall|q|quit|quita|quitall|r|read|rec|recover|redi|redir|red|redo|redr|redraw|redraws|redrawstatus|reg|registers|res|resize|ret|retab|retu|return|rew|rewind|ri|right|rightb|rightbelow|rub|ruby|rubyd|rubydo|rubyf|rubyfile|ru|runtime|rv|rviminfo|sal|sall|san|sandbox|sa|sargument|sav|saveas|sba|sball|sbf|sbfirst|sbl|sblast|sbm|sbmodified|sbn|sbnext|sbN|sbNext|sbp|sbprevious|sbr|sbrewind|sb|sbuffer|scripte|scriptencoding|scrip|scriptnames|se|set|setf|setfiletype|setg|setglobal|setl|setlocal|sf|sfind|sfir|sfirst|sh|shell|sign|sil|silent|sim|simalt|sla|slast|sl|sleep|sm|smagic|sm|smap|smapc|smapclear|sme|smenu|sn|snext|sN|sNext|sni|sniff|sno|snomagic|snor|snoremap|snoreme|snoremenu|sor|sort|so|source|spelld|spelldump|spe|spellgood|spelli|spellinfo|spellr|spellrepall|spellu|spellundo|spellw|spellwrong|sp|split|spr|sprevious|sre|srewind|sta|stag|startg|startgreplace|star|startinsert|startr|startreplace|stj|stjump|st|stop|stopi|stopinsert|sts|stselect|sun|sunhide|sunm|sunmap|sus|suspend|sv|sview|syncbind|t|tab|tabc|tabclose|tabd|tabdo|tabe|tabedit|tabf|tabfind|tabfir|tabfirst|tabl|tablast|tabm|tabmove|tabnew|tabn|tabnext|tabN|tabNext|tabo|tabonly|tabp|tabprevious|tabr|tabrewind|tabs|ta|tag|tags|tc|tcl|tcld|tcldo|tclf|tclfile|te|tearoff|tf|tfirst|th|throw|tj|tjump|tl|tlast|tm|tm|tmenu|tn|tnext|tN|tNext|to|topleft|tp|tprevious|tr|trewind|try|ts|tselect|tu|tu|tunmenu|una|unabbreviate|u|undo|undoj|undojoin|undol|undolist|unh|unhide|unlet|unlo|unlockvar|unm|unmap|up|update|verb|verbose|ve|version|vert|vertical|vie|view|vim|vimgrep|vimgrepa|vimgrepadd|vi|visual|viu|viusage|vmapc|vmapclear|vne|vnew|vs|vsplit|vu|vunmap|wa|wall|wh|while|winc|wincmd|windo|winp|winpos|win|winsize|wn|wnext|wN|wNext|wp|wprevious|wq|wqa|wqall|w|write|ws|wsverb|wv|wviminfo|X|xa|xall|x|xit|xm|xmap|xmapc|xmapclear|xme|xmenu|XMLent|XMLns|xn|xnoremap|xnoreme|xnoremenu|xu|xunmap|y|yank)\b/,
  1680. 'builtin': /\b(?:autocmd|acd|ai|akm|aleph|allowrevins|altkeymap|ambiwidth|ambw|anti|antialias|arab|arabic|arabicshape|ari|arshape|autochdir|autoindent|autoread|autowrite|autowriteall|aw|awa|background|backspace|backup|backupcopy|backupdir|backupext|backupskip|balloondelay|ballooneval|balloonexpr|bdir|bdlay|beval|bex|bexpr|bg|bh|bin|binary|biosk|bioskey|bk|bkc|bomb|breakat|brk|browsedir|bs|bsdir|bsk|bt|bufhidden|buflisted|buftype|casemap|ccv|cdpath|cedit|cfu|ch|charconvert|ci|cin|cindent|cink|cinkeys|cino|cinoptions|cinw|cinwords|clipboard|cmdheight|cmdwinheight|cmp|cms|columns|com|comments|commentstring|compatible|complete|completefunc|completeopt|consk|conskey|copyindent|cot|cpo|cpoptions|cpt|cscopepathcomp|cscopeprg|cscopequickfix|cscopetag|cscopetagorder|cscopeverbose|cspc|csprg|csqf|cst|csto|csverb|cuc|cul|cursorcolumn|cursorline|cwh|debug|deco|def|define|delcombine|dex|dg|dict|dictionary|diff|diffexpr|diffopt|digraph|dip|dir|directory|dy|ea|ead|eadirection|eb|ed|edcompatible|ef|efm|ei|ek|enc|encoding|endofline|eol|ep|equalalways|equalprg|errorbells|errorfile|errorformat|esckeys|et|eventignore|expandtab|exrc|fcl|fcs|fdc|fde|fdi|fdl|fdls|fdm|fdn|fdo|fdt|fen|fenc|fencs|fex|ff|ffs|fileencoding|fileencodings|fileformat|fileformats|fillchars|fk|fkmap|flp|fml|fmr|foldcolumn|foldenable|foldexpr|foldignore|foldlevel|foldlevelstart|foldmarker|foldmethod|foldminlines|foldnestmax|foldtext|formatexpr|formatlistpat|formatoptions|formatprg|fp|fs|fsync|ft|gcr|gd|gdefault|gfm|gfn|gfs|gfw|ghr|gp|grepformat|grepprg|gtl|gtt|guicursor|guifont|guifontset|guifontwide|guiheadroom|guioptions|guipty|guitablabel|guitabtooltip|helpfile|helpheight|helplang|hf|hh|hi|hidden|highlight|hk|hkmap|hkmapp|hkp|hl|hlg|hls|hlsearch|ic|icon|iconstring|ignorecase|im|imactivatekey|imak|imc|imcmdline|imd|imdisable|imi|iminsert|ims|imsearch|inc|include|includeexpr|incsearch|inde|indentexpr|indentkeys|indk|inex|inf|infercase|insertmode|isf|isfname|isi|isident|isk|iskeyword|isprint|joinspaces|js|key|keymap|keymodel|keywordprg|km|kmp|kp|langmap|langmenu|laststatus|lazyredraw|lbr|lcs|linebreak|lines|linespace|lisp|lispwords|listchars|loadplugins|lpl|lsp|lz|macatsui|magic|makeef|makeprg|matchpairs|matchtime|maxcombine|maxfuncdepth|maxmapdepth|maxmem|maxmempattern|maxmemtot|mco|mef|menuitems|mfd|mh|mis|mkspellmem|ml|mls|mm|mmd|mmp|mmt|modeline|modelines|modifiable|modified|more|mouse|mousef|mousefocus|mousehide|mousem|mousemodel|mouses|mouseshape|mouset|mousetime|mp|mps|msm|mzq|mzquantum|nf|nrformats|numberwidth|nuw|odev|oft|ofu|omnifunc|opendevice|operatorfunc|opfunc|osfiletype|pa|para|paragraphs|paste|pastetoggle|patchexpr|patchmode|path|pdev|penc|pex|pexpr|pfn|ph|pheader|pi|pm|pmbcs|pmbfn|popt|preserveindent|previewheight|previewwindow|printdevice|printencoding|printexpr|printfont|printheader|printmbcharset|printmbfont|printoptions|prompt|pt|pumheight|pvh|pvw|qe|quoteescape|readonly|remap|report|restorescreen|revins|rightleft|rightleftcmd|rl|rlc|ro|rs|rtp|ruf|ruler|rulerformat|runtimepath|sbo|sc|scb|scr|scroll|scrollbind|scrolljump|scrolloff|scrollopt|scs|sect|sections|secure|sel|selection|selectmode|sessionoptions|sft|shcf|shellcmdflag|shellpipe|shellquote|shellredir|shellslash|shelltemp|shelltype|shellxquote|shiftround|shiftwidth|shm|shortmess|shortname|showbreak|showcmd|showfulltag|showmatch|showmode|showtabline|shq|si|sidescroll|sidescrolloff|siso|sj|slm|smartcase|smartindent|smarttab|smc|smd|softtabstop|sol|spc|spell|spellcapcheck|spellfile|spelllang|spellsuggest|spf|spl|splitbelow|splitright|sps|sr|srr|ss|ssl|ssop|stal|startofline|statusline|stl|stmp|su|sua|suffixes|suffixesadd|sw|swapfile|swapsync|swb|swf|switchbuf|sws|sxq|syn|synmaxcol|syntax|tabline|tabpagemax|tabstop|tagbsearch|taglength|tagrelative|tagstack|tal|tb|tbi|tbidi|tbis|tbs|tenc|term|termbidi|termencoding|terse|textauto|textmode|textwidth|tgst|thesaurus|tildeop|timeout|timeoutlen|title|titlelen|titleold|titlestring|toolbar|toolbariconsize|top|tpm|tsl|tsr|ttimeout|ttimeoutlen|ttm|tty|ttybuiltin|ttyfast|ttym|ttymouse|ttyscroll|ttytype|tw|tx|uc|ul|undolevels|updatecount|updatetime|ut|vb|vbs|vdir|verbosefile|vfile|viewdir|viewoptions|viminfo|virtualedit|visualbell|vop|wak|warn|wb|wc|wcm|wd|weirdinvert|wfh|wfw|whichwrap|wi|wig|wildchar|wildcharm|wildignore|wildmenu|wildmode|wildoptions|wim|winaltkeys|window|winfixheight|winfixwidth|winheight|winminheight|winminwidth|winwidth|wiv|wiw|wm|wmh|wmnu|wmw|wop|wrap|wrapmargin|wrapscan|writeany|writebackup|writedelay|ww|noacd|noai|noakm|noallowrevins|noaltkeymap|noanti|noantialias|noar|noarab|noarabic|noarabicshape|noari|noarshape|noautochdir|noautoindent|noautoread|noautowrite|noautowriteall|noaw|noawa|nobackup|noballooneval|nobeval|nobin|nobinary|nobiosk|nobioskey|nobk|nobl|nobomb|nobuflisted|nocf|noci|nocin|nocindent|nocompatible|noconfirm|noconsk|noconskey|nocopyindent|nocp|nocscopetag|nocscopeverbose|nocst|nocsverb|nocuc|nocul|nocursorcolumn|nocursorline|nodeco|nodelcombine|nodg|nodiff|nodigraph|nodisable|noea|noeb|noed|noedcompatible|noek|noendofline|noeol|noequalalways|noerrorbells|noesckeys|noet|noex|noexpandtab|noexrc|nofen|nofk|nofkmap|nofoldenable|nogd|nogdefault|noguipty|nohid|nohidden|nohk|nohkmap|nohkmapp|nohkp|nohls|noic|noicon|noignorecase|noim|noimc|noimcmdline|noimd|noincsearch|noinf|noinfercase|noinsertmode|nois|nojoinspaces|nojs|nolazyredraw|nolbr|nolinebreak|nolisp|nolist|noloadplugins|nolpl|nolz|noma|nomacatsui|nomagic|nomh|noml|nomod|nomodeline|nomodifiable|nomodified|nomore|nomousef|nomousefocus|nomousehide|nonu|nonumber|noodev|noopendevice|nopaste|nopi|nopreserveindent|nopreviewwindow|noprompt|nopvw|noreadonly|noremap|norestorescreen|norevins|nori|norightleft|norightleftcmd|norl|norlc|noro|nors|noru|noruler|nosb|nosc|noscb|noscrollbind|noscs|nosecure|nosft|noshellslash|noshelltemp|noshiftround|noshortname|noshowcmd|noshowfulltag|noshowmatch|noshowmode|nosi|nosm|nosmartcase|nosmartindent|nosmarttab|nosmd|nosn|nosol|nospell|nosplitbelow|nosplitright|nospr|nosr|nossl|nosta|nostartofline|nostmp|noswapfile|noswf|nota|notagbsearch|notagrelative|notagstack|notbi|notbidi|notbs|notermbidi|noterse|notextauto|notextmode|notf|notgst|notildeop|notimeout|notitle|noto|notop|notr|nottimeout|nottybuiltin|nottyfast|notx|novb|novisualbell|nowa|nowarn|nowb|noweirdinvert|nowfh|nowfw|nowildmenu|nowinfixheight|nowinfixwidth|nowiv|nowmnu|nowrap|nowrapscan|nowrite|nowriteany|nowritebackup|nows|invacd|invai|invakm|invallowrevins|invaltkeymap|invanti|invantialias|invar|invarab|invarabic|invarabicshape|invari|invarshape|invautochdir|invautoindent|invautoread|invautowrite|invautowriteall|invaw|invawa|invbackup|invballooneval|invbeval|invbin|invbinary|invbiosk|invbioskey|invbk|invbl|invbomb|invbuflisted|invcf|invci|invcin|invcindent|invcompatible|invconfirm|invconsk|invconskey|invcopyindent|invcp|invcscopetag|invcscopeverbose|invcst|invcsverb|invcuc|invcul|invcursorcolumn|invcursorline|invdeco|invdelcombine|invdg|invdiff|invdigraph|invdisable|invea|inveb|inved|invedcompatible|invek|invendofline|inveol|invequalalways|inverrorbells|invesckeys|invet|invex|invexpandtab|invexrc|invfen|invfk|invfkmap|invfoldenable|invgd|invgdefault|invguipty|invhid|invhidden|invhk|invhkmap|invhkmapp|invhkp|invhls|invhlsearch|invic|invicon|invignorecase|invim|invimc|invimcmdline|invimd|invincsearch|invinf|invinfercase|invinsertmode|invis|invjoinspaces|invjs|invlazyredraw|invlbr|invlinebreak|invlisp|invlist|invloadplugins|invlpl|invlz|invma|invmacatsui|invmagic|invmh|invml|invmod|invmodeline|invmodifiable|invmodified|invmore|invmousef|invmousefocus|invmousehide|invnu|invnumber|invodev|invopendevice|invpaste|invpi|invpreserveindent|invpreviewwindow|invprompt|invpvw|invreadonly|invremap|invrestorescreen|invrevins|invri|invrightleft|invrightleftcmd|invrl|invrlc|invro|invrs|invru|invruler|invsb|invsc|invscb|invscrollbind|invscs|invsecure|invsft|invshellslash|invshelltemp|invshiftround|invshortname|invshowcmd|invshowfulltag|invshowmatch|invshowmode|invsi|invsm|invsmartcase|invsmartindent|invsmarttab|invsmd|invsn|invsol|invspell|invsplitbelow|invsplitright|invspr|invsr|invssl|invsta|invstartofline|invstmp|invswapfile|invswf|invta|invtagbsearch|invtagrelative|invtagstack|invtbi|invtbidi|invtbs|invtermbidi|invterse|invtextauto|invtextmode|invtf|invtgst|invtildeop|invtimeout|invtitle|invto|invtop|invtr|invttimeout|invttybuiltin|invttyfast|invtx|invvb|invvisualbell|invwa|invwarn|invwb|invweirdinvert|invwfh|invwfw|invwildmenu|invwinfixheight|invwinfixwidth|invwiv|invwmnu|invwrap|invwrapscan|invwrite|invwriteany|invwritebackup|invws|t_AB|t_AF|t_al|t_AL|t_bc|t_cd|t_ce|t_Ce|t_cl|t_cm|t_Co|t_cs|t_Cs|t_CS|t_CV|t_da|t_db|t_dl|t_DL|t_EI|t_F1|t_F2|t_F3|t_F4|t_F5|t_F6|t_F7|t_F8|t_F9|t_fs|t_IE|t_IS|t_k1|t_K1|t_k2|t_k3|t_K3|t_k4|t_K4|t_k5|t_K5|t_k6|t_K6|t_k7|t_K7|t_k8|t_K8|t_k9|t_K9|t_KA|t_kb|t_kB|t_KB|t_KC|t_kd|t_kD|t_KD|t_ke|t_KE|t_KF|t_KG|t_kh|t_KH|t_kI|t_KI|t_KJ|t_KK|t_kl|t_KL|t_kN|t_kP|t_kr|t_ks|t_ku|t_le|t_mb|t_md|t_me|t_mr|t_ms|t_nd|t_op|t_RI|t_RV|t_Sb|t_se|t_Sf|t_SI|t_so|t_sr|t_te|t_ti|t_ts|t_ue|t_us|t_ut|t_vb|t_ve|t_vi|t_vs|t_WP|t_WS|t_xs|t_ZH|t_ZR)\b/,
  1681. 'number': /\b(?:0x[\da-f]+|\d+(?:\.\d+)?)\b/i,
  1682. 'operator': /\|\||&&|[-+.]=?|[=!](?:[=~][#?]?)?|[<>]=?[#?]?|[*\/%?]|\b(?:is(?:not)?)\b/,
  1683. 'punctuation': /[{}[\](),;:]/
  1684. };
  1685. (function () {
  1686. if (typeof self === 'undefined' || !self.Prism || !self.document) {
  1687. return;
  1688. }
  1689. /**
  1690. * Plugin name which is used as a class name for <pre> which is activating the plugin
  1691. * @type {String}
  1692. */
  1693. var PLUGIN_NAME = 'line-numbers';
  1694. /**
  1695. * Regular expression used for determining line breaks
  1696. * @type {RegExp}
  1697. */
  1698. var NEW_LINE_EXP = /\n(?!$)/g;
  1699. /**
  1700. * Resizes line numbers spans according to height of line of code
  1701. * @param {Element} element <pre> element
  1702. */
  1703. var _resizeElement = function (element) {
  1704. var codeStyles = getStyles(element);
  1705. var whiteSpace = codeStyles['white-space'];
  1706. if (whiteSpace === 'pre-wrap' || whiteSpace === 'pre-line') {
  1707. var codeElement = element.querySelector('code');
  1708. var lineNumbersWrapper = element.querySelector('.line-numbers-rows');
  1709. var lineNumberSizer = element.querySelector('.line-numbers-sizer');
  1710. var codeLines = codeElement.textContent.split(NEW_LINE_EXP);
  1711. if (!lineNumberSizer) {
  1712. lineNumberSizer = document.createElement('span');
  1713. lineNumberSizer.className = 'line-numbers-sizer';
  1714. codeElement.appendChild(lineNumberSizer);
  1715. }
  1716. lineNumberSizer.style.display = 'block';
  1717. codeLines.forEach(function (line, lineNumber) {
  1718. lineNumberSizer.textContent = line || '\n';
  1719. var lineSize = lineNumberSizer.getBoundingClientRect().height;
  1720. lineNumbersWrapper.children[lineNumber].style.height = lineSize + 'px';
  1721. });
  1722. lineNumberSizer.textContent = '';
  1723. lineNumberSizer.style.display = 'none';
  1724. }
  1725. };
  1726. /**
  1727. * Returns style declarations for the element
  1728. * @param {Element} element
  1729. */
  1730. var getStyles = function (element) {
  1731. if (!element) {
  1732. return null;
  1733. }
  1734. return window.getComputedStyle ? getComputedStyle(element) : (element.currentStyle || null);
  1735. };
  1736. window.addEventListener('resize', function () {
  1737. Array.prototype.forEach.call(document.querySelectorAll('pre.' + PLUGIN_NAME), _resizeElement);
  1738. });
  1739. Prism.hooks.add('complete', function (env) {
  1740. if (!env.code) {
  1741. return;
  1742. }
  1743. // works only for <code> wrapped inside <pre> (not inline)
  1744. var pre = env.element.parentNode;
  1745. var clsReg = /\s*\bline-numbers\b\s*/;
  1746. if (
  1747. !pre || !/pre/i.test(pre.nodeName) ||
  1748. // Abort only if nor the <pre> nor the <code> have the class
  1749. (!clsReg.test(pre.className) && !clsReg.test(env.element.className))
  1750. ) {
  1751. return;
  1752. }
  1753. if (env.element.querySelector('.line-numbers-rows')) {
  1754. // Abort if line numbers already exists
  1755. return;
  1756. }
  1757. if (clsReg.test(env.element.className)) {
  1758. // Remove the class 'line-numbers' from the <code>
  1759. env.element.className = env.element.className.replace(clsReg, ' ');
  1760. }
  1761. if (!clsReg.test(pre.className)) {
  1762. // Add the class 'line-numbers' to the <pre>
  1763. pre.className += ' line-numbers';
  1764. }
  1765. var match = env.code.match(NEW_LINE_EXP);
  1766. var linesNum = match ? match.length + 1 : 1;
  1767. var lineNumbersWrapper;
  1768. var lines = new Array(linesNum + 1);
  1769. lines = lines.join('<span></span>');
  1770. lineNumbersWrapper = document.createElement('span');
  1771. lineNumbersWrapper.setAttribute('aria-hidden', 'true');
  1772. lineNumbersWrapper.className = 'line-numbers-rows';
  1773. lineNumbersWrapper.innerHTML = lines;
  1774. if (pre.hasAttribute('data-start')) {
  1775. pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
  1776. }
  1777. env.element.appendChild(lineNumbersWrapper);
  1778. _resizeElement(pre);
  1779. Prism.hooks.run('line-numbers', env);
  1780. });
  1781. Prism.hooks.add('line-numbers', function (env) {
  1782. env.plugins = env.plugins || {};
  1783. env.plugins.lineNumbers = true;
  1784. });
  1785. /**
  1786. * Global exports
  1787. */
  1788. Prism.plugins.lineNumbers = {
  1789. /**
  1790. * Get node for provided line number
  1791. * @param {Element} element pre element
  1792. * @param {Number} number line number
  1793. * @return {Element|undefined}
  1794. */
  1795. getLine: function (element, number) {
  1796. if (element.tagName !== 'PRE' || !element.classList.contains(PLUGIN_NAME)) {
  1797. return;
  1798. }
  1799. var lineNumberRows = element.querySelector('.line-numbers-rows');
  1800. var lineNumberStart = parseInt(element.getAttribute('data-start'), 10) || 1;
  1801. var lineNumberEnd = lineNumberStart + (lineNumberRows.children.length - 1);
  1802. if (number < lineNumberStart) {
  1803. number = lineNumberStart;
  1804. }
  1805. if (number > lineNumberEnd) {
  1806. number = lineNumberEnd;
  1807. }
  1808. var lineIndex = number - lineNumberStart;
  1809. return lineNumberRows.children[lineIndex];
  1810. }
  1811. };
  1812. }());
  1813. (function(){
  1814. if (
  1815. typeof self !== 'undefined' && !self.Prism ||
  1816. typeof global !== 'undefined' && !global.Prism
  1817. ) {
  1818. return;
  1819. }
  1820. var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:=&]+(?:\?[\w\-+%~/.:#=?&!$'()*,;]*)?(?:#[\w\-+%~/.:#=?&!$'()*,;]*)?/,
  1821. email = /\b\S+@[\w.]+[a-z]{2}/,
  1822. linkMd = /\[([^\]]+)]\(([^)]+)\)/,
  1823. // Tokens that may contain URLs and emails
  1824. candidates = ['comment', 'url', 'attr-value', 'string'];
  1825. Prism.plugins.autolinker = {
  1826. processGrammar: function (grammar) {
  1827. // Abort if grammar has already been processed
  1828. if (!grammar || grammar['url-link']) {
  1829. return;
  1830. }
  1831. Prism.languages.DFS(grammar, function (key, def, type) {
  1832. if (candidates.indexOf(type) > -1 && Prism.util.type(def) !== 'Array') {
  1833. if (!def.pattern) {
  1834. def = this[key] = {
  1835. pattern: def
  1836. };
  1837. }
  1838. def.inside = def.inside || {};
  1839. if (type == 'comment') {
  1840. def.inside['md-link'] = linkMd;
  1841. }
  1842. if (type == 'attr-value') {
  1843. Prism.languages.insertBefore('inside', 'punctuation', { 'url-link': url }, def);
  1844. }
  1845. else {
  1846. def.inside['url-link'] = url;
  1847. }
  1848. def.inside['email-link'] = email;
  1849. }
  1850. });
  1851. grammar['url-link'] = url;
  1852. grammar['email-link'] = email;
  1853. }
  1854. };
  1855. Prism.hooks.add('before-highlight', function(env) {
  1856. Prism.plugins.autolinker.processGrammar(env.grammar);
  1857. });
  1858. Prism.hooks.add('wrap', function(env) {
  1859. if (/-link$/.test(env.type)) {
  1860. env.tag = 'a';
  1861. var href = env.content;
  1862. if (env.type == 'email-link' && href.indexOf('mailto:') != 0) {
  1863. href = 'mailto:' + href;
  1864. }
  1865. else if (env.type == 'md-link') {
  1866. // Markdown
  1867. var match = env.content.match(linkMd);
  1868. href = match[2];
  1869. env.content = match[1];
  1870. }
  1871. env.attributes.href = href;
  1872. }
  1873. // Silently catch any error thrown by decodeURIComponent (#1186)
  1874. try {
  1875. env.content = decodeURIComponent(env.content);
  1876. } catch(e) {}
  1877. });
  1878. })();
  1879. (function(){
  1880. if (
  1881. typeof self !== 'undefined' && !self.Prism ||
  1882. typeof global !== 'undefined' && !global.Prism
  1883. ) {
  1884. return;
  1885. }
  1886. if (Prism.languages.css) {
  1887. // check whether the selector is an advanced pattern before extending it
  1888. if (Prism.languages.css.selector.pattern)
  1889. {
  1890. Prism.languages.css.selector.inside['pseudo-class'] = /:[\w-]+/;
  1891. Prism.languages.css.selector.inside['pseudo-element'] = /::[\w-]+/;
  1892. }
  1893. else
  1894. {
  1895. Prism.languages.css.selector = {
  1896. pattern: Prism.languages.css.selector,
  1897. inside: {
  1898. 'pseudo-class': /:[\w-]+/,
  1899. 'pseudo-element': /::[\w-]+/
  1900. }
  1901. };
  1902. }
  1903. }
  1904. if (Prism.languages.markup) {
  1905. Prism.languages.markup.tag.inside.tag.inside['tag-id'] = /[\w-]+/;
  1906. var Tags = {
  1907. HTML: {
  1908. 'a': 1, 'abbr': 1, 'acronym': 1, 'b': 1, 'basefont': 1, 'bdo': 1, 'big': 1, 'blink': 1, 'cite': 1, 'code': 1, 'dfn': 1, 'em': 1, 'kbd': 1, 'i': 1,
  1909. 'rp': 1, 'rt': 1, 'ruby': 1, 's': 1, 'samp': 1, 'small': 1, 'spacer': 1, 'strike': 1, 'strong': 1, 'sub': 1, 'sup': 1, 'time': 1, 'tt': 1, 'u': 1,
  1910. 'var': 1, 'wbr': 1, 'noframes': 1, 'summary': 1, 'command': 1, 'dt': 1, 'dd': 1, 'figure': 1, 'figcaption': 1, 'center': 1, 'section': 1, 'nav': 1,
  1911. 'article': 1, 'aside': 1, 'hgroup': 1, 'header': 1, 'footer': 1, 'address': 1, 'noscript': 1, 'isIndex': 1, 'main': 1, 'mark': 1, 'marquee': 1,
  1912. 'meter': 1, 'menu': 1
  1913. },
  1914. SVG: {
  1915. 'animateColor': 1, 'animateMotion': 1, 'animateTransform': 1, 'glyph': 1, 'feBlend': 1, 'feColorMatrix': 1, 'feComponentTransfer': 1,
  1916. 'feFuncR': 1, 'feFuncG': 1, 'feFuncB': 1, 'feFuncA': 1, 'feComposite': 1, 'feConvolveMatrix': 1, 'feDiffuseLighting': 1, 'feDisplacementMap': 1,
  1917. 'feFlood': 1, 'feGaussianBlur': 1, 'feImage': 1, 'feMerge': 1, 'feMergeNode': 1, 'feMorphology': 1, 'feOffset': 1, 'feSpecularLighting': 1,
  1918. 'feTile': 1, 'feTurbulence': 1, 'feDistantLight': 1, 'fePointLight': 1, 'feSpotLight': 1, 'linearGradient': 1, 'radialGradient': 1, 'altGlyph': 1,
  1919. 'textPath': 1, 'tref': 1, 'altglyph': 1, 'textpath': 1, 'altglyphdef': 1, 'altglyphitem': 1, 'clipPath': 1, 'color-profile': 1, 'cursor': 1,
  1920. 'font-face': 1, 'font-face-format': 1, 'font-face-name': 1, 'font-face-src': 1, 'font-face-uri': 1, 'foreignObject': 1, 'glyphRef': 1,
  1921. 'hkern': 1, 'vkern': 1
  1922. },
  1923. MathML: {}
  1924. }
  1925. }
  1926. var language;
  1927. Prism.hooks.add('wrap', function(env) {
  1928. if ((env.type == 'tag-id'
  1929. || (env.type == 'property' && env.content.indexOf('-') != 0)
  1930. || (env.type == 'rule'&& env.content.indexOf('@-') != 0)
  1931. || (env.type == 'pseudo-class'&& env.content.indexOf(':-') != 0)
  1932. || (env.type == 'pseudo-element'&& env.content.indexOf('::-') != 0)
  1933. || (env.type == 'attr-name' && env.content.indexOf('data-') != 0)
  1934. ) && env.content.indexOf('<') === -1
  1935. ) {
  1936. if (env.language == 'css'
  1937. || env.language == 'scss'
  1938. || env.language == 'markup'
  1939. ) {
  1940. var href = 'https://webplatform.github.io/docs/';
  1941. var content = env.content;
  1942. if (env.language == 'css' || env.language == 'scss') {
  1943. href += 'css/';
  1944. if (env.type == 'property') {
  1945. href += 'properties/';
  1946. }
  1947. else if (env.type == 'rule') {
  1948. href += 'atrules/';
  1949. content = content.substring(1);
  1950. }
  1951. else if (env.type == 'pseudo-class') {
  1952. href += 'selectors/pseudo-classes/';
  1953. content = content.substring(1);
  1954. }
  1955. else if (env.type == 'pseudo-element') {
  1956. href += 'selectors/pseudo-elements/';
  1957. content = content.substring(2);
  1958. }
  1959. }
  1960. else if (env.language == 'markup') {
  1961. if (env.type == 'tag-id') {
  1962. // Check language
  1963. language = getLanguage(env.content) || language;
  1964. if (language) {
  1965. href += language + '/elements/';
  1966. }
  1967. else {
  1968. return; // Abort
  1969. }
  1970. }
  1971. else if (env.type == 'attr-name') {
  1972. if (language) {
  1973. href += language + '/attributes/';
  1974. }
  1975. else {
  1976. return; // Abort
  1977. }
  1978. }
  1979. }
  1980. href += content;
  1981. env.tag = 'a';
  1982. env.attributes.href = href;
  1983. env.attributes.target = '_blank';
  1984. }
  1985. }
  1986. });
  1987. function getLanguage(tag) {
  1988. var tagL = tag.toLowerCase();
  1989. if (Tags.HTML[tagL]) {
  1990. return 'html';
  1991. }
  1992. else if (Tags.SVG[tag]) {
  1993. return 'svg';
  1994. }
  1995. else if (Tags.MathML[tag]) {
  1996. return 'mathml';
  1997. }
  1998. // Not in dictionary, perform check
  1999. if (Tags.HTML[tagL] !== 0 && typeof document !== 'undefined') {
  2000. var htmlInterface = (document.createElement(tag).toString().match(/\[object HTML(.+)Element\]/) || [])[1];
  2001. if (htmlInterface && htmlInterface != 'Unknown') {
  2002. Tags.HTML[tagL] = 1;
  2003. return 'html';
  2004. }
  2005. }
  2006. Tags.HTML[tagL] = 0;
  2007. if (Tags.SVG[tag] !== 0 && typeof document !== 'undefined') {
  2008. var svgInterface = (document.createElementNS('http://www.w3.org/2000/svg', tag).toString().match(/\[object SVG(.+)Element\]/) || [])[1];
  2009. if (svgInterface && svgInterface != 'Unknown') {
  2010. Tags.SVG[tag] = 1;
  2011. return 'svg';
  2012. }
  2013. }
  2014. Tags.SVG[tag] = 0;
  2015. // Lame way to detect MathML, but browsers don’t expose interface names there :(
  2016. if (Tags.MathML[tag] !== 0) {
  2017. if (tag.indexOf('m') === 0) {
  2018. Tags.MathML[tag] = 1;
  2019. return 'mathml';
  2020. }
  2021. }
  2022. Tags.MathML[tag] = 0;
  2023. return null;
  2024. }
  2025. })();
  2026. (function() {
  2027. if (typeof self === 'undefined' || !self.Prism || !self.document) {
  2028. return;
  2029. }
  2030. var clsReg = /\s*\bcommand-line\b\s*/;
  2031. Prism.hooks.add('before-highlight', function (env) {
  2032. env.vars = env.vars || {};
  2033. env.vars['command-line'] = env.vars['command-line'] || {};
  2034. if (env.vars['command-line'].complete || !env.code) {
  2035. env.vars['command-line'].complete = true;
  2036. return;
  2037. }
  2038. // Works only for <code> wrapped inside <pre> (not inline).
  2039. var pre = env.element.parentNode;
  2040. if (!pre || !/pre/i.test(pre.nodeName) || // Abort only if neither the <pre> nor the <code> have the class
  2041. (!clsReg.test(pre.className) && !clsReg.test(env.element.className))) {
  2042. env.vars['command-line'].complete = true;
  2043. return;
  2044. }
  2045. if (env.element.querySelector('.command-line-prompt')) { // Abort if prompt already exists.
  2046. env.vars['command-line'].complete = true;
  2047. return;
  2048. }
  2049. var codeLines = env.code.split('\n');
  2050. env.vars['command-line'].numberOfLines = codeLines.length;
  2051. env.vars['command-line'].outputLines = [];
  2052. var outputSections = pre.getAttribute('data-output');
  2053. var outputFilter = pre.getAttribute('data-filter-output');
  2054. if (outputSections || outputSections === '') { // The user specified the output lines. -- cwells
  2055. outputSections = outputSections.split(',');
  2056. for (var i = 0; i < outputSections.length; i++) { // Parse the output sections into start/end ranges. -- cwells
  2057. var range = outputSections[i].split('-');
  2058. var outputStart = parseInt(range[0], 10);
  2059. var outputEnd = (range.length === 2 ? parseInt(range[1], 10) : outputStart);
  2060. if (!isNaN(outputStart) && !isNaN(outputEnd)) {
  2061. if (outputStart < 1) {
  2062. outputStart = 1;
  2063. }
  2064. if (outputEnd > codeLines.length) {
  2065. outputEnd = codeLines.length;
  2066. }
  2067. // Convert start and end to 0-based to simplify the arrays. -- cwells
  2068. outputStart--;
  2069. outputEnd--;
  2070. // Save the output line in an array and clear it in the code so it's not highlighted. -- cwells
  2071. for (var j = outputStart; j <= outputEnd; j++) {
  2072. env.vars['command-line'].outputLines[j] = codeLines[j];
  2073. codeLines[j] = '';
  2074. }
  2075. }
  2076. }
  2077. } else if (outputFilter) { // Treat lines beginning with this string as output. -- cwells
  2078. for (var i = 0; i < codeLines.length; i++) {
  2079. if (codeLines[i].indexOf(outputFilter) === 0) { // This line is output. -- cwells
  2080. env.vars['command-line'].outputLines[i] = codeLines[i].slice(outputFilter.length);
  2081. codeLines[i] = '';
  2082. }
  2083. }
  2084. }
  2085. env.code = codeLines.join('\n');
  2086. });
  2087. Prism.hooks.add('before-insert', function (env) {
  2088. env.vars = env.vars || {};
  2089. env.vars['command-line'] = env.vars['command-line'] || {};
  2090. if (env.vars['command-line'].complete) {
  2091. return;
  2092. }
  2093. // Reinsert the output lines into the highlighted code. -- cwells
  2094. var codeLines = env.highlightedCode.split('\n');
  2095. for (var i = 0; i < env.vars['command-line'].outputLines.length; i++) {
  2096. if (env.vars['command-line'].outputLines.hasOwnProperty(i)) {
  2097. codeLines[i] = env.vars['command-line'].outputLines[i];
  2098. }
  2099. }
  2100. env.highlightedCode = codeLines.join('\n');
  2101. });
  2102. Prism.hooks.add('complete', function (env) {
  2103. env.vars = env.vars || {};
  2104. env.vars['command-line'] = env.vars['command-line'] || {};
  2105. if (env.vars['command-line'].complete) {
  2106. return;
  2107. }
  2108. var pre = env.element.parentNode;
  2109. if (clsReg.test(env.element.className)) { // Remove the class "command-line" from the <code>
  2110. env.element.className = env.element.className.replace(clsReg, ' ');
  2111. }
  2112. if (!clsReg.test(pre.className)) { // Add the class "command-line" to the <pre>
  2113. pre.className += ' command-line';
  2114. }
  2115. var getAttribute = function(key, defaultValue) {
  2116. return (pre.getAttribute(key) || defaultValue).replace(/"/g, '&quot');
  2117. };
  2118. // Create the "rows" that will become the command-line prompts. -- cwells
  2119. var promptLines = new Array(env.vars['command-line'].numberOfLines + 1);
  2120. var promptText = getAttribute('data-prompt', '');
  2121. if (promptText !== '') {
  2122. promptLines = promptLines.join('<span data-prompt="' + promptText + '"></span>');
  2123. } else {
  2124. var user = getAttribute('data-user', 'user');
  2125. var host = getAttribute('data-host', 'localhost');
  2126. promptLines = promptLines.join('<span data-user="' + user + '" data-host="' + host + '"></span>');
  2127. }
  2128. // Create the wrapper element. -- cwells
  2129. var prompt = document.createElement('span');
  2130. prompt.className = 'command-line-prompt';
  2131. prompt.innerHTML = promptLines;
  2132. // Remove the prompt from the output lines. -- cwells
  2133. for (var i = 0; i < env.vars['command-line'].outputLines.length; i++) {
  2134. if (env.vars['command-line'].outputLines.hasOwnProperty(i)) {
  2135. var node = prompt.children[i];
  2136. node.removeAttribute('data-user');
  2137. node.removeAttribute('data-host');
  2138. node.removeAttribute('data-prompt');
  2139. }
  2140. }
  2141. env.element.insertBefore(prompt, env.element.firstChild);
  2142. env.vars['command-line'].complete = true;
  2143. });
  2144. }());