prismjs.js 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  1. import {
  2. __commonJS
  3. } from "./chunk-WFTEJBJX.js";
  4. // node_modules/prismjs/prism.js
  5. var require_prism = __commonJS({
  6. "node_modules/prismjs/prism.js"(exports, module) {
  7. var _self = typeof window !== "undefined" ? window : typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope ? self : {};
  8. var Prism = function(_self2) {
  9. var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
  10. var uniqueId = 0;
  11. var plainTextGrammar = {};
  12. var _ = {
  13. /**
  14. * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
  15. * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
  16. * additional languages or plugins yourself.
  17. *
  18. * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
  19. *
  20. * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
  21. * empty Prism object into the global scope before loading the Prism script like this:
  22. *
  23. * ```js
  24. * window.Prism = window.Prism || {};
  25. * Prism.manual = true;
  26. * // add a new <script> to load Prism's script
  27. * ```
  28. *
  29. * @default false
  30. * @type {boolean}
  31. * @memberof Prism
  32. * @public
  33. */
  34. manual: _self2.Prism && _self2.Prism.manual,
  35. /**
  36. * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
  37. * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
  38. * own worker, you don't want it to do this.
  39. *
  40. * By setting this value to `true`, Prism will not add its own listeners to the worker.
  41. *
  42. * You obviously have to change this value before Prism executes. To do this, you can add an
  43. * empty Prism object into the global scope before loading the Prism script like this:
  44. *
  45. * ```js
  46. * window.Prism = window.Prism || {};
  47. * Prism.disableWorkerMessageHandler = true;
  48. * // Load Prism's script
  49. * ```
  50. *
  51. * @default false
  52. * @type {boolean}
  53. * @memberof Prism
  54. * @public
  55. */
  56. disableWorkerMessageHandler: _self2.Prism && _self2.Prism.disableWorkerMessageHandler,
  57. /**
  58. * A namespace for utility methods.
  59. *
  60. * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
  61. * change or disappear at any time.
  62. *
  63. * @namespace
  64. * @memberof Prism
  65. */
  66. util: {
  67. encode: function encode(tokens) {
  68. if (tokens instanceof Token) {
  69. return new Token(tokens.type, encode(tokens.content), tokens.alias);
  70. } else if (Array.isArray(tokens)) {
  71. return tokens.map(encode);
  72. } else {
  73. return tokens.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/\u00a0/g, " ");
  74. }
  75. },
  76. /**
  77. * Returns the name of the type of the given value.
  78. *
  79. * @param {any} o
  80. * @returns {string}
  81. * @example
  82. * type(null) === 'Null'
  83. * type(undefined) === 'Undefined'
  84. * type(123) === 'Number'
  85. * type('foo') === 'String'
  86. * type(true) === 'Boolean'
  87. * type([1, 2]) === 'Array'
  88. * type({}) === 'Object'
  89. * type(String) === 'Function'
  90. * type(/abc+/) === 'RegExp'
  91. */
  92. type: function(o) {
  93. return Object.prototype.toString.call(o).slice(8, -1);
  94. },
  95. /**
  96. * Returns a unique number for the given object. Later calls will still return the same number.
  97. *
  98. * @param {Object} obj
  99. * @returns {number}
  100. */
  101. objId: function(obj) {
  102. if (!obj["__id"]) {
  103. Object.defineProperty(obj, "__id", { value: ++uniqueId });
  104. }
  105. return obj["__id"];
  106. },
  107. /**
  108. * Creates a deep clone of the given object.
  109. *
  110. * The main intended use of this function is to clone language definitions.
  111. *
  112. * @param {T} o
  113. * @param {Record<number, any>} [visited]
  114. * @returns {T}
  115. * @template T
  116. */
  117. clone: function deepClone(o, visited) {
  118. visited = visited || {};
  119. var clone;
  120. var id;
  121. switch (_.util.type(o)) {
  122. case "Object":
  123. id = _.util.objId(o);
  124. if (visited[id]) {
  125. return visited[id];
  126. }
  127. clone = /** @type {Record<string, any>} */
  128. {};
  129. visited[id] = clone;
  130. for (var key in o) {
  131. if (o.hasOwnProperty(key)) {
  132. clone[key] = deepClone(o[key], visited);
  133. }
  134. }
  135. return (
  136. /** @type {any} */
  137. clone
  138. );
  139. case "Array":
  140. id = _.util.objId(o);
  141. if (visited[id]) {
  142. return visited[id];
  143. }
  144. clone = [];
  145. visited[id] = clone;
  146. /** @type {Array} */
  147. /** @type {any} */
  148. o.forEach(function(v, i) {
  149. clone[i] = deepClone(v, visited);
  150. });
  151. return (
  152. /** @type {any} */
  153. clone
  154. );
  155. default:
  156. return o;
  157. }
  158. },
  159. /**
  160. * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
  161. *
  162. * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
  163. *
  164. * @param {Element} element
  165. * @returns {string}
  166. */
  167. getLanguage: function(element) {
  168. while (element) {
  169. var m = lang.exec(element.className);
  170. if (m) {
  171. return m[1].toLowerCase();
  172. }
  173. element = element.parentElement;
  174. }
  175. return "none";
  176. },
  177. /**
  178. * Sets the Prism `language-xxxx` class of the given element.
  179. *
  180. * @param {Element} element
  181. * @param {string} language
  182. * @returns {void}
  183. */
  184. setLanguage: function(element, language) {
  185. element.className = element.className.replace(RegExp(lang, "gi"), "");
  186. element.classList.add("language-" + language);
  187. },
  188. /**
  189. * Returns the script element that is currently executing.
  190. *
  191. * This does __not__ work for line script element.
  192. *
  193. * @returns {HTMLScriptElement | null}
  194. */
  195. currentScript: function() {
  196. if (typeof document === "undefined") {
  197. return null;
  198. }
  199. if (document.currentScript && document.currentScript.tagName === "SCRIPT" && 1 < 2) {
  200. return (
  201. /** @type {any} */
  202. document.currentScript
  203. );
  204. }
  205. try {
  206. throw new Error();
  207. } catch (err) {
  208. var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
  209. if (src) {
  210. var scripts = document.getElementsByTagName("script");
  211. for (var i in scripts) {
  212. if (scripts[i].src == src) {
  213. return scripts[i];
  214. }
  215. }
  216. }
  217. return null;
  218. }
  219. },
  220. /**
  221. * Returns whether a given class is active for `element`.
  222. *
  223. * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
  224. * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
  225. * given class is just the given class with a `no-` prefix.
  226. *
  227. * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
  228. * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
  229. * ancestors have the given class or the negated version of it, then the default activation will be returned.
  230. *
  231. * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
  232. * version of it, the class is considered active.
  233. *
  234. * @param {Element} element
  235. * @param {string} className
  236. * @param {boolean} [defaultActivation=false]
  237. * @returns {boolean}
  238. */
  239. isActive: function(element, className, defaultActivation) {
  240. var no = "no-" + className;
  241. while (element) {
  242. var classList = element.classList;
  243. if (classList.contains(className)) {
  244. return true;
  245. }
  246. if (classList.contains(no)) {
  247. return false;
  248. }
  249. element = element.parentElement;
  250. }
  251. return !!defaultActivation;
  252. }
  253. },
  254. /**
  255. * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
  256. *
  257. * @namespace
  258. * @memberof Prism
  259. * @public
  260. */
  261. languages: {
  262. /**
  263. * The grammar for plain, unformatted text.
  264. */
  265. plain: plainTextGrammar,
  266. plaintext: plainTextGrammar,
  267. text: plainTextGrammar,
  268. txt: plainTextGrammar,
  269. /**
  270. * Creates a deep copy of the language with the given id and appends the given tokens.
  271. *
  272. * If a token in `redef` also appears in the copied language, then the existing token in the copied language
  273. * will be overwritten at its original position.
  274. *
  275. * ## Best practices
  276. *
  277. * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
  278. * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
  279. * understand the language definition because, normally, the order of tokens matters in Prism grammars.
  280. *
  281. * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
  282. * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
  283. *
  284. * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
  285. * @param {Grammar} redef The new tokens to append.
  286. * @returns {Grammar} The new language created.
  287. * @public
  288. * @example
  289. * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
  290. * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
  291. * // at its original position
  292. * 'comment': { ... },
  293. * // CSS doesn't have a 'color' token, so this token will be appended
  294. * 'color': /\b(?:red|green|blue)\b/
  295. * });
  296. */
  297. extend: function(id, redef) {
  298. var lang2 = _.util.clone(_.languages[id]);
  299. for (var key in redef) {
  300. lang2[key] = redef[key];
  301. }
  302. return lang2;
  303. },
  304. /**
  305. * Inserts tokens _before_ another token in a language definition or any other grammar.
  306. *
  307. * ## Usage
  308. *
  309. * This helper method makes it easy to modify existing languages. For example, the CSS language definition
  310. * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
  311. * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
  312. * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
  313. * this:
  314. *
  315. * ```js
  316. * Prism.languages.markup.style = {
  317. * // token
  318. * };
  319. * ```
  320. *
  321. * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
  322. * before existing tokens. For the CSS example above, you would use it like this:
  323. *
  324. * ```js
  325. * Prism.languages.insertBefore('markup', 'cdata', {
  326. * 'style': {
  327. * // token
  328. * }
  329. * });
  330. * ```
  331. *
  332. * ## Special cases
  333. *
  334. * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
  335. * will be ignored.
  336. *
  337. * This behavior can be used to insert tokens after `before`:
  338. *
  339. * ```js
  340. * Prism.languages.insertBefore('markup', 'comment', {
  341. * 'comment': Prism.languages.markup.comment,
  342. * // tokens after 'comment'
  343. * });
  344. * ```
  345. *
  346. * ## Limitations
  347. *
  348. * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
  349. * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
  350. * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
  351. * deleting properties which is necessary to insert at arbitrary positions.
  352. *
  353. * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
  354. * Instead, it will create a new object and replace all references to the target object with the new one. This
  355. * can be done without temporarily deleting properties, so the iteration order is well-defined.
  356. *
  357. * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
  358. * you hold the target object in a variable, then the value of the variable will not change.
  359. *
  360. * ```js
  361. * var oldMarkup = Prism.languages.markup;
  362. * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
  363. *
  364. * assert(oldMarkup !== Prism.languages.markup);
  365. * assert(newMarkup === Prism.languages.markup);
  366. * ```
  367. *
  368. * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
  369. * object to be modified.
  370. * @param {string} before The key to insert before.
  371. * @param {Grammar} insert An object containing the key-value pairs to be inserted.
  372. * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
  373. * object to be modified.
  374. *
  375. * Defaults to `Prism.languages`.
  376. * @returns {Grammar} The new grammar object.
  377. * @public
  378. */
  379. insertBefore: function(inside, before, insert, root) {
  380. root = root || /** @type {any} */
  381. _.languages;
  382. var grammar = root[inside];
  383. var ret = {};
  384. for (var token in grammar) {
  385. if (grammar.hasOwnProperty(token)) {
  386. if (token == before) {
  387. for (var newToken in insert) {
  388. if (insert.hasOwnProperty(newToken)) {
  389. ret[newToken] = insert[newToken];
  390. }
  391. }
  392. }
  393. if (!insert.hasOwnProperty(token)) {
  394. ret[token] = grammar[token];
  395. }
  396. }
  397. }
  398. var old = root[inside];
  399. root[inside] = ret;
  400. _.languages.DFS(_.languages, function(key, value) {
  401. if (value === old && key != inside) {
  402. this[key] = ret;
  403. }
  404. });
  405. return ret;
  406. },
  407. // Traverse a language definition with Depth First Search
  408. DFS: function DFS(o, callback, type, visited) {
  409. visited = visited || {};
  410. var objId = _.util.objId;
  411. for (var i in o) {
  412. if (o.hasOwnProperty(i)) {
  413. callback.call(o, i, o[i], type || i);
  414. var property = o[i];
  415. var propertyType = _.util.type(property);
  416. if (propertyType === "Object" && !visited[objId(property)]) {
  417. visited[objId(property)] = true;
  418. DFS(property, callback, null, visited);
  419. } else if (propertyType === "Array" && !visited[objId(property)]) {
  420. visited[objId(property)] = true;
  421. DFS(property, callback, i, visited);
  422. }
  423. }
  424. }
  425. }
  426. },
  427. plugins: {},
  428. /**
  429. * This is the most high-level function in Prism’s API.
  430. * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
  431. * each one of them.
  432. *
  433. * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
  434. *
  435. * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
  436. * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
  437. * @memberof Prism
  438. * @public
  439. */
  440. highlightAll: function(async, callback) {
  441. _.highlightAllUnder(document, async, callback);
  442. },
  443. /**
  444. * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
  445. * {@link Prism.highlightElement} on each one of them.
  446. *
  447. * The following hooks will be run:
  448. * 1. `before-highlightall`
  449. * 2. `before-all-elements-highlight`
  450. * 3. All hooks of {@link Prism.highlightElement} for each element.
  451. *
  452. * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
  453. * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
  454. * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
  455. * @memberof Prism
  456. * @public
  457. */
  458. highlightAllUnder: function(container, async, callback) {
  459. var env = {
  460. callback,
  461. container,
  462. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  463. };
  464. _.hooks.run("before-highlightall", env);
  465. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  466. _.hooks.run("before-all-elements-highlight", env);
  467. for (var i = 0, element; element = env.elements[i++]; ) {
  468. _.highlightElement(element, async === true, env.callback);
  469. }
  470. },
  471. /**
  472. * Highlights the code inside a single element.
  473. *
  474. * The following hooks will be run:
  475. * 1. `before-sanity-check`
  476. * 2. `before-highlight`
  477. * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
  478. * 4. `before-insert`
  479. * 5. `after-highlight`
  480. * 6. `complete`
  481. *
  482. * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
  483. * the element's language.
  484. *
  485. * @param {Element} element The element containing the code.
  486. * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
  487. * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
  488. * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
  489. * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
  490. *
  491. * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
  492. * asynchronous highlighting to work. You can build your own bundle on the
  493. * [Download page](https://prismjs.com/download.html).
  494. * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
  495. * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
  496. * @memberof Prism
  497. * @public
  498. */
  499. highlightElement: function(element, async, callback) {
  500. var language = _.util.getLanguage(element);
  501. var grammar = _.languages[language];
  502. _.util.setLanguage(element, language);
  503. var parent = element.parentElement;
  504. if (parent && parent.nodeName.toLowerCase() === "pre") {
  505. _.util.setLanguage(parent, language);
  506. }
  507. var code = element.textContent;
  508. var env = {
  509. element,
  510. language,
  511. grammar,
  512. code
  513. };
  514. function insertHighlightedCode(highlightedCode) {
  515. env.highlightedCode = highlightedCode;
  516. _.hooks.run("before-insert", env);
  517. env.element.innerHTML = env.highlightedCode;
  518. _.hooks.run("after-highlight", env);
  519. _.hooks.run("complete", env);
  520. callback && callback.call(env.element);
  521. }
  522. _.hooks.run("before-sanity-check", env);
  523. parent = env.element.parentElement;
  524. if (parent && parent.nodeName.toLowerCase() === "pre" && !parent.hasAttribute("tabindex")) {
  525. parent.setAttribute("tabindex", "0");
  526. }
  527. if (!env.code) {
  528. _.hooks.run("complete", env);
  529. callback && callback.call(env.element);
  530. return;
  531. }
  532. _.hooks.run("before-highlight", env);
  533. if (!env.grammar) {
  534. insertHighlightedCode(_.util.encode(env.code));
  535. return;
  536. }
  537. if (async && _self2.Worker) {
  538. var worker = new Worker(_.filename);
  539. worker.onmessage = function(evt) {
  540. insertHighlightedCode(evt.data);
  541. };
  542. worker.postMessage(JSON.stringify({
  543. language: env.language,
  544. code: env.code,
  545. immediateClose: true
  546. }));
  547. } else {
  548. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  549. }
  550. },
  551. /**
  552. * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
  553. * and the language definitions to use, and returns a string with the HTML produced.
  554. *
  555. * The following hooks will be run:
  556. * 1. `before-tokenize`
  557. * 2. `after-tokenize`
  558. * 3. `wrap`: On each {@link Token}.
  559. *
  560. * @param {string} text A string with the code to be highlighted.
  561. * @param {Grammar} grammar An object containing the tokens to use.
  562. *
  563. * Usually a language definition like `Prism.languages.markup`.
  564. * @param {string} language The name of the language definition passed to `grammar`.
  565. * @returns {string} The highlighted HTML.
  566. * @memberof Prism
  567. * @public
  568. * @example
  569. * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
  570. */
  571. highlight: function(text, grammar, language) {
  572. var env = {
  573. code: text,
  574. grammar,
  575. language
  576. };
  577. _.hooks.run("before-tokenize", env);
  578. if (!env.grammar) {
  579. throw new Error('The language "' + env.language + '" has no grammar.');
  580. }
  581. env.tokens = _.tokenize(env.code, env.grammar);
  582. _.hooks.run("after-tokenize", env);
  583. return Token.stringify(_.util.encode(env.tokens), env.language);
  584. },
  585. /**
  586. * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
  587. * and the language definitions to use, and returns an array with the tokenized code.
  588. *
  589. * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
  590. *
  591. * This method could be useful in other contexts as well, as a very crude parser.
  592. *
  593. * @param {string} text A string with the code to be highlighted.
  594. * @param {Grammar} grammar An object containing the tokens to use.
  595. *
  596. * Usually a language definition like `Prism.languages.markup`.
  597. * @returns {TokenStream} An array of strings and tokens, a token stream.
  598. * @memberof Prism
  599. * @public
  600. * @example
  601. * let code = `var foo = 0;`;
  602. * let tokens = Prism.tokenize(code, Prism.languages.javascript);
  603. * tokens.forEach(token => {
  604. * if (token instanceof Prism.Token && token.type === 'number') {
  605. * console.log(`Found numeric literal: ${token.content}`);
  606. * }
  607. * });
  608. */
  609. tokenize: function(text, grammar) {
  610. var rest = grammar.rest;
  611. if (rest) {
  612. for (var token in rest) {
  613. grammar[token] = rest[token];
  614. }
  615. delete grammar.rest;
  616. }
  617. var tokenList = new LinkedList();
  618. addAfter(tokenList, tokenList.head, text);
  619. matchGrammar(text, tokenList, grammar, tokenList.head, 0);
  620. return toArray(tokenList);
  621. },
  622. /**
  623. * @namespace
  624. * @memberof Prism
  625. * @public
  626. */
  627. hooks: {
  628. all: {},
  629. /**
  630. * Adds the given callback to the list of callbacks for the given hook.
  631. *
  632. * The callback will be invoked when the hook it is registered for is run.
  633. * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
  634. *
  635. * One callback function can be registered to multiple hooks and the same hook multiple times.
  636. *
  637. * @param {string} name The name of the hook.
  638. * @param {HookCallback} callback The callback function which is given environment variables.
  639. * @public
  640. */
  641. add: function(name, callback) {
  642. var hooks = _.hooks.all;
  643. hooks[name] = hooks[name] || [];
  644. hooks[name].push(callback);
  645. },
  646. /**
  647. * Runs a hook invoking all registered callbacks with the given environment variables.
  648. *
  649. * Callbacks will be invoked synchronously and in the order in which they were registered.
  650. *
  651. * @param {string} name The name of the hook.
  652. * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
  653. * @public
  654. */
  655. run: function(name, env) {
  656. var callbacks = _.hooks.all[name];
  657. if (!callbacks || !callbacks.length) {
  658. return;
  659. }
  660. for (var i = 0, callback; callback = callbacks[i++]; ) {
  661. callback(env);
  662. }
  663. }
  664. },
  665. Token
  666. };
  667. _self2.Prism = _;
  668. function Token(type, content, alias, matchedStr) {
  669. this.type = type;
  670. this.content = content;
  671. this.alias = alias;
  672. this.length = (matchedStr || "").length | 0;
  673. }
  674. Token.stringify = function stringify(o, language) {
  675. if (typeof o == "string") {
  676. return o;
  677. }
  678. if (Array.isArray(o)) {
  679. var s = "";
  680. o.forEach(function(e) {
  681. s += stringify(e, language);
  682. });
  683. return s;
  684. }
  685. var env = {
  686. type: o.type,
  687. content: stringify(o.content, language),
  688. tag: "span",
  689. classes: ["token", o.type],
  690. attributes: {},
  691. language
  692. };
  693. var aliases = o.alias;
  694. if (aliases) {
  695. if (Array.isArray(aliases)) {
  696. Array.prototype.push.apply(env.classes, aliases);
  697. } else {
  698. env.classes.push(aliases);
  699. }
  700. }
  701. _.hooks.run("wrap", env);
  702. var attributes = "";
  703. for (var name in env.attributes) {
  704. attributes += " " + name + '="' + (env.attributes[name] || "").replace(/"/g, "&quot;") + '"';
  705. }
  706. return "<" + env.tag + ' class="' + env.classes.join(" ") + '"' + attributes + ">" + env.content + "</" + env.tag + ">";
  707. };
  708. function matchPattern(pattern, pos, text, lookbehind) {
  709. pattern.lastIndex = pos;
  710. var match = pattern.exec(text);
  711. if (match && lookbehind && match[1]) {
  712. var lookbehindLength = match[1].length;
  713. match.index += lookbehindLength;
  714. match[0] = match[0].slice(lookbehindLength);
  715. }
  716. return match;
  717. }
  718. function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
  719. for (var token in grammar) {
  720. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  721. continue;
  722. }
  723. var patterns = grammar[token];
  724. patterns = Array.isArray(patterns) ? patterns : [patterns];
  725. for (var j = 0; j < patterns.length; ++j) {
  726. if (rematch && rematch.cause == token + "," + j) {
  727. return;
  728. }
  729. var patternObj = patterns[j];
  730. var inside = patternObj.inside;
  731. var lookbehind = !!patternObj.lookbehind;
  732. var greedy = !!patternObj.greedy;
  733. var alias = patternObj.alias;
  734. if (greedy && !patternObj.pattern.global) {
  735. var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
  736. patternObj.pattern = RegExp(patternObj.pattern.source, flags + "g");
  737. }
  738. var pattern = patternObj.pattern || patternObj;
  739. for (var currentNode = startNode.next, pos = startPos; currentNode !== tokenList.tail; pos += currentNode.value.length, currentNode = currentNode.next) {
  740. if (rematch && pos >= rematch.reach) {
  741. break;
  742. }
  743. var str = currentNode.value;
  744. if (tokenList.length > text.length) {
  745. return;
  746. }
  747. if (str instanceof Token) {
  748. continue;
  749. }
  750. var removeCount = 1;
  751. var match;
  752. if (greedy) {
  753. match = matchPattern(pattern, pos, text, lookbehind);
  754. if (!match || match.index >= text.length) {
  755. break;
  756. }
  757. var from = match.index;
  758. var to = match.index + match[0].length;
  759. var p = pos;
  760. p += currentNode.value.length;
  761. while (from >= p) {
  762. currentNode = currentNode.next;
  763. p += currentNode.value.length;
  764. }
  765. p -= currentNode.value.length;
  766. pos = p;
  767. if (currentNode.value instanceof Token) {
  768. continue;
  769. }
  770. for (var k = currentNode; k !== tokenList.tail && (p < to || typeof k.value === "string"); k = k.next) {
  771. removeCount++;
  772. p += k.value.length;
  773. }
  774. removeCount--;
  775. str = text.slice(pos, p);
  776. match.index -= pos;
  777. } else {
  778. match = matchPattern(pattern, 0, str, lookbehind);
  779. if (!match) {
  780. continue;
  781. }
  782. }
  783. var from = match.index;
  784. var matchStr = match[0];
  785. var before = str.slice(0, from);
  786. var after = str.slice(from + matchStr.length);
  787. var reach = pos + str.length;
  788. if (rematch && reach > rematch.reach) {
  789. rematch.reach = reach;
  790. }
  791. var removeFrom = currentNode.prev;
  792. if (before) {
  793. removeFrom = addAfter(tokenList, removeFrom, before);
  794. pos += before.length;
  795. }
  796. removeRange(tokenList, removeFrom, removeCount);
  797. var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
  798. currentNode = addAfter(tokenList, removeFrom, wrapped);
  799. if (after) {
  800. addAfter(tokenList, currentNode, after);
  801. }
  802. if (removeCount > 1) {
  803. var nestedRematch = {
  804. cause: token + "," + j,
  805. reach
  806. };
  807. matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
  808. if (rematch && nestedRematch.reach > rematch.reach) {
  809. rematch.reach = nestedRematch.reach;
  810. }
  811. }
  812. }
  813. }
  814. }
  815. }
  816. function LinkedList() {
  817. var head = { value: null, prev: null, next: null };
  818. var tail = { value: null, prev: head, next: null };
  819. head.next = tail;
  820. this.head = head;
  821. this.tail = tail;
  822. this.length = 0;
  823. }
  824. function addAfter(list, node, value) {
  825. var next = node.next;
  826. var newNode = { value, prev: node, next };
  827. node.next = newNode;
  828. next.prev = newNode;
  829. list.length++;
  830. return newNode;
  831. }
  832. function removeRange(list, node, count) {
  833. var next = node.next;
  834. for (var i = 0; i < count && next !== list.tail; i++) {
  835. next = next.next;
  836. }
  837. node.next = next;
  838. next.prev = node;
  839. list.length -= i;
  840. }
  841. function toArray(list) {
  842. var array = [];
  843. var node = list.head.next;
  844. while (node !== list.tail) {
  845. array.push(node.value);
  846. node = node.next;
  847. }
  848. return array;
  849. }
  850. if (!_self2.document) {
  851. if (!_self2.addEventListener) {
  852. return _;
  853. }
  854. if (!_.disableWorkerMessageHandler) {
  855. _self2.addEventListener("message", function(evt) {
  856. var message = JSON.parse(evt.data);
  857. var lang2 = message.language;
  858. var code = message.code;
  859. var immediateClose = message.immediateClose;
  860. _self2.postMessage(_.highlight(code, _.languages[lang2], lang2));
  861. if (immediateClose) {
  862. _self2.close();
  863. }
  864. }, false);
  865. }
  866. return _;
  867. }
  868. var script = _.util.currentScript();
  869. if (script) {
  870. _.filename = script.src;
  871. if (script.hasAttribute("data-manual")) {
  872. _.manual = true;
  873. }
  874. }
  875. function highlightAutomaticallyCallback() {
  876. if (!_.manual) {
  877. _.highlightAll();
  878. }
  879. }
  880. if (!_.manual) {
  881. var readyState = document.readyState;
  882. if (readyState === "loading" || readyState === "interactive" && script && script.defer) {
  883. document.addEventListener("DOMContentLoaded", highlightAutomaticallyCallback);
  884. } else {
  885. if (window.requestAnimationFrame) {
  886. window.requestAnimationFrame(highlightAutomaticallyCallback);
  887. } else {
  888. window.setTimeout(highlightAutomaticallyCallback, 16);
  889. }
  890. }
  891. }
  892. return _;
  893. }(_self);
  894. if (typeof module !== "undefined" && module.exports) {
  895. module.exports = Prism;
  896. }
  897. if (typeof global !== "undefined") {
  898. global.Prism = Prism;
  899. }
  900. Prism.languages.markup = {
  901. "comment": {
  902. pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
  903. greedy: true
  904. },
  905. "prolog": {
  906. pattern: /<\?[\s\S]+?\?>/,
  907. greedy: true
  908. },
  909. "doctype": {
  910. // https://www.w3.org/TR/xml/#NT-doctypedecl
  911. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
  912. greedy: true,
  913. inside: {
  914. "internal-subset": {
  915. pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
  916. lookbehind: true,
  917. greedy: true,
  918. inside: null
  919. // see below
  920. },
  921. "string": {
  922. pattern: /"[^"]*"|'[^']*'/,
  923. greedy: true
  924. },
  925. "punctuation": /^<!|>$|[[\]]/,
  926. "doctype-tag": /^DOCTYPE/i,
  927. "name": /[^\s<>'"]+/
  928. }
  929. },
  930. "cdata": {
  931. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  932. greedy: true
  933. },
  934. "tag": {
  935. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
  936. greedy: true,
  937. inside: {
  938. "tag": {
  939. pattern: /^<\/?[^\s>\/]+/,
  940. inside: {
  941. "punctuation": /^<\/?/,
  942. "namespace": /^[^\s>\/:]+:/
  943. }
  944. },
  945. "special-attr": [],
  946. "attr-value": {
  947. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
  948. inside: {
  949. "punctuation": [
  950. {
  951. pattern: /^=/,
  952. alias: "attr-equals"
  953. },
  954. {
  955. pattern: /^(\s*)["']|["']$/,
  956. lookbehind: true
  957. }
  958. ]
  959. }
  960. },
  961. "punctuation": /\/?>/,
  962. "attr-name": {
  963. pattern: /[^\s>\/]+/,
  964. inside: {
  965. "namespace": /^[^\s>\/:]+:/
  966. }
  967. }
  968. }
  969. },
  970. "entity": [
  971. {
  972. pattern: /&[\da-z]{1,8};/i,
  973. alias: "named-entity"
  974. },
  975. /&#x?[\da-f]{1,8};/i
  976. ]
  977. };
  978. Prism.languages.markup["tag"].inside["attr-value"].inside["entity"] = Prism.languages.markup["entity"];
  979. Prism.languages.markup["doctype"].inside["internal-subset"].inside = Prism.languages.markup;
  980. Prism.hooks.add("wrap", function(env) {
  981. if (env.type === "entity") {
  982. env.attributes["title"] = env.content.replace(/&amp;/, "&");
  983. }
  984. });
  985. Object.defineProperty(Prism.languages.markup.tag, "addInlined", {
  986. /**
  987. * Adds an inlined language to markup.
  988. *
  989. * An example of an inlined language is CSS with `<style>` tags.
  990. *
  991. * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
  992. * case insensitive.
  993. * @param {string} lang The language key.
  994. * @example
  995. * addInlined('style', 'css');
  996. */
  997. value: function addInlined(tagName, lang) {
  998. var includedCdataInside = {};
  999. includedCdataInside["language-" + lang] = {
  1000. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  1001. lookbehind: true,
  1002. inside: Prism.languages[lang]
  1003. };
  1004. includedCdataInside["cdata"] = /^<!\[CDATA\[|\]\]>$/i;
  1005. var inside = {
  1006. "included-cdata": {
  1007. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1008. inside: includedCdataInside
  1009. }
  1010. };
  1011. inside["language-" + lang] = {
  1012. pattern: /[\s\S]+/,
  1013. inside: Prism.languages[lang]
  1014. };
  1015. var def = {};
  1016. def[tagName] = {
  1017. pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function() {
  1018. return tagName;
  1019. }), "i"),
  1020. lookbehind: true,
  1021. greedy: true,
  1022. inside
  1023. };
  1024. Prism.languages.insertBefore("markup", "cdata", def);
  1025. }
  1026. });
  1027. Object.defineProperty(Prism.languages.markup.tag, "addAttribute", {
  1028. /**
  1029. * Adds an pattern to highlight languages embedded in HTML attributes.
  1030. *
  1031. * An example of an inlined language is CSS with `style` attributes.
  1032. *
  1033. * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
  1034. * case insensitive.
  1035. * @param {string} lang The language key.
  1036. * @example
  1037. * addAttribute('style', 'css');
  1038. */
  1039. value: function(attrName, lang) {
  1040. Prism.languages.markup.tag.inside["special-attr"].push({
  1041. pattern: RegExp(
  1042. /(^|["'\s])/.source + "(?:" + attrName + ")" + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
  1043. "i"
  1044. ),
  1045. lookbehind: true,
  1046. inside: {
  1047. "attr-name": /^[^\s=]+/,
  1048. "attr-value": {
  1049. pattern: /=[\s\S]+/,
  1050. inside: {
  1051. "value": {
  1052. pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
  1053. lookbehind: true,
  1054. alias: [lang, "language-" + lang],
  1055. inside: Prism.languages[lang]
  1056. },
  1057. "punctuation": [
  1058. {
  1059. pattern: /^=/,
  1060. alias: "attr-equals"
  1061. },
  1062. /"|'/
  1063. ]
  1064. }
  1065. }
  1066. }
  1067. });
  1068. }
  1069. });
  1070. Prism.languages.html = Prism.languages.markup;
  1071. Prism.languages.mathml = Prism.languages.markup;
  1072. Prism.languages.svg = Prism.languages.markup;
  1073. Prism.languages.xml = Prism.languages.extend("markup", {});
  1074. Prism.languages.ssml = Prism.languages.xml;
  1075. Prism.languages.atom = Prism.languages.xml;
  1076. Prism.languages.rss = Prism.languages.xml;
  1077. (function(Prism2) {
  1078. var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
  1079. Prism2.languages.css = {
  1080. "comment": /\/\*[\s\S]*?\*\//,
  1081. "atrule": {
  1082. pattern: RegExp("@[\\w-](?:" + /[^;{\s"']|\s+(?!\s)/.source + "|" + string.source + ")*?" + /(?:;|(?=\s*\{))/.source),
  1083. inside: {
  1084. "rule": /^@[\w-]+/,
  1085. "selector-function-argument": {
  1086. pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
  1087. lookbehind: true,
  1088. alias: "selector"
  1089. },
  1090. "keyword": {
  1091. pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
  1092. lookbehind: true
  1093. }
  1094. // See rest below
  1095. }
  1096. },
  1097. "url": {
  1098. // https://drafts.csswg.org/css-values-3/#urls
  1099. pattern: RegExp("\\burl\\((?:" + string.source + "|" + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ")\\)", "i"),
  1100. greedy: true,
  1101. inside: {
  1102. "function": /^url/i,
  1103. "punctuation": /^\(|\)$/,
  1104. "string": {
  1105. pattern: RegExp("^" + string.source + "$"),
  1106. alias: "url"
  1107. }
  1108. }
  1109. },
  1110. "selector": {
  1111. pattern: RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|` + string.source + ")*(?=\\s*\\{)"),
  1112. lookbehind: true
  1113. },
  1114. "string": {
  1115. pattern: string,
  1116. greedy: true
  1117. },
  1118. "property": {
  1119. pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
  1120. lookbehind: true
  1121. },
  1122. "important": /!important\b/i,
  1123. "function": {
  1124. pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
  1125. lookbehind: true
  1126. },
  1127. "punctuation": /[(){};:,]/
  1128. };
  1129. Prism2.languages.css["atrule"].inside.rest = Prism2.languages.css;
  1130. var markup = Prism2.languages.markup;
  1131. if (markup) {
  1132. markup.tag.addInlined("style", "css");
  1133. markup.tag.addAttribute("style", "css");
  1134. }
  1135. })(Prism);
  1136. Prism.languages.clike = {
  1137. "comment": [
  1138. {
  1139. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  1140. lookbehind: true,
  1141. greedy: true
  1142. },
  1143. {
  1144. pattern: /(^|[^\\:])\/\/.*/,
  1145. lookbehind: true,
  1146. greedy: true
  1147. }
  1148. ],
  1149. "string": {
  1150. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  1151. greedy: true
  1152. },
  1153. "class-name": {
  1154. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
  1155. lookbehind: true,
  1156. inside: {
  1157. "punctuation": /[.\\]/
  1158. }
  1159. },
  1160. "keyword": /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
  1161. "boolean": /\b(?:false|true)\b/,
  1162. "function": /\b\w+(?=\()/,
  1163. "number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
  1164. "operator": /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  1165. "punctuation": /[{}[\];(),.:]/
  1166. };
  1167. Prism.languages.javascript = Prism.languages.extend("clike", {
  1168. "class-name": [
  1169. Prism.languages.clike["class-name"],
  1170. {
  1171. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
  1172. lookbehind: true
  1173. }
  1174. ],
  1175. "keyword": [
  1176. {
  1177. pattern: /((?:^|\})\s*)catch\b/,
  1178. lookbehind: true
  1179. },
  1180. {
  1181. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
  1182. lookbehind: true
  1183. }
  1184. ],
  1185. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  1186. "function": /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  1187. "number": {
  1188. pattern: RegExp(
  1189. /(^|[^\w$])/.source + "(?:" + // constant
  1190. (/NaN|Infinity/.source + "|" + // binary integer
  1191. /0[bB][01]+(?:_[01]+)*n?/.source + "|" + // octal integer
  1192. /0[oO][0-7]+(?:_[0-7]+)*n?/.source + "|" + // hexadecimal integer
  1193. /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + "|" + // decimal bigint
  1194. /\d+(?:_\d+)*n/.source + "|" + // decimal number (integer or float) but no bigint
  1195. /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ")" + /(?![\w$])/.source
  1196. ),
  1197. lookbehind: true
  1198. },
  1199. "operator": /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
  1200. });
  1201. Prism.languages.javascript["class-name"][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
  1202. Prism.languages.insertBefore("javascript", "keyword", {
  1203. "regex": {
  1204. pattern: RegExp(
  1205. // lookbehind
  1206. // eslint-disable-next-line regexp/no-dupe-characters-character-class
  1207. /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + // Regex pattern:
  1208. // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
  1209. // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
  1210. // with the only syntax, so we have to define 2 different regex patterns.
  1211. /\//.source + "(?:" + /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source + "|" + // `v` flag syntax. This supports 3 levels of nested character classes.
  1212. /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ")" + // lookahead
  1213. /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
  1214. ),
  1215. lookbehind: true,
  1216. greedy: true,
  1217. inside: {
  1218. "regex-source": {
  1219. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  1220. lookbehind: true,
  1221. alias: "language-regex",
  1222. inside: Prism.languages.regex
  1223. },
  1224. "regex-delimiter": /^\/|\/$/,
  1225. "regex-flags": /^[a-z]+$/
  1226. }
  1227. },
  1228. // This must be declared before keyword because we use "function" inside the look-forward
  1229. "function-variable": {
  1230. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
  1231. alias: "function"
  1232. },
  1233. "parameter": [
  1234. {
  1235. pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
  1236. lookbehind: true,
  1237. inside: Prism.languages.javascript
  1238. },
  1239. {
  1240. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
  1241. lookbehind: true,
  1242. inside: Prism.languages.javascript
  1243. },
  1244. {
  1245. pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
  1246. lookbehind: true,
  1247. inside: Prism.languages.javascript
  1248. },
  1249. {
  1250. pattern: /((?:\b|\s|^)(?!(?: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|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
  1251. lookbehind: true,
  1252. inside: Prism.languages.javascript
  1253. }
  1254. ],
  1255. "constant": /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  1256. });
  1257. Prism.languages.insertBefore("javascript", "string", {
  1258. "hashbang": {
  1259. pattern: /^#!.*/,
  1260. greedy: true,
  1261. alias: "comment"
  1262. },
  1263. "template-string": {
  1264. pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
  1265. greedy: true,
  1266. inside: {
  1267. "template-punctuation": {
  1268. pattern: /^`|`$/,
  1269. alias: "string"
  1270. },
  1271. "interpolation": {
  1272. pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
  1273. lookbehind: true,
  1274. inside: {
  1275. "interpolation-punctuation": {
  1276. pattern: /^\$\{|\}$/,
  1277. alias: "punctuation"
  1278. },
  1279. rest: Prism.languages.javascript
  1280. }
  1281. },
  1282. "string": /[\s\S]+/
  1283. }
  1284. },
  1285. "string-property": {
  1286. pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
  1287. lookbehind: true,
  1288. greedy: true,
  1289. alias: "property"
  1290. }
  1291. });
  1292. Prism.languages.insertBefore("javascript", "operator", {
  1293. "literal-property": {
  1294. pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
  1295. lookbehind: true,
  1296. alias: "property"
  1297. }
  1298. });
  1299. if (Prism.languages.markup) {
  1300. Prism.languages.markup.tag.addInlined("script", "javascript");
  1301. Prism.languages.markup.tag.addAttribute(
  1302. /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
  1303. "javascript"
  1304. );
  1305. }
  1306. Prism.languages.js = Prism.languages.javascript;
  1307. (function() {
  1308. if (typeof Prism === "undefined" || typeof document === "undefined") {
  1309. return;
  1310. }
  1311. if (!Element.prototype.matches) {
  1312. Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
  1313. }
  1314. var LOADING_MESSAGE = "Loading…";
  1315. var FAILURE_MESSAGE = function(status, message) {
  1316. return "✖ Error " + status + " while fetching file: " + message;
  1317. };
  1318. var FAILURE_EMPTY_MESSAGE = "✖ Error: File does not exist or is empty";
  1319. var EXTENSIONS = {
  1320. "js": "javascript",
  1321. "py": "python",
  1322. "rb": "ruby",
  1323. "ps1": "powershell",
  1324. "psm1": "powershell",
  1325. "sh": "bash",
  1326. "bat": "batch",
  1327. "h": "c",
  1328. "tex": "latex"
  1329. };
  1330. var STATUS_ATTR = "data-src-status";
  1331. var STATUS_LOADING = "loading";
  1332. var STATUS_LOADED = "loaded";
  1333. var STATUS_FAILED = "failed";
  1334. var SELECTOR = "pre[data-src]:not([" + STATUS_ATTR + '="' + STATUS_LOADED + '"]):not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
  1335. function loadFile(src, success, error) {
  1336. var xhr = new XMLHttpRequest();
  1337. xhr.open("GET", src, true);
  1338. xhr.onreadystatechange = function() {
  1339. if (xhr.readyState == 4) {
  1340. if (xhr.status < 400 && xhr.responseText) {
  1341. success(xhr.responseText);
  1342. } else {
  1343. if (xhr.status >= 400) {
  1344. error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
  1345. } else {
  1346. error(FAILURE_EMPTY_MESSAGE);
  1347. }
  1348. }
  1349. }
  1350. };
  1351. xhr.send(null);
  1352. }
  1353. function parseRange(range) {
  1354. var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || "");
  1355. if (m) {
  1356. var start = Number(m[1]);
  1357. var comma = m[2];
  1358. var end = m[3];
  1359. if (!comma) {
  1360. return [start, start];
  1361. }
  1362. if (!end) {
  1363. return [start, void 0];
  1364. }
  1365. return [start, Number(end)];
  1366. }
  1367. return void 0;
  1368. }
  1369. Prism.hooks.add("before-highlightall", function(env) {
  1370. env.selector += ", " + SELECTOR;
  1371. });
  1372. Prism.hooks.add("before-sanity-check", function(env) {
  1373. var pre = (
  1374. /** @type {HTMLPreElement} */
  1375. env.element
  1376. );
  1377. if (pre.matches(SELECTOR)) {
  1378. env.code = "";
  1379. pre.setAttribute(STATUS_ATTR, STATUS_LOADING);
  1380. var code = pre.appendChild(document.createElement("CODE"));
  1381. code.textContent = LOADING_MESSAGE;
  1382. var src = pre.getAttribute("data-src");
  1383. var language = env.language;
  1384. if (language === "none") {
  1385. var extension = (/\.(\w+)$/.exec(src) || [, "none"])[1];
  1386. language = EXTENSIONS[extension] || extension;
  1387. }
  1388. Prism.util.setLanguage(code, language);
  1389. Prism.util.setLanguage(pre, language);
  1390. var autoloader = Prism.plugins.autoloader;
  1391. if (autoloader) {
  1392. autoloader.loadLanguages(language);
  1393. }
  1394. loadFile(
  1395. src,
  1396. function(text) {
  1397. pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
  1398. var range = parseRange(pre.getAttribute("data-range"));
  1399. if (range) {
  1400. var lines = text.split(/\r\n?|\n/g);
  1401. var start = range[0];
  1402. var end = range[1] == null ? lines.length : range[1];
  1403. if (start < 0) {
  1404. start += lines.length;
  1405. }
  1406. start = Math.max(0, Math.min(start - 1, lines.length));
  1407. if (end < 0) {
  1408. end += lines.length;
  1409. }
  1410. end = Math.max(0, Math.min(end, lines.length));
  1411. text = lines.slice(start, end).join("\n");
  1412. if (!pre.hasAttribute("data-start")) {
  1413. pre.setAttribute("data-start", String(start + 1));
  1414. }
  1415. }
  1416. code.textContent = text;
  1417. Prism.highlightElement(code);
  1418. },
  1419. function(error) {
  1420. pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
  1421. code.textContent = error;
  1422. }
  1423. );
  1424. }
  1425. });
  1426. Prism.plugins.fileHighlight = {
  1427. /**
  1428. * Executes the File Highlight plugin for all matching `pre` elements under the given container.
  1429. *
  1430. * Note: Elements which are already loaded or currently loading will not be touched by this method.
  1431. *
  1432. * @param {ParentNode} [container=document]
  1433. */
  1434. highlight: function highlight(container) {
  1435. var elements = (container || document).querySelectorAll(SELECTOR);
  1436. for (var i = 0, element; element = elements[i++]; ) {
  1437. Prism.highlightElement(element);
  1438. }
  1439. }
  1440. };
  1441. var logged = false;
  1442. Prism.fileHighlight = function() {
  1443. if (!logged) {
  1444. console.warn("Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.");
  1445. logged = true;
  1446. }
  1447. Prism.plugins.fileHighlight.highlight.apply(this, arguments);
  1448. };
  1449. })();
  1450. }
  1451. });
  1452. export default require_prism();
  1453. /*! Bundled license information:
  1454. prismjs/prism.js:
  1455. (**
  1456. * Prism: Lightweight, robust, elegant syntax highlighting
  1457. *
  1458. * @license MIT <https://opensource.org/licenses/MIT>
  1459. * @author Lea Verou <https://lea.verou.me>
  1460. * @namespace
  1461. * @public
  1462. *)
  1463. */
  1464. //# sourceMappingURL=prismjs.js.map