prism.js 161 KB

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