prism.js 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611
  1. /* PrismJS 1.23.0
  2. https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+coffeescript+crystal+d+dart+diff+django+elixir+erlang+go+groovy+java+json+julia+kotlin+latex+lua+markup-templating+matlab+nginx+nim+ocaml+perl+php+python+r+jsx+ruby+rust+scss+shell-session+sql+typescript+yaml */
  3. /// <reference lib="WebWorker"/>
  4. var _self = (typeof window !== 'undefined')
  5. ? window // if in browser
  6. : (
  7. (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
  8. ? self // if in worker
  9. : {} // if in node js
  10. );
  11. /**
  12. * Prism: Lightweight, robust, elegant syntax highlighting
  13. *
  14. * @license MIT <https://opensource.org/licenses/MIT>
  15. * @author Lea Verou <https://lea.verou.me>
  16. * @namespace
  17. * @public
  18. */
  19. var Prism = (function (_self) {
  20. // Private helper vars
  21. var lang = /\blang(?:uage)?-([\w-]+)\b/i;
  22. var uniqueId = 0;
  23. // The grammar object for plaintext
  24. var plainTextGrammar = {};
  25. var _ = {
  26. /**
  27. * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
  28. * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
  29. * additional languages or plugins yourself.
  30. *
  31. * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
  32. *
  33. * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
  34. * empty Prism object into the global scope before loading the Prism script like this:
  35. *
  36. * ```js
  37. * window.Prism = window.Prism || {};
  38. * Prism.manual = true;
  39. * // add a new <script> to load Prism's script
  40. * ```
  41. *
  42. * @default false
  43. * @type {boolean}
  44. * @memberof Prism
  45. * @public
  46. */
  47. manual: _self.Prism && _self.Prism.manual,
  48. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  49. /**
  50. * A namespace for utility methods.
  51. *
  52. * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
  53. * change or disappear at any time.
  54. *
  55. * @namespace
  56. * @memberof Prism
  57. */
  58. util: {
  59. encode: function encode(tokens) {
  60. if (tokens instanceof Token) {
  61. return new Token(tokens.type, encode(tokens.content), tokens.alias);
  62. } else if (Array.isArray(tokens)) {
  63. return tokens.map(encode);
  64. } else {
  65. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  66. }
  67. },
  68. /**
  69. * Returns the name of the type of the given value.
  70. *
  71. * @param {any} o
  72. * @returns {string}
  73. * @example
  74. * type(null) === 'Null'
  75. * type(undefined) === 'Undefined'
  76. * type(123) === 'Number'
  77. * type('foo') === 'String'
  78. * type(true) === 'Boolean'
  79. * type([1, 2]) === 'Array'
  80. * type({}) === 'Object'
  81. * type(String) === 'Function'
  82. * type(/abc+/) === 'RegExp'
  83. */
  84. type: function (o) {
  85. return Object.prototype.toString.call(o).slice(8, -1);
  86. },
  87. /**
  88. * Returns a unique number for the given object. Later calls will still return the same number.
  89. *
  90. * @param {Object} obj
  91. * @returns {number}
  92. */
  93. objId: function (obj) {
  94. if (!obj['__id']) {
  95. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  96. }
  97. return obj['__id'];
  98. },
  99. /**
  100. * Creates a deep clone of the given object.
  101. *
  102. * The main intended use of this function is to clone language definitions.
  103. *
  104. * @param {T} o
  105. * @param {Record<number, any>} [visited]
  106. * @returns {T}
  107. * @template T
  108. */
  109. clone: function deepClone(o, visited) {
  110. visited = visited || {};
  111. var clone; var id;
  112. switch (_.util.type(o)) {
  113. case 'Object':
  114. id = _.util.objId(o);
  115. if (visited[id]) {
  116. return visited[id];
  117. }
  118. clone = /** @type {Record<string, any>} */ ({});
  119. visited[id] = clone;
  120. for (var key in o) {
  121. if (o.hasOwnProperty(key)) {
  122. clone[key] = deepClone(o[key], visited);
  123. }
  124. }
  125. return /** @type {any} */ (clone);
  126. case 'Array':
  127. id = _.util.objId(o);
  128. if (visited[id]) {
  129. return visited[id];
  130. }
  131. clone = [];
  132. visited[id] = clone;
  133. (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
  134. clone[i] = deepClone(v, visited);
  135. });
  136. return /** @type {any} */ (clone);
  137. default:
  138. return o;
  139. }
  140. },
  141. /**
  142. * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
  143. *
  144. * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
  145. *
  146. * @param {Element} element
  147. * @returns {string}
  148. */
  149. getLanguage: function (element) {
  150. while (element && !lang.test(element.className)) {
  151. element = element.parentElement;
  152. }
  153. if (element) {
  154. return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
  155. }
  156. return 'none';
  157. },
  158. /**
  159. * Returns the script element that is currently executing.
  160. *
  161. * This does __not__ work for line script element.
  162. *
  163. * @returns {HTMLScriptElement | null}
  164. */
  165. currentScript: function () {
  166. if (typeof document === 'undefined') {
  167. return null;
  168. }
  169. if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
  170. return /** @type {any} */ (document.currentScript);
  171. }
  172. // IE11 workaround
  173. // we'll get the src of the current script by parsing IE11's error stack trace
  174. // this will not work for inline scripts
  175. try {
  176. throw new Error();
  177. } catch (err) {
  178. // Get file src url from stack. Specifically works with the format of stack traces in IE.
  179. // A stack will look like this:
  180. //
  181. // Error
  182. // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
  183. // at Global code (http://localhost/components/prism-core.js:606:1)
  184. var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
  185. if (src) {
  186. var scripts = document.getElementsByTagName('script');
  187. for (var i in scripts) {
  188. if (scripts[i].src == src) {
  189. return scripts[i];
  190. }
  191. }
  192. }
  193. return null;
  194. }
  195. },
  196. /**
  197. * Returns whether a given class is active for `element`.
  198. *
  199. * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
  200. * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
  201. * given class is just the given class with a `no-` prefix.
  202. *
  203. * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
  204. * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
  205. * ancestors have the given class or the negated version of it, then the default activation will be returned.
  206. *
  207. * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
  208. * version of it, the class is considered active.
  209. *
  210. * @param {Element} element
  211. * @param {string} className
  212. * @param {boolean} [defaultActivation=false]
  213. * @returns {boolean}
  214. */
  215. isActive: function (element, className, defaultActivation) {
  216. var no = 'no-' + className;
  217. while (element) {
  218. var classList = element.classList;
  219. if (classList.contains(className)) {
  220. return true;
  221. }
  222. if (classList.contains(no)) {
  223. return false;
  224. }
  225. element = element.parentElement;
  226. }
  227. return !!defaultActivation;
  228. }
  229. },
  230. /**
  231. * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
  232. *
  233. * @namespace
  234. * @memberof Prism
  235. * @public
  236. */
  237. languages: {
  238. /**
  239. * The grammar for plain, unformatted text.
  240. */
  241. plain: plainTextGrammar,
  242. plaintext: plainTextGrammar,
  243. text: plainTextGrammar,
  244. txt: plainTextGrammar,
  245. /**
  246. * Creates a deep copy of the language with the given id and appends the given tokens.
  247. *
  248. * If a token in `redef` also appears in the copied language, then the existing token in the copied language
  249. * will be overwritten at its original position.
  250. *
  251. * ## Best practices
  252. *
  253. * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
  254. * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
  255. * understand the language definition because, normally, the order of tokens matters in Prism grammars.
  256. *
  257. * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
  258. * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
  259. *
  260. * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
  261. * @param {Grammar} redef The new tokens to append.
  262. * @returns {Grammar} The new language created.
  263. * @public
  264. * @example
  265. * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
  266. * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
  267. * // at its original position
  268. * 'comment': { ... },
  269. * // CSS doesn't have a 'color' token, so this token will be appended
  270. * 'color': /\b(?:red|green|blue)\b/
  271. * });
  272. */
  273. extend: function (id, redef) {
  274. var lang = _.util.clone(_.languages[id]);
  275. for (var key in redef) {
  276. lang[key] = redef[key];
  277. }
  278. return lang;
  279. },
  280. /**
  281. * Inserts tokens _before_ another token in a language definition or any other grammar.
  282. *
  283. * ## Usage
  284. *
  285. * This helper method makes it easy to modify existing languages. For example, the CSS language definition
  286. * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
  287. * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
  288. * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
  289. * this:
  290. *
  291. * ```js
  292. * Prism.languages.markup.style = {
  293. * // token
  294. * };
  295. * ```
  296. *
  297. * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
  298. * before existing tokens. For the CSS example above, you would use it like this:
  299. *
  300. * ```js
  301. * Prism.languages.insertBefore('markup', 'cdata', {
  302. * 'style': {
  303. * // token
  304. * }
  305. * });
  306. * ```
  307. *
  308. * ## Special cases
  309. *
  310. * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
  311. * will be ignored.
  312. *
  313. * This behavior can be used to insert tokens after `before`:
  314. *
  315. * ```js
  316. * Prism.languages.insertBefore('markup', 'comment', {
  317. * 'comment': Prism.languages.markup.comment,
  318. * // tokens after 'comment'
  319. * });
  320. * ```
  321. *
  322. * ## Limitations
  323. *
  324. * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
  325. * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
  326. * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
  327. * deleting properties which is necessary to insert at arbitrary positions.
  328. *
  329. * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
  330. * Instead, it will create a new object and replace all references to the target object with the new one. This
  331. * can be done without temporarily deleting properties, so the iteration order is well-defined.
  332. *
  333. * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
  334. * you hold the target object in a variable, then the value of the variable will not change.
  335. *
  336. * ```js
  337. * var oldMarkup = Prism.languages.markup;
  338. * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
  339. *
  340. * assert(oldMarkup !== Prism.languages.markup);
  341. * assert(newMarkup === Prism.languages.markup);
  342. * ```
  343. *
  344. * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
  345. * object to be modified.
  346. * @param {string} before The key to insert before.
  347. * @param {Grammar} insert An object containing the key-value pairs to be inserted.
  348. * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
  349. * object to be modified.
  350. *
  351. * Defaults to `Prism.languages`.
  352. * @returns {Grammar} The new grammar object.
  353. * @public
  354. */
  355. insertBefore: function (inside, before, insert, root) {
  356. root = root || /** @type {any} */ (_.languages);
  357. var grammar = root[inside];
  358. /** @type {Grammar} */
  359. var ret = {};
  360. for (var token in grammar) {
  361. if (grammar.hasOwnProperty(token)) {
  362. if (token == before) {
  363. for (var newToken in insert) {
  364. if (insert.hasOwnProperty(newToken)) {
  365. ret[newToken] = insert[newToken];
  366. }
  367. }
  368. }
  369. // Do not insert token which also occur in insert. See #1525
  370. if (!insert.hasOwnProperty(token)) {
  371. ret[token] = grammar[token];
  372. }
  373. }
  374. }
  375. var old = root[inside];
  376. root[inside] = ret;
  377. // Update references in other language definitions
  378. _.languages.DFS(_.languages, function (key, value) {
  379. if (value === old && key != inside) {
  380. this[key] = ret;
  381. }
  382. });
  383. return ret;
  384. },
  385. // Traverse a language definition with Depth First Search
  386. DFS: function DFS(o, callback, type, visited) {
  387. visited = visited || {};
  388. var objId = _.util.objId;
  389. for (var i in o) {
  390. if (o.hasOwnProperty(i)) {
  391. callback.call(o, i, o[i], type || i);
  392. var property = o[i];
  393. var propertyType = _.util.type(property);
  394. if (propertyType === 'Object' && !visited[objId(property)]) {
  395. visited[objId(property)] = true;
  396. DFS(property, callback, null, visited);
  397. } else if (propertyType === 'Array' && !visited[objId(property)]) {
  398. visited[objId(property)] = true;
  399. DFS(property, callback, i, visited);
  400. }
  401. }
  402. }
  403. }
  404. },
  405. plugins: {},
  406. /**
  407. * This is the most high-level function in Prism’s API.
  408. * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
  409. * each one of them.
  410. *
  411. * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
  412. *
  413. * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
  414. * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
  415. * @memberof Prism
  416. * @public
  417. */
  418. highlightAll: function (async, callback) {
  419. _.highlightAllUnder(document, async, callback);
  420. },
  421. /**
  422. * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
  423. * {@link Prism.highlightElement} on each one of them.
  424. *
  425. * The following hooks will be run:
  426. * 1. `before-highlightall`
  427. * 2. `before-all-elements-highlight`
  428. * 3. All hooks of {@link Prism.highlightElement} for each element.
  429. *
  430. * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
  431. * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
  432. * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
  433. * @memberof Prism
  434. * @public
  435. */
  436. highlightAllUnder: function (container, async, callback) {
  437. var env = {
  438. callback: callback,
  439. container: container,
  440. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  441. };
  442. _.hooks.run('before-highlightall', env);
  443. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  444. _.hooks.run('before-all-elements-highlight', env);
  445. for (var i = 0, element; (element = env.elements[i++]);) {
  446. _.highlightElement(element, async === true, env.callback);
  447. }
  448. },
  449. /**
  450. * Highlights the code inside a single element.
  451. *
  452. * The following hooks will be run:
  453. * 1. `before-sanity-check`
  454. * 2. `before-highlight`
  455. * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
  456. * 4. `before-insert`
  457. * 5. `after-highlight`
  458. * 6. `complete`
  459. *
  460. * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
  461. * the element's language.
  462. *
  463. * @param {Element} element The element containing the code.
  464. * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
  465. * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
  466. * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
  467. * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
  468. *
  469. * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
  470. * asynchronous highlighting to work. You can build your own bundle on the
  471. * [Download page](https://prismjs.com/download.html).
  472. * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
  473. * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
  474. * @memberof Prism
  475. * @public
  476. */
  477. highlightElement: function (element, async, callback) {
  478. // Find language
  479. var language = _.util.getLanguage(element);
  480. var grammar = _.languages[language];
  481. // Set language on the element, if not present
  482. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  483. // Set language on the parent, for styling
  484. var parent = element.parentElement;
  485. if (parent && parent.nodeName.toLowerCase() === 'pre') {
  486. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  487. }
  488. var code = element.textContent;
  489. var env = {
  490. element: element,
  491. language: language,
  492. grammar: grammar,
  493. code: code
  494. };
  495. function insertHighlightedCode(highlightedCode) {
  496. env.highlightedCode = highlightedCode;
  497. _.hooks.run('before-insert', env);
  498. env.element.innerHTML = env.highlightedCode;
  499. _.hooks.run('after-highlight', env);
  500. _.hooks.run('complete', env);
  501. callback && callback.call(env.element);
  502. }
  503. _.hooks.run('before-sanity-check', env);
  504. // plugins may change/add the parent/element
  505. parent = env.element.parentElement;
  506. if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
  507. parent.setAttribute('tabindex', '0');
  508. }
  509. if (!env.code) {
  510. _.hooks.run('complete', env);
  511. callback && callback.call(env.element);
  512. return;
  513. }
  514. _.hooks.run('before-highlight', env);
  515. if (!env.grammar) {
  516. insertHighlightedCode(_.util.encode(env.code));
  517. return;
  518. }
  519. if (async && _self.Worker) {
  520. var worker = new Worker(_.filename);
  521. worker.onmessage = function (evt) {
  522. insertHighlightedCode(evt.data);
  523. };
  524. worker.postMessage(JSON.stringify({
  525. language: env.language,
  526. code: env.code,
  527. immediateClose: true
  528. }));
  529. } else {
  530. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  531. }
  532. },
  533. /**
  534. * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
  535. * and the language definitions to use, and returns a string with the HTML produced.
  536. *
  537. * The following hooks will be run:
  538. * 1. `before-tokenize`
  539. * 2. `after-tokenize`
  540. * 3. `wrap`: On each {@link Token}.
  541. *
  542. * @param {string} text A string with the code to be highlighted.
  543. * @param {Grammar} grammar An object containing the tokens to use.
  544. *
  545. * Usually a language definition like `Prism.languages.markup`.
  546. * @param {string} language The name of the language definition passed to `grammar`.
  547. * @returns {string} The highlighted HTML.
  548. * @memberof Prism
  549. * @public
  550. * @example
  551. * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
  552. */
  553. highlight: function (text, grammar, language) {
  554. var env = {
  555. code: text,
  556. grammar: grammar,
  557. language: language
  558. };
  559. _.hooks.run('before-tokenize', env);
  560. env.tokens = _.tokenize(env.code, env.grammar);
  561. _.hooks.run('after-tokenize', env);
  562. return Token.stringify(_.util.encode(env.tokens), env.language);
  563. },
  564. /**
  565. * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
  566. * and the language definitions to use, and returns an array with the tokenized code.
  567. *
  568. * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
  569. *
  570. * This method could be useful in other contexts as well, as a very crude parser.
  571. *
  572. * @param {string} text A string with the code to be highlighted.
  573. * @param {Grammar} grammar An object containing the tokens to use.
  574. *
  575. * Usually a language definition like `Prism.languages.markup`.
  576. * @returns {TokenStream} An array of strings and tokens, a token stream.
  577. * @memberof Prism
  578. * @public
  579. * @example
  580. * let code = `var foo = 0;`;
  581. * let tokens = Prism.tokenize(code, Prism.languages.javascript);
  582. * tokens.forEach(token => {
  583. * if (token instanceof Prism.Token && token.type === 'number') {
  584. * console.log(`Found numeric literal: ${token.content}`);
  585. * }
  586. * });
  587. */
  588. tokenize: function (text, grammar) {
  589. var rest = grammar.rest;
  590. if (rest) {
  591. for (var token in rest) {
  592. grammar[token] = rest[token];
  593. }
  594. delete grammar.rest;
  595. }
  596. var tokenList = new LinkedList();
  597. addAfter(tokenList, tokenList.head, text);
  598. matchGrammar(text, tokenList, grammar, tokenList.head, 0);
  599. return toArray(tokenList);
  600. },
  601. /**
  602. * @namespace
  603. * @memberof Prism
  604. * @public
  605. */
  606. hooks: {
  607. all: {},
  608. /**
  609. * Adds the given callback to the list of callbacks for the given hook.
  610. *
  611. * The callback will be invoked when the hook it is registered for is run.
  612. * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
  613. *
  614. * One callback function can be registered to multiple hooks and the same hook multiple times.
  615. *
  616. * @param {string} name The name of the hook.
  617. * @param {HookCallback} callback The callback function which is given environment variables.
  618. * @public
  619. */
  620. add: function (name, callback) {
  621. var hooks = _.hooks.all;
  622. hooks[name] = hooks[name] || [];
  623. hooks[name].push(callback);
  624. },
  625. /**
  626. * Runs a hook invoking all registered callbacks with the given environment variables.
  627. *
  628. * Callbacks will be invoked synchronously and in the order in which they were registered.
  629. *
  630. * @param {string} name The name of the hook.
  631. * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
  632. * @public
  633. */
  634. run: function (name, env) {
  635. var callbacks = _.hooks.all[name];
  636. if (!callbacks || !callbacks.length) {
  637. return;
  638. }
  639. for (var i = 0, callback; (callback = callbacks[i++]);) {
  640. callback(env);
  641. }
  642. }
  643. },
  644. Token: Token
  645. };
  646. _self.Prism = _;
  647. // Typescript note:
  648. // The following can be used to import the Token type in JSDoc:
  649. //
  650. // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
  651. /**
  652. * Creates a new token.
  653. *
  654. * @param {string} type See {@link Token#type type}
  655. * @param {string | TokenStream} content See {@link Token#content content}
  656. * @param {string|string[]} [alias] The alias(es) of the token.
  657. * @param {string} [matchedStr=""] A copy of the full string this token was created from.
  658. * @class
  659. * @global
  660. * @public
  661. */
  662. function Token(type, content, alias, matchedStr) {
  663. /**
  664. * The type of the token.
  665. *
  666. * This is usually the key of a pattern in a {@link Grammar}.
  667. *
  668. * @type {string}
  669. * @see GrammarToken
  670. * @public
  671. */
  672. this.type = type;
  673. /**
  674. * The strings or tokens contained by this token.
  675. *
  676. * This will be a token stream if the pattern matched also defined an `inside` grammar.
  677. *
  678. * @type {string | TokenStream}
  679. * @public
  680. */
  681. this.content = content;
  682. /**
  683. * The alias(es) of the token.
  684. *
  685. * @type {string|string[]}
  686. * @see GrammarToken
  687. * @public
  688. */
  689. this.alias = alias;
  690. // Copy of the full string this token was created from
  691. this.length = (matchedStr || '').length | 0;
  692. }
  693. /**
  694. * A token stream is an array of strings and {@link Token Token} objects.
  695. *
  696. * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
  697. * them.
  698. *
  699. * 1. No adjacent strings.
  700. * 2. No empty strings.
  701. *
  702. * The only exception here is the token stream that only contains the empty string and nothing else.
  703. *
  704. * @typedef {Array<string | Token>} TokenStream
  705. * @global
  706. * @public
  707. */
  708. /**
  709. * Converts the given token or token stream to an HTML representation.
  710. *
  711. * The following hooks will be run:
  712. * 1. `wrap`: On each {@link Token}.
  713. *
  714. * @param {string | Token | TokenStream} o The token or token stream to be converted.
  715. * @param {string} language The name of current language.
  716. * @returns {string} The HTML representation of the token or token stream.
  717. * @memberof Token
  718. * @static
  719. */
  720. Token.stringify = function stringify(o, language) {
  721. if (typeof o == 'string') {
  722. return o;
  723. }
  724. if (Array.isArray(o)) {
  725. var s = '';
  726. o.forEach(function (e) {
  727. s += stringify(e, language);
  728. });
  729. return s;
  730. }
  731. var env = {
  732. type: o.type,
  733. content: stringify(o.content, language),
  734. tag: 'span',
  735. classes: ['token', o.type],
  736. attributes: {},
  737. language: language
  738. };
  739. var aliases = o.alias;
  740. if (aliases) {
  741. if (Array.isArray(aliases)) {
  742. Array.prototype.push.apply(env.classes, aliases);
  743. } else {
  744. env.classes.push(aliases);
  745. }
  746. }
  747. _.hooks.run('wrap', env);
  748. var attributes = '';
  749. for (var name in env.attributes) {
  750. attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  751. }
  752. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
  753. };
  754. /**
  755. * @param {RegExp} pattern
  756. * @param {number} pos
  757. * @param {string} text
  758. * @param {boolean} lookbehind
  759. * @returns {RegExpExecArray | null}
  760. */
  761. function matchPattern(pattern, pos, text, lookbehind) {
  762. pattern.lastIndex = pos;
  763. var match = pattern.exec(text);
  764. if (match && lookbehind && match[1]) {
  765. // change the match to remove the text matched by the Prism lookbehind group
  766. var lookbehindLength = match[1].length;
  767. match.index += lookbehindLength;
  768. match[0] = match[0].slice(lookbehindLength);
  769. }
  770. return match;
  771. }
  772. /**
  773. * @param {string} text
  774. * @param {LinkedList<string | Token>} tokenList
  775. * @param {any} grammar
  776. * @param {LinkedListNode<string | Token>} startNode
  777. * @param {number} startPos
  778. * @param {RematchOptions} [rematch]
  779. * @returns {void}
  780. * @private
  781. *
  782. * @typedef RematchOptions
  783. * @property {string} cause
  784. * @property {number} reach
  785. */
  786. function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
  787. for (var token in grammar) {
  788. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  789. continue;
  790. }
  791. var patterns = grammar[token];
  792. patterns = Array.isArray(patterns) ? patterns : [patterns];
  793. for (var j = 0; j < patterns.length; ++j) {
  794. if (rematch && rematch.cause == token + ',' + j) {
  795. return;
  796. }
  797. var patternObj = patterns[j];
  798. var inside = patternObj.inside;
  799. var lookbehind = !!patternObj.lookbehind;
  800. var greedy = !!patternObj.greedy;
  801. var alias = patternObj.alias;
  802. if (greedy && !patternObj.pattern.global) {
  803. // Without the global flag, lastIndex won't work
  804. var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
  805. patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
  806. }
  807. /** @type {RegExp} */
  808. var pattern = patternObj.pattern || patternObj;
  809. for ( // iterate the token list and keep track of the current token/string position
  810. var currentNode = startNode.next, pos = startPos;
  811. currentNode !== tokenList.tail;
  812. pos += currentNode.value.length, currentNode = currentNode.next
  813. ) {
  814. if (rematch && pos >= rematch.reach) {
  815. break;
  816. }
  817. var str = currentNode.value;
  818. if (tokenList.length > text.length) {
  819. // Something went terribly wrong, ABORT, ABORT!
  820. return;
  821. }
  822. if (str instanceof Token) {
  823. continue;
  824. }
  825. var removeCount = 1; // this is the to parameter of removeBetween
  826. var match;
  827. if (greedy) {
  828. match = matchPattern(pattern, pos, text, lookbehind);
  829. if (!match) {
  830. break;
  831. }
  832. var from = match.index;
  833. var to = match.index + match[0].length;
  834. var p = pos;
  835. // find the node that contains the match
  836. p += currentNode.value.length;
  837. while (from >= p) {
  838. currentNode = currentNode.next;
  839. p += currentNode.value.length;
  840. }
  841. // adjust pos (and p)
  842. p -= currentNode.value.length;
  843. pos = p;
  844. // the current node is a Token, then the match starts inside another Token, which is invalid
  845. if (currentNode.value instanceof Token) {
  846. continue;
  847. }
  848. // find the last node which is affected by this match
  849. for (
  850. var k = currentNode;
  851. k !== tokenList.tail && (p < to || typeof k.value === 'string');
  852. k = k.next
  853. ) {
  854. removeCount++;
  855. p += k.value.length;
  856. }
  857. removeCount--;
  858. // replace with the new match
  859. str = text.slice(pos, p);
  860. match.index -= pos;
  861. } else {
  862. match = matchPattern(pattern, 0, str, lookbehind);
  863. if (!match) {
  864. continue;
  865. }
  866. }
  867. // eslint-disable-next-line no-redeclare
  868. var from = match.index;
  869. var matchStr = match[0];
  870. var before = str.slice(0, from);
  871. var after = str.slice(from + matchStr.length);
  872. var reach = pos + str.length;
  873. if (rematch && reach > rematch.reach) {
  874. rematch.reach = reach;
  875. }
  876. var removeFrom = currentNode.prev;
  877. if (before) {
  878. removeFrom = addAfter(tokenList, removeFrom, before);
  879. pos += before.length;
  880. }
  881. removeRange(tokenList, removeFrom, removeCount);
  882. var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
  883. currentNode = addAfter(tokenList, removeFrom, wrapped);
  884. if (after) {
  885. addAfter(tokenList, currentNode, after);
  886. }
  887. if (removeCount > 1) {
  888. // at least one Token object was removed, so we have to do some rematching
  889. // this can only happen if the current pattern is greedy
  890. /** @type {RematchOptions} */
  891. var nestedRematch = {
  892. cause: token + ',' + j,
  893. reach: reach
  894. };
  895. matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
  896. // the reach might have been extended because of the rematching
  897. if (rematch && nestedRematch.reach > rematch.reach) {
  898. rematch.reach = nestedRematch.reach;
  899. }
  900. }
  901. }
  902. }
  903. }
  904. }
  905. /**
  906. * @typedef LinkedListNode
  907. * @property {T} value
  908. * @property {LinkedListNode<T> | null} prev The previous node.
  909. * @property {LinkedListNode<T> | null} next The next node.
  910. * @template T
  911. * @private
  912. */
  913. /**
  914. * @template T
  915. * @private
  916. */
  917. function LinkedList() {
  918. /** @type {LinkedListNode<T>} */
  919. var head = { value: null, prev: null, next: null };
  920. /** @type {LinkedListNode<T>} */
  921. var tail = { value: null, prev: head, next: null };
  922. head.next = tail;
  923. /** @type {LinkedListNode<T>} */
  924. this.head = head;
  925. /** @type {LinkedListNode<T>} */
  926. this.tail = tail;
  927. this.length = 0;
  928. }
  929. /**
  930. * Adds a new node with the given value to the list.
  931. *
  932. * @param {LinkedList<T>} list
  933. * @param {LinkedListNode<T>} node
  934. * @param {T} value
  935. * @returns {LinkedListNode<T>} The added node.
  936. * @template T
  937. */
  938. function addAfter(list, node, value) {
  939. // assumes that node != list.tail && values.length >= 0
  940. var next = node.next;
  941. var newNode = { value: value, prev: node, next: next };
  942. node.next = newNode;
  943. next.prev = newNode;
  944. list.length++;
  945. return newNode;
  946. }
  947. /**
  948. * Removes `count` nodes after the given node. The given node will not be removed.
  949. *
  950. * @param {LinkedList<T>} list
  951. * @param {LinkedListNode<T>} node
  952. * @param {number} count
  953. * @template T
  954. */
  955. function removeRange(list, node, count) {
  956. var next = node.next;
  957. for (var i = 0; i < count && next !== list.tail; i++) {
  958. next = next.next;
  959. }
  960. node.next = next;
  961. next.prev = node;
  962. list.length -= i;
  963. }
  964. /**
  965. * @param {LinkedList<T>} list
  966. * @returns {T[]}
  967. * @template T
  968. */
  969. function toArray(list) {
  970. var array = [];
  971. var node = list.head.next;
  972. while (node !== list.tail) {
  973. array.push(node.value);
  974. node = node.next;
  975. }
  976. return array;
  977. }
  978. if (!_self.document) {
  979. if (!_self.addEventListener) {
  980. // in Node.js
  981. return _;
  982. }
  983. if (!_.disableWorkerMessageHandler) {
  984. // In worker
  985. _self.addEventListener('message', function (evt) {
  986. var message = JSON.parse(evt.data);
  987. var lang = message.language;
  988. var code = message.code;
  989. var immediateClose = message.immediateClose;
  990. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  991. if (immediateClose) {
  992. _self.close();
  993. }
  994. }, false);
  995. }
  996. return _;
  997. }
  998. // Get current script and highlight
  999. var script = _.util.currentScript();
  1000. if (script) {
  1001. _.filename = script.src;
  1002. if (script.hasAttribute('data-manual')) {
  1003. _.manual = true;
  1004. }
  1005. }
  1006. function highlightAutomaticallyCallback() {
  1007. if (!_.manual) {
  1008. _.highlightAll();
  1009. }
  1010. }
  1011. if (!_.manual) {
  1012. // If the document state is "loading", then we'll use DOMContentLoaded.
  1013. // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
  1014. // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
  1015. // might take longer one animation frame to execute which can create a race condition where only some plugins have
  1016. // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
  1017. // See https://github.com/PrismJS/prism/issues/2102
  1018. var readyState = document.readyState;
  1019. if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
  1020. document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
  1021. } else {
  1022. if (window.requestAnimationFrame) {
  1023. window.requestAnimationFrame(highlightAutomaticallyCallback);
  1024. } else {
  1025. window.setTimeout(highlightAutomaticallyCallback, 16);
  1026. }
  1027. }
  1028. }
  1029. return _;
  1030. }(_self));
  1031. if (typeof module !== 'undefined' && module.exports) {
  1032. module.exports = Prism;
  1033. }
  1034. // hack for components to work correctly in node.js
  1035. if (typeof global !== 'undefined') {
  1036. global.Prism = Prism;
  1037. }
  1038. // some additional documentation/types
  1039. /**
  1040. * The expansion of a simple `RegExp` literal to support additional properties.
  1041. *
  1042. * @typedef GrammarToken
  1043. * @property {RegExp} pattern The regular expression of the token.
  1044. * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
  1045. * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
  1046. * @property {boolean} [greedy=false] Whether the token is greedy.
  1047. * @property {string|string[]} [alias] An optional alias or list of aliases.
  1048. * @property {Grammar} [inside] The nested grammar of this token.
  1049. *
  1050. * The `inside` grammar will be used to tokenize the text value of each token of this kind.
  1051. *
  1052. * This can be used to make nested and even recursive language definitions.
  1053. *
  1054. * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
  1055. * each another.
  1056. * @global
  1057. * @public
  1058. */
  1059. /**
  1060. * @typedef Grammar
  1061. * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
  1062. * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
  1063. * @global
  1064. * @public
  1065. */
  1066. /**
  1067. * A function which will invoked after an element was successfully highlighted.
  1068. *
  1069. * @callback HighlightCallback
  1070. * @param {Element} element The element successfully highlighted.
  1071. * @returns {void}
  1072. * @global
  1073. * @public
  1074. */
  1075. /**
  1076. * @callback HookCallback
  1077. * @param {Object<string, any>} env The environment variables of the hook.
  1078. * @returns {void}
  1079. * @global
  1080. * @public
  1081. */
  1082. ;
  1083. Prism.languages.markup = {
  1084. 'comment': /<!--[\s\S]*?-->/,
  1085. 'prolog': /<\?[\s\S]+?\?>/,
  1086. 'doctype': {
  1087. // https://www.w3.org/TR/xml/#NT-doctypedecl
  1088. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
  1089. greedy: true,
  1090. inside: {
  1091. 'internal-subset': {
  1092. pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
  1093. lookbehind: true,
  1094. greedy: true,
  1095. inside: null // see below
  1096. },
  1097. 'string': {
  1098. pattern: /"[^"]*"|'[^']*'/,
  1099. greedy: true
  1100. },
  1101. 'punctuation': /^<!|>$|[[\]]/,
  1102. 'doctype-tag': /^DOCTYPE/,
  1103. 'name': /[^\s<>'"]+/
  1104. }
  1105. },
  1106. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  1107. 'tag': {
  1108. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
  1109. greedy: true,
  1110. inside: {
  1111. 'tag': {
  1112. pattern: /^<\/?[^\s>\/]+/,
  1113. inside: {
  1114. 'punctuation': /^<\/?/,
  1115. 'namespace': /^[^\s>\/:]+:/
  1116. }
  1117. },
  1118. 'special-attr': [],
  1119. 'attr-value': {
  1120. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
  1121. inside: {
  1122. 'punctuation': [
  1123. {
  1124. pattern: /^=/,
  1125. alias: 'attr-equals'
  1126. },
  1127. /"|'/
  1128. ]
  1129. }
  1130. },
  1131. 'punctuation': /\/?>/,
  1132. 'attr-name': {
  1133. pattern: /[^\s>\/]+/,
  1134. inside: {
  1135. 'namespace': /^[^\s>\/:]+:/
  1136. }
  1137. }
  1138. }
  1139. },
  1140. 'entity': [
  1141. {
  1142. pattern: /&[\da-z]{1,8};/i,
  1143. alias: 'named-entity'
  1144. },
  1145. /&#x?[\da-f]{1,8};/i
  1146. ]
  1147. };
  1148. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
  1149. Prism.languages.markup['entity'];
  1150. Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
  1151. // Plugin to make entity title show the real entity, idea by Roman Komarov
  1152. Prism.hooks.add('wrap', function (env) {
  1153. if (env.type === 'entity') {
  1154. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  1155. }
  1156. });
  1157. Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
  1158. /**
  1159. * Adds an inlined language to markup.
  1160. *
  1161. * An example of an inlined language is CSS with `<style>` tags.
  1162. *
  1163. * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
  1164. * case insensitive.
  1165. * @param {string} lang The language key.
  1166. * @example
  1167. * addInlined('style', 'css');
  1168. */
  1169. value: function addInlined(tagName, lang) {
  1170. var includedCdataInside = {};
  1171. includedCdataInside['language-' + lang] = {
  1172. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  1173. lookbehind: true,
  1174. inside: Prism.languages[lang]
  1175. };
  1176. includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
  1177. var inside = {
  1178. 'included-cdata': {
  1179. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1180. inside: includedCdataInside
  1181. }
  1182. };
  1183. inside['language-' + lang] = {
  1184. pattern: /[\s\S]+/,
  1185. inside: Prism.languages[lang]
  1186. };
  1187. var def = {};
  1188. def[tagName] = {
  1189. pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
  1190. lookbehind: true,
  1191. greedy: true,
  1192. inside: inside
  1193. };
  1194. Prism.languages.insertBefore('markup', 'cdata', def);
  1195. }
  1196. });
  1197. Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
  1198. /**
  1199. * Adds an pattern to highlight languages embedded in HTML attributes.
  1200. *
  1201. * An example of an inlined language is CSS with `style` attributes.
  1202. *
  1203. * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
  1204. * case insensitive.
  1205. * @param {string} lang The language key.
  1206. * @example
  1207. * addAttribute('style', 'css');
  1208. */
  1209. value: function (attrName, lang) {
  1210. Prism.languages.markup.tag.inside['special-attr'].push({
  1211. pattern: RegExp(
  1212. /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
  1213. 'i'
  1214. ),
  1215. lookbehind: true,
  1216. inside: {
  1217. 'attr-name': /^[^\s=]+/,
  1218. 'attr-value': {
  1219. pattern: /=[\s\S]+/,
  1220. inside: {
  1221. 'value': {
  1222. pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
  1223. lookbehind: true,
  1224. alias: [lang, 'language-' + lang],
  1225. inside: Prism.languages[lang]
  1226. },
  1227. 'punctuation': [
  1228. {
  1229. pattern: /^=/,
  1230. alias: 'attr-equals'
  1231. },
  1232. /"|'/
  1233. ]
  1234. }
  1235. }
  1236. }
  1237. });
  1238. }
  1239. });
  1240. Prism.languages.html = Prism.languages.markup;
  1241. Prism.languages.mathml = Prism.languages.markup;
  1242. Prism.languages.svg = Prism.languages.markup;
  1243. Prism.languages.xml = Prism.languages.extend('markup', {});
  1244. Prism.languages.ssml = Prism.languages.xml;
  1245. Prism.languages.atom = Prism.languages.xml;
  1246. Prism.languages.rss = Prism.languages.xml;
  1247. (function (Prism) {
  1248. var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
  1249. Prism.languages.css = {
  1250. 'comment': /\/\*[\s\S]*?\*\//,
  1251. 'atrule': {
  1252. pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
  1253. inside: {
  1254. 'rule': /^@[\w-]+/,
  1255. 'selector-function-argument': {
  1256. pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
  1257. lookbehind: true,
  1258. alias: 'selector'
  1259. },
  1260. 'keyword': {
  1261. pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
  1262. lookbehind: true
  1263. }
  1264. // See rest below
  1265. }
  1266. },
  1267. 'url': {
  1268. // https://drafts.csswg.org/css-values-3/#urls
  1269. pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
  1270. greedy: true,
  1271. inside: {
  1272. 'function': /^url/i,
  1273. 'punctuation': /^\(|\)$/,
  1274. 'string': {
  1275. pattern: RegExp('^' + string.source + '$'),
  1276. alias: 'url'
  1277. }
  1278. }
  1279. },
  1280. 'selector': {
  1281. pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
  1282. lookbehind: true
  1283. },
  1284. 'string': {
  1285. pattern: string,
  1286. greedy: true
  1287. },
  1288. 'property': {
  1289. pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
  1290. lookbehind: true
  1291. },
  1292. 'important': /!important\b/i,
  1293. 'function': {
  1294. pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
  1295. lookbehind: true
  1296. },
  1297. 'punctuation': /[(){};:,]/
  1298. };
  1299. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  1300. var markup = Prism.languages.markup;
  1301. if (markup) {
  1302. markup.tag.addInlined('style', 'css');
  1303. markup.tag.addAttribute('style', 'css');
  1304. }
  1305. }(Prism));
  1306. Prism.languages.clike = {
  1307. 'comment': [
  1308. {
  1309. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  1310. lookbehind: true,
  1311. greedy: true
  1312. },
  1313. {
  1314. pattern: /(^|[^\\:])\/\/.*/,
  1315. lookbehind: true,
  1316. greedy: true
  1317. }
  1318. ],
  1319. 'string': {
  1320. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  1321. greedy: true
  1322. },
  1323. 'class-name': {
  1324. pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
  1325. lookbehind: true,
  1326. inside: {
  1327. 'punctuation': /[.\\]/
  1328. }
  1329. },
  1330. 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  1331. 'boolean': /\b(?:true|false)\b/,
  1332. 'function': /\b\w+(?=\()/,
  1333. 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
  1334. 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  1335. 'punctuation': /[{}[\];(),.:]/
  1336. };
  1337. Prism.languages.javascript = Prism.languages.extend('clike', {
  1338. 'class-name': [
  1339. Prism.languages.clike['class-name'],
  1340. {
  1341. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:prototype|constructor))/,
  1342. lookbehind: true
  1343. }
  1344. ],
  1345. 'keyword': [
  1346. {
  1347. pattern: /((?:^|})\s*)catch\b/,
  1348. lookbehind: true
  1349. },
  1350. {
  1351. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|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/,
  1352. lookbehind: true
  1353. },
  1354. ],
  1355. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  1356. 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  1357. 'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
  1358. 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
  1359. });
  1360. Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
  1361. Prism.languages.insertBefore('javascript', 'keyword', {
  1362. 'regex': {
  1363. pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
  1364. lookbehind: true,
  1365. greedy: true,
  1366. inside: {
  1367. 'regex-source': {
  1368. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  1369. lookbehind: true,
  1370. alias: 'language-regex',
  1371. inside: Prism.languages.regex
  1372. },
  1373. 'regex-delimiter': /^\/|\/$/,
  1374. 'regex-flags': /^[a-z]+$/,
  1375. }
  1376. },
  1377. // This must be declared before keyword because we use "function" inside the look-forward
  1378. 'function-variable': {
  1379. 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*=>))/,
  1380. alias: 'function'
  1381. },
  1382. 'parameter': [
  1383. {
  1384. pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
  1385. lookbehind: true,
  1386. inside: Prism.languages.javascript
  1387. },
  1388. {
  1389. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
  1390. lookbehind: true,
  1391. inside: Prism.languages.javascript
  1392. },
  1393. {
  1394. pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
  1395. lookbehind: true,
  1396. inside: Prism.languages.javascript
  1397. },
  1398. {
  1399. 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*\{)/,
  1400. lookbehind: true,
  1401. inside: Prism.languages.javascript
  1402. }
  1403. ],
  1404. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  1405. });
  1406. Prism.languages.insertBefore('javascript', 'string', {
  1407. 'hashbang': {
  1408. pattern: /^#!.*/,
  1409. greedy: true,
  1410. alias: 'comment'
  1411. },
  1412. 'template-string': {
  1413. pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
  1414. greedy: true,
  1415. inside: {
  1416. 'template-punctuation': {
  1417. pattern: /^`|`$/,
  1418. alias: 'string'
  1419. },
  1420. 'interpolation': {
  1421. pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
  1422. lookbehind: true,
  1423. inside: {
  1424. 'interpolation-punctuation': {
  1425. pattern: /^\${|}$/,
  1426. alias: 'punctuation'
  1427. },
  1428. rest: Prism.languages.javascript
  1429. }
  1430. },
  1431. 'string': /[\s\S]+/
  1432. }
  1433. }
  1434. });
  1435. if (Prism.languages.markup) {
  1436. Prism.languages.markup.tag.addInlined('script', 'javascript');
  1437. // add attribute support for all DOM events.
  1438. // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
  1439. Prism.languages.markup.tag.addAttribute(
  1440. /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,
  1441. 'javascript'
  1442. );
  1443. }
  1444. Prism.languages.js = Prism.languages.javascript;
  1445. (function (Prism) {
  1446. // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
  1447. // + LC_ALL, RANDOM, REPLY, SECONDS.
  1448. // + make sure PS1..4 are here as they are not always set,
  1449. // - some useless things.
  1450. var envVars = '\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b';
  1451. var commandAfterHeredoc = {
  1452. pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
  1453. lookbehind: true,
  1454. alias: 'punctuation', // this looks reasonably well in all themes
  1455. inside: null // see below
  1456. };
  1457. var insideString = {
  1458. 'bash': commandAfterHeredoc,
  1459. 'environment': {
  1460. pattern: RegExp('\\$' + envVars),
  1461. alias: 'constant'
  1462. },
  1463. 'variable': [
  1464. // [0]: Arithmetic Environment
  1465. {
  1466. pattern: /\$?\(\([\s\S]+?\)\)/,
  1467. greedy: true,
  1468. inside: {
  1469. // If there is a $ sign at the beginning highlight $(( and )) as variable
  1470. 'variable': [
  1471. {
  1472. pattern: /(^\$\(\([\s\S]+)\)\)/,
  1473. lookbehind: true
  1474. },
  1475. /^\$\(\(/
  1476. ],
  1477. 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
  1478. // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
  1479. 'operator': /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
  1480. // If there is no $ sign at the beginning highlight (( and )) as punctuation
  1481. 'punctuation': /\(\(?|\)\)?|,|;/
  1482. }
  1483. },
  1484. // [1]: Command Substitution
  1485. {
  1486. pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
  1487. greedy: true,
  1488. inside: {
  1489. 'variable': /^\$\(|^`|\)$|`$/
  1490. }
  1491. },
  1492. // [2]: Brace expansion
  1493. {
  1494. pattern: /\$\{[^}]+\}/,
  1495. greedy: true,
  1496. inside: {
  1497. 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
  1498. 'punctuation': /[\[\]]/,
  1499. 'environment': {
  1500. pattern: RegExp('(\\{)' + envVars),
  1501. lookbehind: true,
  1502. alias: 'constant'
  1503. }
  1504. }
  1505. },
  1506. /\$(?:\w+|[#?*!@$])/
  1507. ],
  1508. // Escape sequences from echo and printf's manuals, and escaped quotes.
  1509. 'entity': /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})/
  1510. };
  1511. Prism.languages.bash = {
  1512. 'shebang': {
  1513. pattern: /^#!\s*\/.*/,
  1514. alias: 'important'
  1515. },
  1516. 'comment': {
  1517. pattern: /(^|[^"{\\$])#.*/,
  1518. lookbehind: true
  1519. },
  1520. 'function-name': [
  1521. // a) function foo {
  1522. // b) foo() {
  1523. // c) function foo() {
  1524. // but not “foo {”
  1525. {
  1526. // a) and c)
  1527. pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
  1528. lookbehind: true,
  1529. alias: 'function'
  1530. },
  1531. {
  1532. // b)
  1533. pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/,
  1534. alias: 'function'
  1535. }
  1536. ],
  1537. // Highlight variable names as variables in for and select beginnings.
  1538. 'for-or-select': {
  1539. pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
  1540. alias: 'variable',
  1541. lookbehind: true
  1542. },
  1543. // Highlight variable names as variables in the left-hand part
  1544. // of assignments (“=” and “+=”).
  1545. 'assign-left': {
  1546. pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
  1547. inside: {
  1548. 'environment': {
  1549. pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars),
  1550. lookbehind: true,
  1551. alias: 'constant'
  1552. }
  1553. },
  1554. alias: 'variable',
  1555. lookbehind: true
  1556. },
  1557. 'string': [
  1558. // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
  1559. {
  1560. pattern: /((?:^|[^<])<<-?\s*)(\w+?)\s[\s\S]*?(?:\r?\n|\r)\2/,
  1561. lookbehind: true,
  1562. greedy: true,
  1563. inside: insideString
  1564. },
  1565. // Here-document with quotes around the tag
  1566. // → No expansion (so no “inside”).
  1567. {
  1568. pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
  1569. lookbehind: true,
  1570. greedy: true,
  1571. inside: {
  1572. 'bash': commandAfterHeredoc
  1573. }
  1574. },
  1575. // “Normal” string
  1576. {
  1577. // https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
  1578. pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
  1579. lookbehind: true,
  1580. greedy: true,
  1581. inside: insideString
  1582. },
  1583. {
  1584. // https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html
  1585. pattern: /(^|[^$\\])'[^']*'/,
  1586. lookbehind: true,
  1587. greedy: true
  1588. },
  1589. {
  1590. // https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
  1591. pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
  1592. greedy: true,
  1593. inside: {
  1594. 'entity': insideString.entity
  1595. }
  1596. }
  1597. ],
  1598. 'environment': {
  1599. pattern: RegExp('\\$?' + envVars),
  1600. alias: 'constant'
  1601. },
  1602. 'variable': insideString.variable,
  1603. 'function': {
  1604. pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|aptitude|apt-cache|apt-get|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,
  1605. lookbehind: true
  1606. },
  1607. 'keyword': {
  1608. pattern: /(^|[\s;|&]|[<>]\()(?:if|then|else|elif|fi|for|while|in|case|esac|function|select|do|done|until)(?=$|[)\s;|&])/,
  1609. lookbehind: true
  1610. },
  1611. // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
  1612. 'builtin': {
  1613. pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|break|cd|continue|eval|exec|exit|export|getopts|hash|pwd|readonly|return|shift|test|times|trap|umask|unset|alias|bind|builtin|caller|command|declare|echo|enable|help|let|local|logout|mapfile|printf|read|readarray|source|type|typeset|ulimit|unalias|set|shopt)(?=$|[)\s;|&])/,
  1614. lookbehind: true,
  1615. // Alias added to make those easier to distinguish from strings.
  1616. alias: 'class-name'
  1617. },
  1618. 'boolean': {
  1619. pattern: /(^|[\s;|&]|[<>]\()(?:true|false)(?=$|[)\s;|&])/,
  1620. lookbehind: true
  1621. },
  1622. 'file-descriptor': {
  1623. pattern: /\B&\d\b/,
  1624. alias: 'important'
  1625. },
  1626. 'operator': {
  1627. // Lots of redirections here, but not just that.
  1628. pattern: /\d?<>|>\||\+=|==?|!=?|=~|<<[<-]?|[&\d]?>>|\d?[<>]&?|&[>&]?|\|[&|]?|<=?|>=?/,
  1629. inside: {
  1630. 'file-descriptor': {
  1631. pattern: /^\d/,
  1632. alias: 'important'
  1633. }
  1634. }
  1635. },
  1636. 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
  1637. 'number': {
  1638. pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
  1639. lookbehind: true
  1640. }
  1641. };
  1642. commandAfterHeredoc.inside = Prism.languages.bash;
  1643. /* Patterns in command substitution. */
  1644. var toBeCopied = [
  1645. 'comment',
  1646. 'function-name',
  1647. 'for-or-select',
  1648. 'assign-left',
  1649. 'string',
  1650. 'environment',
  1651. 'function',
  1652. 'keyword',
  1653. 'builtin',
  1654. 'boolean',
  1655. 'file-descriptor',
  1656. 'operator',
  1657. 'punctuation',
  1658. 'number'
  1659. ];
  1660. var inside = insideString.variable[1].inside;
  1661. for (var i = 0; i < toBeCopied.length; i++) {
  1662. inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
  1663. }
  1664. Prism.languages.shell = Prism.languages.bash;
  1665. }(Prism));
  1666. Prism.languages.c = Prism.languages.extend('clike', {
  1667. 'comment': {
  1668. pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
  1669. greedy: true
  1670. },
  1671. 'class-name': {
  1672. pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
  1673. lookbehind: true
  1674. },
  1675. 'keyword': /\b(?:__attribute__|_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/,
  1676. 'function': /\b[a-z_]\w*(?=\s*\()/i,
  1677. 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
  1678. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
  1679. });
  1680. Prism.languages.insertBefore('c', 'string', {
  1681. 'macro': {
  1682. // allow for multiline macro definitions
  1683. // spaces after the # character compile fine with gcc
  1684. pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
  1685. lookbehind: true,
  1686. greedy: true,
  1687. alias: 'property',
  1688. inside: {
  1689. 'string': [
  1690. {
  1691. // highlight the path of the include statement as a string
  1692. pattern: /^(#\s*include\s*)<[^>]+>/,
  1693. lookbehind: true
  1694. },
  1695. Prism.languages.c['string']
  1696. ],
  1697. 'comment': Prism.languages.c['comment'],
  1698. 'macro-name': [
  1699. {
  1700. pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
  1701. lookbehind: true
  1702. },
  1703. {
  1704. pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
  1705. lookbehind: true,
  1706. alias: 'function'
  1707. }
  1708. ],
  1709. // highlight macro directives as keywords
  1710. 'directive': {
  1711. pattern: /^(#\s*)[a-z]+/,
  1712. lookbehind: true,
  1713. alias: 'keyword'
  1714. },
  1715. 'directive-hash': /^#/,
  1716. 'punctuation': /##|\\(?=[\r\n])/,
  1717. 'expression': {
  1718. pattern: /\S[\s\S]*/,
  1719. inside: Prism.languages.c
  1720. }
  1721. }
  1722. },
  1723. // highlight predefined macros as constants
  1724. 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
  1725. });
  1726. delete Prism.languages.c['boolean'];
  1727. (function (Prism) {
  1728. var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|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/;
  1729. var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; });
  1730. Prism.languages.cpp = Prism.languages.extend('c', {
  1731. 'class-name': [
  1732. {
  1733. pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
  1734. .replace(/<keyword>/g, function () { return keyword.source; })),
  1735. lookbehind: true
  1736. },
  1737. // This is intended to capture the class name of method implementations like:
  1738. // void foo::bar() const {}
  1739. // However! The `foo` in the above example could also be a namespace, so we only capture the class name if
  1740. // it starts with an uppercase letter. This approximation should give decent results.
  1741. /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
  1742. // This will capture the class name before destructors like:
  1743. // Foo::~Foo() {}
  1744. /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
  1745. // This also intends to capture the class name of method implementations but here the class has template
  1746. // parameters, so it can't be a namespace (until C++ adds generic namespaces).
  1747. /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
  1748. ],
  1749. 'keyword': keyword,
  1750. 'number': {
  1751. pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
  1752. greedy: true
  1753. },
  1754. 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
  1755. 'boolean': /\b(?:true|false)\b/
  1756. });
  1757. Prism.languages.insertBefore('cpp', 'string', {
  1758. 'module': {
  1759. // https://en.cppreference.com/w/cpp/language/modules
  1760. pattern: RegExp(
  1761. /(\b(?:module|import)\s+)/.source +
  1762. '(?:' +
  1763. // header-name
  1764. /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
  1765. '|' +
  1766. // module name or partition or both
  1767. /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) +
  1768. ')'
  1769. ),
  1770. lookbehind: true,
  1771. greedy: true,
  1772. inside: {
  1773. 'string': /^[<"][\s\S]+/,
  1774. 'operator': /:/,
  1775. 'punctuation': /\./
  1776. }
  1777. },
  1778. 'raw-string': {
  1779. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  1780. alias: 'string',
  1781. greedy: true
  1782. }
  1783. });
  1784. Prism.languages.insertBefore('cpp', 'keyword', {
  1785. 'generic-function': {
  1786. pattern: /\b[a-z_]\w*\s*<(?:[^<>]|<(?:[^<>])*>)*>(?=\s*\()/i,
  1787. inside: {
  1788. 'function': /^\w+/,
  1789. 'generic': {
  1790. pattern: /<[\s\S]+/,
  1791. alias: 'class-name',
  1792. inside: Prism.languages.cpp
  1793. }
  1794. }
  1795. }
  1796. });
  1797. Prism.languages.insertBefore('cpp', 'operator', {
  1798. 'double-colon': {
  1799. pattern: /::/,
  1800. alias: 'punctuation'
  1801. }
  1802. });
  1803. Prism.languages.insertBefore('cpp', 'class-name', {
  1804. // the base clause is an optional list of parent classes
  1805. // https://en.cppreference.com/w/cpp/language/class
  1806. 'base-clause': {
  1807. pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
  1808. lookbehind: true,
  1809. greedy: true,
  1810. inside: Prism.languages.extend('cpp', {})
  1811. }
  1812. });
  1813. Prism.languages.insertBefore('inside', 'double-colon', {
  1814. // All untokenized words that are not namespaces should be class names
  1815. 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i
  1816. }, Prism.languages.cpp['base-clause']);
  1817. }(Prism));
  1818. (function (Prism) {
  1819. // Ignore comments starting with { to privilege string interpolation highlighting
  1820. var comment = /#(?!\{).+/;
  1821. var interpolation = {
  1822. pattern: /#\{[^}]+\}/,
  1823. alias: 'variable'
  1824. };
  1825. Prism.languages.coffeescript = Prism.languages.extend('javascript', {
  1826. 'comment': comment,
  1827. 'string': [
  1828. // Strings are multiline
  1829. {
  1830. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1831. greedy: true
  1832. },
  1833. {
  1834. // Strings are multiline
  1835. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1836. greedy: true,
  1837. inside: {
  1838. 'interpolation': interpolation
  1839. }
  1840. }
  1841. ],
  1842. 'keyword': /\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,
  1843. 'class-member': {
  1844. pattern: /@(?!\d)\w+/,
  1845. alias: 'variable'
  1846. }
  1847. });
  1848. Prism.languages.insertBefore('coffeescript', 'comment', {
  1849. 'multiline-comment': {
  1850. pattern: /###[\s\S]+?###/,
  1851. alias: 'comment'
  1852. },
  1853. // Block regexp can contain comments and interpolation
  1854. 'block-regex': {
  1855. pattern: /\/{3}[\s\S]*?\/{3}/,
  1856. alias: 'regex',
  1857. inside: {
  1858. 'comment': comment,
  1859. 'interpolation': interpolation
  1860. }
  1861. }
  1862. });
  1863. Prism.languages.insertBefore('coffeescript', 'string', {
  1864. 'inline-javascript': {
  1865. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  1866. inside: {
  1867. 'delimiter': {
  1868. pattern: /^`|`$/,
  1869. alias: 'punctuation'
  1870. },
  1871. 'script': {
  1872. pattern: /[\s\S]+/,
  1873. alias: 'language-javascript',
  1874. inside: Prism.languages.javascript
  1875. }
  1876. }
  1877. },
  1878. // Block strings
  1879. 'multiline-string': [
  1880. {
  1881. pattern: /'''[\s\S]*?'''/,
  1882. greedy: true,
  1883. alias: 'string'
  1884. },
  1885. {
  1886. pattern: /"""[\s\S]*?"""/,
  1887. greedy: true,
  1888. alias: 'string',
  1889. inside: {
  1890. interpolation: interpolation
  1891. }
  1892. }
  1893. ]
  1894. });
  1895. Prism.languages.insertBefore('coffeescript', 'keyword', {
  1896. // Object property
  1897. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  1898. });
  1899. delete Prism.languages.coffeescript['template-string'];
  1900. Prism.languages.coffee = Prism.languages.coffeescript;
  1901. }(Prism));
  1902. /**
  1903. * Original by Samuel Flores
  1904. *
  1905. * Adds the following new token classes:
  1906. * constant, builtin, variable, symbol, regex
  1907. */
  1908. (function (Prism) {
  1909. Prism.languages.ruby = Prism.languages.extend('clike', {
  1910. 'comment': [
  1911. /#.*/,
  1912. {
  1913. pattern: /^=begin\s[\s\S]*?^=end/m,
  1914. greedy: true
  1915. }
  1916. ],
  1917. 'class-name': {
  1918. pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
  1919. lookbehind: true,
  1920. inside: {
  1921. 'punctuation': /[.\\]/
  1922. }
  1923. },
  1924. 'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/
  1925. });
  1926. var interpolation = {
  1927. pattern: /#\{[^}]+\}/,
  1928. inside: {
  1929. 'delimiter': {
  1930. pattern: /^#\{|\}$/,
  1931. alias: 'tag'
  1932. },
  1933. rest: Prism.languages.ruby
  1934. }
  1935. };
  1936. delete Prism.languages.ruby.function;
  1937. Prism.languages.insertBefore('ruby', 'keyword', {
  1938. 'regex': [
  1939. {
  1940. pattern: RegExp(/%r/.source + '(?:' + [
  1941. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  1942. /\((?:[^()\\]|\\[\s\S])*\)/.source,
  1943. // Here we need to specifically allow interpolation
  1944. /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
  1945. /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
  1946. /<(?:[^<>\\]|\\[\s\S])*>/.source
  1947. ].join('|') + ')' + /[egimnosux]{0,6}/.source),
  1948. greedy: true,
  1949. inside: {
  1950. 'interpolation': interpolation
  1951. }
  1952. },
  1953. {
  1954. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
  1955. lookbehind: true,
  1956. greedy: true,
  1957. inside: {
  1958. 'interpolation': interpolation
  1959. }
  1960. }
  1961. ],
  1962. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  1963. 'symbol': {
  1964. pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
  1965. lookbehind: true
  1966. },
  1967. 'method-definition': {
  1968. pattern: /(\bdef\s+)[\w.]+/,
  1969. lookbehind: true,
  1970. inside: {
  1971. 'function': /\w+$/,
  1972. rest: Prism.languages.ruby
  1973. }
  1974. }
  1975. });
  1976. Prism.languages.insertBefore('ruby', 'number', {
  1977. 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
  1978. 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
  1979. });
  1980. Prism.languages.ruby.string = [
  1981. {
  1982. pattern: RegExp(/%[qQiIwWxs]?/.source + '(?:' + [
  1983. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  1984. /\((?:[^()\\]|\\[\s\S])*\)/.source,
  1985. // Here we need to specifically allow interpolation
  1986. /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
  1987. /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
  1988. /<(?:[^<>\\]|\\[\s\S])*>/.source
  1989. ].join('|') + ')'),
  1990. greedy: true,
  1991. inside: {
  1992. 'interpolation': interpolation
  1993. }
  1994. },
  1995. {
  1996. pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
  1997. greedy: true,
  1998. inside: {
  1999. 'interpolation': interpolation
  2000. }
  2001. },
  2002. {
  2003. pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  2004. alias: 'heredoc-string',
  2005. greedy: true,
  2006. inside: {
  2007. 'delimiter': {
  2008. pattern: /^<<[-~]?[a-z_]\w*|[a-z_]\w*$/i,
  2009. alias: 'symbol',
  2010. inside: {
  2011. 'punctuation': /^<<[-~]?/
  2012. }
  2013. },
  2014. 'interpolation': interpolation
  2015. }
  2016. },
  2017. {
  2018. pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  2019. alias: 'heredoc-string',
  2020. greedy: true,
  2021. inside: {
  2022. 'delimiter': {
  2023. pattern: /^<<[-~]?'[a-z_]\w*'|[a-z_]\w*$/i,
  2024. alias: 'symbol',
  2025. inside: {
  2026. 'punctuation': /^<<[-~]?'|'$/,
  2027. }
  2028. }
  2029. }
  2030. }
  2031. ];
  2032. Prism.languages.rb = Prism.languages.ruby;
  2033. }(Prism));
  2034. (function (Prism) {
  2035. Prism.languages.crystal = Prism.languages.extend('ruby', {
  2036. keyword: [
  2037. /\b(?:abstract|alias|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|rescue|return|require|select|self|sizeof|struct|super|then|type|typeof|uninitialized|union|unless|until|when|while|with|yield|__DIR__|__END_LINE__|__FILE__|__LINE__)\b/,
  2038. {
  2039. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  2040. lookbehind: true
  2041. }
  2042. ],
  2043. number: /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[\da-fA-F_]*[\da-fA-F]|(?:\d(?:[\d_]*\d)?)(?:\.[\d_]*\d)?(?:[eE][+-]?[\d_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/
  2044. });
  2045. Prism.languages.insertBefore('crystal', 'string', {
  2046. attribute: {
  2047. pattern: /@\[.+?\]/,
  2048. alias: 'attr-name',
  2049. inside: {
  2050. delimiter: {
  2051. pattern: /^@\[|\]$/,
  2052. alias: 'tag'
  2053. },
  2054. rest: Prism.languages.crystal
  2055. }
  2056. },
  2057. expansion: [
  2058. {
  2059. pattern: /\{\{.+?\}\}/,
  2060. inside: {
  2061. delimiter: {
  2062. pattern: /^\{\{|\}\}$/,
  2063. alias: 'tag'
  2064. },
  2065. rest: Prism.languages.crystal
  2066. }
  2067. },
  2068. {
  2069. pattern: /\{%.+?%\}/,
  2070. inside: {
  2071. delimiter: {
  2072. pattern: /^\{%|%\}$/,
  2073. alias: 'tag'
  2074. },
  2075. rest: Prism.languages.crystal
  2076. }
  2077. }
  2078. ]
  2079. });
  2080. }(Prism));
  2081. Prism.languages.d = Prism.languages.extend('clike', {
  2082. 'comment': [
  2083. {
  2084. // Shebang
  2085. pattern: /^\s*#!.+/,
  2086. greedy: true
  2087. },
  2088. {
  2089. pattern: RegExp(/(^|[^\\])/.source + '(?:' + [
  2090. // /+ comment +/
  2091. // Allow one level of nesting
  2092. /\/\+(?:\/\+(?:[^+]|\+(?!\/))*\+\/|(?!\/\+)[\s\S])*?\+\//.source,
  2093. // // comment
  2094. /\/\/.*/.source,
  2095. // /* comment */
  2096. /\/\*[\s\S]*?\*\//.source
  2097. ].join('|') + ')'),
  2098. lookbehind: true,
  2099. greedy: true
  2100. }
  2101. ],
  2102. 'string': [
  2103. {
  2104. pattern: RegExp([
  2105. // r"", x""
  2106. /\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/.source,
  2107. // q"[]", q"()", q"<>", q"{}"
  2108. /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/.source,
  2109. // q"IDENT
  2110. // ...
  2111. // IDENT"
  2112. /\bq"((?!\d)\w+)$[\s\S]*?^\1"/.source,
  2113. // q"//", q"||", etc.
  2114. /\bq"(.)[\s\S]*?\2"/.source,
  2115. // Characters
  2116. // 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
  2117. /'(?:\\(?:\W|\w+)|[^\\])'/.source,
  2118. /(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
  2119. ].join('|'), 'm'),
  2120. greedy: true
  2121. },
  2122. {
  2123. pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
  2124. greedy: true,
  2125. alias: 'token-string'
  2126. }
  2127. ],
  2128. // In order: $, keywords and special tokens, globally defined symbols
  2129. 'keyword': /\$|\b(?:abstract|alias|align|asm|assert|auto|body|bool|break|byte|case|cast|catch|cdouble|cent|cfloat|char|class|const|continue|creal|dchar|debug|default|delegate|delete|deprecated|do|double|else|enum|export|extern|false|final|finally|float|for|foreach|foreach_reverse|function|goto|idouble|if|ifloat|immutable|import|inout|int|interface|invariant|ireal|lazy|long|macro|mixin|module|new|nothrow|null|out|override|package|pragma|private|protected|public|pure|real|ref|return|scope|shared|short|static|struct|super|switch|synchronized|template|this|throw|true|try|typedef|typeid|typeof|ubyte|ucent|uint|ulong|union|unittest|ushort|version|void|volatile|wchar|while|with|__(?:(?:FILE|MODULE|LINE|FUNCTION|PRETTY_FUNCTION|DATE|EOF|TIME|TIMESTAMP|VENDOR|VERSION)__|gshared|traits|vector|parameters)|string|wstring|dstring|size_t|ptrdiff_t)\b/,
  2130. 'number': [
  2131. // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
  2132. // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
  2133. /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]{0,4}/i,
  2134. {
  2135. pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]{0,4}/i,
  2136. lookbehind: true
  2137. }
  2138. ],
  2139. 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
  2140. });
  2141. Prism.languages.insertBefore('d', 'keyword', {
  2142. 'property': /\B@\w*/
  2143. });
  2144. Prism.languages.insertBefore('d', 'function', {
  2145. 'register': {
  2146. // Iasm registers
  2147. pattern: /\b(?:[ABCD][LHX]|E[ABCD]X|E?(?:BP|SP|DI|SI)|[ECSDGF]S|CR[0234]|DR[012367]|TR[3-7]|X?MM[0-7]|R[ABCD]X|[BS]PL|R[BS]P|[DS]IL|R[DS]I|R(?:[89]|1[0-5])[BWD]?|XMM(?:[89]|1[0-5])|YMM(?:1[0-5]|\d))\b|\bST(?:\([0-7]\)|\b)/,
  2148. alias: 'variable'
  2149. }
  2150. });
  2151. (function (Prism) {
  2152. var keywords = [
  2153. /\b(?:async|sync|yield)\*/,
  2154. /\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extension|external|extends|factory|final|finally|for|get|hide|if|implements|interface|import|in|library|mixin|new|null|on|operator|part|rethrow|return|set|show|static|super|switch|sync|this|throw|try|typedef|var|void|while|with|yield)\b/
  2155. ];
  2156. // Handles named imports, such as http.Client
  2157. var packagePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2158. // based on the dart naming conventions
  2159. var className = {
  2160. pattern: RegExp(packagePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2161. lookbehind: true,
  2162. inside: {
  2163. 'namespace': {
  2164. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2165. inside: {
  2166. 'punctuation': /\./
  2167. }
  2168. },
  2169. }
  2170. };
  2171. Prism.languages.dart = Prism.languages.extend('clike', {
  2172. 'string': [
  2173. {
  2174. pattern: /r?("""|''')[\s\S]*?\1/,
  2175. greedy: true
  2176. },
  2177. {
  2178. pattern: /r?(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2179. greedy: true
  2180. }
  2181. ],
  2182. 'class-name': [
  2183. className,
  2184. {
  2185. // variables and parameters
  2186. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2187. pattern: RegExp(packagePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source),
  2188. lookbehind: true,
  2189. inside: className.inside
  2190. }
  2191. ],
  2192. 'keyword': keywords,
  2193. 'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
  2194. });
  2195. Prism.languages.insertBefore('dart', 'function', {
  2196. 'metadata': {
  2197. pattern: /@\w+/,
  2198. alias: 'symbol'
  2199. }
  2200. });
  2201. Prism.languages.insertBefore('dart', 'class-name', {
  2202. 'generics': {
  2203. pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
  2204. inside: {
  2205. 'class-name': className,
  2206. 'keyword': keywords,
  2207. 'punctuation': /[<>(),.:]/,
  2208. 'operator': /[?&|]/
  2209. }
  2210. },
  2211. });
  2212. }(Prism));
  2213. (function (Prism) {
  2214. Prism.languages.diff = {
  2215. 'coord': [
  2216. // Match all kinds of coord lines (prefixed by "+++", "---" or "***").
  2217. /^(?:\*{3}|-{3}|\+{3}).*$/m,
  2218. // Match "@@ ... @@" coord lines in unified diff.
  2219. /^@@.*@@$/m,
  2220. // Match coord lines in normal diff (starts with a number).
  2221. /^\d.*$/m
  2222. ]
  2223. // deleted, inserted, unchanged, diff
  2224. };
  2225. /**
  2226. * A map from the name of a block to its line prefix.
  2227. *
  2228. * @type {Object<string, string>}
  2229. */
  2230. var PREFIXES = {
  2231. 'deleted-sign': '-',
  2232. 'deleted-arrow': '<',
  2233. 'inserted-sign': '+',
  2234. 'inserted-arrow': '>',
  2235. 'unchanged': ' ',
  2236. 'diff': '!',
  2237. };
  2238. // add a token for each prefix
  2239. Object.keys(PREFIXES).forEach(function (name) {
  2240. var prefix = PREFIXES[name];
  2241. var alias = [];
  2242. if (!/^\w+$/.test(name)) { // "deleted-sign" -> "deleted"
  2243. alias.push(/\w+/.exec(name)[0]);
  2244. }
  2245. if (name === 'diff') {
  2246. alias.push('bold');
  2247. }
  2248. Prism.languages.diff[name] = {
  2249. pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'),
  2250. alias: alias,
  2251. inside: {
  2252. 'line': {
  2253. pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/,
  2254. lookbehind: true
  2255. },
  2256. 'prefix': {
  2257. pattern: /[\s\S]/,
  2258. alias: /\w+/.exec(name)[0]
  2259. }
  2260. }
  2261. };
  2262. });
  2263. // make prefixes available to Diff plugin
  2264. Object.defineProperty(Prism.languages.diff, 'PREFIXES', {
  2265. value: PREFIXES
  2266. });
  2267. }(Prism));
  2268. (function (Prism) {
  2269. /**
  2270. * Returns the placeholder for the given language id and index.
  2271. *
  2272. * @param {string} language
  2273. * @param {string|number} index
  2274. * @returns {string}
  2275. */
  2276. function getPlaceholder(language, index) {
  2277. return '___' + language.toUpperCase() + index + '___';
  2278. }
  2279. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  2280. buildPlaceholders: {
  2281. /**
  2282. * Tokenize all inline templating expressions matching `placeholderPattern`.
  2283. *
  2284. * If `replaceFilter` is provided, only matches of `placeholderPattern` for which `replaceFilter` returns
  2285. * `true` will be replaced.
  2286. *
  2287. * @param {object} env The environment of the `before-tokenize` hook.
  2288. * @param {string} language The language id.
  2289. * @param {RegExp} placeholderPattern The matches of this pattern will be replaced by placeholders.
  2290. * @param {(match: string) => boolean} [replaceFilter]
  2291. */
  2292. value: function (env, language, placeholderPattern, replaceFilter) {
  2293. if (env.language !== language) {
  2294. return;
  2295. }
  2296. var tokenStack = env.tokenStack = [];
  2297. env.code = env.code.replace(placeholderPattern, function (match) {
  2298. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  2299. return match;
  2300. }
  2301. var i = tokenStack.length;
  2302. var placeholder;
  2303. // Check for existing strings
  2304. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1) {
  2305. ++i;
  2306. }
  2307. // Create a sparse array
  2308. tokenStack[i] = match;
  2309. return placeholder;
  2310. });
  2311. // Switch the grammar to markup
  2312. env.grammar = Prism.languages.markup;
  2313. }
  2314. },
  2315. tokenizePlaceholders: {
  2316. /**
  2317. * Replace placeholders with proper tokens after tokenizing.
  2318. *
  2319. * @param {object} env The environment of the `after-tokenize` hook.
  2320. * @param {string} language The language id.
  2321. */
  2322. value: function (env, language) {
  2323. if (env.language !== language || !env.tokenStack) {
  2324. return;
  2325. }
  2326. // Switch the grammar back
  2327. env.grammar = Prism.languages[language];
  2328. var j = 0;
  2329. var keys = Object.keys(env.tokenStack);
  2330. function walkTokens(tokens) {
  2331. for (var i = 0; i < tokens.length; i++) {
  2332. // all placeholders are replaced already
  2333. if (j >= keys.length) {
  2334. break;
  2335. }
  2336. var token = tokens[i];
  2337. if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
  2338. var k = keys[j];
  2339. var t = env.tokenStack[k];
  2340. var s = typeof token === 'string' ? token : token.content;
  2341. var placeholder = getPlaceholder(language, k);
  2342. var index = s.indexOf(placeholder);
  2343. if (index > -1) {
  2344. ++j;
  2345. var before = s.substring(0, index);
  2346. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  2347. var after = s.substring(index + placeholder.length);
  2348. var replacement = [];
  2349. if (before) {
  2350. replacement.push.apply(replacement, walkTokens([before]));
  2351. }
  2352. replacement.push(middle);
  2353. if (after) {
  2354. replacement.push.apply(replacement, walkTokens([after]));
  2355. }
  2356. if (typeof token === 'string') {
  2357. tokens.splice.apply(tokens, [i, 1].concat(replacement));
  2358. } else {
  2359. token.content = replacement;
  2360. }
  2361. }
  2362. } else if (token.content /* && typeof token.content !== 'string' */) {
  2363. walkTokens(token.content);
  2364. }
  2365. }
  2366. return tokens;
  2367. }
  2368. walkTokens(env.tokens);
  2369. }
  2370. }
  2371. });
  2372. }(Prism));
  2373. // Django/Jinja2 syntax definition for Prism.js <http://prismjs.com> syntax highlighter.
  2374. // Mostly it works OK but can paint code incorrectly on complex html/template tag combinations.
  2375. (function (Prism) {
  2376. Prism.languages.django = {
  2377. 'comment': /^{#[\s\S]*?#}$/,
  2378. 'tag': {
  2379. pattern: /(^{%[+-]?\s*)\w+/,
  2380. lookbehind: true,
  2381. alias: 'keyword'
  2382. },
  2383. 'delimiter': {
  2384. pattern: /^{[{%][+-]?|[+-]?[}%]}$/,
  2385. alias: 'punctuation'
  2386. },
  2387. 'string': {
  2388. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2389. greedy: true
  2390. },
  2391. 'filter': {
  2392. pattern: /(\|)\w+/,
  2393. lookbehind: true,
  2394. alias: 'function'
  2395. },
  2396. 'test': {
  2397. pattern: /(\bis\s+(?:not\s+)?)(?!not\b)\w+/,
  2398. lookbehind: true,
  2399. alias: 'function'
  2400. },
  2401. 'function': /\b[a-z_]\w+(?=\s*\()/i,
  2402. 'keyword': /\b(?:and|as|by|else|for|if|import|in|is|loop|not|or|recursive|with|without)\b/,
  2403. 'operator': /[-+*/%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  2404. 'number': /\b\d+(?:\.\d+)?\b/,
  2405. 'boolean': /[Tt]rue|[Ff]alse|[Nn]one/,
  2406. 'variable': /\b\w+?\b/,
  2407. 'punctuation': /[{}[\](),.:;]/
  2408. };
  2409. var pattern = /{{[\s\S]*?}}|{%[\s\S]*?%}|{#[\s\S]*?#}/g;
  2410. var markupTemplating = Prism.languages['markup-templating'];
  2411. Prism.hooks.add('before-tokenize', function (env) {
  2412. markupTemplating.buildPlaceholders(env, 'django', pattern);
  2413. });
  2414. Prism.hooks.add('after-tokenize', function (env) {
  2415. markupTemplating.tokenizePlaceholders(env, 'django');
  2416. });
  2417. // Add an Jinja2 alias
  2418. Prism.languages.jinja2 = Prism.languages.django;
  2419. Prism.hooks.add('before-tokenize', function (env) {
  2420. markupTemplating.buildPlaceholders(env, 'jinja2', pattern);
  2421. });
  2422. Prism.hooks.add('after-tokenize', function (env) {
  2423. markupTemplating.tokenizePlaceholders(env, 'jinja2');
  2424. });
  2425. }(Prism));
  2426. Prism.languages.elixir = {
  2427. 'doc': {
  2428. pattern: /@(?:doc|moduledoc)\s+(?:("""|''')[\s\S]*?\1|("|')(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2)/,
  2429. inside: {
  2430. 'attribute': /^@\w+/,
  2431. 'string': /['"][\s\S]+/
  2432. }
  2433. },
  2434. 'comment': {
  2435. pattern: /#.*/m,
  2436. greedy: true
  2437. },
  2438. // ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  2439. 'regex': {
  2440. pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
  2441. greedy: true
  2442. },
  2443. 'string': [
  2444. {
  2445. // ~s"""foo""" (multi-line), ~s'''foo''' (multi-line), ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo} (with interpolation care), ~s<foo>
  2446. pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|#(?!\{)|[^#\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/,
  2447. greedy: true,
  2448. inside: {
  2449. // See interpolation below
  2450. }
  2451. },
  2452. {
  2453. pattern: /("""|''')[\s\S]*?\1/,
  2454. greedy: true,
  2455. inside: {
  2456. // See interpolation below
  2457. }
  2458. },
  2459. {
  2460. // Multi-line strings are allowed
  2461. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2462. greedy: true,
  2463. inside: {
  2464. // See interpolation below
  2465. }
  2466. }
  2467. ],
  2468. 'atom': {
  2469. // Look-behind prevents bad highlighting of the :: operator
  2470. pattern: /(^|[^:]):\w+/,
  2471. lookbehind: true,
  2472. alias: 'symbol'
  2473. },
  2474. 'module': {
  2475. pattern: /\b[A-Z]\w*\b/,
  2476. alias: 'class-name'
  2477. },
  2478. // Look-ahead prevents bad highlighting of the :: operator
  2479. 'attr-name': /\b\w+\??:(?!:)/,
  2480. 'argument': {
  2481. // Look-behind prevents bad highlighting of the && operator
  2482. pattern: /(^|[^&])&\d+/,
  2483. lookbehind: true,
  2484. alias: 'variable'
  2485. },
  2486. 'attribute': {
  2487. pattern: /@\w+/,
  2488. alias: 'variable'
  2489. },
  2490. 'function': /\b[_a-zA-Z]\w*[?!]?(?:(?=\s*(?:\.\s*)?\()|(?=\/\d+))/,
  2491. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  2492. 'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct|delegate)?|do|else|end|fn|for|if|import|not|or|raise|require|rescue|try|unless|use|when)\b/,
  2493. 'boolean': /\b(?:true|false|nil)\b/,
  2494. 'operator': [
  2495. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  2496. {
  2497. // We don't want to match <<
  2498. pattern: /([^<])<(?!<)/,
  2499. lookbehind: true
  2500. },
  2501. {
  2502. // We don't want to match >>
  2503. pattern: /([^>])>(?!>)/,
  2504. lookbehind: true
  2505. }
  2506. ],
  2507. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  2508. };
  2509. Prism.languages.elixir.string.forEach(function (o) {
  2510. o.inside = {
  2511. 'interpolation': {
  2512. pattern: /#\{[^}]+\}/,
  2513. inside: {
  2514. 'delimiter': {
  2515. pattern: /^#\{|\}$/,
  2516. alias: 'punctuation'
  2517. },
  2518. rest: Prism.languages.elixir
  2519. }
  2520. }
  2521. };
  2522. });
  2523. Prism.languages.erlang = {
  2524. 'comment': /%.+/,
  2525. 'string': {
  2526. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  2527. greedy: true
  2528. },
  2529. 'quoted-function': {
  2530. pattern: /'(?:\\.|[^\\'\r\n])+'(?=\()/,
  2531. alias: 'function'
  2532. },
  2533. 'quoted-atom': {
  2534. pattern: /'(?:\\.|[^\\'\r\n])+'/,
  2535. alias: 'atom'
  2536. },
  2537. 'boolean': /\b(?:true|false)\b/,
  2538. 'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
  2539. 'number': [
  2540. /\$\\?./,
  2541. /\b\d+#[a-z0-9]+/i,
  2542. /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i
  2543. ],
  2544. 'function': /\b[a-z][\w@]*(?=\()/,
  2545. 'variable': {
  2546. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  2547. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  2548. lookbehind: true
  2549. },
  2550. 'operator': [
  2551. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,
  2552. {
  2553. // We don't want to match <<
  2554. pattern: /(^|[^<])<(?!<)/,
  2555. lookbehind: true
  2556. },
  2557. {
  2558. // We don't want to match >>
  2559. pattern: /(^|[^>])>(?!>)/,
  2560. lookbehind: true
  2561. }
  2562. ],
  2563. 'atom': /\b[a-z][\w@]*/,
  2564. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  2565. };
  2566. Prism.languages.go = Prism.languages.extend('clike', {
  2567. 'string': {
  2568. pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
  2569. greedy: true
  2570. },
  2571. '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/,
  2572. 'boolean': /\b(?:_|iota|nil|true|false)\b/,
  2573. 'number': /(?:\b0x[a-f\d]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[-+]?\d+)?)i?/i,
  2574. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  2575. '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/
  2576. });
  2577. delete Prism.languages.go['class-name'];
  2578. Prism.languages.groovy = Prism.languages.extend('clike', {
  2579. 'string': [
  2580. {
  2581. // https://groovy-lang.org/syntax.html#_dollar_slashy_string
  2582. pattern: /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
  2583. greedy: true
  2584. },
  2585. {
  2586. // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
  2587. // simple division (see JS regex), so find a fix maybe?
  2588. pattern: /(["'/])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2589. greedy: true
  2590. }
  2591. ],
  2592. 'keyword': /\b(?:as|def|in|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|trait|transient|try|void|volatile|while)\b/,
  2593. 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?[\d]+)?)[glidf]?\b/i,
  2594. 'operator': {
  2595. pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
  2596. lookbehind: true
  2597. },
  2598. 'punctuation': /\.+|[{}[\];(),:$]/
  2599. });
  2600. Prism.languages.insertBefore('groovy', 'string', {
  2601. 'shebang': {
  2602. pattern: /#!.+/,
  2603. alias: 'comment'
  2604. }
  2605. });
  2606. Prism.languages.insertBefore('groovy', 'punctuation', {
  2607. 'spock-block': /\b(?:setup|given|when|then|and|cleanup|expect|where):/
  2608. });
  2609. Prism.languages.insertBefore('groovy', 'function', {
  2610. 'annotation': {
  2611. pattern: /(^|[^.])@\w+/,
  2612. lookbehind: true,
  2613. alias: 'punctuation'
  2614. }
  2615. });
  2616. // Handle string interpolation
  2617. Prism.hooks.add('wrap', function (env) {
  2618. if (env.language === 'groovy' && env.type === 'string') {
  2619. var delimiter = env.content[0];
  2620. if (delimiter != "'") {
  2621. var pattern = /([^\\])(?:\$(?:\{.*?\}|[\w.]+))/;
  2622. if (delimiter === '$') {
  2623. pattern = /([^\$])(?:\$(?:\{.*?\}|[\w.]+))/;
  2624. }
  2625. // To prevent double HTML-encoding we have to decode env.content first
  2626. env.content = env.content.replace(/&lt;/g, '<').replace(/&amp;/g, '&');
  2627. env.content = Prism.highlight(env.content, {
  2628. 'expression': {
  2629. pattern: pattern,
  2630. lookbehind: true,
  2631. inside: Prism.languages.groovy
  2632. }
  2633. });
  2634. env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
  2635. }
  2636. }
  2637. });
  2638. (function (Prism) {
  2639. var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
  2640. // full package (optional) + parent classes (optional)
  2641. var classNamePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2642. // based on the java naming conventions
  2643. var className = {
  2644. pattern: RegExp(classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2645. lookbehind: true,
  2646. inside: {
  2647. 'namespace': {
  2648. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2649. inside: {
  2650. 'punctuation': /\./
  2651. }
  2652. },
  2653. 'punctuation': /\./
  2654. }
  2655. };
  2656. Prism.languages.java = Prism.languages.extend('clike', {
  2657. 'class-name': [
  2658. className,
  2659. {
  2660. // variables and parameters
  2661. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2662. pattern: RegExp(classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=())])/.source),
  2663. lookbehind: true,
  2664. inside: className.inside
  2665. }
  2666. ],
  2667. 'keyword': keywords,
  2668. 'function': [
  2669. Prism.languages.clike.function,
  2670. {
  2671. pattern: /(\:\:\s*)[a-z_]\w*/,
  2672. lookbehind: true
  2673. }
  2674. ],
  2675. 'number': /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
  2676. 'operator': {
  2677. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  2678. lookbehind: true
  2679. }
  2680. });
  2681. Prism.languages.insertBefore('java', 'string', {
  2682. 'triple-quoted-string': {
  2683. // http://openjdk.java.net/jeps/355#Description
  2684. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  2685. greedy: true,
  2686. alias: 'string'
  2687. }
  2688. });
  2689. Prism.languages.insertBefore('java', 'class-name', {
  2690. 'annotation': {
  2691. pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
  2692. lookbehind: true,
  2693. alias: 'punctuation'
  2694. },
  2695. 'generics': {
  2696. pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
  2697. inside: {
  2698. 'class-name': className,
  2699. 'keyword': keywords,
  2700. 'punctuation': /[<>(),.:]/,
  2701. 'operator': /[?&|]/
  2702. }
  2703. },
  2704. 'namespace': {
  2705. pattern: RegExp(
  2706. /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
  2707. .source.replace(/<keyword>/g, function () { return keywords.source; })),
  2708. lookbehind: true,
  2709. inside: {
  2710. 'punctuation': /\./,
  2711. }
  2712. }
  2713. });
  2714. }(Prism));
  2715. // https://www.json.org/json-en.html
  2716. Prism.languages.json = {
  2717. 'property': {
  2718. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
  2719. lookbehind: true,
  2720. greedy: true
  2721. },
  2722. 'string': {
  2723. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  2724. lookbehind: true,
  2725. greedy: true
  2726. },
  2727. 'comment': {
  2728. pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
  2729. greedy: true
  2730. },
  2731. 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
  2732. 'punctuation': /[{}[\],]/,
  2733. 'operator': /:/,
  2734. 'boolean': /\b(?:true|false)\b/,
  2735. 'null': {
  2736. pattern: /\bnull\b/,
  2737. alias: 'keyword'
  2738. }
  2739. };
  2740. Prism.languages.webmanifest = Prism.languages.json;
  2741. Prism.languages.julia = {
  2742. 'comment': {
  2743. // support one level of nested comments
  2744. // https://github.com/JuliaLang/julia/pull/6128
  2745. pattern: /(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/,
  2746. lookbehind: true
  2747. },
  2748. 'regex': {
  2749. // https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1
  2750. pattern: /r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/,
  2751. greedy: true
  2752. },
  2753. 'string': {
  2754. // https://docs.julialang.org/en/v1/manual/strings/#man-characters-1
  2755. // https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1
  2756. // https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1
  2757. // https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1
  2758. pattern: /"""[\s\S]+?"""|(?:\b\w+)?"(?:\\.|[^"\\\r\n])*"|(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'|`(?:[^\\`\r\n]|\\.)*`/,
  2759. lookbehind: true,
  2760. greedy: true
  2761. },
  2762. 'keyword': /\b(?:abstract|baremodule|begin|bitstype|break|catch|ccall|const|continue|do|else|elseif|end|export|finally|for|function|global|if|immutable|import|importall|in|let|local|macro|module|print|println|quote|return|struct|try|type|typealias|using|while)\b/,
  2763. 'boolean': /\b(?:true|false)\b/,
  2764. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i,
  2765. // https://docs.julialang.org/en/v1/manual/mathematical-operations/
  2766. // https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1
  2767. 'operator': /&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/,
  2768. 'punctuation': /::?|[{}[\]();,.?]/,
  2769. // https://docs.julialang.org/en/v1/base/numbers/#Base.im
  2770. 'constant': /\b(?:(?:NaN|Inf)(?:16|32|64)?|im|pi)\b|[πℯ]/
  2771. };
  2772. (function (Prism) {
  2773. Prism.languages.kotlin = Prism.languages.extend('clike', {
  2774. 'keyword': {
  2775. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  2776. pattern: /(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,
  2777. lookbehind: true
  2778. },
  2779. 'function': [
  2780. {
  2781. pattern: /(?:`[^\r\n`]+`|\b\w+)(?=\s*\()/,
  2782. greedy: true
  2783. },
  2784. {
  2785. pattern: /(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/,
  2786. lookbehind: true,
  2787. greedy: true
  2788. }
  2789. ],
  2790. 'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
  2791. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  2792. });
  2793. delete Prism.languages.kotlin['class-name'];
  2794. Prism.languages.insertBefore('kotlin', 'string', {
  2795. 'raw-string': {
  2796. pattern: /("""|''')[\s\S]*?\1/,
  2797. alias: 'string'
  2798. // See interpolation below
  2799. }
  2800. });
  2801. Prism.languages.insertBefore('kotlin', 'keyword', {
  2802. 'annotation': {
  2803. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  2804. alias: 'builtin'
  2805. }
  2806. });
  2807. Prism.languages.insertBefore('kotlin', 'function', {
  2808. 'label': {
  2809. pattern: /\b\w+@|@\w+\b/,
  2810. alias: 'symbol'
  2811. }
  2812. });
  2813. var interpolation = [
  2814. {
  2815. pattern: /\$\{[^}]+\}/,
  2816. inside: {
  2817. 'delimiter': {
  2818. pattern: /^\$\{|\}$/,
  2819. alias: 'variable'
  2820. },
  2821. rest: Prism.languages.kotlin
  2822. }
  2823. },
  2824. {
  2825. pattern: /\$\w+/,
  2826. alias: 'variable'
  2827. }
  2828. ];
  2829. Prism.languages.kotlin['string'].inside = Prism.languages.kotlin['raw-string'].inside = {
  2830. interpolation: interpolation
  2831. };
  2832. Prism.languages.kt = Prism.languages.kotlin;
  2833. Prism.languages.kts = Prism.languages.kotlin;
  2834. }(Prism));
  2835. (function (Prism) {
  2836. var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i;
  2837. var insideEqu = {
  2838. 'equation-command': {
  2839. pattern: funcPattern,
  2840. alias: 'regex'
  2841. }
  2842. };
  2843. Prism.languages.latex = {
  2844. 'comment': /%.*/m,
  2845. // the verbatim environment prints whitespace to the document
  2846. 'cdata': {
  2847. pattern: /(\\begin\{((?:verbatim|lstlisting)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  2848. lookbehind: true
  2849. },
  2850. /*
  2851. * equations can be between $$ $$ or $ $ or \( \) or \[ \]
  2852. * (all are multiline)
  2853. */
  2854. 'equation': [
  2855. {
  2856. pattern: /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
  2857. inside: insideEqu,
  2858. alias: 'string'
  2859. },
  2860. {
  2861. pattern: /(\\begin\{((?:equation|math|eqnarray|align|multline|gather)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  2862. lookbehind: true,
  2863. inside: insideEqu,
  2864. alias: 'string'
  2865. }
  2866. ],
  2867. /*
  2868. * arguments which are keywords or references are highlighted
  2869. * as keywords
  2870. */
  2871. 'keyword': {
  2872. pattern: /(\\(?:begin|end|ref|cite|label|usepackage|documentclass)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  2873. lookbehind: true
  2874. },
  2875. 'url': {
  2876. pattern: /(\\url\{)[^}]+(?=\})/,
  2877. lookbehind: true
  2878. },
  2879. /*
  2880. * section or chapter headlines are highlighted as bold so that
  2881. * they stand out more
  2882. */
  2883. 'headline': {
  2884. pattern: /(\\(?:part|chapter|section|subsection|frametitle|subsubsection|paragraph|subparagraph|subsubparagraph|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\}(?:\[[^\]]+\])?)/,
  2885. lookbehind: true,
  2886. alias: 'class-name'
  2887. },
  2888. 'function': {
  2889. pattern: funcPattern,
  2890. alias: 'selector'
  2891. },
  2892. 'punctuation': /[[\]{}&]/
  2893. };
  2894. Prism.languages.tex = Prism.languages.latex;
  2895. Prism.languages.context = Prism.languages.latex;
  2896. }(Prism));
  2897. Prism.languages.lua = {
  2898. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  2899. // \z may be used to skip the following space
  2900. 'string': {
  2901. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  2902. greedy: true
  2903. },
  2904. 'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  2905. 'keyword': /\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/,
  2906. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  2907. 'operator': [
  2908. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  2909. {
  2910. // Match ".." but don't break "..."
  2911. pattern: /(^|[^.])\.\.(?!\.)/,
  2912. lookbehind: true
  2913. }
  2914. ],
  2915. 'punctuation': /[\[\](){},;]|\.+|:+/
  2916. };
  2917. Prism.languages.matlab = {
  2918. 'comment': [
  2919. /%\{[\s\S]*?\}%/,
  2920. /%.+/
  2921. ],
  2922. 'string': {
  2923. pattern: /\B'(?:''|[^'\r\n])*'/,
  2924. greedy: true
  2925. },
  2926. // FIXME We could handle imaginary numbers as a whole
  2927. 'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[eE][+-]?\d+)?(?:[ij])?|\b[ij]\b/,
  2928. 'keyword': /\b(?:break|case|catch|continue|else|elseif|end|for|function|if|inf|NaN|otherwise|parfor|pause|pi|return|switch|try|while)\b/,
  2929. 'function': /\b(?!\d)\w+(?=\s*\()/,
  2930. 'operator': /\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,
  2931. 'punctuation': /\.{3}|[.,;\[\](){}!]/
  2932. };
  2933. (function (Prism) {
  2934. var variable = /\$(?:\w[a-z\d]*(?:_[^\x00-\x1F\s"'\\()$]*)?|\{[^}\s"'\\]+\})/i;
  2935. Prism.languages.nginx = {
  2936. 'comment': {
  2937. pattern: /(^|[\s{};])#.*/,
  2938. lookbehind: true
  2939. },
  2940. 'directive': {
  2941. pattern: /(^|\s)\w(?:[^;{}"'\\\s]|\\.|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\s+(?:#.*(?!.)|(?![#\s])))*?(?=\s*[;{])/,
  2942. lookbehind: true,
  2943. greedy: true,
  2944. inside: {
  2945. 'string': {
  2946. pattern: /((?:^|[^\\])(?:\\\\)*)(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/,
  2947. lookbehind: true,
  2948. inside: {
  2949. 'escape': {
  2950. pattern: /\\["'\\nrt]/,
  2951. alias: 'entity'
  2952. },
  2953. 'variable': variable
  2954. }
  2955. },
  2956. 'comment': {
  2957. pattern: /(\s)#.*/,
  2958. lookbehind: true,
  2959. greedy: true
  2960. },
  2961. 'keyword': {
  2962. pattern: /^\S+/,
  2963. greedy: true
  2964. },
  2965. // other patterns
  2966. 'boolean': {
  2967. pattern: /(\s)(?:off|on)(?!\S)/,
  2968. lookbehind: true
  2969. },
  2970. 'number': {
  2971. pattern: /(\s)\d+[a-z]*(?!\S)/i,
  2972. lookbehind: true
  2973. },
  2974. 'variable': variable
  2975. }
  2976. },
  2977. 'punctuation': /[{};]/
  2978. };
  2979. }(Prism));
  2980. Prism.languages.nim = {
  2981. 'comment': /#.*/,
  2982. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  2983. // Character literals are handled specifically to prevent issues with numeric type suffixes
  2984. 'string': {
  2985. pattern: /(?:(?:\b(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")|'(?:\\(?:\d+|x[\da-fA-F]{2}|.)|[^'])')/,
  2986. greedy: true
  2987. },
  2988. // The negative look ahead prevents wrong highlighting of the .. operator
  2989. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  2990. 'keyword': /\b(?:addr|as|asm|atomic|bind|block|break|case|cast|concept|const|continue|converter|defer|discard|distinct|do|elif|else|end|enum|except|export|finally|for|from|func|generic|if|import|include|interface|iterator|let|macro|method|mixin|nil|object|out|proc|ptr|raise|ref|return|static|template|try|tuple|type|using|var|when|while|with|without|yield)\b/,
  2991. 'function': {
  2992. pattern: /(?:(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  2993. inside: {
  2994. 'operator': /\*$/
  2995. }
  2996. },
  2997. // We don't want to highlight operators inside backticks
  2998. 'ignore': {
  2999. pattern: /`[^`\r\n]+`/,
  3000. inside: {
  3001. 'punctuation': /`/
  3002. }
  3003. },
  3004. 'operator': {
  3005. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  3006. // but allow the slice operator .. to take precedence over them
  3007. // One can define his own operators in Nim so all combination of operators might be an operator.
  3008. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|of|or|in|is|isnot|mod|not|notin|shl|shr|xor)\b)/m,
  3009. lookbehind: true
  3010. },
  3011. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  3012. };
  3013. Prism.languages.ocaml = {
  3014. 'comment': /\(\*[\s\S]*?\*\)/,
  3015. 'string': [
  3016. {
  3017. pattern: /"(?:\\.|[^\\\r\n"])*"/,
  3018. greedy: true
  3019. },
  3020. {
  3021. pattern: /(['`])(?:\\(?:\d+|x[\da-f]+|.)|(?!\1)[^\\\r\n])\1/i,
  3022. greedy: true
  3023. }
  3024. ],
  3025. 'number': /\b(?:0x[\da-f][\da-f_]+|(?:0[bo])?\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?[\d_]+)?)/i,
  3026. 'directive': {
  3027. pattern: /\B#\w+/,
  3028. alias: 'important'
  3029. },
  3030. 'label': {
  3031. pattern: /\B~\w+/,
  3032. alias: 'function'
  3033. },
  3034. 'type-variable': {
  3035. pattern: /\B'\w+/,
  3036. alias: 'function'
  3037. },
  3038. 'variant': {
  3039. pattern: /`\w+/,
  3040. alias: 'variable'
  3041. },
  3042. 'module': {
  3043. pattern: /\b[A-Z]\w+/,
  3044. alias: 'variable'
  3045. },
  3046. // For the list of keywords and operators,
  3047. // see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
  3048. 'keyword': /\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|nonrec|object|of|open|private|rec|sig|struct|then|to|try|type|val|value|virtual|when|where|while|with)\b/,
  3049. 'boolean': /\b(?:false|true)\b/,
  3050. // Custom operators are allowed
  3051. 'operator': /:=|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
  3052. 'punctuation': /[(){}\[\]|.,:;]|\b_\b/
  3053. };
  3054. Prism.languages.perl = {
  3055. 'comment': [
  3056. {
  3057. // POD
  3058. pattern: /(^\s*)=\w[\s\S]*?=cut.*/m,
  3059. lookbehind: true
  3060. },
  3061. {
  3062. pattern: /(^|[^\\$])#.*/,
  3063. lookbehind: true
  3064. }
  3065. ],
  3066. // TODO Could be nice to handle Heredoc too.
  3067. 'string': [
  3068. // q/.../
  3069. {
  3070. pattern: /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  3071. greedy: true
  3072. },
  3073. // q a...a
  3074. {
  3075. pattern: /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  3076. greedy: true
  3077. },
  3078. // q(...)
  3079. {
  3080. pattern: /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,
  3081. greedy: true
  3082. },
  3083. // q{...}
  3084. {
  3085. pattern: /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,
  3086. greedy: true
  3087. },
  3088. // q[...]
  3089. {
  3090. pattern: /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,
  3091. greedy: true
  3092. },
  3093. // q<...>
  3094. {
  3095. pattern: /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,
  3096. greedy: true
  3097. },
  3098. // "...", `...`
  3099. {
  3100. pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  3101. greedy: true
  3102. },
  3103. // '...'
  3104. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  3105. {
  3106. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  3107. greedy: true
  3108. }
  3109. ],
  3110. 'regex': [
  3111. // m/.../
  3112. {
  3113. pattern: /\b(?:m|qr)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[msixpodualngc]*/,
  3114. greedy: true
  3115. },
  3116. // m a...a
  3117. {
  3118. pattern: /\b(?:m|qr)\s+([a-zA-Z0-9])(?:(?!\1)[^\\]|\\[\s\S])*\1[msixpodualngc]*/,
  3119. greedy: true
  3120. },
  3121. // m(...)
  3122. {
  3123. pattern: /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,
  3124. greedy: true
  3125. },
  3126. // m{...}
  3127. {
  3128. pattern: /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,
  3129. greedy: true
  3130. },
  3131. // m[...]
  3132. {
  3133. pattern: /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,
  3134. greedy: true
  3135. },
  3136. // m<...>
  3137. {
  3138. pattern: /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,
  3139. greedy: true
  3140. },
  3141. // The lookbehinds prevent -s from breaking
  3142. // FIXME We don't handle change of separator like s(...)[...]
  3143. // s/.../.../
  3144. {
  3145. pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2[msixpodualngcer]*/,
  3146. lookbehind: true,
  3147. greedy: true
  3148. },
  3149. // s a...a...a
  3150. {
  3151. pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2[msixpodualngcer]*/,
  3152. lookbehind: true,
  3153. greedy: true
  3154. },
  3155. // s(...)(...)
  3156. {
  3157. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,
  3158. lookbehind: true,
  3159. greedy: true
  3160. },
  3161. // s{...}{...}
  3162. {
  3163. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,
  3164. lookbehind: true,
  3165. greedy: true
  3166. },
  3167. // s[...][...]
  3168. {
  3169. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,
  3170. lookbehind: true,
  3171. greedy: true
  3172. },
  3173. // s<...><...>
  3174. {
  3175. pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,
  3176. lookbehind: true,
  3177. greedy: true
  3178. },
  3179. // /.../
  3180. // The look-ahead tries to prevent two divisions on
  3181. // the same line from being highlighted as regex.
  3182. // This does not support multi-line regex.
  3183. {
  3184. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(?:lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/,
  3185. greedy: true
  3186. }
  3187. ],
  3188. // FIXME Not sure about the handling of ::, ', and #
  3189. 'variable': [
  3190. // ${^POSTMATCH}
  3191. /[&*$@%]\{\^[A-Z]+\}/,
  3192. // $^V
  3193. /[&*$@%]\^[A-Z_]/,
  3194. // ${...}
  3195. /[&*$@%]#?(?=\{)/,
  3196. // $foo
  3197. /[&*$@%]#?(?:(?:::)*'?(?!\d)[\w$]+(?![\w$]))+(?:::)*/i,
  3198. // $1
  3199. /[&*$@%]\d+/,
  3200. // $_, @_, %!
  3201. // The negative lookahead prevents from breaking the %= operator
  3202. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  3203. ],
  3204. 'filehandle': {
  3205. // <>, <FOO>, _
  3206. pattern: /<(?![<=])\S*>|\b_\b/,
  3207. alias: 'symbol'
  3208. },
  3209. 'vstring': {
  3210. // v1.2, 1.2.3
  3211. pattern: /v\d+(?:\.\d+)*|\d+(?:\.\d+){2,}/,
  3212. alias: 'string'
  3213. },
  3214. 'function': {
  3215. pattern: /sub [a-z0-9_]+/i,
  3216. inside: {
  3217. keyword: /sub/
  3218. }
  3219. },
  3220. 'keyword': /\b(?:any|break|continue|default|delete|die|do|else|elsif|eval|for|foreach|given|goto|if|last|local|my|next|our|package|print|redo|require|return|say|state|sub|switch|undef|unless|until|use|when|while)\b/,
  3221. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)\b/,
  3222. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(?:lt|gt|le|ge|eq|ne|cmp|not|and|or|xor)\b/,
  3223. 'punctuation': /[{}[\];(),:]/
  3224. };
  3225. /**
  3226. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  3227. * Modified by Miles Johnson: http://milesj.me
  3228. * Rewritten by Tom Pavelec
  3229. *
  3230. * Supports PHP 5.3 - 8.0
  3231. */
  3232. (function (Prism) {
  3233. var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
  3234. var constant = [
  3235. {
  3236. pattern: /\b(?:false|true)\b/i,
  3237. alias: 'boolean'
  3238. },
  3239. {
  3240. pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
  3241. greedy: true,
  3242. lookbehind: true,
  3243. },
  3244. {
  3245. pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
  3246. greedy: true,
  3247. lookbehind: true,
  3248. },
  3249. /\b(?:null)\b/i,
  3250. /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
  3251. ];
  3252. var number = /\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i;
  3253. var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
  3254. var punctuation = /[{}\[\](),:;]/;
  3255. Prism.languages.php = {
  3256. 'delimiter': {
  3257. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  3258. alias: 'important'
  3259. },
  3260. 'comment': comment,
  3261. 'variable': /\$+(?:\w+\b|(?={))/i,
  3262. 'package': {
  3263. pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3264. lookbehind: true,
  3265. inside: {
  3266. 'punctuation': /\\/
  3267. }
  3268. },
  3269. 'class-name-definition': {
  3270. pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
  3271. lookbehind: true,
  3272. alias: 'class-name'
  3273. },
  3274. 'function-definition': {
  3275. pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
  3276. lookbehind: true,
  3277. alias: 'function'
  3278. },
  3279. 'keyword': [
  3280. {
  3281. pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,
  3282. alias: 'type-casting',
  3283. greedy: true,
  3284. lookbehind: true
  3285. },
  3286. {
  3287. pattern: /([(,?]\s*)\b(?:bool|int|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b(?=\s*\$)/i,
  3288. alias: 'type-hint',
  3289. greedy: true,
  3290. lookbehind: true
  3291. },
  3292. {
  3293. pattern: /([(,?]\s*[a-z0-9_|]\|\s*)(?:null|false)\b(?=\s*\$)/i,
  3294. alias: 'type-hint',
  3295. greedy: true,
  3296. lookbehind: true
  3297. },
  3298. {
  3299. pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b/i,
  3300. alias: 'return-type',
  3301. greedy: true,
  3302. lookbehind: true
  3303. },
  3304. {
  3305. pattern: /(\)\s*:\s*(?:\?\s*)?[a-z0-9_|]\|\s*)(?:null|false)\b/i,
  3306. alias: 'return-type',
  3307. greedy: true,
  3308. lookbehind: true
  3309. },
  3310. {
  3311. pattern: /\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|iterable|(?:null|false)(?=\s*\|))\b/i,
  3312. alias: 'type-declaration',
  3313. greedy: true
  3314. },
  3315. {
  3316. pattern: /(\|\s*)(?:null|false)\b/i,
  3317. alias: 'type-declaration',
  3318. greedy: true,
  3319. lookbehind: true
  3320. },
  3321. {
  3322. pattern: /\b(?:parent|self|static)(?=\s*::)/i,
  3323. alias: 'static-context',
  3324. greedy: true
  3325. },
  3326. {
  3327. // yield from
  3328. pattern: /(\byield\s+)from\b/i,
  3329. lookbehind: true
  3330. },
  3331. // `class` is always a keyword unlike other keywords
  3332. /\bclass\b/i,
  3333. {
  3334. // https://www.php.net/manual/en/reserved.keywords.php
  3335. //
  3336. // keywords cannot be preceded by "->"
  3337. // the complex lookbehind means `(?<!(?:->|::)\s*)`
  3338. pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,
  3339. lookbehind: true
  3340. }
  3341. ],
  3342. 'argument-name': {
  3343. pattern: /([(,]\s+)\b[a-z_]\w*(?=\s*:(?!:))/i,
  3344. lookbehind: true
  3345. },
  3346. 'class-name': [
  3347. {
  3348. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
  3349. greedy: true,
  3350. lookbehind: true
  3351. },
  3352. {
  3353. pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
  3354. greedy: true,
  3355. lookbehind: true
  3356. },
  3357. {
  3358. pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
  3359. greedy: true
  3360. },
  3361. {
  3362. pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
  3363. alias: 'class-name-fully-qualified',
  3364. greedy: true,
  3365. lookbehind: true,
  3366. inside: {
  3367. 'punctuation': /\\/
  3368. }
  3369. },
  3370. {
  3371. pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
  3372. alias: 'class-name-fully-qualified',
  3373. greedy: true,
  3374. inside: {
  3375. 'punctuation': /\\/
  3376. }
  3377. },
  3378. {
  3379. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3380. alias: 'class-name-fully-qualified',
  3381. greedy: true,
  3382. lookbehind: true,
  3383. inside: {
  3384. 'punctuation': /\\/
  3385. }
  3386. },
  3387. {
  3388. pattern: /\b[a-z_]\w*(?=\s*\$)/i,
  3389. alias: 'type-declaration',
  3390. greedy: true
  3391. },
  3392. {
  3393. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  3394. alias: ['class-name-fully-qualified', 'type-declaration'],
  3395. greedy: true,
  3396. inside: {
  3397. 'punctuation': /\\/
  3398. }
  3399. },
  3400. {
  3401. pattern: /\b[a-z_]\w*(?=\s*::)/i,
  3402. alias: 'static-context',
  3403. greedy: true
  3404. },
  3405. {
  3406. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
  3407. alias: ['class-name-fully-qualified', 'static-context'],
  3408. greedy: true,
  3409. inside: {
  3410. 'punctuation': /\\/
  3411. }
  3412. },
  3413. {
  3414. pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
  3415. alias: 'type-hint',
  3416. greedy: true,
  3417. lookbehind: true
  3418. },
  3419. {
  3420. pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  3421. alias: ['class-name-fully-qualified', 'type-hint'],
  3422. greedy: true,
  3423. lookbehind: true,
  3424. inside: {
  3425. 'punctuation': /\\/
  3426. }
  3427. },
  3428. {
  3429. pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
  3430. alias: 'return-type',
  3431. greedy: true,
  3432. lookbehind: true
  3433. },
  3434. {
  3435. pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3436. alias: ['class-name-fully-qualified', 'return-type'],
  3437. greedy: true,
  3438. lookbehind: true,
  3439. inside: {
  3440. 'punctuation': /\\/
  3441. }
  3442. }
  3443. ],
  3444. 'constant': constant,
  3445. 'function': {
  3446. pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
  3447. lookbehind: true,
  3448. inside: {
  3449. 'punctuation': /\\/
  3450. }
  3451. },
  3452. 'property': {
  3453. pattern: /(->\s*)\w+/,
  3454. lookbehind: true
  3455. },
  3456. 'number': number,
  3457. 'operator': operator,
  3458. 'punctuation': punctuation
  3459. };
  3460. var string_interpolation = {
  3461. pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
  3462. lookbehind: true,
  3463. inside: Prism.languages.php
  3464. };
  3465. var string = [
  3466. {
  3467. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  3468. alias: 'nowdoc-string',
  3469. greedy: true,
  3470. inside: {
  3471. 'delimiter': {
  3472. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  3473. alias: 'symbol',
  3474. inside: {
  3475. 'punctuation': /^<<<'?|[';]$/
  3476. }
  3477. }
  3478. }
  3479. },
  3480. {
  3481. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  3482. alias: 'heredoc-string',
  3483. greedy: true,
  3484. inside: {
  3485. 'delimiter': {
  3486. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  3487. alias: 'symbol',
  3488. inside: {
  3489. 'punctuation': /^<<<"?|[";]$/
  3490. }
  3491. },
  3492. 'interpolation': string_interpolation
  3493. }
  3494. },
  3495. {
  3496. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  3497. alias: 'backtick-quoted-string',
  3498. greedy: true
  3499. },
  3500. {
  3501. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  3502. alias: 'single-quoted-string',
  3503. greedy: true
  3504. },
  3505. {
  3506. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  3507. alias: 'double-quoted-string',
  3508. greedy: true,
  3509. inside: {
  3510. 'interpolation': string_interpolation
  3511. }
  3512. }
  3513. ];
  3514. Prism.languages.insertBefore('php', 'variable', {
  3515. 'string': string,
  3516. 'attribute': {
  3517. pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/mi,
  3518. greedy: true,
  3519. inside: {
  3520. 'attribute-content': {
  3521. pattern: /^(#\[)[\s\S]+(?=]$)/,
  3522. lookbehind: true,
  3523. // inside can appear subset of php
  3524. inside: {
  3525. 'comment': comment,
  3526. 'string': string,
  3527. 'attribute-class-name': [
  3528. {
  3529. pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
  3530. alias: 'class-name',
  3531. greedy: true,
  3532. lookbehind: true
  3533. },
  3534. {
  3535. pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
  3536. alias: [
  3537. 'class-name',
  3538. 'class-name-fully-qualified'
  3539. ],
  3540. greedy: true,
  3541. lookbehind: true,
  3542. inside: {
  3543. 'punctuation': /\\/
  3544. }
  3545. }
  3546. ],
  3547. 'constant': constant,
  3548. 'number': number,
  3549. 'operator': operator,
  3550. 'punctuation': punctuation
  3551. }
  3552. },
  3553. 'delimiter': {
  3554. pattern: /^#\[|]$/,
  3555. alias: 'punctuation'
  3556. }
  3557. }
  3558. },
  3559. });
  3560. Prism.hooks.add('before-tokenize', function (env) {
  3561. if (!/<\?/.test(env.code)) {
  3562. return;
  3563. }
  3564. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/ig;
  3565. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  3566. });
  3567. Prism.hooks.add('after-tokenize', function (env) {
  3568. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  3569. });
  3570. }(Prism));
  3571. Prism.languages.python = {
  3572. 'comment': {
  3573. pattern: /(^|[^\\])#.*/,
  3574. lookbehind: true
  3575. },
  3576. 'string-interpolation': {
  3577. pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  3578. greedy: true,
  3579. inside: {
  3580. 'interpolation': {
  3581. // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
  3582. pattern: /((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,
  3583. lookbehind: true,
  3584. inside: {
  3585. 'format-spec': {
  3586. pattern: /(:)[^:(){}]+(?=}$)/,
  3587. lookbehind: true
  3588. },
  3589. 'conversion-option': {
  3590. pattern: /![sra](?=[:}]$)/,
  3591. alias: 'punctuation'
  3592. },
  3593. rest: null
  3594. }
  3595. },
  3596. 'string': /[\s\S]+/
  3597. }
  3598. },
  3599. 'triple-quoted-string': {
  3600. pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,
  3601. greedy: true,
  3602. alias: 'string'
  3603. },
  3604. 'string': {
  3605. pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  3606. greedy: true
  3607. },
  3608. 'function': {
  3609. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  3610. lookbehind: true
  3611. },
  3612. 'class-name': {
  3613. pattern: /(\bclass\s+)\w+/i,
  3614. lookbehind: true
  3615. },
  3616. 'decorator': {
  3617. pattern: /(^[\t ]*)@\w+(?:\.\w+)*/im,
  3618. lookbehind: true,
  3619. alias: ['annotation', 'punctuation'],
  3620. inside: {
  3621. 'punctuation': /\./
  3622. }
  3623. },
  3624. 'keyword': /\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
  3625. '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/,
  3626. 'boolean': /\b(?:True|False|None)\b/,
  3627. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  3628. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  3629. 'punctuation': /[{}[\];(),.:]/
  3630. };
  3631. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  3632. Prism.languages.py = Prism.languages.python;
  3633. Prism.languages.r = {
  3634. 'comment': /#.*/,
  3635. 'string': {
  3636. pattern: /(['"])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  3637. greedy: true
  3638. },
  3639. 'percent-operator': {
  3640. // Includes user-defined operators
  3641. // and %%, %*%, %/%, %in%, %o%, %x%
  3642. pattern: /%[^%\s]*%/,
  3643. alias: 'operator'
  3644. },
  3645. 'boolean': /\b(?:TRUE|FALSE)\b/,
  3646. 'ellipsis': /\.\.(?:\.|\d+)/,
  3647. 'number': [
  3648. /\b(?:NaN|Inf)\b/,
  3649. /(?:\b0x[\dA-Fa-f]+(?:\.\d*)?|\b\d+(?:\.\d*)?|\B\.\d+)(?:[EePp][+-]?\d+)?[iL]?/
  3650. ],
  3651. 'keyword': /\b(?:if|else|repeat|while|function|for|in|next|break|NULL|NA|NA_integer_|NA_real_|NA_complex_|NA_character_)\b/,
  3652. 'operator': /->?>?|<(?:=|<?-)?|[>=!]=?|::?|&&?|\|\|?|[+*\/^$@~]/,
  3653. 'punctuation': /[(){}\[\],;]/
  3654. };
  3655. (function (Prism) {
  3656. var javascript = Prism.util.clone(Prism.languages.javascript);
  3657. var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
  3658. var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
  3659. var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
  3660. /**
  3661. * @param {string} source
  3662. * @param {string} [flags]
  3663. */
  3664. function re(source, flags) {
  3665. source = source
  3666. .replace(/<S>/g, function () { return space; })
  3667. .replace(/<BRACES>/g, function () { return braces; })
  3668. .replace(/<SPREAD>/g, function () { return spread; });
  3669. return RegExp(source, flags);
  3670. }
  3671. spread = re(spread).source;
  3672. Prism.languages.jsx = Prism.languages.extend('markup', javascript);
  3673. Prism.languages.jsx.tag.pattern = re(
  3674. /<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[^]|[^\\"])*"|'(?:\\[^]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
  3675. );
  3676. Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/i;
  3677. Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[^]|[^\\"])*"|'(?:\\[^]|[^\\'])*'|[^\s'">]+)/i;
  3678. Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
  3679. Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
  3680. Prism.languages.insertBefore('inside', 'attr-name', {
  3681. 'spread': {
  3682. pattern: re(/<SPREAD>/.source),
  3683. inside: Prism.languages.jsx
  3684. }
  3685. }, Prism.languages.jsx.tag);
  3686. Prism.languages.insertBefore('inside', 'special-attr', {
  3687. 'script': {
  3688. // Allow for two levels of nesting
  3689. pattern: re(/=<BRACES>/.source),
  3690. inside: {
  3691. 'script-punctuation': {
  3692. pattern: /^=(?={)/,
  3693. alias: 'punctuation'
  3694. },
  3695. rest: Prism.languages.jsx
  3696. },
  3697. 'alias': 'language-javascript'
  3698. }
  3699. }, Prism.languages.jsx.tag);
  3700. // The following will handle plain text inside tags
  3701. var stringifyToken = function (token) {
  3702. if (!token) {
  3703. return '';
  3704. }
  3705. if (typeof token === 'string') {
  3706. return token;
  3707. }
  3708. if (typeof token.content === 'string') {
  3709. return token.content;
  3710. }
  3711. return token.content.map(stringifyToken).join('');
  3712. };
  3713. var walkTokens = function (tokens) {
  3714. var openedTags = [];
  3715. for (var i = 0; i < tokens.length; i++) {
  3716. var token = tokens[i];
  3717. var notTagNorBrace = false;
  3718. if (typeof token !== 'string') {
  3719. if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
  3720. // We found a tag, now find its kind
  3721. if (token.content[0].content[0].content === '</') {
  3722. // Closing tag
  3723. if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
  3724. // Pop matching opening tag
  3725. openedTags.pop();
  3726. }
  3727. } else {
  3728. if (token.content[token.content.length - 1].content === '/>') {
  3729. // Autoclosed tag, ignore
  3730. } else {
  3731. // Opening tag
  3732. openedTags.push({
  3733. tagName: stringifyToken(token.content[0].content[1]),
  3734. openedBraces: 0
  3735. });
  3736. }
  3737. }
  3738. } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
  3739. // Here we might have entered a JSX context inside a tag
  3740. openedTags[openedTags.length - 1].openedBraces++;
  3741. } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
  3742. // Here we might have left a JSX context inside a tag
  3743. openedTags[openedTags.length - 1].openedBraces--;
  3744. } else {
  3745. notTagNorBrace = true;
  3746. }
  3747. }
  3748. if (notTagNorBrace || typeof token === 'string') {
  3749. if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
  3750. // Here we are inside a tag, and not inside a JSX context.
  3751. // That's plain text: drop any tokens matched.
  3752. var plainText = stringifyToken(token);
  3753. // And merge text with adjacent text
  3754. if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
  3755. plainText += stringifyToken(tokens[i + 1]);
  3756. tokens.splice(i + 1, 1);
  3757. }
  3758. if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
  3759. plainText = stringifyToken(tokens[i - 1]) + plainText;
  3760. tokens.splice(i - 1, 1);
  3761. i--;
  3762. }
  3763. tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
  3764. }
  3765. }
  3766. if (token.content && typeof token.content !== 'string') {
  3767. walkTokens(token.content);
  3768. }
  3769. }
  3770. };
  3771. Prism.hooks.add('after-tokenize', function (env) {
  3772. if (env.language !== 'jsx' && env.language !== 'tsx') {
  3773. return;
  3774. }
  3775. walkTokens(env.tokens);
  3776. });
  3777. }(Prism));
  3778. (function (Prism) {
  3779. var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
  3780. for (var i = 0; i < 2; i++) {
  3781. // support 4 levels of nested comments
  3782. multilineComment = multilineComment.replace(/<self>/g, function () { return multilineComment; });
  3783. }
  3784. multilineComment = multilineComment.replace(/<self>/g, function () { return /[^\s\S]/.source; });
  3785. Prism.languages.rust = {
  3786. 'comment': [
  3787. {
  3788. pattern: RegExp(/(^|[^\\])/.source + multilineComment),
  3789. lookbehind: true,
  3790. greedy: true
  3791. },
  3792. {
  3793. pattern: /(^|[^\\:])\/\/.*/,
  3794. lookbehind: true,
  3795. greedy: true
  3796. }
  3797. ],
  3798. 'string': {
  3799. pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
  3800. greedy: true
  3801. },
  3802. 'char': {
  3803. pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
  3804. greedy: true,
  3805. alias: 'string'
  3806. },
  3807. 'attribute': {
  3808. pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
  3809. greedy: true,
  3810. alias: 'attr-name',
  3811. inside: {
  3812. 'string': null // see below
  3813. }
  3814. },
  3815. // Closure params should not be confused with bitwise OR |
  3816. 'closure-params': {
  3817. pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
  3818. lookbehind: true,
  3819. greedy: true,
  3820. inside: {
  3821. 'closure-punctuation': {
  3822. pattern: /^\||\|$/,
  3823. alias: 'punctuation'
  3824. },
  3825. rest: null // see below
  3826. }
  3827. },
  3828. 'lifetime-annotation': {
  3829. pattern: /'\w+/,
  3830. alias: 'symbol'
  3831. },
  3832. 'fragment-specifier': {
  3833. pattern: /(\$\w+:)[a-z]+/,
  3834. lookbehind: true,
  3835. alias: 'punctuation'
  3836. },
  3837. 'variable': /\$\w+/,
  3838. 'function-definition': {
  3839. pattern: /(\bfn\s+)\w+/,
  3840. lookbehind: true,
  3841. alias: 'function'
  3842. },
  3843. 'type-definition': {
  3844. pattern: /(\b(?:enum|struct|union)\s+)\w+/,
  3845. lookbehind: true,
  3846. alias: 'class-name'
  3847. },
  3848. 'module-declaration': [
  3849. {
  3850. pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
  3851. lookbehind: true,
  3852. alias: 'namespace'
  3853. },
  3854. {
  3855. pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
  3856. lookbehind: true,
  3857. alias: 'namespace',
  3858. inside: {
  3859. 'punctuation': /::/
  3860. }
  3861. }
  3862. ],
  3863. 'keyword': [
  3864. // https://github.com/rust-lang/reference/blob/master/src/keywords.md
  3865. /\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,
  3866. // primitives and str
  3867. // https://doc.rust-lang.org/stable/rust-by-example/primitives.html
  3868. /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/
  3869. ],
  3870. // functions can technically start with an upper-case letter, but this will introduce a lot of false positives
  3871. // and Rust's naming conventions recommend snake_case anyway.
  3872. // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
  3873. 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
  3874. 'macro': {
  3875. pattern: /\b\w+!/,
  3876. alias: 'property'
  3877. },
  3878. 'constant': /\b[A-Z_][A-Z_\d]+\b/,
  3879. 'class-name': /\b[A-Z]\w*\b/,
  3880. 'namespace': {
  3881. pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
  3882. inside: {
  3883. 'punctuation': /::/
  3884. }
  3885. },
  3886. // Hex, oct, bin, dec numbers with visual separators and type suffix
  3887. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/,
  3888. 'boolean': /\b(?:false|true)\b/,
  3889. 'punctuation': /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
  3890. 'operator': /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
  3891. };
  3892. Prism.languages.rust['closure-params'].inside.rest = Prism.languages.rust;
  3893. Prism.languages.rust['attribute'].inside['string'] = Prism.languages.rust['string'];
  3894. }(Prism));
  3895. Prism.languages.scss = Prism.languages.extend('css', {
  3896. 'comment': {
  3897. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  3898. lookbehind: true
  3899. },
  3900. 'atrule': {
  3901. pattern: /@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,
  3902. inside: {
  3903. 'rule': /@[\w-]+/
  3904. // See rest below
  3905. }
  3906. },
  3907. // url, compassified
  3908. 'url': /(?:[-a-z]+-)?url(?=\()/i,
  3909. // CSS selector regex is not appropriate for Sass
  3910. // since there can be lot more things (var, @ directive, nesting..)
  3911. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  3912. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  3913. // 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
  3914. // can "pass" as a selector- e.g: proper#{$erty})
  3915. // this one was hard to do, so please be careful if you edit this one :)
  3916. 'selector': {
  3917. // Initial look-ahead is used to prevent matching of blank selectors
  3918. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]+))/m,
  3919. inside: {
  3920. 'parent': {
  3921. pattern: /&/,
  3922. alias: 'important'
  3923. },
  3924. 'placeholder': /%[-\w]+/,
  3925. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  3926. }
  3927. },
  3928. 'property': {
  3929. pattern: /(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,
  3930. inside: {
  3931. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  3932. }
  3933. }
  3934. });
  3935. Prism.languages.insertBefore('scss', 'atrule', {
  3936. 'keyword': [
  3937. /@(?:if|else(?: if)?|forward|for|each|while|import|use|extend|debug|warn|mixin|include|function|return|content)\b/i,
  3938. {
  3939. pattern: /( )(?:from|through)(?= )/,
  3940. lookbehind: true
  3941. }
  3942. ]
  3943. });
  3944. Prism.languages.insertBefore('scss', 'important', {
  3945. // var and interpolated vars
  3946. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  3947. });
  3948. Prism.languages.insertBefore('scss', 'function', {
  3949. 'module-modifier': {
  3950. pattern: /\b(?:as|with|show|hide)\b/i,
  3951. alias: 'keyword'
  3952. },
  3953. 'placeholder': {
  3954. pattern: /%[-\w]+/,
  3955. alias: 'selector'
  3956. },
  3957. 'statement': {
  3958. pattern: /\B!(?:default|optional)\b/i,
  3959. alias: 'keyword'
  3960. },
  3961. 'boolean': /\b(?:true|false)\b/,
  3962. 'null': {
  3963. pattern: /\bnull\b/,
  3964. alias: 'keyword'
  3965. },
  3966. 'operator': {
  3967. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|or|not)(?=\s)/,
  3968. lookbehind: true
  3969. }
  3970. });
  3971. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;
  3972. (function (Prism) {
  3973. // CAREFUL!
  3974. // The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
  3975. var strings = [
  3976. // normal string
  3977. /"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/.source,
  3978. /'[^']*'/.source,
  3979. /\$'(?:[^'\\]|\\[\s\S])*'/.source,
  3980. // here doc
  3981. // 2 capturing groups
  3982. /<<-?\s*(["']?)(\w+)\1\s[\s\S]*?[\r\n]\2/.source
  3983. ].join('|');
  3984. Prism.languages['shell-session'] = {
  3985. 'command': {
  3986. pattern: RegExp(
  3987. // user info
  3988. /^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>:;|]+)?/.source +
  3989. // shell symbol
  3990. /[$#]/.source +
  3991. // bash command
  3992. /(?:[^\\\r\n'"<$]|\\(?:[^\r]|\r\n?)|\$(?!')|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
  3993. 'm'
  3994. ),
  3995. greedy: true,
  3996. inside: {
  3997. 'info': {
  3998. // foo@bar:~/files$ exit
  3999. // foo@bar$ exit
  4000. // ~/files$ exit
  4001. pattern: /^[^#$]+/,
  4002. alias: 'punctuation',
  4003. inside: {
  4004. 'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+/,
  4005. 'punctuation': /:/,
  4006. 'path': /[\s\S]+/
  4007. }
  4008. },
  4009. 'bash': {
  4010. pattern: /(^[$#]\s*)\S[\s\S]*/,
  4011. lookbehind: true,
  4012. alias: 'language-bash',
  4013. inside: Prism.languages.bash
  4014. },
  4015. 'shell-symbol': {
  4016. pattern: /^[$#]/,
  4017. alias: 'important'
  4018. }
  4019. }
  4020. },
  4021. 'output': /.(?:.*(?:[\r\n]|.$))*/
  4022. };
  4023. Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
  4024. }(Prism));
  4025. Prism.languages.sql = {
  4026. 'comment': {
  4027. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  4028. lookbehind: true
  4029. },
  4030. 'variable': [
  4031. {
  4032. pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
  4033. greedy: true
  4034. },
  4035. /@[\w.$]+/
  4036. ],
  4037. 'string': {
  4038. pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
  4039. greedy: true,
  4040. lookbehind: true
  4041. },
  4042. '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?
  4043. '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|RETURN(?:S|ING)?|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,
  4044. 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
  4045. 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
  4046. 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|IN|ILIKE|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  4047. 'punctuation': /[;[\]()`,.]/
  4048. };
  4049. (function (Prism) {
  4050. Prism.languages.typescript = Prism.languages.extend('javascript', {
  4051. 'class-name': {
  4052. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
  4053. lookbehind: true,
  4054. greedy: true,
  4055. inside: null // see below
  4056. },
  4057. 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
  4058. });
  4059. // The keywords TypeScript adds to JavaScript
  4060. Prism.languages.typescript.keyword.push(
  4061. /\b(?:abstract|as|declare|implements|is|keyof|readonly|require)\b/,
  4062. // keywords that have to be followed by an identifier
  4063. /\b(?:asserts|infer|interface|module|namespace|type)(?!\s*[^\s_${}*a-zA-Z\xA0-\uFFFF])/
  4064. );
  4065. // doesn't work with TS because TS is too complex
  4066. delete Prism.languages.typescript['parameter'];
  4067. // a version of typescript specifically for highlighting types
  4068. var typeInside = Prism.languages.extend('typescript', {});
  4069. delete typeInside['class-name'];
  4070. Prism.languages.typescript['class-name'].inside = typeInside;
  4071. Prism.languages.insertBefore('typescript', 'function', {
  4072. 'decorator': {
  4073. pattern: /@[$\w\xA0-\uFFFF]+/,
  4074. inside: {
  4075. 'at': {
  4076. pattern: /^@/,
  4077. alias: 'operator'
  4078. },
  4079. 'function': /^[\s\S]+/
  4080. }
  4081. },
  4082. 'generic-function': {
  4083. // e.g. foo<T extends "bar" | "baz">( ...
  4084. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
  4085. greedy: true,
  4086. inside: {
  4087. 'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
  4088. 'generic': {
  4089. pattern: /<[\s\S]+/, // everything after the first <
  4090. alias: 'class-name',
  4091. inside: typeInside
  4092. }
  4093. }
  4094. }
  4095. });
  4096. Prism.languages.ts = Prism.languages.typescript;
  4097. }(Prism));
  4098. (function (Prism) {
  4099. // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
  4100. // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
  4101. var anchorOrAlias = /[*&][^\s[\]{},]+/;
  4102. // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
  4103. var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
  4104. // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
  4105. var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
  4106. + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
  4107. // https://yaml.org/spec/1.2/spec.html#ns-plain(n,c)
  4108. // This is a simplified version that doesn't support "#" and multiline keys
  4109. // All these long scarry character classes are simplified versions of YAML's characters
  4110. var plainKey = /(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*/.source
  4111. .replace(/<PLAIN>/g, function () { return /[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source; });
  4112. var string = /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;
  4113. /**
  4114. *
  4115. * @param {string} value
  4116. * @param {string} [flags]
  4117. * @returns {RegExp}
  4118. */
  4119. function createValuePattern(value, flags) {
  4120. flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
  4121. var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|]|}|(?:[\r\n]\s*)?#))/.source
  4122. .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
  4123. return RegExp(pattern, flags);
  4124. }
  4125. Prism.languages.yaml = {
  4126. 'scalar': {
  4127. pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source
  4128. .replace(/<<prop>>/g, function () { return properties; })),
  4129. lookbehind: true,
  4130. alias: 'string'
  4131. },
  4132. 'comment': /#.*/,
  4133. 'key': {
  4134. pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\s*:\s)/.source
  4135. .replace(/<<prop>>/g, function () { return properties; })
  4136. .replace(/<<key>>/g, function () { return '(?:' + plainKey + '|' + string + ')'; })),
  4137. lookbehind: true,
  4138. greedy: true,
  4139. alias: 'atrule'
  4140. },
  4141. 'directive': {
  4142. pattern: /(^[ \t]*)%.+/m,
  4143. lookbehind: true,
  4144. alias: 'important'
  4145. },
  4146. 'datetime': {
  4147. pattern: createValuePattern(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),
  4148. lookbehind: true,
  4149. alias: 'number'
  4150. },
  4151. 'boolean': {
  4152. pattern: createValuePattern(/true|false/.source, 'i'),
  4153. lookbehind: true,
  4154. alias: 'important'
  4155. },
  4156. 'null': {
  4157. pattern: createValuePattern(/null|~/.source, 'i'),
  4158. lookbehind: true,
  4159. alias: 'important'
  4160. },
  4161. 'string': {
  4162. pattern: createValuePattern(string),
  4163. lookbehind: true,
  4164. greedy: true
  4165. },
  4166. 'number': {
  4167. pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
  4168. lookbehind: true
  4169. },
  4170. 'tag': tag,
  4171. 'important': anchorOrAlias,
  4172. 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
  4173. };
  4174. Prism.languages.yml = Prism.languages.yaml;
  4175. }(Prism));
  4176. Prism.languages.cmake = {
  4177. 'comment' : /#.*/,
  4178. 'string': {
  4179. 'pattern' : /"(?:[^\\"]|\\.)*"/,
  4180. 'greedy' : !0,
  4181. 'inside' : {
  4182. 'interpolation' : {
  4183. 'pattern' : /\$\{(?:[^{}$]|\$\{[^{}$]*\})*\}/,
  4184. 'inside' : {
  4185. 'punctuation' : /\$\{|\}/,
  4186. 'variable':/\w+/
  4187. }
  4188. }
  4189. }
  4190. },
  4191. 'variable' : /\b(?:CMAKE_\w+|\w+_(?:VERSION(?:_MAJOR|_MINOR|_PATCH|_TWEAK)?|(?:BINARY|SOURCE)_DIR|DESCRIPTION|HOMEPAGE_URL|ROOT)|(?:ANDROID|APPLE|BORLAND|BUILD_SHARED_LIBS|CACHE|CPACK_(?:ABSOLUTE_DESTINATION_FILES|COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY|ERROR_ON_ABSOLUTE_INSTALL_DESTINATION|INCLUDE_TOPLEVEL_DIRECTORY|INSTALL_DEFAULT_DIRECTORY_PERMISSIONS|INSTALL_SCRIPT|PACKAGING_INSTALL_PREFIX|SET_DESTDIR|WARN_ON_ABSOLUTE_INSTALL_DESTINATION)|CTEST_(?:BINARY_DIRECTORY|BUILD_COMMAND|BUILD_NAME|BZR_COMMAND|BZR_UPDATE_OPTIONS|CHANGE_ID|CHECKOUT_COMMAND|CONFIGURATION_TYPE|CONFIGURE_COMMAND|COVERAGE_COMMAND|COVERAGE_EXTRA_FLAGS|CURL_OPTIONS|CUSTOM_(?:COVERAGE_EXCLUDE|ERROR_EXCEPTION|ERROR_MATCH|ERROR_POST_CONTEXT|ERROR_PRE_CONTEXT|MAXIMUM_FAILED_TEST_OUTPUT_SIZE|MAXIMUM_NUMBER_OF_(?:ERRORS|WARNINGS)|MAXIMUM_PASSED_TEST_OUTPUT_SIZE|MEMCHECK_IGNORE|POST_MEMCHECK|POST_TEST|PRE_MEMCHECK|PRE_TEST|TESTS_IGNORE|WARNING_EXCEPTION|WARNING_MATCH)|CVS_CHECKOUT|CVS_COMMAND|CVS_UPDATE_OPTIONS|DROP_LOCATION|DROP_METHOD|DROP_SITE|DROP_SITE_CDASH|DROP_SITE_PASSWORD|DROP_SITE_USER|EXTRA_COVERAGE_GLOB|GIT_COMMAND|GIT_INIT_SUBMODULES|GIT_UPDATE_CUSTOM|GIT_UPDATE_OPTIONS|HG_COMMAND|HG_UPDATE_OPTIONS|LABELS_FOR_SUBPROJECTS|MEMORYCHECK_(?:COMMAND|COMMAND_OPTIONS|SANITIZER_OPTIONS|SUPPRESSIONS_FILE|TYPE)|NIGHTLY_START_TIME|P4_CLIENT|P4_COMMAND|P4_OPTIONS|P4_UPDATE_OPTIONS|RUN_CURRENT_SCRIPT|SCP_COMMAND|SITE|SOURCE_DIRECTORY|SUBMIT_URL|SVN_COMMAND|SVN_OPTIONS|SVN_UPDATE_OPTIONS|TEST_LOAD|TEST_TIMEOUT|TRIGGER_SITE|UPDATE_COMMAND|UPDATE_OPTIONS|UPDATE_VERSION_ONLY|USE_LAUNCHERS)|CYGWIN|ENV|EXECUTABLE_OUTPUT_PATH|GHS-MULTI|IOS|LIBRARY_OUTPUT_PATH|MINGW|MSVC(?:10|11|12|14|60|70|71|80|90|_IDE|_TOOLSET_VERSION|_VERSION)?|MSYS|PROJECT_(?:BINARY_DIR|DESCRIPTION|HOMEPAGE_URL|NAME|SOURCE_DIR|VERSION|VERSION_(?:MAJOR|MINOR|PATCH|TWEAK))|UNIX|WIN32|WINCE|WINDOWS_PHONE|WINDOWS_STORE|XCODE|XCODE_VERSION))\b/,
  4192. 'property' : /\b(?:cxx_\w+|(?:ARCHIVE_OUTPUT_(?:DIRECTORY|NAME)|COMPILE_DEFINITIONS|COMPILE_PDB_NAME|COMPILE_PDB_OUTPUT_DIRECTORY|EXCLUDE_FROM_DEFAULT_BUILD|IMPORTED_(?:IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_LANGUAGES|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|NO_SONAME|OBJECTS|SONAME)|INTERPROCEDURAL_OPTIMIZATION|LIBRARY_OUTPUT_DIRECTORY|LIBRARY_OUTPUT_NAME|LINK_FLAGS|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|MAP_IMPORTED_CONFIG|OSX_ARCHITECTURES|OUTPUT_NAME|PDB_NAME|PDB_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_NAME|STATIC_LIBRARY_FLAGS|VS_CSHARP|VS_DOTNET_REFERENCEPROP|VS_DOTNET_REFERENCE|VS_GLOBAL_SECTION_POST|VS_GLOBAL_SECTION_PRE|VS_GLOBAL|XCODE_ATTRIBUTE)_\w+|\w+_(?:CLANG_TIDY|COMPILER_LAUNCHER|CPPCHECK|CPPLINT|INCLUDE_WHAT_YOU_USE|OUTPUT_NAME|POSTFIX|VISIBILITY_PRESET)|ABSTRACT|ADDITIONAL_MAKE_CLEAN_FILES|ADVANCED|ALIASED_TARGET|ALLOW_DUPLICATE_CUSTOM_TARGETS|ANDROID_(?:ANT_ADDITIONAL_OPTIONS|API|API_MIN|ARCH|ASSETS_DIRECTORIES|GUI|JAR_DEPENDENCIES|NATIVE_LIB_DEPENDENCIES|NATIVE_LIB_DIRECTORIES|PROCESS_MAX|PROGUARD|PROGUARD_CONFIG_PATH|SECURE_PROPS_PATH|SKIP_ANT_STEP|STL_TYPE)|ARCHIVE_OUTPUT_DIRECTORY|ATTACHED_FILES|ATTACHED_FILES_ON_FAIL|AUTOGEN_(?:BUILD_DIR|ORIGIN_DEPENDS|PARALLEL|SOURCE_GROUP|TARGETS_FOLDER|TARGET_DEPENDS)|AUTOMOC|AUTOMOC_(?:COMPILER_PREDEFINES|DEPEND_FILTERS|EXECUTABLE|MACRO_NAMES|MOC_OPTIONS|SOURCE_GROUP|TARGETS_FOLDER)|AUTORCC|AUTORCC_EXECUTABLE|AUTORCC_OPTIONS|AUTORCC_SOURCE_GROUP|AUTOUIC|AUTOUIC_EXECUTABLE|AUTOUIC_OPTIONS|AUTOUIC_SEARCH_PATHS|BINARY_DIR|BUILDSYSTEM_TARGETS|BUILD_RPATH|BUILD_RPATH_USE_ORIGIN|BUILD_WITH_INSTALL_NAME_DIR|BUILD_WITH_INSTALL_RPATH|BUNDLE|BUNDLE_EXTENSION|CACHE_VARIABLES|CLEAN_NO_CUSTOM|COMMON_LANGUAGE_RUNTIME|COMPATIBLE_INTERFACE_(?:BOOL|NUMBER_MAX|NUMBER_MIN|STRING)|COMPILE_(?:DEFINITIONS|FEATURES|FLAGS|OPTIONS|PDB_NAME|PDB_OUTPUT_DIRECTORY)|COST|CPACK_DESKTOP_SHORTCUTS|CPACK_NEVER_OVERWRITE|CPACK_PERMANENT|CPACK_STARTUP_SHORTCUTS|CPACK_START_MENU_SHORTCUTS|CPACK_WIX_ACL|CROSSCOMPILING_EMULATOR|CUDA_EXTENSIONS|CUDA_PTX_COMPILATION|CUDA_RESOLVE_DEVICE_SYMBOLS|CUDA_SEPARABLE_COMPILATION|CUDA_STANDARD|CUDA_STANDARD_REQUIRED|CXX_EXTENSIONS|CXX_STANDARD|CXX_STANDARD_REQUIRED|C_EXTENSIONS|C_STANDARD|C_STANDARD_REQUIRED|DEBUG_CONFIGURATIONS|DEFINE_SYMBOL|DEFINITIONS|DEPENDS|DEPLOYMENT_ADDITIONAL_FILES|DEPLOYMENT_REMOTE_DIRECTORY|DISABLED|DISABLED_FEATURES|ECLIPSE_EXTRA_CPROJECT_CONTENTS|ECLIPSE_EXTRA_NATURES|ENABLED_FEATURES|ENABLED_LANGUAGES|ENABLE_EXPORTS|ENVIRONMENT|EXCLUDE_FROM_ALL|EXCLUDE_FROM_DEFAULT_BUILD|EXPORT_NAME|EXPORT_PROPERTIES|EXTERNAL_OBJECT|EchoString|FAIL_REGULAR_EXPRESSION|FIND_LIBRARY_USE_LIB32_PATHS|FIND_LIBRARY_USE_LIB64_PATHS|FIND_LIBRARY_USE_LIBX32_PATHS|FIND_LIBRARY_USE_OPENBSD_VERSIONING|FIXTURES_CLEANUP|FIXTURES_REQUIRED|FIXTURES_SETUP|FOLDER|FRAMEWORK|Fortran_FORMAT|Fortran_MODULE_DIRECTORY|GENERATED|GENERATOR_FILE_NAME|GENERATOR_IS_MULTI_CONFIG|GHS_INTEGRITY_APP|GHS_NO_SOURCE_GROUP_FILE|GLOBAL_DEPENDS_DEBUG_MODE|GLOBAL_DEPENDS_NO_CYCLES|GNUtoMS|HAS_CXX|HEADER_FILE_ONLY|HELPSTRING|IMPLICIT_DEPENDS_INCLUDE_TRANSFORM|IMPORTED|IMPORTED_(?:COMMON_LANGUAGE_RUNTIME|CONFIGURATIONS|GLOBAL|IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_(?:LANGUAGES|LIBRARIES|MULTIPLICITY)|LOCATION|NO_SONAME|OBJECTS|SONAME)|IMPORT_PREFIX|IMPORT_SUFFIX|INCLUDE_DIRECTORIES|INCLUDE_REGULAR_EXPRESSION|INSTALL_NAME_DIR|INSTALL_RPATH|INSTALL_RPATH_USE_LINK_PATH|INTERFACE_(?:AUTOUIC_OPTIONS|COMPILE_DEFINITIONS|COMPILE_FEATURES|COMPILE_OPTIONS|INCLUDE_DIRECTORIES|LINK_DEPENDS|LINK_DIRECTORIES|LINK_LIBRARIES|LINK_OPTIONS|POSITION_INDEPENDENT_CODE|SOURCES|SYSTEM_INCLUDE_DIRECTORIES)|INTERPROCEDURAL_OPTIMIZATION|IN_TRY_COMPILE|IOS_INSTALL_COMBINED|JOB_POOLS|JOB_POOL_COMPILE|JOB_POOL_LINK|KEEP_EXTENSION|LABELS|LANGUAGE|LIBRARY_OUTPUT_DIRECTORY|LINKER_LANGUAGE|LINK_(?:DEPENDS|DEPENDS_NO_SHARED|DIRECTORIES|FLAGS|INTERFACE_LIBRARIES|INTERFACE_MULTIPLICITY|LIBRARIES|OPTIONS|SEARCH_END_STATIC|SEARCH_START_STATIC|WHAT_YOU_USE)|LISTFILE_STACK|LOCATION|MACOSX_BUNDLE|MACOSX_BUNDLE_INFO_PLIST|MACOSX_FRAMEWORK_INFO_PLIST|MACOSX_PACKAGE_LOCATION|MACOSX_RPATH|MACROS|MANUALLY_ADDED_DEPENDENCIES|MEASUREMENT|MODIFIED|NAME|NO_SONAME|NO_SYSTEM_FROM_IMPORTED|OBJECT_DEPENDS|OBJECT_OUTPUTS|OSX_ARCHITECTURES|OUTPUT_NAME|PACKAGES_FOUND|PACKAGES_NOT_FOUND|PARENT_DIRECTORY|PASS_REGULAR_EXPRESSION|PDB_NAME|PDB_OUTPUT_DIRECTORY|POSITION_INDEPENDENT_CODE|POST_INSTALL_SCRIPT|PREDEFINED_TARGETS_FOLDER|PREFIX|PRE_INSTALL_SCRIPT|PRIVATE_HEADER|PROCESSORS|PROCESSOR_AFFINITY|PROJECT_LABEL|PUBLIC_HEADER|REPORT_UNDEFINED_PROPERTIES|REQUIRED_FILES|RESOURCE|RESOURCE_LOCK|RULE_LAUNCH_COMPILE|RULE_LAUNCH_CUSTOM|RULE_LAUNCH_LINK|RULE_MESSAGES|RUNTIME_OUTPUT_DIRECTORY|RUN_SERIAL|SKIP_AUTOGEN|SKIP_AUTOMOC|SKIP_AUTORCC|SKIP_AUTOUIC|SKIP_BUILD_RPATH|SKIP_RETURN_CODE|SOURCES|SOURCE_DIR|SOVERSION|STATIC_LIBRARY_FLAGS|STATIC_LIBRARY_OPTIONS|STRINGS|SUBDIRECTORIES|SUFFIX|SYMBOLIC|TARGET_ARCHIVES_MAY_BE_SHARED_LIBS|TARGET_MESSAGES|TARGET_SUPPORTS_SHARED_LIBS|TESTS|TEST_INCLUDE_FILE|TEST_INCLUDE_FILES|TIMEOUT|TIMEOUT_AFTER_MATCH|TYPE|USE_FOLDERS|VALUE|VARIABLES|VERSION|VISIBILITY_INLINES_HIDDEN|VS_(?:CONFIGURATION_TYPE|COPY_TO_OUT_DIR|DEBUGGER_(?:COMMAND|COMMAND_ARGUMENTS|ENVIRONMENT|WORKING_DIRECTORY)|DEPLOYMENT_CONTENT|DEPLOYMENT_LOCATION|DOTNET_REFERENCES|DOTNET_REFERENCES_COPY_LOCAL|GLOBAL_KEYWORD|GLOBAL_PROJECT_TYPES|GLOBAL_ROOTNAMESPACE|INCLUDE_IN_VSIX|IOT_STARTUP_TASK|KEYWORD|RESOURCE_GENERATOR|SCC_AUXPATH|SCC_LOCALPATH|SCC_PROJECTNAME|SCC_PROVIDER|SDK_REFERENCES|SHADER_(?:DISABLE_OPTIMIZATIONS|ENABLE_DEBUG|ENTRYPOINT|FLAGS|MODEL|OBJECT_FILE_NAME|OUTPUT_HEADER_FILE|TYPE|VARIABLE_NAME)|STARTUP_PROJECT|TOOL_OVERRIDE|USER_PROPS|WINRT_COMPONENT|WINRT_EXTENSIONS|WINRT_REFERENCES|XAML_TYPE)|WILL_FAIL|WIN32_EXECUTABLE|WINDOWS_EXPORT_ALL_SYMBOLS|WORKING_DIRECTORY|WRAP_EXCLUDE|XCODE_(?:EMIT_EFFECTIVE_PLATFORM_NAME|EXPLICIT_FILE_TYPE|FILE_ATTRIBUTES|LAST_KNOWN_FILE_TYPE|PRODUCT_TYPE|SCHEME_(?:ADDRESS_SANITIZER|ADDRESS_SANITIZER_USE_AFTER_RETURN|ARGUMENTS|DISABLE_MAIN_THREAD_CHECKER|DYNAMIC_LIBRARY_LOADS|DYNAMIC_LINKER_API_USAGE|ENVIRONMENT|EXECUTABLE|GUARD_MALLOC|MAIN_THREAD_CHECKER_STOP|MALLOC_GUARD_EDGES|MALLOC_SCRIBBLE|MALLOC_STACK|THREAD_SANITIZER(?:_STOP)?|UNDEFINED_BEHAVIOUR_SANITIZER(?:_STOP)?|ZOMBIE_OBJECTS))|XCTEST)\b/,
  4193. 'keyword' : /\b(?:add_compile_definitions|add_compile_options|add_custom_command|add_custom_target|add_definitions|add_dependencies|add_executable|add_library|add_link_options|add_subdirectory|add_test|aux_source_directory|break|build_command|build_name|cmake_host_system_information|cmake_minimum_required|cmake_parse_arguments|cmake_policy|configure_file|continue|create_test_sourcelist|ctest_build|ctest_configure|ctest_coverage|ctest_empty_binary_directory|ctest_memcheck|ctest_read_custom_files|ctest_run_script|ctest_sleep|ctest_start|ctest_submit|ctest_test|ctest_update|ctest_upload|define_property|else|elseif|enable_language|enable_testing|endforeach|endfunction|endif|endmacro|endwhile|exec_program|execute_process|export|export_library_dependencies|file|find_file|find_library|find_package|find_path|find_program|fltk_wrap_ui|foreach|function|get_cmake_property|get_directory_property|get_filename_component|get_property|get_source_file_property|get_target_property|get_test_property|if|include|include_directories|include_external_msproject|include_guard|include_regular_expression|install|install_files|install_programs|install_targets|link_directories|link_libraries|list|load_cache|load_command|macro|make_directory|mark_as_advanced|math|message|option|output_required_files|project|qt_wrap_cpp|qt_wrap_ui|remove|remove_definitions|return|separate_arguments|set|set_directory_properties|set_property|set_source_files_properties|set_target_properties|set_tests_properties|site_name|source_group|string|subdir_depends|subdirs|target_compile_definitions|target_compile_features|target_compile_options|target_include_directories|target_link_directories|target_link_libraries|target_link_options|target_sources|try_compile|try_run|unset|use_mangled_mesa|utility_source|variable_requires|variable_watch|while|write_file)(?=\s*\()\b/,
  4194. 'boolean' : /\b(?:ON|OFF|TRUE|FALSE)\b/,
  4195. 'namespace' : /\b(?:PROPERTIES|SHARED|PRIVATE|STATIC|PUBLIC|INTERFACE|TARGET_OBJECTS)\b/,
  4196. 'operator' : /\b(?:NOT|AND|OR|MATCHES|LESS|GREATER|EQUAL|STRLESS|STRGREATER|STREQUAL|VERSION_LESS|VERSION_EQUAL|VERSION_GREATER|DEFINED)\b/,
  4197. 'inserted' : {
  4198. 'pattern' : /\b\w+::\w+\b/,
  4199. 'alias' : "class-name"
  4200. },
  4201. 'number' : /\b\d+(?:\.\d+)*\b/,
  4202. 'function' : /\b[a-z_]\w*(?=\s*\()\b/i,
  4203. 'punctuation' : /[()>}]|\$[<{]/
  4204. };