prism.js 166 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145
  1. /* PrismJS 1.28.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+nix+ocaml+perl+php+python+qml+r+jsx+ruby+rust+scss+scala+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: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
  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. pattern: RegExp(
  1440. // lookbehind
  1441. // eslint-disable-next-line regexp/no-dupe-characters-character-class
  1442. /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
  1443. // Regex pattern:
  1444. // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
  1445. // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
  1446. // with the only syntax, so we have to define 2 different regex patterns.
  1447. /\//.source +
  1448. '(?:' +
  1449. /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
  1450. '|' +
  1451. // `v` flag syntax. This supports 3 levels of nested character classes.
  1452. /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
  1453. ')' +
  1454. // lookahead
  1455. /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
  1456. ),
  1457. lookbehind: true,
  1458. greedy: true,
  1459. inside: {
  1460. 'regex-source': {
  1461. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  1462. lookbehind: true,
  1463. alias: 'language-regex',
  1464. inside: Prism.languages.regex
  1465. },
  1466. 'regex-delimiter': /^\/|\/$/,
  1467. 'regex-flags': /^[a-z]+$/,
  1468. }
  1469. },
  1470. // This must be declared before keyword because we use "function" inside the look-forward
  1471. 'function-variable': {
  1472. 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*=>))/,
  1473. alias: 'function'
  1474. },
  1475. 'parameter': [
  1476. {
  1477. pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
  1478. lookbehind: true,
  1479. inside: Prism.languages.javascript
  1480. },
  1481. {
  1482. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
  1483. lookbehind: true,
  1484. inside: Prism.languages.javascript
  1485. },
  1486. {
  1487. pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
  1488. lookbehind: true,
  1489. inside: Prism.languages.javascript
  1490. },
  1491. {
  1492. 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*\{)/,
  1493. lookbehind: true,
  1494. inside: Prism.languages.javascript
  1495. }
  1496. ],
  1497. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  1498. });
  1499. Prism.languages.insertBefore('javascript', 'string', {
  1500. 'hashbang': {
  1501. pattern: /^#!.*/,
  1502. greedy: true,
  1503. alias: 'comment'
  1504. },
  1505. 'template-string': {
  1506. pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
  1507. greedy: true,
  1508. inside: {
  1509. 'template-punctuation': {
  1510. pattern: /^`|`$/,
  1511. alias: 'string'
  1512. },
  1513. 'interpolation': {
  1514. pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
  1515. lookbehind: true,
  1516. inside: {
  1517. 'interpolation-punctuation': {
  1518. pattern: /^\$\{|\}$/,
  1519. alias: 'punctuation'
  1520. },
  1521. rest: Prism.languages.javascript
  1522. }
  1523. },
  1524. 'string': /[\s\S]+/
  1525. }
  1526. },
  1527. 'string-property': {
  1528. pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
  1529. lookbehind: true,
  1530. greedy: true,
  1531. alias: 'property'
  1532. }
  1533. });
  1534. Prism.languages.insertBefore('javascript', 'operator', {
  1535. 'literal-property': {
  1536. pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
  1537. lookbehind: true,
  1538. alias: 'property'
  1539. },
  1540. });
  1541. if (Prism.languages.markup) {
  1542. Prism.languages.markup.tag.addInlined('script', 'javascript');
  1543. // add attribute support for all DOM events.
  1544. // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
  1545. Prism.languages.markup.tag.addAttribute(
  1546. /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,
  1547. 'javascript'
  1548. );
  1549. }
  1550. Prism.languages.js = Prism.languages.javascript;
  1551. (function (Prism) {
  1552. // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
  1553. // + LC_ALL, RANDOM, REPLY, SECONDS.
  1554. // + make sure PS1..4 are here as they are not always set,
  1555. // - some useless things.
  1556. 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';
  1557. var commandAfterHeredoc = {
  1558. pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
  1559. lookbehind: true,
  1560. alias: 'punctuation', // this looks reasonably well in all themes
  1561. inside: null // see below
  1562. };
  1563. var insideString = {
  1564. 'bash': commandAfterHeredoc,
  1565. 'environment': {
  1566. pattern: RegExp('\\$' + envVars),
  1567. alias: 'constant'
  1568. },
  1569. 'variable': [
  1570. // [0]: Arithmetic Environment
  1571. {
  1572. pattern: /\$?\(\([\s\S]+?\)\)/,
  1573. greedy: true,
  1574. inside: {
  1575. // If there is a $ sign at the beginning highlight $(( and )) as variable
  1576. 'variable': [
  1577. {
  1578. pattern: /(^\$\(\([\s\S]+)\)\)/,
  1579. lookbehind: true
  1580. },
  1581. /^\$\(\(/
  1582. ],
  1583. 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
  1584. // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
  1585. 'operator': /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
  1586. // If there is no $ sign at the beginning highlight (( and )) as punctuation
  1587. 'punctuation': /\(\(?|\)\)?|,|;/
  1588. }
  1589. },
  1590. // [1]: Command Substitution
  1591. {
  1592. pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
  1593. greedy: true,
  1594. inside: {
  1595. 'variable': /^\$\(|^`|\)$|`$/
  1596. }
  1597. },
  1598. // [2]: Brace expansion
  1599. {
  1600. pattern: /\$\{[^}]+\}/,
  1601. greedy: true,
  1602. inside: {
  1603. 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
  1604. 'punctuation': /[\[\]]/,
  1605. 'environment': {
  1606. pattern: RegExp('(\\{)' + envVars),
  1607. lookbehind: true,
  1608. alias: 'constant'
  1609. }
  1610. }
  1611. },
  1612. /\$(?:\w+|[#?*!@$])/
  1613. ],
  1614. // Escape sequences from echo and printf's manuals, and escaped quotes.
  1615. '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})/
  1616. };
  1617. Prism.languages.bash = {
  1618. 'shebang': {
  1619. pattern: /^#!\s*\/.*/,
  1620. alias: 'important'
  1621. },
  1622. 'comment': {
  1623. pattern: /(^|[^"{\\$])#.*/,
  1624. lookbehind: true
  1625. },
  1626. 'function-name': [
  1627. // a) function foo {
  1628. // b) foo() {
  1629. // c) function foo() {
  1630. // but not “foo {”
  1631. {
  1632. // a) and c)
  1633. pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
  1634. lookbehind: true,
  1635. alias: 'function'
  1636. },
  1637. {
  1638. // b)
  1639. pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/,
  1640. alias: 'function'
  1641. }
  1642. ],
  1643. // Highlight variable names as variables in for and select beginnings.
  1644. 'for-or-select': {
  1645. pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
  1646. alias: 'variable',
  1647. lookbehind: true
  1648. },
  1649. // Highlight variable names as variables in the left-hand part
  1650. // of assignments (“=” and “+=”).
  1651. 'assign-left': {
  1652. pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
  1653. inside: {
  1654. 'environment': {
  1655. pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars),
  1656. lookbehind: true,
  1657. alias: 'constant'
  1658. }
  1659. },
  1660. alias: 'variable',
  1661. lookbehind: true
  1662. },
  1663. 'string': [
  1664. // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
  1665. {
  1666. pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,
  1667. lookbehind: true,
  1668. greedy: true,
  1669. inside: insideString
  1670. },
  1671. // Here-document with quotes around the tag
  1672. // → No expansion (so no “inside”).
  1673. {
  1674. pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
  1675. lookbehind: true,
  1676. greedy: true,
  1677. inside: {
  1678. 'bash': commandAfterHeredoc
  1679. }
  1680. },
  1681. // “Normal” string
  1682. {
  1683. // https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
  1684. pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
  1685. lookbehind: true,
  1686. greedy: true,
  1687. inside: insideString
  1688. },
  1689. {
  1690. // https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html
  1691. pattern: /(^|[^$\\])'[^']*'/,
  1692. lookbehind: true,
  1693. greedy: true
  1694. },
  1695. {
  1696. // https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
  1697. pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
  1698. greedy: true,
  1699. inside: {
  1700. 'entity': insideString.entity
  1701. }
  1702. }
  1703. ],
  1704. 'environment': {
  1705. pattern: RegExp('\\$?' + envVars),
  1706. alias: 'constant'
  1707. },
  1708. 'variable': insideString.variable,
  1709. 'function': {
  1710. 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;|&])/,
  1711. lookbehind: true
  1712. },
  1713. 'keyword': {
  1714. pattern: /(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,
  1715. lookbehind: true
  1716. },
  1717. // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
  1718. 'builtin': {
  1719. 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;|&])/,
  1720. lookbehind: true,
  1721. // Alias added to make those easier to distinguish from strings.
  1722. alias: 'class-name'
  1723. },
  1724. 'boolean': {
  1725. pattern: /(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,
  1726. lookbehind: true
  1727. },
  1728. 'file-descriptor': {
  1729. pattern: /\B&\d\b/,
  1730. alias: 'important'
  1731. },
  1732. 'operator': {
  1733. // Lots of redirections here, but not just that.
  1734. pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,
  1735. inside: {
  1736. 'file-descriptor': {
  1737. pattern: /^\d/,
  1738. alias: 'important'
  1739. }
  1740. }
  1741. },
  1742. 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
  1743. 'number': {
  1744. pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
  1745. lookbehind: true
  1746. }
  1747. };
  1748. commandAfterHeredoc.inside = Prism.languages.bash;
  1749. /* Patterns in command substitution. */
  1750. var toBeCopied = [
  1751. 'comment',
  1752. 'function-name',
  1753. 'for-or-select',
  1754. 'assign-left',
  1755. 'string',
  1756. 'environment',
  1757. 'function',
  1758. 'keyword',
  1759. 'builtin',
  1760. 'boolean',
  1761. 'file-descriptor',
  1762. 'operator',
  1763. 'punctuation',
  1764. 'number'
  1765. ];
  1766. var inside = insideString.variable[1].inside;
  1767. for (var i = 0; i < toBeCopied.length; i++) {
  1768. inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
  1769. }
  1770. Prism.languages.shell = Prism.languages.bash;
  1771. }(Prism));
  1772. Prism.languages.c = Prism.languages.extend('clike', {
  1773. 'comment': {
  1774. pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
  1775. greedy: true
  1776. },
  1777. 'string': {
  1778. // https://en.cppreference.com/w/c/language/string_literal
  1779. pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
  1780. greedy: true
  1781. },
  1782. 'class-name': {
  1783. pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
  1784. lookbehind: true
  1785. },
  1786. '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/,
  1787. 'function': /\b[a-z_]\w*(?=\s*\()/i,
  1788. 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
  1789. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
  1790. });
  1791. Prism.languages.insertBefore('c', 'string', {
  1792. 'char': {
  1793. // https://en.cppreference.com/w/c/language/character_constant
  1794. pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
  1795. greedy: true
  1796. }
  1797. });
  1798. Prism.languages.insertBefore('c', 'string', {
  1799. 'macro': {
  1800. // allow for multiline macro definitions
  1801. // spaces after the # character compile fine with gcc
  1802. pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
  1803. lookbehind: true,
  1804. greedy: true,
  1805. alias: 'property',
  1806. inside: {
  1807. 'string': [
  1808. {
  1809. // highlight the path of the include statement as a string
  1810. pattern: /^(#\s*include\s*)<[^>]+>/,
  1811. lookbehind: true
  1812. },
  1813. Prism.languages.c['string']
  1814. ],
  1815. 'char': Prism.languages.c['char'],
  1816. 'comment': Prism.languages.c['comment'],
  1817. 'macro-name': [
  1818. {
  1819. pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
  1820. lookbehind: true
  1821. },
  1822. {
  1823. pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
  1824. lookbehind: true,
  1825. alias: 'function'
  1826. }
  1827. ],
  1828. // highlight macro directives as keywords
  1829. 'directive': {
  1830. pattern: /^(#\s*)[a-z]+/,
  1831. lookbehind: true,
  1832. alias: 'keyword'
  1833. },
  1834. 'directive-hash': /^#/,
  1835. 'punctuation': /##|\\(?=[\r\n])/,
  1836. 'expression': {
  1837. pattern: /\S[\s\S]*/,
  1838. inside: Prism.languages.c
  1839. }
  1840. }
  1841. }
  1842. });
  1843. Prism.languages.insertBefore('c', 'function', {
  1844. // highlight predefined macros as constants
  1845. 'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
  1846. });
  1847. delete Prism.languages.c['boolean'];
  1848. (function (Prism) {
  1849. 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/;
  1850. var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; });
  1851. Prism.languages.cpp = Prism.languages.extend('c', {
  1852. 'class-name': [
  1853. {
  1854. pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
  1855. .replace(/<keyword>/g, function () { return keyword.source; })),
  1856. lookbehind: true
  1857. },
  1858. // This is intended to capture the class name of method implementations like:
  1859. // void foo::bar() const {}
  1860. // However! The `foo` in the above example could also be a namespace, so we only capture the class name if
  1861. // it starts with an uppercase letter. This approximation should give decent results.
  1862. /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
  1863. // This will capture the class name before destructors like:
  1864. // Foo::~Foo() {}
  1865. /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
  1866. // This also intends to capture the class name of method implementations but here the class has template
  1867. // parameters, so it can't be a namespace (until C++ adds generic namespaces).
  1868. /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
  1869. ],
  1870. 'keyword': keyword,
  1871. 'number': {
  1872. pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
  1873. greedy: true
  1874. },
  1875. 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
  1876. 'boolean': /\b(?:false|true)\b/
  1877. });
  1878. Prism.languages.insertBefore('cpp', 'string', {
  1879. 'module': {
  1880. // https://en.cppreference.com/w/cpp/language/modules
  1881. pattern: RegExp(
  1882. /(\b(?:import|module)\s+)/.source +
  1883. '(?:' +
  1884. // header-name
  1885. /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
  1886. '|' +
  1887. // module name or partition or both
  1888. /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) +
  1889. ')'
  1890. ),
  1891. lookbehind: true,
  1892. greedy: true,
  1893. inside: {
  1894. 'string': /^[<"][\s\S]+/,
  1895. 'operator': /:/,
  1896. 'punctuation': /\./
  1897. }
  1898. },
  1899. 'raw-string': {
  1900. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  1901. alias: 'string',
  1902. greedy: true
  1903. }
  1904. });
  1905. Prism.languages.insertBefore('cpp', 'keyword', {
  1906. 'generic-function': {
  1907. pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
  1908. inside: {
  1909. 'function': /^\w+/,
  1910. 'generic': {
  1911. pattern: /<[\s\S]+/,
  1912. alias: 'class-name',
  1913. inside: Prism.languages.cpp
  1914. }
  1915. }
  1916. }
  1917. });
  1918. Prism.languages.insertBefore('cpp', 'operator', {
  1919. 'double-colon': {
  1920. pattern: /::/,
  1921. alias: 'punctuation'
  1922. }
  1923. });
  1924. Prism.languages.insertBefore('cpp', 'class-name', {
  1925. // the base clause is an optional list of parent classes
  1926. // https://en.cppreference.com/w/cpp/language/class
  1927. 'base-clause': {
  1928. pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
  1929. lookbehind: true,
  1930. greedy: true,
  1931. inside: Prism.languages.extend('cpp', {})
  1932. }
  1933. });
  1934. Prism.languages.insertBefore('inside', 'double-colon', {
  1935. // All untokenized words that are not namespaces should be class names
  1936. 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i
  1937. }, Prism.languages.cpp['base-clause']);
  1938. }(Prism));
  1939. Prism.languages.cmake = {
  1940. 'comment': /#.*/,
  1941. 'string': {
  1942. pattern: /"(?:[^\\"]|\\.)*"/,
  1943. greedy: true,
  1944. inside: {
  1945. 'interpolation': {
  1946. pattern: /\$\{(?:[^{}$]|\$\{[^{}$]*\})*\}/,
  1947. inside: {
  1948. 'punctuation': /\$\{|\}/,
  1949. 'variable': /\w+/
  1950. }
  1951. }
  1952. }
  1953. },
  1954. '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_NAME|UNIX|WIN32|WINCE|WINDOWS_PHONE|WINDOWS_STORE|XCODE))\b/,
  1955. '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|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/,
  1956. '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/,
  1957. 'boolean': /\b(?:FALSE|OFF|ON|TRUE)\b/,
  1958. 'namespace': /\b(?:INTERFACE|PRIVATE|PROPERTIES|PUBLIC|SHARED|STATIC|TARGET_OBJECTS)\b/,
  1959. 'operator': /\b(?:AND|DEFINED|EQUAL|GREATER|LESS|MATCHES|NOT|OR|STREQUAL|STRGREATER|STRLESS|VERSION_EQUAL|VERSION_GREATER|VERSION_LESS)\b/,
  1960. 'inserted': {
  1961. pattern: /\b\w+::\w+\b/,
  1962. alias: 'class-name'
  1963. },
  1964. 'number': /\b\d+(?:\.\d+)*\b/,
  1965. 'function': /\b[a-z_]\w*(?=\s*\()\b/i,
  1966. 'punctuation': /[()>}]|\$[<{]/
  1967. };
  1968. (function (Prism) {
  1969. // Ignore comments starting with { to privilege string interpolation highlighting
  1970. var comment = /#(?!\{).+/;
  1971. var interpolation = {
  1972. pattern: /#\{[^}]+\}/,
  1973. alias: 'variable'
  1974. };
  1975. Prism.languages.coffeescript = Prism.languages.extend('javascript', {
  1976. 'comment': comment,
  1977. 'string': [
  1978. // Strings are multiline
  1979. {
  1980. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1981. greedy: true
  1982. },
  1983. {
  1984. // Strings are multiline
  1985. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1986. greedy: true,
  1987. inside: {
  1988. 'interpolation': interpolation
  1989. }
  1990. }
  1991. ],
  1992. '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/,
  1993. 'class-member': {
  1994. pattern: /@(?!\d)\w+/,
  1995. alias: 'variable'
  1996. }
  1997. });
  1998. Prism.languages.insertBefore('coffeescript', 'comment', {
  1999. 'multiline-comment': {
  2000. pattern: /###[\s\S]+?###/,
  2001. alias: 'comment'
  2002. },
  2003. // Block regexp can contain comments and interpolation
  2004. 'block-regex': {
  2005. pattern: /\/{3}[\s\S]*?\/{3}/,
  2006. alias: 'regex',
  2007. inside: {
  2008. 'comment': comment,
  2009. 'interpolation': interpolation
  2010. }
  2011. }
  2012. });
  2013. Prism.languages.insertBefore('coffeescript', 'string', {
  2014. 'inline-javascript': {
  2015. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  2016. inside: {
  2017. 'delimiter': {
  2018. pattern: /^`|`$/,
  2019. alias: 'punctuation'
  2020. },
  2021. 'script': {
  2022. pattern: /[\s\S]+/,
  2023. alias: 'language-javascript',
  2024. inside: Prism.languages.javascript
  2025. }
  2026. }
  2027. },
  2028. // Block strings
  2029. 'multiline-string': [
  2030. {
  2031. pattern: /'''[\s\S]*?'''/,
  2032. greedy: true,
  2033. alias: 'string'
  2034. },
  2035. {
  2036. pattern: /"""[\s\S]*?"""/,
  2037. greedy: true,
  2038. alias: 'string',
  2039. inside: {
  2040. interpolation: interpolation
  2041. }
  2042. }
  2043. ]
  2044. });
  2045. Prism.languages.insertBefore('coffeescript', 'keyword', {
  2046. // Object property
  2047. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  2048. });
  2049. delete Prism.languages.coffeescript['template-string'];
  2050. Prism.languages.coffee = Prism.languages.coffeescript;
  2051. }(Prism));
  2052. /**
  2053. * Original by Samuel Flores
  2054. *
  2055. * Adds the following new token classes:
  2056. * constant, builtin, variable, symbol, regex
  2057. */
  2058. (function (Prism) {
  2059. Prism.languages.ruby = Prism.languages.extend('clike', {
  2060. 'comment': {
  2061. pattern: /#.*|^=begin\s[\s\S]*?^=end/m,
  2062. greedy: true
  2063. },
  2064. 'class-name': {
  2065. pattern: /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/,
  2066. lookbehind: true,
  2067. inside: {
  2068. 'punctuation': /[.\\]/
  2069. }
  2070. },
  2071. '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/,
  2072. 'operator': /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/,
  2073. 'punctuation': /[(){}[\].,;]/,
  2074. });
  2075. Prism.languages.insertBefore('ruby', 'operator', {
  2076. 'double-colon': {
  2077. pattern: /::/,
  2078. alias: 'punctuation'
  2079. },
  2080. });
  2081. var interpolation = {
  2082. pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/,
  2083. lookbehind: true,
  2084. inside: {
  2085. 'content': {
  2086. pattern: /^(#\{)[\s\S]+(?=\}$)/,
  2087. lookbehind: true,
  2088. inside: Prism.languages.ruby
  2089. },
  2090. 'delimiter': {
  2091. pattern: /^#\{|\}$/,
  2092. alias: 'punctuation'
  2093. }
  2094. }
  2095. };
  2096. delete Prism.languages.ruby.function;
  2097. var percentExpression = '(?:' + [
  2098. /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  2099. /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source,
  2100. /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source,
  2101. /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source,
  2102. /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source
  2103. ].join('|') + ')';
  2104. var symbolName = /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source;
  2105. Prism.languages.insertBefore('ruby', 'keyword', {
  2106. 'regex-literal': [
  2107. {
  2108. pattern: RegExp(/%r/.source + percentExpression + /[egimnosux]{0,6}/.source),
  2109. greedy: true,
  2110. inside: {
  2111. 'interpolation': interpolation,
  2112. 'regex': /[\s\S]+/
  2113. }
  2114. },
  2115. {
  2116. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
  2117. lookbehind: true,
  2118. greedy: true,
  2119. inside: {
  2120. 'interpolation': interpolation,
  2121. 'regex': /[\s\S]+/
  2122. }
  2123. }
  2124. ],
  2125. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  2126. 'symbol': [
  2127. {
  2128. pattern: RegExp(/(^|[^:]):/.source + symbolName),
  2129. lookbehind: true,
  2130. greedy: true
  2131. },
  2132. {
  2133. pattern: RegExp(/([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source),
  2134. lookbehind: true,
  2135. greedy: true
  2136. },
  2137. ],
  2138. 'method-definition': {
  2139. pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/,
  2140. lookbehind: true,
  2141. inside: {
  2142. 'function': /\b\w+$/,
  2143. 'keyword': /^self\b/,
  2144. 'class-name': /^\w+/,
  2145. 'punctuation': /\./
  2146. }
  2147. }
  2148. });
  2149. Prism.languages.insertBefore('ruby', 'string', {
  2150. 'string-literal': [
  2151. {
  2152. pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression),
  2153. greedy: true,
  2154. inside: {
  2155. 'interpolation': interpolation,
  2156. 'string': /[\s\S]+/
  2157. }
  2158. },
  2159. {
  2160. pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
  2161. greedy: true,
  2162. inside: {
  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. 'interpolation': interpolation,
  2180. 'string': /[\s\S]+/
  2181. }
  2182. },
  2183. {
  2184. pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  2185. alias: 'heredoc-string',
  2186. greedy: true,
  2187. inside: {
  2188. 'delimiter': {
  2189. pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i,
  2190. inside: {
  2191. 'symbol': /\b\w+/,
  2192. 'punctuation': /^<<[-~]?'|'$/,
  2193. }
  2194. },
  2195. 'string': /[\s\S]+/
  2196. }
  2197. }
  2198. ],
  2199. 'command-literal': [
  2200. {
  2201. pattern: RegExp(/%x/.source + percentExpression),
  2202. greedy: true,
  2203. inside: {
  2204. 'interpolation': interpolation,
  2205. 'command': {
  2206. pattern: /[\s\S]+/,
  2207. alias: 'string'
  2208. }
  2209. }
  2210. },
  2211. {
  2212. pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/,
  2213. greedy: true,
  2214. inside: {
  2215. 'interpolation': interpolation,
  2216. 'command': {
  2217. pattern: /[\s\S]+/,
  2218. alias: 'string'
  2219. }
  2220. }
  2221. }
  2222. ]
  2223. });
  2224. delete Prism.languages.ruby.string;
  2225. Prism.languages.insertBefore('ruby', 'number', {
  2226. '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/,
  2227. 'constant': /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/
  2228. });
  2229. Prism.languages.rb = Prism.languages.ruby;
  2230. }(Prism));
  2231. (function (Prism) {
  2232. Prism.languages.crystal = Prism.languages.extend('ruby', {
  2233. 'keyword': [
  2234. /\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/,
  2235. {
  2236. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  2237. lookbehind: true
  2238. }
  2239. ],
  2240. '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/,
  2241. 'operator': [
  2242. /->/,
  2243. Prism.languages.ruby.operator,
  2244. ],
  2245. 'punctuation': /[(){}[\].,;\\]/,
  2246. });
  2247. Prism.languages.insertBefore('crystal', 'string-literal', {
  2248. 'attribute': {
  2249. pattern: /@\[.*?\]/,
  2250. inside: {
  2251. 'delimiter': {
  2252. pattern: /^@\[|\]$/,
  2253. alias: 'punctuation'
  2254. },
  2255. 'attribute': {
  2256. pattern: /^(\s*)\w+/,
  2257. lookbehind: true,
  2258. alias: 'class-name'
  2259. },
  2260. 'args': {
  2261. pattern: /\S(?:[\s\S]*\S)?/,
  2262. inside: Prism.languages.crystal
  2263. },
  2264. }
  2265. },
  2266. 'expansion': {
  2267. pattern: /\{(?:\{.*?\}|%.*?%)\}/,
  2268. inside: {
  2269. 'content': {
  2270. pattern: /^(\{.)[\s\S]+(?=.\}$)/,
  2271. lookbehind: true,
  2272. inside: Prism.languages.crystal
  2273. },
  2274. 'delimiter': {
  2275. pattern: /^\{[\{%]|[\}%]\}$/,
  2276. alias: 'operator'
  2277. }
  2278. }
  2279. },
  2280. 'char': {
  2281. pattern: /'(?:[^\\\r\n]{1,2}|\\(?:.|u(?:[A-Fa-f0-9]{1,4}|\{[A-Fa-f0-9]{1,6}\})))'/,
  2282. greedy: true
  2283. }
  2284. });
  2285. }(Prism));
  2286. Prism.languages.d = Prism.languages.extend('clike', {
  2287. 'comment': [
  2288. {
  2289. // Shebang
  2290. pattern: /^\s*#!.+/,
  2291. greedy: true
  2292. },
  2293. {
  2294. pattern: RegExp(/(^|[^\\])/.source + '(?:' + [
  2295. // /+ comment +/
  2296. // Allow one level of nesting
  2297. /\/\+(?:\/\+(?:[^+]|\+(?!\/))*\+\/|(?!\/\+)[\s\S])*?\+\//.source,
  2298. // // comment
  2299. /\/\/.*/.source,
  2300. // /* comment */
  2301. /\/\*[\s\S]*?\*\//.source
  2302. ].join('|') + ')'),
  2303. lookbehind: true,
  2304. greedy: true
  2305. }
  2306. ],
  2307. 'string': [
  2308. {
  2309. pattern: RegExp([
  2310. // r"", x""
  2311. /\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/.source,
  2312. // q"[]", q"()", q"<>", q"{}"
  2313. /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/.source,
  2314. // q"IDENT
  2315. // ...
  2316. // IDENT"
  2317. /\bq"((?!\d)\w+)$[\s\S]*?^\1"/.source,
  2318. // q"//", q"||", etc.
  2319. // eslint-disable-next-line regexp/strict
  2320. /\bq"(.)[\s\S]*?\2"/.source,
  2321. // eslint-disable-next-line regexp/strict
  2322. /(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
  2323. ].join('|'), 'm'),
  2324. greedy: true
  2325. },
  2326. {
  2327. pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
  2328. greedy: true,
  2329. alias: 'token-string'
  2330. }
  2331. ],
  2332. // In order: $, keywords and special tokens, globally defined symbols
  2333. '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/,
  2334. 'number': [
  2335. // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
  2336. // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
  2337. /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]{0,4}/i,
  2338. {
  2339. pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]{0,4}/i,
  2340. lookbehind: true
  2341. }
  2342. ],
  2343. 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
  2344. });
  2345. Prism.languages.insertBefore('d', 'string', {
  2346. // Characters
  2347. // 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
  2348. 'char': /'(?:\\(?:\W|\w+)|[^\\])'/
  2349. });
  2350. Prism.languages.insertBefore('d', 'keyword', {
  2351. 'property': /\B@\w*/
  2352. });
  2353. Prism.languages.insertBefore('d', 'function', {
  2354. 'register': {
  2355. // Iasm registers
  2356. 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)/,
  2357. alias: 'variable'
  2358. }
  2359. });
  2360. (function (Prism) {
  2361. var keywords = [
  2362. /\b(?:async|sync|yield)\*/,
  2363. /\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/
  2364. ];
  2365. // Handles named imports, such as http.Client
  2366. var packagePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2367. // based on the dart naming conventions
  2368. var className = {
  2369. pattern: RegExp(packagePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2370. lookbehind: true,
  2371. inside: {
  2372. 'namespace': {
  2373. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2374. inside: {
  2375. 'punctuation': /\./
  2376. }
  2377. },
  2378. }
  2379. };
  2380. Prism.languages.dart = Prism.languages.extend('clike', {
  2381. 'class-name': [
  2382. className,
  2383. {
  2384. // variables and parameters
  2385. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2386. pattern: RegExp(packagePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source),
  2387. lookbehind: true,
  2388. inside: className.inside
  2389. }
  2390. ],
  2391. 'keyword': keywords,
  2392. 'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
  2393. });
  2394. Prism.languages.insertBefore('dart', 'string', {
  2395. 'string-literal': {
  2396. pattern: /r?(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\r\n])*\2(?!\2))/,
  2397. greedy: true,
  2398. inside: {
  2399. 'interpolation': {
  2400. pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
  2401. lookbehind: true,
  2402. inside: {
  2403. 'punctuation': /^\$\{?|\}$/,
  2404. 'expression': {
  2405. pattern: /[\s\S]+/,
  2406. inside: Prism.languages.dart
  2407. }
  2408. }
  2409. },
  2410. 'string': /[\s\S]+/
  2411. }
  2412. },
  2413. 'string': undefined
  2414. });
  2415. Prism.languages.insertBefore('dart', 'class-name', {
  2416. 'metadata': {
  2417. pattern: /@\w+/,
  2418. alias: 'function'
  2419. }
  2420. });
  2421. Prism.languages.insertBefore('dart', 'class-name', {
  2422. 'generics': {
  2423. pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
  2424. inside: {
  2425. 'class-name': className,
  2426. 'keyword': keywords,
  2427. 'punctuation': /[<>(),.:]/,
  2428. 'operator': /[?&|]/
  2429. }
  2430. },
  2431. });
  2432. }(Prism));
  2433. (function (Prism) {
  2434. Prism.languages.diff = {
  2435. 'coord': [
  2436. // Match all kinds of coord lines (prefixed by "+++", "---" or "***").
  2437. /^(?:\*{3}|-{3}|\+{3}).*$/m,
  2438. // Match "@@ ... @@" coord lines in unified diff.
  2439. /^@@.*@@$/m,
  2440. // Match coord lines in normal diff (starts with a number).
  2441. /^\d.*$/m
  2442. ]
  2443. // deleted, inserted, unchanged, diff
  2444. };
  2445. /**
  2446. * A map from the name of a block to its line prefix.
  2447. *
  2448. * @type {Object<string, string>}
  2449. */
  2450. var PREFIXES = {
  2451. 'deleted-sign': '-',
  2452. 'deleted-arrow': '<',
  2453. 'inserted-sign': '+',
  2454. 'inserted-arrow': '>',
  2455. 'unchanged': ' ',
  2456. 'diff': '!',
  2457. };
  2458. // add a token for each prefix
  2459. Object.keys(PREFIXES).forEach(function (name) {
  2460. var prefix = PREFIXES[name];
  2461. var alias = [];
  2462. if (!/^\w+$/.test(name)) { // "deleted-sign" -> "deleted"
  2463. alias.push(/\w+/.exec(name)[0]);
  2464. }
  2465. if (name === 'diff') {
  2466. alias.push('bold');
  2467. }
  2468. Prism.languages.diff[name] = {
  2469. pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'),
  2470. alias: alias,
  2471. inside: {
  2472. 'line': {
  2473. pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/,
  2474. lookbehind: true
  2475. },
  2476. 'prefix': {
  2477. pattern: /[\s\S]/,
  2478. alias: /\w+/.exec(name)[0]
  2479. }
  2480. }
  2481. };
  2482. });
  2483. // make prefixes available to Diff plugin
  2484. Object.defineProperty(Prism.languages.diff, 'PREFIXES', {
  2485. value: PREFIXES
  2486. });
  2487. }(Prism));
  2488. (function (Prism) {
  2489. /**
  2490. * Returns the placeholder for the given language id and index.
  2491. *
  2492. * @param {string} language
  2493. * @param {string|number} index
  2494. * @returns {string}
  2495. */
  2496. function getPlaceholder(language, index) {
  2497. return '___' + language.toUpperCase() + index + '___';
  2498. }
  2499. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  2500. buildPlaceholders: {
  2501. /**
  2502. * Tokenize all inline templating expressions matching `placeholderPattern`.
  2503. *
  2504. * If `replaceFilter` is provided, only matches of `placeholderPattern` for which `replaceFilter` returns
  2505. * `true` will be replaced.
  2506. *
  2507. * @param {object} env The environment of the `before-tokenize` hook.
  2508. * @param {string} language The language id.
  2509. * @param {RegExp} placeholderPattern The matches of this pattern will be replaced by placeholders.
  2510. * @param {(match: string) => boolean} [replaceFilter]
  2511. */
  2512. value: function (env, language, placeholderPattern, replaceFilter) {
  2513. if (env.language !== language) {
  2514. return;
  2515. }
  2516. var tokenStack = env.tokenStack = [];
  2517. env.code = env.code.replace(placeholderPattern, function (match) {
  2518. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  2519. return match;
  2520. }
  2521. var i = tokenStack.length;
  2522. var placeholder;
  2523. // Check for existing strings
  2524. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1) {
  2525. ++i;
  2526. }
  2527. // Create a sparse array
  2528. tokenStack[i] = match;
  2529. return placeholder;
  2530. });
  2531. // Switch the grammar to markup
  2532. env.grammar = Prism.languages.markup;
  2533. }
  2534. },
  2535. tokenizePlaceholders: {
  2536. /**
  2537. * Replace placeholders with proper tokens after tokenizing.
  2538. *
  2539. * @param {object} env The environment of the `after-tokenize` hook.
  2540. * @param {string} language The language id.
  2541. */
  2542. value: function (env, language) {
  2543. if (env.language !== language || !env.tokenStack) {
  2544. return;
  2545. }
  2546. // Switch the grammar back
  2547. env.grammar = Prism.languages[language];
  2548. var j = 0;
  2549. var keys = Object.keys(env.tokenStack);
  2550. function walkTokens(tokens) {
  2551. for (var i = 0; i < tokens.length; i++) {
  2552. // all placeholders are replaced already
  2553. if (j >= keys.length) {
  2554. break;
  2555. }
  2556. var token = tokens[i];
  2557. if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
  2558. var k = keys[j];
  2559. var t = env.tokenStack[k];
  2560. var s = typeof token === 'string' ? token : token.content;
  2561. var placeholder = getPlaceholder(language, k);
  2562. var index = s.indexOf(placeholder);
  2563. if (index > -1) {
  2564. ++j;
  2565. var before = s.substring(0, index);
  2566. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  2567. var after = s.substring(index + placeholder.length);
  2568. var replacement = [];
  2569. if (before) {
  2570. replacement.push.apply(replacement, walkTokens([before]));
  2571. }
  2572. replacement.push(middle);
  2573. if (after) {
  2574. replacement.push.apply(replacement, walkTokens([after]));
  2575. }
  2576. if (typeof token === 'string') {
  2577. tokens.splice.apply(tokens, [i, 1].concat(replacement));
  2578. } else {
  2579. token.content = replacement;
  2580. }
  2581. }
  2582. } else if (token.content /* && typeof token.content !== 'string' */) {
  2583. walkTokens(token.content);
  2584. }
  2585. }
  2586. return tokens;
  2587. }
  2588. walkTokens(env.tokens);
  2589. }
  2590. }
  2591. });
  2592. }(Prism));
  2593. // Django/Jinja2 syntax definition for Prism.js <http://prismjs.com> syntax highlighter.
  2594. // Mostly it works OK but can paint code incorrectly on complex html/template tag combinations.
  2595. (function (Prism) {
  2596. Prism.languages.django = {
  2597. 'comment': /^\{#[\s\S]*?#\}$/,
  2598. 'tag': {
  2599. pattern: /(^\{%[+-]?\s*)\w+/,
  2600. lookbehind: true,
  2601. alias: 'keyword'
  2602. },
  2603. 'delimiter': {
  2604. pattern: /^\{[{%][+-]?|[+-]?[}%]\}$/,
  2605. alias: 'punctuation'
  2606. },
  2607. 'string': {
  2608. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2609. greedy: true
  2610. },
  2611. 'filter': {
  2612. pattern: /(\|)\w+/,
  2613. lookbehind: true,
  2614. alias: 'function'
  2615. },
  2616. 'test': {
  2617. pattern: /(\bis\s+(?:not\s+)?)(?!not\b)\w+/,
  2618. lookbehind: true,
  2619. alias: 'function'
  2620. },
  2621. 'function': /\b[a-z_]\w+(?=\s*\()/i,
  2622. 'keyword': /\b(?:and|as|by|else|for|if|import|in|is|loop|not|or|recursive|with|without)\b/,
  2623. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  2624. 'number': /\b\d+(?:\.\d+)?\b/,
  2625. 'boolean': /[Ff]alse|[Nn]one|[Tt]rue/,
  2626. 'variable': /\b\w+\b/,
  2627. 'punctuation': /[{}[\](),.:;]/
  2628. };
  2629. var pattern = /\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}|\{#[\s\S]*?#\}/g;
  2630. var markupTemplating = Prism.languages['markup-templating'];
  2631. Prism.hooks.add('before-tokenize', function (env) {
  2632. markupTemplating.buildPlaceholders(env, 'django', pattern);
  2633. });
  2634. Prism.hooks.add('after-tokenize', function (env) {
  2635. markupTemplating.tokenizePlaceholders(env, 'django');
  2636. });
  2637. // Add an Jinja2 alias
  2638. Prism.languages.jinja2 = Prism.languages.django;
  2639. Prism.hooks.add('before-tokenize', function (env) {
  2640. markupTemplating.buildPlaceholders(env, 'jinja2', pattern);
  2641. });
  2642. Prism.hooks.add('after-tokenize', function (env) {
  2643. markupTemplating.tokenizePlaceholders(env, 'jinja2');
  2644. });
  2645. }(Prism));
  2646. Prism.languages.elixir = {
  2647. 'doc': {
  2648. pattern: /@(?:doc|moduledoc)\s+(?:("""|''')[\s\S]*?\1|("|')(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2)/,
  2649. inside: {
  2650. 'attribute': /^@\w+/,
  2651. 'string': /['"][\s\S]+/
  2652. }
  2653. },
  2654. 'comment': {
  2655. pattern: /#.*/,
  2656. greedy: true
  2657. },
  2658. // ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  2659. 'regex': {
  2660. pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
  2661. greedy: true
  2662. },
  2663. 'string': [
  2664. {
  2665. // ~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>
  2666. pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|#(?!\{)|[^#\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/,
  2667. greedy: true,
  2668. inside: {
  2669. // See interpolation below
  2670. }
  2671. },
  2672. {
  2673. pattern: /("""|''')[\s\S]*?\1/,
  2674. greedy: true,
  2675. inside: {
  2676. // See interpolation below
  2677. }
  2678. },
  2679. {
  2680. // Multi-line strings are allowed
  2681. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2682. greedy: true,
  2683. inside: {
  2684. // See interpolation below
  2685. }
  2686. }
  2687. ],
  2688. 'atom': {
  2689. // Look-behind prevents bad highlighting of the :: operator
  2690. pattern: /(^|[^:]):\w+/,
  2691. lookbehind: true,
  2692. alias: 'symbol'
  2693. },
  2694. 'module': {
  2695. pattern: /\b[A-Z]\w*\b/,
  2696. alias: 'class-name'
  2697. },
  2698. // Look-ahead prevents bad highlighting of the :: operator
  2699. 'attr-name': /\b\w+\??:(?!:)/,
  2700. 'argument': {
  2701. // Look-behind prevents bad highlighting of the && operator
  2702. pattern: /(^|[^&])&\d+/,
  2703. lookbehind: true,
  2704. alias: 'variable'
  2705. },
  2706. 'attribute': {
  2707. pattern: /@\w+/,
  2708. alias: 'variable'
  2709. },
  2710. 'function': /\b[_a-zA-Z]\w*[?!]?(?:(?=\s*(?:\.\s*)?\()|(?=\/\d))/,
  2711. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  2712. '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/,
  2713. 'boolean': /\b(?:false|nil|true)\b/,
  2714. 'operator': [
  2715. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  2716. {
  2717. // We don't want to match <<
  2718. pattern: /([^<])<(?!<)/,
  2719. lookbehind: true
  2720. },
  2721. {
  2722. // We don't want to match >>
  2723. pattern: /([^>])>(?!>)/,
  2724. lookbehind: true
  2725. }
  2726. ],
  2727. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  2728. };
  2729. Prism.languages.elixir.string.forEach(function (o) {
  2730. o.inside = {
  2731. 'interpolation': {
  2732. pattern: /#\{[^}]+\}/,
  2733. inside: {
  2734. 'delimiter': {
  2735. pattern: /^#\{|\}$/,
  2736. alias: 'punctuation'
  2737. },
  2738. rest: Prism.languages.elixir
  2739. }
  2740. }
  2741. };
  2742. });
  2743. Prism.languages.erlang = {
  2744. 'comment': /%.+/,
  2745. 'string': {
  2746. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  2747. greedy: true
  2748. },
  2749. 'quoted-function': {
  2750. pattern: /'(?:\\.|[^\\'\r\n])+'(?=\()/,
  2751. alias: 'function'
  2752. },
  2753. 'quoted-atom': {
  2754. pattern: /'(?:\\.|[^\\'\r\n])+'/,
  2755. alias: 'atom'
  2756. },
  2757. 'boolean': /\b(?:false|true)\b/,
  2758. 'keyword': /\b(?:after|begin|case|catch|end|fun|if|of|receive|try|when)\b/,
  2759. 'number': [
  2760. /\$\\?./,
  2761. /\b\d+#[a-z0-9]+/i,
  2762. /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i
  2763. ],
  2764. 'function': /\b[a-z][\w@]*(?=\()/,
  2765. 'variable': {
  2766. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  2767. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  2768. lookbehind: true
  2769. },
  2770. 'operator': [
  2771. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:and|andalso|band|bnot|bor|bsl|bsr|bxor|div|not|or|orelse|rem|xor)\b/,
  2772. {
  2773. // We don't want to match <<
  2774. pattern: /(^|[^<])<(?!<)/,
  2775. lookbehind: true
  2776. },
  2777. {
  2778. // We don't want to match >>
  2779. pattern: /(^|[^>])>(?!>)/,
  2780. lookbehind: true
  2781. }
  2782. ],
  2783. 'atom': /\b[a-z][\w@]*/,
  2784. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  2785. };
  2786. Prism.languages.go = Prism.languages.extend('clike', {
  2787. 'string': {
  2788. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,
  2789. lookbehind: true,
  2790. greedy: true
  2791. },
  2792. '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/,
  2793. 'boolean': /\b(?:_|false|iota|nil|true)\b/,
  2794. 'number': [
  2795. // binary and octal integers
  2796. /\b0(?:b[01_]+|o[0-7_]+)i?\b/i,
  2797. // hexadecimal integers and floats
  2798. /\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,
  2799. // decimal integers and floats
  2800. /(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i
  2801. ],
  2802. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  2803. '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/
  2804. });
  2805. Prism.languages.insertBefore('go', 'string', {
  2806. 'char': {
  2807. pattern: /'(?:\\.|[^'\\\r\n]){0,10}'/,
  2808. greedy: true
  2809. }
  2810. });
  2811. delete Prism.languages.go['class-name'];
  2812. (function (Prism) {
  2813. var interpolation = {
  2814. pattern: /((?:^|[^\\$])(?:\\{2})*)\$(?:\w+|\{[^{}]*\})/,
  2815. lookbehind: true,
  2816. inside: {
  2817. 'interpolation-punctuation': {
  2818. pattern: /^\$\{?|\}$/,
  2819. alias: 'punctuation'
  2820. },
  2821. 'expression': {
  2822. pattern: /[\s\S]+/,
  2823. inside: null // see below
  2824. }
  2825. }
  2826. };
  2827. Prism.languages.groovy = Prism.languages.extend('clike', {
  2828. 'string': {
  2829. // https://groovy-lang.org/syntax.html#_dollar_slashy_string
  2830. pattern: /'''(?:[^\\]|\\[\s\S])*?'''|'(?:\\.|[^\\'\r\n])*'/,
  2831. greedy: true
  2832. },
  2833. '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/,
  2834. 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
  2835. 'operator': {
  2836. pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
  2837. lookbehind: true
  2838. },
  2839. 'punctuation': /\.+|[{}[\];(),:$]/
  2840. });
  2841. Prism.languages.insertBefore('groovy', 'string', {
  2842. 'shebang': {
  2843. pattern: /#!.+/,
  2844. alias: 'comment',
  2845. greedy: true
  2846. },
  2847. 'interpolation-string': {
  2848. // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
  2849. // simple division (see JS regex), so find a fix maybe?
  2850. pattern: /"""(?:[^\\]|\\[\s\S])*?"""|(["/])(?:\\.|(?!\1)[^\\\r\n])*\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
  2851. greedy: true,
  2852. inside: {
  2853. 'interpolation': interpolation,
  2854. 'string': /[\s\S]+/
  2855. }
  2856. }
  2857. });
  2858. Prism.languages.insertBefore('groovy', 'punctuation', {
  2859. 'spock-block': /\b(?:and|cleanup|expect|given|setup|then|when|where):/
  2860. });
  2861. Prism.languages.insertBefore('groovy', 'function', {
  2862. 'annotation': {
  2863. pattern: /(^|[^.])@\w+/,
  2864. lookbehind: true,
  2865. alias: 'punctuation'
  2866. }
  2867. });
  2868. interpolation.inside.expression.inside = Prism.languages.groovy;
  2869. }(Prism));
  2870. (function (Prism) {
  2871. 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(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
  2872. // full package (optional) + parent classes (optional)
  2873. var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2874. // based on the java naming conventions
  2875. var className = {
  2876. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2877. lookbehind: true,
  2878. inside: {
  2879. 'namespace': {
  2880. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2881. inside: {
  2882. 'punctuation': /\./
  2883. }
  2884. },
  2885. 'punctuation': /\./
  2886. }
  2887. };
  2888. Prism.languages.java = Prism.languages.extend('clike', {
  2889. 'string': {
  2890. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
  2891. lookbehind: true,
  2892. greedy: true
  2893. },
  2894. 'class-name': [
  2895. className,
  2896. {
  2897. // variables, parameters, and constructor references
  2898. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2899. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),
  2900. lookbehind: true,
  2901. inside: className.inside
  2902. },
  2903. {
  2904. // class names based on keyword
  2905. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2906. pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source),
  2907. lookbehind: true,
  2908. inside: className.inside
  2909. }
  2910. ],
  2911. 'keyword': keywords,
  2912. 'function': [
  2913. Prism.languages.clike.function,
  2914. {
  2915. pattern: /(::\s*)[a-z_]\w*/,
  2916. lookbehind: true
  2917. }
  2918. ],
  2919. '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,
  2920. 'operator': {
  2921. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  2922. lookbehind: true
  2923. }
  2924. });
  2925. Prism.languages.insertBefore('java', 'string', {
  2926. 'triple-quoted-string': {
  2927. // http://openjdk.java.net/jeps/355#Description
  2928. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  2929. greedy: true,
  2930. alias: 'string'
  2931. },
  2932. 'char': {
  2933. pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
  2934. greedy: true
  2935. }
  2936. });
  2937. Prism.languages.insertBefore('java', 'class-name', {
  2938. 'annotation': {
  2939. pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
  2940. lookbehind: true,
  2941. alias: 'punctuation'
  2942. },
  2943. 'generics': {
  2944. pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
  2945. inside: {
  2946. 'class-name': className,
  2947. 'keyword': keywords,
  2948. 'punctuation': /[<>(),.:]/,
  2949. 'operator': /[?&|]/
  2950. }
  2951. },
  2952. 'import': [
  2953. {
  2954. pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source),
  2955. lookbehind: true,
  2956. inside: {
  2957. 'namespace': className.inside.namespace,
  2958. 'punctuation': /\./,
  2959. 'operator': /\*/,
  2960. 'class-name': /\w+/
  2961. }
  2962. },
  2963. {
  2964. pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source),
  2965. lookbehind: true,
  2966. alias: 'static',
  2967. inside: {
  2968. 'namespace': className.inside.namespace,
  2969. 'static': /\b\w+$/,
  2970. 'punctuation': /\./,
  2971. 'operator': /\*/,
  2972. 'class-name': /\w+/
  2973. }
  2974. }
  2975. ],
  2976. 'namespace': {
  2977. pattern: RegExp(
  2978. /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
  2979. .source.replace(/<keyword>/g, function () { return keywords.source; })),
  2980. lookbehind: true,
  2981. inside: {
  2982. 'punctuation': /\./,
  2983. }
  2984. }
  2985. });
  2986. }(Prism));
  2987. // https://www.json.org/json-en.html
  2988. Prism.languages.json = {
  2989. 'property': {
  2990. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
  2991. lookbehind: true,
  2992. greedy: true
  2993. },
  2994. 'string': {
  2995. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  2996. lookbehind: true,
  2997. greedy: true
  2998. },
  2999. 'comment': {
  3000. pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
  3001. greedy: true
  3002. },
  3003. 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
  3004. 'punctuation': /[{}[\],]/,
  3005. 'operator': /:/,
  3006. 'boolean': /\b(?:false|true)\b/,
  3007. 'null': {
  3008. pattern: /\bnull\b/,
  3009. alias: 'keyword'
  3010. }
  3011. };
  3012. Prism.languages.webmanifest = Prism.languages.json;
  3013. Prism.languages.julia = {
  3014. 'comment': {
  3015. // support one level of nested comments
  3016. // https://github.com/JuliaLang/julia/pull/6128
  3017. pattern: /(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/,
  3018. lookbehind: true
  3019. },
  3020. 'regex': {
  3021. // https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1
  3022. pattern: /r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/,
  3023. greedy: true
  3024. },
  3025. 'string': {
  3026. // https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1
  3027. // https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1
  3028. // https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1
  3029. pattern: /"""[\s\S]+?"""|(?:\b\w+)?"(?:\\.|[^"\\\r\n])*"|`(?:[^\\`\r\n]|\\.)*`/,
  3030. greedy: true
  3031. },
  3032. 'char': {
  3033. // https://docs.julialang.org/en/v1/manual/strings/#man-characters-1
  3034. pattern: /(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'/,
  3035. lookbehind: true,
  3036. greedy: true
  3037. },
  3038. '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/,
  3039. 'boolean': /\b(?:false|true)\b/,
  3040. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i,
  3041. // https://docs.julialang.org/en/v1/manual/mathematical-operations/
  3042. // https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1
  3043. 'operator': /&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/,
  3044. 'punctuation': /::?|[{}[\]();,.?]/,
  3045. // https://docs.julialang.org/en/v1/base/numbers/#Base.im
  3046. 'constant': /\b(?:(?:Inf|NaN)(?:16|32|64)?|im|pi)\b|[πℯ]/
  3047. };
  3048. (function (Prism) {
  3049. Prism.languages.kotlin = Prism.languages.extend('clike', {
  3050. 'keyword': {
  3051. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  3052. 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/,
  3053. lookbehind: true
  3054. },
  3055. 'function': [
  3056. {
  3057. pattern: /(?:`[^\r\n`]+`|\b\w+)(?=\s*\()/,
  3058. greedy: true
  3059. },
  3060. {
  3061. pattern: /(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/,
  3062. lookbehind: true,
  3063. greedy: true
  3064. }
  3065. ],
  3066. 'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
  3067. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  3068. });
  3069. delete Prism.languages.kotlin['class-name'];
  3070. var interpolationInside = {
  3071. 'interpolation-punctuation': {
  3072. pattern: /^\$\{?|\}$/,
  3073. alias: 'punctuation'
  3074. },
  3075. 'expression': {
  3076. pattern: /[\s\S]+/,
  3077. inside: Prism.languages.kotlin
  3078. }
  3079. };
  3080. Prism.languages.insertBefore('kotlin', 'string', {
  3081. // https://kotlinlang.org/spec/expressions.html#string-interpolation-expressions
  3082. 'string-literal': [
  3083. {
  3084. pattern: /"""(?:[^$]|\$(?:(?!\{)|\{[^{}]*\}))*?"""/,
  3085. alias: 'multiline',
  3086. inside: {
  3087. 'interpolation': {
  3088. pattern: /\$(?:[a-z_]\w*|\{[^{}]*\})/i,
  3089. inside: interpolationInside
  3090. },
  3091. 'string': /[\s\S]+/
  3092. }
  3093. },
  3094. {
  3095. pattern: /"(?:[^"\\\r\n$]|\\.|\$(?:(?!\{)|\{[^{}]*\}))*"/,
  3096. alias: 'singleline',
  3097. inside: {
  3098. 'interpolation': {
  3099. pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:[a-z_]\w*|\{[^{}]*\})/i,
  3100. lookbehind: true,
  3101. inside: interpolationInside
  3102. },
  3103. 'string': /[\s\S]+/
  3104. }
  3105. }
  3106. ],
  3107. 'char': {
  3108. // https://kotlinlang.org/spec/expressions.html#character-literals
  3109. pattern: /'(?:[^'\\\r\n]|\\(?:.|u[a-fA-F0-9]{0,4}))'/,
  3110. greedy: true
  3111. }
  3112. });
  3113. delete Prism.languages.kotlin['string'];
  3114. Prism.languages.insertBefore('kotlin', 'keyword', {
  3115. 'annotation': {
  3116. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  3117. alias: 'builtin'
  3118. }
  3119. });
  3120. Prism.languages.insertBefore('kotlin', 'function', {
  3121. 'label': {
  3122. pattern: /\b\w+@|@\w+\b/,
  3123. alias: 'symbol'
  3124. }
  3125. });
  3126. Prism.languages.kt = Prism.languages.kotlin;
  3127. Prism.languages.kts = Prism.languages.kotlin;
  3128. }(Prism));
  3129. (function (Prism) {
  3130. var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i;
  3131. var insideEqu = {
  3132. 'equation-command': {
  3133. pattern: funcPattern,
  3134. alias: 'regex'
  3135. }
  3136. };
  3137. Prism.languages.latex = {
  3138. 'comment': /%.*/,
  3139. // the verbatim environment prints whitespace to the document
  3140. 'cdata': {
  3141. pattern: /(\\begin\{((?:lstlisting|verbatim)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  3142. lookbehind: true
  3143. },
  3144. /*
  3145. * equations can be between $$ $$ or $ $ or \( \) or \[ \]
  3146. * (all are multiline)
  3147. */
  3148. 'equation': [
  3149. {
  3150. pattern: /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
  3151. inside: insideEqu,
  3152. alias: 'string'
  3153. },
  3154. {
  3155. pattern: /(\\begin\{((?:align|eqnarray|equation|gather|math|multline)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  3156. lookbehind: true,
  3157. inside: insideEqu,
  3158. alias: 'string'
  3159. }
  3160. ],
  3161. /*
  3162. * arguments which are keywords or references are highlighted
  3163. * as keywords
  3164. */
  3165. 'keyword': {
  3166. pattern: /(\\(?:begin|cite|documentclass|end|label|ref|usepackage)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  3167. lookbehind: true
  3168. },
  3169. 'url': {
  3170. pattern: /(\\url\{)[^}]+(?=\})/,
  3171. lookbehind: true
  3172. },
  3173. /*
  3174. * section or chapter headlines are highlighted as bold so that
  3175. * they stand out more
  3176. */
  3177. 'headline': {
  3178. pattern: /(\\(?:chapter|frametitle|paragraph|part|section|subparagraph|subsection|subsubparagraph|subsubsection|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  3179. lookbehind: true,
  3180. alias: 'class-name'
  3181. },
  3182. 'function': {
  3183. pattern: funcPattern,
  3184. alias: 'selector'
  3185. },
  3186. 'punctuation': /[[\]{}&]/
  3187. };
  3188. Prism.languages.tex = Prism.languages.latex;
  3189. Prism.languages.context = Prism.languages.latex;
  3190. }(Prism));
  3191. Prism.languages.lua = {
  3192. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  3193. // \z may be used to skip the following space
  3194. 'string': {
  3195. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  3196. greedy: true
  3197. },
  3198. 'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  3199. '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/,
  3200. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  3201. 'operator': [
  3202. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  3203. {
  3204. // Match ".." but don't break "..."
  3205. pattern: /(^|[^.])\.\.(?!\.)/,
  3206. lookbehind: true
  3207. }
  3208. ],
  3209. 'punctuation': /[\[\](){},;]|\.+|:+/
  3210. };
  3211. Prism.languages.matlab = {
  3212. 'comment': [
  3213. /%\{[\s\S]*?\}%/,
  3214. /%.+/
  3215. ],
  3216. 'string': {
  3217. pattern: /\B'(?:''|[^'\r\n])*'/,
  3218. greedy: true
  3219. },
  3220. // FIXME We could handle imaginary numbers as a whole
  3221. 'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[eE][+-]?\d+)?(?:[ij])?|\b[ij]\b/,
  3222. 'keyword': /\b(?:NaN|break|case|catch|continue|else|elseif|end|for|function|if|inf|otherwise|parfor|pause|pi|return|switch|try|while)\b/,
  3223. 'function': /\b(?!\d)\w+(?=\s*\()/,
  3224. 'operator': /\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,
  3225. 'punctuation': /\.{3}|[.,;\[\](){}!]/
  3226. };
  3227. (function (Prism) {
  3228. var variable = /\$(?:\w[a-z\d]*(?:_[^\x00-\x1F\s"'\\()$]*)?|\{[^}\s"'\\]+\})/i;
  3229. Prism.languages.nginx = {
  3230. 'comment': {
  3231. pattern: /(^|[\s{};])#.*/,
  3232. lookbehind: true,
  3233. greedy: true
  3234. },
  3235. 'directive': {
  3236. pattern: /(^|\s)\w(?:[^;{}"'\\\s]|\\.|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\s+(?:#.*(?!.)|(?![#\s])))*?(?=\s*[;{])/,
  3237. lookbehind: true,
  3238. greedy: true,
  3239. inside: {
  3240. 'string': {
  3241. pattern: /((?:^|[^\\])(?:\\\\)*)(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/,
  3242. lookbehind: true,
  3243. greedy: true,
  3244. inside: {
  3245. 'escape': {
  3246. pattern: /\\["'\\nrt]/,
  3247. alias: 'entity'
  3248. },
  3249. 'variable': variable
  3250. }
  3251. },
  3252. 'comment': {
  3253. pattern: /(\s)#.*/,
  3254. lookbehind: true,
  3255. greedy: true
  3256. },
  3257. 'keyword': {
  3258. pattern: /^\S+/,
  3259. greedy: true
  3260. },
  3261. // other patterns
  3262. 'boolean': {
  3263. pattern: /(\s)(?:off|on)(?!\S)/,
  3264. lookbehind: true
  3265. },
  3266. 'number': {
  3267. pattern: /(\s)\d+[a-z]*(?!\S)/i,
  3268. lookbehind: true
  3269. },
  3270. 'variable': variable
  3271. }
  3272. },
  3273. 'punctuation': /[{};]/
  3274. };
  3275. }(Prism));
  3276. Prism.languages.nim = {
  3277. 'comment': {
  3278. pattern: /#.*/,
  3279. greedy: true
  3280. },
  3281. 'string': {
  3282. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  3283. pattern: /(?:\b(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")/,
  3284. greedy: true
  3285. },
  3286. 'char': {
  3287. // Character literals are handled specifically to prevent issues with numeric type suffixes
  3288. pattern: /'(?:\\(?:\d+|x[\da-fA-F]{0,2}|.)|[^'])'/,
  3289. greedy: true
  3290. },
  3291. 'function': {
  3292. pattern: /(?:(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  3293. greedy: true,
  3294. inside: {
  3295. 'operator': /\*$/
  3296. }
  3297. },
  3298. // We don't want to highlight operators (and anything really) inside backticks
  3299. 'identifier': {
  3300. pattern: /`[^`\r\n]+`/,
  3301. greedy: true,
  3302. inside: {
  3303. 'punctuation': /`/
  3304. }
  3305. },
  3306. // The negative look ahead prevents wrong highlighting of the .. operator
  3307. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  3308. '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/,
  3309. 'operator': {
  3310. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  3311. // but allow the slice operator .. to take precedence over them
  3312. // One can define his own operators in Nim so all combination of operators might be an operator.
  3313. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|in|is|isnot|mod|not|notin|of|or|shl|shr|xor)\b)/m,
  3314. lookbehind: true
  3315. },
  3316. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  3317. };
  3318. Prism.languages.nix = {
  3319. 'comment': {
  3320. pattern: /\/\*[\s\S]*?\*\/|#.*/,
  3321. greedy: true
  3322. },
  3323. 'string': {
  3324. pattern: /"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,
  3325. greedy: true,
  3326. inside: {
  3327. 'interpolation': {
  3328. // The lookbehind ensures the ${} is not preceded by \ or ''
  3329. pattern: /(^|(?:^|(?!'').)[^\\])\$\{(?:[^{}]|\{[^}]*\})*\}/,
  3330. lookbehind: true,
  3331. inside: null // see below
  3332. }
  3333. }
  3334. },
  3335. 'url': [
  3336. /\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,
  3337. {
  3338. pattern: /([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,
  3339. lookbehind: true
  3340. }
  3341. ],
  3342. 'antiquotation': {
  3343. pattern: /\$(?=\{)/,
  3344. alias: 'important'
  3345. },
  3346. 'number': /\b\d+\b/,
  3347. 'keyword': /\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,
  3348. 'function': /\b(?:abort|add|all|any|attrNames|attrValues|baseNameOf|compareVersions|concatLists|currentSystem|deepSeq|derivation|dirOf|div|elem(?:At)?|fetch(?:Tarball|url)|filter(?:Source)?|fromJSON|genList|getAttr|getEnv|hasAttr|hashString|head|import|intersectAttrs|is(?:Attrs|Bool|Function|Int|List|Null|String)|length|lessThan|listToAttrs|map|mul|parseDrvName|pathExists|read(?:Dir|File)|removeAttrs|replaceStrings|seq|sort|stringLength|sub(?:string)?|tail|throw|to(?:File|JSON|Path|String|XML)|trace|typeOf)\b|\bfoldl'\B/,
  3349. 'boolean': /\b(?:false|true)\b/,
  3350. 'operator': /[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,
  3351. 'punctuation': /[{}()[\].,:;]/
  3352. };
  3353. Prism.languages.nix.string.inside.interpolation.inside = Prism.languages.nix;
  3354. // https://ocaml.org/manual/lex.html
  3355. Prism.languages.ocaml = {
  3356. 'comment': {
  3357. pattern: /\(\*[\s\S]*?\*\)/,
  3358. greedy: true
  3359. },
  3360. 'char': {
  3361. pattern: /'(?:[^\\\r\n']|\\(?:.|[ox]?[0-9a-f]{1,3}))'/i,
  3362. greedy: true
  3363. },
  3364. 'string': [
  3365. {
  3366. pattern: /"(?:\\(?:[\s\S]|\r\n)|[^\\\r\n"])*"/,
  3367. greedy: true
  3368. },
  3369. {
  3370. pattern: /\{([a-z_]*)\|[\s\S]*?\|\1\}/,
  3371. greedy: true
  3372. }
  3373. ],
  3374. 'number': [
  3375. // binary and octal
  3376. /\b(?:0b[01][01_]*|0o[0-7][0-7_]*)\b/i,
  3377. // hexadecimal
  3378. /\b0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]*)?(?:p[+-]?\d[\d_]*)?(?!\w)/i,
  3379. // decimal
  3380. /\b\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?\d[\d_]*)?(?!\w)/i,
  3381. ],
  3382. 'directive': {
  3383. pattern: /\B#\w+/,
  3384. alias: 'property'
  3385. },
  3386. 'label': {
  3387. pattern: /\B~\w+/,
  3388. alias: 'property'
  3389. },
  3390. 'type-variable': {
  3391. pattern: /\B'\w+/,
  3392. alias: 'function'
  3393. },
  3394. 'variant': {
  3395. pattern: /`\w+/,
  3396. alias: 'symbol'
  3397. },
  3398. // For the list of keywords and operators,
  3399. // see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
  3400. '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/,
  3401. 'boolean': /\b(?:false|true)\b/,
  3402. 'operator-like-punctuation': {
  3403. pattern: /\[[<>|]|[>|]\]|\{<|>\}/,
  3404. alias: 'punctuation'
  3405. },
  3406. // Custom operators are allowed
  3407. 'operator': /\.[.~]|:[=>]|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
  3408. 'punctuation': /;;|::|[(){}\[\].,:;#]|\b_\b/
  3409. };
  3410. (function (Prism) {
  3411. var brackets = /(?:\((?:[^()\\]|\\[\s\S])*\)|\{(?:[^{}\\]|\\[\s\S])*\}|\[(?:[^[\]\\]|\\[\s\S])*\]|<(?:[^<>\\]|\\[\s\S])*>)/.source;
  3412. Prism.languages.perl = {
  3413. 'comment': [
  3414. {
  3415. // POD
  3416. pattern: /(^\s*)=\w[\s\S]*?=cut.*/m,
  3417. lookbehind: true,
  3418. greedy: true
  3419. },
  3420. {
  3421. pattern: /(^|[^\\$])#.*/,
  3422. lookbehind: true,
  3423. greedy: true
  3424. }
  3425. ],
  3426. // TODO Could be nice to handle Heredoc too.
  3427. 'string': [
  3428. {
  3429. pattern: RegExp(
  3430. /\b(?:q|qq|qw|qx)(?![a-zA-Z0-9])\s*/.source +
  3431. '(?:' +
  3432. [
  3433. // q/.../
  3434. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  3435. // q a...a
  3436. // eslint-disable-next-line regexp/strict
  3437. /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3438. // q(...)
  3439. // q{...}
  3440. // q[...]
  3441. // q<...>
  3442. brackets,
  3443. ].join('|') +
  3444. ')'
  3445. ),
  3446. greedy: true
  3447. },
  3448. // "...", `...`
  3449. {
  3450. pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  3451. greedy: true
  3452. },
  3453. // '...'
  3454. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  3455. {
  3456. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  3457. greedy: true
  3458. }
  3459. ],
  3460. 'regex': [
  3461. {
  3462. pattern: RegExp(
  3463. /\b(?:m|qr)(?![a-zA-Z0-9])\s*/.source +
  3464. '(?:' +
  3465. [
  3466. // m/.../
  3467. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  3468. // m a...a
  3469. // eslint-disable-next-line regexp/strict
  3470. /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3471. // m(...)
  3472. // m{...}
  3473. // m[...]
  3474. // m<...>
  3475. brackets,
  3476. ].join('|') +
  3477. ')' +
  3478. /[msixpodualngc]*/.source
  3479. ),
  3480. greedy: true
  3481. },
  3482. // The lookbehinds prevent -s from breaking
  3483. {
  3484. pattern: RegExp(
  3485. /(^|[^-])\b(?:s|tr|y)(?![a-zA-Z0-9])\s*/.source +
  3486. '(?:' +
  3487. [
  3488. // s/.../.../
  3489. // eslint-disable-next-line regexp/strict
  3490. /([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3491. // s a...a...a
  3492. // eslint-disable-next-line regexp/strict
  3493. /([a-zA-Z0-9])(?:(?!\3)[^\\]|\\[\s\S])*\3(?:(?!\3)[^\\]|\\[\s\S])*\3/.source,
  3494. // s(...)(...)
  3495. // s{...}{...}
  3496. // s[...][...]
  3497. // s<...><...>
  3498. // s(...)[...]
  3499. brackets + /\s*/.source + brackets,
  3500. ].join('|') +
  3501. ')' +
  3502. /[msixpodualngcer]*/.source
  3503. ),
  3504. lookbehind: true,
  3505. greedy: true
  3506. },
  3507. // /.../
  3508. // The look-ahead tries to prevent two divisions on
  3509. // the same line from being highlighted as regex.
  3510. // This does not support multi-line regex.
  3511. {
  3512. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|x|xor)\b))/,
  3513. greedy: true
  3514. }
  3515. ],
  3516. // FIXME Not sure about the handling of ::, ', and #
  3517. 'variable': [
  3518. // ${^POSTMATCH}
  3519. /[&*$@%]\{\^[A-Z]+\}/,
  3520. // $^V
  3521. /[&*$@%]\^[A-Z_]/,
  3522. // ${...}
  3523. /[&*$@%]#?(?=\{)/,
  3524. // $foo
  3525. /[&*$@%]#?(?:(?:::)*'?(?!\d)[\w$]+(?![\w$]))+(?:::)*/,
  3526. // $1
  3527. /[&*$@%]\d+/,
  3528. // $_, @_, %!
  3529. // The negative lookahead prevents from breaking the %= operator
  3530. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  3531. ],
  3532. 'filehandle': {
  3533. // <>, <FOO>, _
  3534. pattern: /<(?![<=])\S*?>|\b_\b/,
  3535. alias: 'symbol'
  3536. },
  3537. 'v-string': {
  3538. // v1.2, 1.2.3
  3539. pattern: /v\d+(?:\.\d+)*|\d+(?:\.\d+){2,}/,
  3540. alias: 'string'
  3541. },
  3542. 'function': {
  3543. pattern: /(\bsub[ \t]+)\w+/,
  3544. lookbehind: true
  3545. },
  3546. '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/,
  3547. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)\b/,
  3548. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)\b/,
  3549. 'punctuation': /[{}[\];(),:]/
  3550. };
  3551. }(Prism));
  3552. /**
  3553. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  3554. * Modified by Miles Johnson: http://milesj.me
  3555. * Rewritten by Tom Pavelec
  3556. *
  3557. * Supports PHP 5.3 - 8.0
  3558. */
  3559. (function (Prism) {
  3560. var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
  3561. var constant = [
  3562. {
  3563. pattern: /\b(?:false|true)\b/i,
  3564. alias: 'boolean'
  3565. },
  3566. {
  3567. pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
  3568. greedy: true,
  3569. lookbehind: true,
  3570. },
  3571. {
  3572. pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
  3573. greedy: true,
  3574. lookbehind: true,
  3575. },
  3576. /\b(?:null)\b/i,
  3577. /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
  3578. ];
  3579. 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;
  3580. var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
  3581. var punctuation = /[{}\[\](),:;]/;
  3582. Prism.languages.php = {
  3583. 'delimiter': {
  3584. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  3585. alias: 'important'
  3586. },
  3587. 'comment': comment,
  3588. 'variable': /\$+(?:\w+\b|(?=\{))/,
  3589. 'package': {
  3590. pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3591. lookbehind: true,
  3592. inside: {
  3593. 'punctuation': /\\/
  3594. }
  3595. },
  3596. 'class-name-definition': {
  3597. pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
  3598. lookbehind: true,
  3599. alias: 'class-name'
  3600. },
  3601. 'function-definition': {
  3602. pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
  3603. lookbehind: true,
  3604. alias: 'function'
  3605. },
  3606. 'keyword': [
  3607. {
  3608. pattern: /(\(\s*)\b(?:array|bool|boolean|float|int|integer|object|string)\b(?=\s*\))/i,
  3609. alias: 'type-casting',
  3610. greedy: true,
  3611. lookbehind: true
  3612. },
  3613. {
  3614. pattern: /([(,?]\s*)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string)\b(?=\s*\$)/i,
  3615. alias: 'type-hint',
  3616. greedy: true,
  3617. lookbehind: true
  3618. },
  3619. {
  3620. pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i,
  3621. alias: 'return-type',
  3622. greedy: true,
  3623. lookbehind: true
  3624. },
  3625. {
  3626. pattern: /\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i,
  3627. alias: 'type-declaration',
  3628. greedy: true
  3629. },
  3630. {
  3631. pattern: /(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i,
  3632. alias: 'type-declaration',
  3633. greedy: true,
  3634. lookbehind: true
  3635. },
  3636. {
  3637. pattern: /\b(?:parent|self|static)(?=\s*::)/i,
  3638. alias: 'static-context',
  3639. greedy: true
  3640. },
  3641. {
  3642. // yield from
  3643. pattern: /(\byield\s+)from\b/i,
  3644. lookbehind: true
  3645. },
  3646. // `class` is always a keyword unlike other keywords
  3647. /\bclass\b/i,
  3648. {
  3649. // https://www.php.net/manual/en/reserved.keywords.php
  3650. //
  3651. // keywords cannot be preceded by "->"
  3652. // the complex lookbehind means `(?<!(?:->|::)\s*)`
  3653. 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|never|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i,
  3654. lookbehind: true
  3655. }
  3656. ],
  3657. 'argument-name': {
  3658. pattern: /([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i,
  3659. lookbehind: true
  3660. },
  3661. 'class-name': [
  3662. {
  3663. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
  3664. greedy: true,
  3665. lookbehind: true
  3666. },
  3667. {
  3668. pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
  3669. greedy: true,
  3670. lookbehind: true
  3671. },
  3672. {
  3673. pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
  3674. greedy: true
  3675. },
  3676. {
  3677. pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
  3678. alias: 'class-name-fully-qualified',
  3679. greedy: true,
  3680. lookbehind: true,
  3681. inside: {
  3682. 'punctuation': /\\/
  3683. }
  3684. },
  3685. {
  3686. pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
  3687. alias: 'class-name-fully-qualified',
  3688. greedy: true,
  3689. inside: {
  3690. 'punctuation': /\\/
  3691. }
  3692. },
  3693. {
  3694. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3695. alias: 'class-name-fully-qualified',
  3696. greedy: true,
  3697. lookbehind: true,
  3698. inside: {
  3699. 'punctuation': /\\/
  3700. }
  3701. },
  3702. {
  3703. pattern: /\b[a-z_]\w*(?=\s*\$)/i,
  3704. alias: 'type-declaration',
  3705. greedy: true
  3706. },
  3707. {
  3708. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  3709. alias: ['class-name-fully-qualified', 'type-declaration'],
  3710. greedy: true,
  3711. inside: {
  3712. 'punctuation': /\\/
  3713. }
  3714. },
  3715. {
  3716. pattern: /\b[a-z_]\w*(?=\s*::)/i,
  3717. alias: 'static-context',
  3718. greedy: true
  3719. },
  3720. {
  3721. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
  3722. alias: ['class-name-fully-qualified', 'static-context'],
  3723. greedy: true,
  3724. inside: {
  3725. 'punctuation': /\\/
  3726. }
  3727. },
  3728. {
  3729. pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
  3730. alias: 'type-hint',
  3731. greedy: true,
  3732. lookbehind: true
  3733. },
  3734. {
  3735. pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  3736. alias: ['class-name-fully-qualified', 'type-hint'],
  3737. greedy: true,
  3738. lookbehind: true,
  3739. inside: {
  3740. 'punctuation': /\\/
  3741. }
  3742. },
  3743. {
  3744. pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
  3745. alias: 'return-type',
  3746. greedy: true,
  3747. lookbehind: true
  3748. },
  3749. {
  3750. pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3751. alias: ['class-name-fully-qualified', 'return-type'],
  3752. greedy: true,
  3753. lookbehind: true,
  3754. inside: {
  3755. 'punctuation': /\\/
  3756. }
  3757. }
  3758. ],
  3759. 'constant': constant,
  3760. 'function': {
  3761. pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
  3762. lookbehind: true,
  3763. inside: {
  3764. 'punctuation': /\\/
  3765. }
  3766. },
  3767. 'property': {
  3768. pattern: /(->\s*)\w+/,
  3769. lookbehind: true
  3770. },
  3771. 'number': number,
  3772. 'operator': operator,
  3773. 'punctuation': punctuation
  3774. };
  3775. var string_interpolation = {
  3776. pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
  3777. lookbehind: true,
  3778. inside: Prism.languages.php
  3779. };
  3780. var string = [
  3781. {
  3782. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  3783. alias: 'nowdoc-string',
  3784. greedy: true,
  3785. inside: {
  3786. 'delimiter': {
  3787. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  3788. alias: 'symbol',
  3789. inside: {
  3790. 'punctuation': /^<<<'?|[';]$/
  3791. }
  3792. }
  3793. }
  3794. },
  3795. {
  3796. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  3797. alias: 'heredoc-string',
  3798. greedy: true,
  3799. inside: {
  3800. 'delimiter': {
  3801. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  3802. alias: 'symbol',
  3803. inside: {
  3804. 'punctuation': /^<<<"?|[";]$/
  3805. }
  3806. },
  3807. 'interpolation': string_interpolation
  3808. }
  3809. },
  3810. {
  3811. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  3812. alias: 'backtick-quoted-string',
  3813. greedy: true
  3814. },
  3815. {
  3816. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  3817. alias: 'single-quoted-string',
  3818. greedy: true
  3819. },
  3820. {
  3821. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  3822. alias: 'double-quoted-string',
  3823. greedy: true,
  3824. inside: {
  3825. 'interpolation': string_interpolation
  3826. }
  3827. }
  3828. ];
  3829. Prism.languages.insertBefore('php', 'variable', {
  3830. 'string': string,
  3831. 'attribute': {
  3832. pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,
  3833. greedy: true,
  3834. inside: {
  3835. 'attribute-content': {
  3836. pattern: /^(#\[)[\s\S]+(?=\]$)/,
  3837. lookbehind: true,
  3838. // inside can appear subset of php
  3839. inside: {
  3840. 'comment': comment,
  3841. 'string': string,
  3842. 'attribute-class-name': [
  3843. {
  3844. pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
  3845. alias: 'class-name',
  3846. greedy: true,
  3847. lookbehind: true
  3848. },
  3849. {
  3850. pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
  3851. alias: [
  3852. 'class-name',
  3853. 'class-name-fully-qualified'
  3854. ],
  3855. greedy: true,
  3856. lookbehind: true,
  3857. inside: {
  3858. 'punctuation': /\\/
  3859. }
  3860. }
  3861. ],
  3862. 'constant': constant,
  3863. 'number': number,
  3864. 'operator': operator,
  3865. 'punctuation': punctuation
  3866. }
  3867. },
  3868. 'delimiter': {
  3869. pattern: /^#\[|\]$/,
  3870. alias: 'punctuation'
  3871. }
  3872. }
  3873. },
  3874. });
  3875. Prism.hooks.add('before-tokenize', function (env) {
  3876. if (!/<\?/.test(env.code)) {
  3877. return;
  3878. }
  3879. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g;
  3880. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  3881. });
  3882. Prism.hooks.add('after-tokenize', function (env) {
  3883. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  3884. });
  3885. }(Prism));
  3886. Prism.languages.python = {
  3887. 'comment': {
  3888. pattern: /(^|[^\\])#.*/,
  3889. lookbehind: true,
  3890. greedy: true
  3891. },
  3892. 'string-interpolation': {
  3893. pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  3894. greedy: true,
  3895. inside: {
  3896. 'interpolation': {
  3897. // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
  3898. pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
  3899. lookbehind: true,
  3900. inside: {
  3901. 'format-spec': {
  3902. pattern: /(:)[^:(){}]+(?=\}$)/,
  3903. lookbehind: true
  3904. },
  3905. 'conversion-option': {
  3906. pattern: /![sra](?=[:}]$)/,
  3907. alias: 'punctuation'
  3908. },
  3909. rest: null
  3910. }
  3911. },
  3912. 'string': /[\s\S]+/
  3913. }
  3914. },
  3915. 'triple-quoted-string': {
  3916. pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
  3917. greedy: true,
  3918. alias: 'string'
  3919. },
  3920. 'string': {
  3921. pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  3922. greedy: true
  3923. },
  3924. 'function': {
  3925. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  3926. lookbehind: true
  3927. },
  3928. 'class-name': {
  3929. pattern: /(\bclass\s+)\w+/i,
  3930. lookbehind: true
  3931. },
  3932. 'decorator': {
  3933. pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
  3934. lookbehind: true,
  3935. alias: ['annotation', 'punctuation'],
  3936. inside: {
  3937. 'punctuation': /\./
  3938. }
  3939. },
  3940. '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/,
  3941. '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/,
  3942. 'boolean': /\b(?:False|None|True)\b/,
  3943. '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,
  3944. 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  3945. 'punctuation': /[{}[\];(),.:]/
  3946. };
  3947. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  3948. Prism.languages.py = Prism.languages.python;
  3949. (function (Prism) {
  3950. var jsString = /"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*'/.source;
  3951. var jsComment = /\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))*\*\//.source;
  3952. var jsExpr = /(?:[^\\()[\]{}"'/]|<string>|\/(?![*/])|<comment>|\(<expr>*\)|\[<expr>*\]|\{<expr>*\}|\\[\s\S])/
  3953. .source.replace(/<string>/g, function () { return jsString; }).replace(/<comment>/g, function () { return jsComment; });
  3954. // the pattern will blow up, so only a few iterations
  3955. for (var i = 0; i < 2; i++) {
  3956. jsExpr = jsExpr.replace(/<expr>/g, function () { return jsExpr; });
  3957. }
  3958. jsExpr = jsExpr.replace(/<expr>/g, '[^\\s\\S]');
  3959. Prism.languages.qml = {
  3960. 'comment': {
  3961. pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
  3962. greedy: true
  3963. },
  3964. 'javascript-function': {
  3965. 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'),
  3966. lookbehind: true,
  3967. greedy: true,
  3968. alias: 'language-javascript',
  3969. inside: Prism.languages.javascript
  3970. },
  3971. 'class-name': {
  3972. pattern: /((?:^|[:;])[ \t]*)(?!\d)\w+(?=[ \t]*\{|[ \t]+on\b)/m,
  3973. lookbehind: true
  3974. },
  3975. 'property': [
  3976. {
  3977. pattern: /((?:^|[;{])[ \t]*)(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  3978. lookbehind: true
  3979. },
  3980. {
  3981. pattern: /((?:^|[;{])[ \t]*)property[ \t]+(?!\d)\w+(?:\.\w+)*[ \t]+(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  3982. lookbehind: true,
  3983. inside: {
  3984. 'keyword': /^property/,
  3985. 'property': /\w+(?:\.\w+)*/
  3986. }
  3987. }
  3988. ],
  3989. 'javascript-expression': {
  3990. pattern: RegExp(/(:[ \t]*)(?![\s;}[])(?:(?!$|[;}])<js>)+/.source.replace(/<js>/g, function () { return jsExpr; }), 'm'),
  3991. lookbehind: true,
  3992. greedy: true,
  3993. alias: 'language-javascript',
  3994. inside: Prism.languages.javascript
  3995. },
  3996. 'string': {
  3997. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  3998. greedy: true
  3999. },
  4000. 'keyword': /\b(?:as|import|on)\b/,
  4001. 'punctuation': /[{}[\]:;,]/
  4002. };
  4003. }(Prism));
  4004. Prism.languages.r = {
  4005. 'comment': /#.*/,
  4006. 'string': {
  4007. pattern: /(['"])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  4008. greedy: true
  4009. },
  4010. 'percent-operator': {
  4011. // Includes user-defined operators
  4012. // and %%, %*%, %/%, %in%, %o%, %x%
  4013. pattern: /%[^%\s]*%/,
  4014. alias: 'operator'
  4015. },
  4016. 'boolean': /\b(?:FALSE|TRUE)\b/,
  4017. 'ellipsis': /\.\.(?:\.|\d+)/,
  4018. 'number': [
  4019. /\b(?:Inf|NaN)\b/,
  4020. /(?:\b0x[\dA-Fa-f]+(?:\.\d*)?|\b\d+(?:\.\d*)?|\B\.\d+)(?:[EePp][+-]?\d+)?[iL]?/
  4021. ],
  4022. 'keyword': /\b(?:NA|NA_character_|NA_complex_|NA_integer_|NA_real_|NULL|break|else|for|function|if|in|next|repeat|while)\b/,
  4023. 'operator': /->?>?|<(?:=|<?-)?|[>=!]=?|::?|&&?|\|\|?|[+*\/^$@~]/,
  4024. 'punctuation': /[(){}\[\],;]/
  4025. };
  4026. (function (Prism) {
  4027. var javascript = Prism.util.clone(Prism.languages.javascript);
  4028. var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
  4029. var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
  4030. var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
  4031. /**
  4032. * @param {string} source
  4033. * @param {string} [flags]
  4034. */
  4035. function re(source, flags) {
  4036. source = source
  4037. .replace(/<S>/g, function () { return space; })
  4038. .replace(/<BRACES>/g, function () { return braces; })
  4039. .replace(/<SPREAD>/g, function () { return spread; });
  4040. return RegExp(source, flags);
  4041. }
  4042. spread = re(spread).source;
  4043. Prism.languages.jsx = Prism.languages.extend('markup', javascript);
  4044. Prism.languages.jsx.tag.pattern = re(
  4045. /<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
  4046. );
  4047. Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/;
  4048. Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/;
  4049. Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
  4050. Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
  4051. Prism.languages.insertBefore('inside', 'attr-name', {
  4052. 'spread': {
  4053. pattern: re(/<SPREAD>/.source),
  4054. inside: Prism.languages.jsx
  4055. }
  4056. }, Prism.languages.jsx.tag);
  4057. Prism.languages.insertBefore('inside', 'special-attr', {
  4058. 'script': {
  4059. // Allow for two levels of nesting
  4060. pattern: re(/=<BRACES>/.source),
  4061. alias: 'language-javascript',
  4062. inside: {
  4063. 'script-punctuation': {
  4064. pattern: /^=(?=\{)/,
  4065. alias: 'punctuation'
  4066. },
  4067. rest: Prism.languages.jsx
  4068. },
  4069. }
  4070. }, Prism.languages.jsx.tag);
  4071. // The following will handle plain text inside tags
  4072. var stringifyToken = function (token) {
  4073. if (!token) {
  4074. return '';
  4075. }
  4076. if (typeof token === 'string') {
  4077. return token;
  4078. }
  4079. if (typeof token.content === 'string') {
  4080. return token.content;
  4081. }
  4082. return token.content.map(stringifyToken).join('');
  4083. };
  4084. var walkTokens = function (tokens) {
  4085. var openedTags = [];
  4086. for (var i = 0; i < tokens.length; i++) {
  4087. var token = tokens[i];
  4088. var notTagNorBrace = false;
  4089. if (typeof token !== 'string') {
  4090. if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
  4091. // We found a tag, now find its kind
  4092. if (token.content[0].content[0].content === '</') {
  4093. // Closing tag
  4094. if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
  4095. // Pop matching opening tag
  4096. openedTags.pop();
  4097. }
  4098. } else {
  4099. if (token.content[token.content.length - 1].content === '/>') {
  4100. // Autoclosed tag, ignore
  4101. } else {
  4102. // Opening tag
  4103. openedTags.push({
  4104. tagName: stringifyToken(token.content[0].content[1]),
  4105. openedBraces: 0
  4106. });
  4107. }
  4108. }
  4109. } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
  4110. // Here we might have entered a JSX context inside a tag
  4111. openedTags[openedTags.length - 1].openedBraces++;
  4112. } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
  4113. // Here we might have left a JSX context inside a tag
  4114. openedTags[openedTags.length - 1].openedBraces--;
  4115. } else {
  4116. notTagNorBrace = true;
  4117. }
  4118. }
  4119. if (notTagNorBrace || typeof token === 'string') {
  4120. if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
  4121. // Here we are inside a tag, and not inside a JSX context.
  4122. // That's plain text: drop any tokens matched.
  4123. var plainText = stringifyToken(token);
  4124. // And merge text with adjacent text
  4125. if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
  4126. plainText += stringifyToken(tokens[i + 1]);
  4127. tokens.splice(i + 1, 1);
  4128. }
  4129. if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
  4130. plainText = stringifyToken(tokens[i - 1]) + plainText;
  4131. tokens.splice(i - 1, 1);
  4132. i--;
  4133. }
  4134. tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
  4135. }
  4136. }
  4137. if (token.content && typeof token.content !== 'string') {
  4138. walkTokens(token.content);
  4139. }
  4140. }
  4141. };
  4142. Prism.hooks.add('after-tokenize', function (env) {
  4143. if (env.language !== 'jsx' && env.language !== 'tsx') {
  4144. return;
  4145. }
  4146. walkTokens(env.tokens);
  4147. });
  4148. }(Prism));
  4149. (function (Prism) {
  4150. var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
  4151. for (var i = 0; i < 2; i++) {
  4152. // support 4 levels of nested comments
  4153. multilineComment = multilineComment.replace(/<self>/g, function () { return multilineComment; });
  4154. }
  4155. multilineComment = multilineComment.replace(/<self>/g, function () { return /[^\s\S]/.source; });
  4156. Prism.languages.rust = {
  4157. 'comment': [
  4158. {
  4159. pattern: RegExp(/(^|[^\\])/.source + multilineComment),
  4160. lookbehind: true,
  4161. greedy: true
  4162. },
  4163. {
  4164. pattern: /(^|[^\\:])\/\/.*/,
  4165. lookbehind: true,
  4166. greedy: true
  4167. }
  4168. ],
  4169. 'string': {
  4170. pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
  4171. greedy: true
  4172. },
  4173. 'char': {
  4174. pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
  4175. greedy: true
  4176. },
  4177. 'attribute': {
  4178. pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
  4179. greedy: true,
  4180. alias: 'attr-name',
  4181. inside: {
  4182. 'string': null // see below
  4183. }
  4184. },
  4185. // Closure params should not be confused with bitwise OR |
  4186. 'closure-params': {
  4187. pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
  4188. lookbehind: true,
  4189. greedy: true,
  4190. inside: {
  4191. 'closure-punctuation': {
  4192. pattern: /^\||\|$/,
  4193. alias: 'punctuation'
  4194. },
  4195. rest: null // see below
  4196. }
  4197. },
  4198. 'lifetime-annotation': {
  4199. pattern: /'\w+/,
  4200. alias: 'symbol'
  4201. },
  4202. 'fragment-specifier': {
  4203. pattern: /(\$\w+:)[a-z]+/,
  4204. lookbehind: true,
  4205. alias: 'punctuation'
  4206. },
  4207. 'variable': /\$\w+/,
  4208. 'function-definition': {
  4209. pattern: /(\bfn\s+)\w+/,
  4210. lookbehind: true,
  4211. alias: 'function'
  4212. },
  4213. 'type-definition': {
  4214. pattern: /(\b(?:enum|struct|trait|type|union)\s+)\w+/,
  4215. lookbehind: true,
  4216. alias: 'class-name'
  4217. },
  4218. 'module-declaration': [
  4219. {
  4220. pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
  4221. lookbehind: true,
  4222. alias: 'namespace'
  4223. },
  4224. {
  4225. pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
  4226. lookbehind: true,
  4227. alias: 'namespace',
  4228. inside: {
  4229. 'punctuation': /::/
  4230. }
  4231. }
  4232. ],
  4233. 'keyword': [
  4234. // https://github.com/rust-lang/reference/blob/master/src/keywords.md
  4235. /\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/,
  4236. // primitives and str
  4237. // https://doc.rust-lang.org/stable/rust-by-example/primitives.html
  4238. /\b(?:bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/
  4239. ],
  4240. // functions can technically start with an upper-case letter, but this will introduce a lot of false positives
  4241. // and Rust's naming conventions recommend snake_case anyway.
  4242. // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
  4243. 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
  4244. 'macro': {
  4245. pattern: /\b\w+!/,
  4246. alias: 'property'
  4247. },
  4248. 'constant': /\b[A-Z_][A-Z_\d]+\b/,
  4249. 'class-name': /\b[A-Z]\w*\b/,
  4250. 'namespace': {
  4251. pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
  4252. inside: {
  4253. 'punctuation': /::/
  4254. }
  4255. },
  4256. // Hex, oct, bin, dec numbers with visual separators and type suffix
  4257. '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/,
  4258. 'boolean': /\b(?:false|true)\b/,
  4259. 'punctuation': /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
  4260. 'operator': /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
  4261. };
  4262. Prism.languages.rust['closure-params'].inside.rest = Prism.languages.rust;
  4263. Prism.languages.rust['attribute'].inside['string'] = Prism.languages.rust['string'];
  4264. }(Prism));
  4265. Prism.languages.scss = Prism.languages.extend('css', {
  4266. 'comment': {
  4267. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  4268. lookbehind: true
  4269. },
  4270. 'atrule': {
  4271. pattern: /@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,
  4272. inside: {
  4273. 'rule': /@[\w-]+/
  4274. // See rest below
  4275. }
  4276. },
  4277. // url, compassified
  4278. 'url': /(?:[-a-z]+-)?url(?=\()/i,
  4279. // CSS selector regex is not appropriate for Sass
  4280. // since there can be lot more things (var, @ directive, nesting..)
  4281. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  4282. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  4283. // 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
  4284. // can "pass" as a selector- e.g: proper#{$erty})
  4285. // this one was hard to do, so please be careful if you edit this one :)
  4286. 'selector': {
  4287. // Initial look-ahead is used to prevent matching of blank selectors
  4288. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,
  4289. inside: {
  4290. 'parent': {
  4291. pattern: /&/,
  4292. alias: 'important'
  4293. },
  4294. 'placeholder': /%[-\w]+/,
  4295. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4296. }
  4297. },
  4298. 'property': {
  4299. pattern: /(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,
  4300. inside: {
  4301. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4302. }
  4303. }
  4304. });
  4305. Prism.languages.insertBefore('scss', 'atrule', {
  4306. 'keyword': [
  4307. /@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,
  4308. {
  4309. pattern: /( )(?:from|through)(?= )/,
  4310. lookbehind: true
  4311. }
  4312. ]
  4313. });
  4314. Prism.languages.insertBefore('scss', 'important', {
  4315. // var and interpolated vars
  4316. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4317. });
  4318. Prism.languages.insertBefore('scss', 'function', {
  4319. 'module-modifier': {
  4320. pattern: /\b(?:as|hide|show|with)\b/i,
  4321. alias: 'keyword'
  4322. },
  4323. 'placeholder': {
  4324. pattern: /%[-\w]+/,
  4325. alias: 'selector'
  4326. },
  4327. 'statement': {
  4328. pattern: /\B!(?:default|optional)\b/i,
  4329. alias: 'keyword'
  4330. },
  4331. 'boolean': /\b(?:false|true)\b/,
  4332. 'null': {
  4333. pattern: /\bnull\b/,
  4334. alias: 'keyword'
  4335. },
  4336. 'operator': {
  4337. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,
  4338. lookbehind: true
  4339. }
  4340. });
  4341. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;
  4342. Prism.languages.scala = Prism.languages.extend('java', {
  4343. 'triple-quoted-string': {
  4344. pattern: /"""[\s\S]*?"""/,
  4345. greedy: true,
  4346. alias: 'string'
  4347. },
  4348. 'string': {
  4349. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  4350. greedy: true
  4351. },
  4352. 'keyword': /<-|=>|\b(?:abstract|case|catch|class|def|do|else|extends|final|finally|for|forSome|if|implicit|import|lazy|match|new|null|object|override|package|private|protected|return|sealed|self|super|this|throw|trait|try|type|val|var|while|with|yield)\b/,
  4353. 'number': /\b0x(?:[\da-f]*\.)?[\da-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e\d+)?[dfl]?/i,
  4354. 'builtin': /\b(?:Any|AnyRef|AnyVal|Boolean|Byte|Char|Double|Float|Int|Long|Nothing|Short|String|Unit)\b/,
  4355. 'symbol': /'[^\d\s\\]\w*/
  4356. });
  4357. Prism.languages.insertBefore('scala', 'triple-quoted-string', {
  4358. 'string-interpolation': {
  4359. pattern: /\b[a-z]\w*(?:"""(?:[^$]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*?"""|"(?:[^$"\r\n]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*")/i,
  4360. greedy: true,
  4361. inside: {
  4362. 'id': {
  4363. pattern: /^\w+/,
  4364. greedy: true,
  4365. alias: 'function'
  4366. },
  4367. 'escape': {
  4368. pattern: /\\\$"|\$[$"]/,
  4369. greedy: true,
  4370. alias: 'symbol'
  4371. },
  4372. 'interpolation': {
  4373. pattern: /\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
  4374. greedy: true,
  4375. inside: {
  4376. 'punctuation': /^\$\{?|\}$/,
  4377. 'expression': {
  4378. pattern: /[\s\S]+/,
  4379. inside: Prism.languages.scala
  4380. }
  4381. }
  4382. },
  4383. 'string': /[\s\S]+/
  4384. }
  4385. }
  4386. });
  4387. delete Prism.languages.scala['class-name'];
  4388. delete Prism.languages.scala['function'];
  4389. (function (Prism) {
  4390. // CAREFUL!
  4391. // The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
  4392. var strings = [
  4393. // normal string
  4394. /"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/.source,
  4395. /'[^']*'/.source,
  4396. /\$'(?:[^'\\]|\\[\s\S])*'/.source,
  4397. // here doc
  4398. // 2 capturing groups
  4399. /<<-?\s*(["']?)(\w+)\1\s[\s\S]*?[\r\n]\2/.source
  4400. ].join('|');
  4401. Prism.languages['shell-session'] = {
  4402. 'command': {
  4403. pattern: RegExp(
  4404. // user info
  4405. /^/.source +
  4406. '(?:' +
  4407. (
  4408. // <user> ":" ( <path> )?
  4409. /[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+(?::[^\0-\x1F$#%*?"<>:;|]+)?/.source +
  4410. '|' +
  4411. // <path>
  4412. // Since the path pattern is quite general, we will require it to start with a special character to
  4413. // prevent false positives.
  4414. /[/~.][^\0-\x1F$#%*?"<>@:;|]*/.source
  4415. ) +
  4416. ')?' +
  4417. // shell symbol
  4418. /[$#%](?=\s)/.source +
  4419. // bash command
  4420. /(?:[^\\\r\n \t'"<$]|[ \t](?:(?!#)|#.*$)|\\(?:[^\r]|\r\n?)|\$(?!')|<(?!<)|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
  4421. 'm'
  4422. ),
  4423. greedy: true,
  4424. inside: {
  4425. 'info': {
  4426. // foo@bar:~/files$ exit
  4427. // foo@bar$ exit
  4428. // ~/files$ exit
  4429. pattern: /^[^#$%]+/,
  4430. alias: 'punctuation',
  4431. inside: {
  4432. 'user': /^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,
  4433. 'punctuation': /:/,
  4434. 'path': /[\s\S]+/
  4435. }
  4436. },
  4437. 'bash': {
  4438. pattern: /(^[$#%]\s*)\S[\s\S]*/,
  4439. lookbehind: true,
  4440. alias: 'language-bash',
  4441. inside: Prism.languages.bash
  4442. },
  4443. 'shell-symbol': {
  4444. pattern: /^[$#%]/,
  4445. alias: 'important'
  4446. }
  4447. }
  4448. },
  4449. 'output': /.(?:.*(?:[\r\n]|.$))*/
  4450. };
  4451. Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
  4452. }(Prism));
  4453. Prism.languages.sql = {
  4454. 'comment': {
  4455. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  4456. lookbehind: true
  4457. },
  4458. 'variable': [
  4459. {
  4460. pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
  4461. greedy: true
  4462. },
  4463. /@[\w.$]+/
  4464. ],
  4465. 'string': {
  4466. pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
  4467. greedy: true,
  4468. lookbehind: true
  4469. },
  4470. 'identifier': {
  4471. pattern: /(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,
  4472. greedy: true,
  4473. lookbehind: true,
  4474. inside: {
  4475. 'punctuation': /^`|`$/
  4476. }
  4477. },
  4478. '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?
  4479. '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,
  4480. 'boolean': /\b(?:FALSE|NULL|TRUE)\b/i,
  4481. 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
  4482. 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  4483. 'punctuation': /[;[\]()`,.]/
  4484. };
  4485. (function (Prism) {
  4486. Prism.languages.typescript = Prism.languages.extend('javascript', {
  4487. 'class-name': {
  4488. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
  4489. lookbehind: true,
  4490. greedy: true,
  4491. inside: null // see below
  4492. },
  4493. 'builtin': /\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/,
  4494. });
  4495. // The keywords TypeScript adds to JavaScript
  4496. Prism.languages.typescript.keyword.push(
  4497. /\b(?:abstract|declare|is|keyof|readonly|require)\b/,
  4498. // keywords that have to be followed by an identifier
  4499. /\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
  4500. // This is for `import type *, {}`
  4501. /\btype\b(?=\s*(?:[\{*]|$))/
  4502. );
  4503. // doesn't work with TS because TS is too complex
  4504. delete Prism.languages.typescript['parameter'];
  4505. delete Prism.languages.typescript['literal-property'];
  4506. // a version of typescript specifically for highlighting types
  4507. var typeInside = Prism.languages.extend('typescript', {});
  4508. delete typeInside['class-name'];
  4509. Prism.languages.typescript['class-name'].inside = typeInside;
  4510. Prism.languages.insertBefore('typescript', 'function', {
  4511. 'decorator': {
  4512. pattern: /@[$\w\xA0-\uFFFF]+/,
  4513. inside: {
  4514. 'at': {
  4515. pattern: /^@/,
  4516. alias: 'operator'
  4517. },
  4518. 'function': /^[\s\S]+/
  4519. }
  4520. },
  4521. 'generic-function': {
  4522. // e.g. foo<T extends "bar" | "baz">( ...
  4523. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
  4524. greedy: true,
  4525. inside: {
  4526. 'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
  4527. 'generic': {
  4528. pattern: /<[\s\S]+/, // everything after the first <
  4529. alias: 'class-name',
  4530. inside: typeInside
  4531. }
  4532. }
  4533. }
  4534. });
  4535. Prism.languages.ts = Prism.languages.typescript;
  4536. }(Prism));
  4537. (function (Prism) {
  4538. // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
  4539. // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
  4540. var anchorOrAlias = /[*&][^\s[\]{},]+/;
  4541. // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
  4542. var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
  4543. // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
  4544. var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
  4545. + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
  4546. // https://yaml.org/spec/1.2/spec.html#ns-plain(n,c)
  4547. // This is a simplified version that doesn't support "#" and multiline keys
  4548. // All these long scarry character classes are simplified versions of YAML's characters
  4549. var plainKey = /(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*/.source
  4550. .replace(/<PLAIN>/g, function () { return /[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source; });
  4551. var string = /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;
  4552. /**
  4553. *
  4554. * @param {string} value
  4555. * @param {string} [flags]
  4556. * @returns {RegExp}
  4557. */
  4558. function createValuePattern(value, flags) {
  4559. flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
  4560. var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source
  4561. .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
  4562. return RegExp(pattern, flags);
  4563. }
  4564. Prism.languages.yaml = {
  4565. 'scalar': {
  4566. pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source
  4567. .replace(/<<prop>>/g, function () { return properties; })),
  4568. lookbehind: true,
  4569. alias: 'string'
  4570. },
  4571. 'comment': /#.*/,
  4572. 'key': {
  4573. pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\s*:\s)/.source
  4574. .replace(/<<prop>>/g, function () { return properties; })
  4575. .replace(/<<key>>/g, function () { return '(?:' + plainKey + '|' + string + ')'; })),
  4576. lookbehind: true,
  4577. greedy: true,
  4578. alias: 'atrule'
  4579. },
  4580. 'directive': {
  4581. pattern: /(^[ \t]*)%.+/m,
  4582. lookbehind: true,
  4583. alias: 'important'
  4584. },
  4585. 'datetime': {
  4586. 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),
  4587. lookbehind: true,
  4588. alias: 'number'
  4589. },
  4590. 'boolean': {
  4591. pattern: createValuePattern(/false|true/.source, 'i'),
  4592. lookbehind: true,
  4593. alias: 'important'
  4594. },
  4595. 'null': {
  4596. pattern: createValuePattern(/null|~/.source, 'i'),
  4597. lookbehind: true,
  4598. alias: 'important'
  4599. },
  4600. 'string': {
  4601. pattern: createValuePattern(string),
  4602. lookbehind: true,
  4603. greedy: true
  4604. },
  4605. 'number': {
  4606. pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
  4607. lookbehind: true
  4608. },
  4609. 'tag': tag,
  4610. 'important': anchorOrAlias,
  4611. 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
  4612. };
  4613. Prism.languages.yml = Prism.languages.yaml;
  4614. }(Prism));
  4615. (function (Prism) {
  4616. function literal(str) {
  4617. return function () { return str; };
  4618. }
  4619. 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/;
  4620. var IDENTIFIER = '\\b(?!' + keyword.source + ')(?!\\d)\\w+\\b';
  4621. var ALIGN = /align\s*\((?:[^()]|\([^()]*\))*\)/.source;
  4622. var PREFIX_TYPE_OP = /(?:\?|\bpromise->|(?:\[[^[\]]*\]|\*(?!\*)|\*\*)(?:\s*<ALIGN>|\s*const\b|\s*volatile\b|\s*allowzero\b)*)/.source.replace(/<ALIGN>/g, literal(ALIGN));
  4623. var SUFFIX_EXPR = /(?:\bpromise\b|(?:\berror\.)?<ID>(?:\.<ID>)*(?!\s+<ID>))/.source.replace(/<ID>/g, literal(IDENTIFIER));
  4624. var TYPE = '(?!\\s)(?:!?\\s*(?:' + PREFIX_TYPE_OP + '\\s*)*' + SUFFIX_EXPR + ')+';
  4625. /*
  4626. * A simplified grammar for Zig compile time type literals:
  4627. *
  4628. * TypeExpr = ( "!"? PREFIX_TYPE_OP* SUFFIX_EXPR )+
  4629. *
  4630. * SUFFIX_EXPR = ( \b "promise" \b | ( \b "error" "." )? IDENTIFIER ( "." IDENTIFIER )* (?! \s+ IDENTIFIER ) )
  4631. *
  4632. * PREFIX_TYPE_OP = "?"
  4633. * | \b "promise" "->"
  4634. * | ( "[" [^\[\]]* "]" | "*" | "**" ) ( ALIGN | "const" \b | "volatile" \b | "allowzero" \b )*
  4635. *
  4636. * ALIGN = "align" "(" ( [^()] | "(" [^()]* ")" )* ")"
  4637. *
  4638. * IDENTIFIER = \b (?! KEYWORD ) [a-zA-Z_] \w* \b
  4639. *
  4640. */
  4641. Prism.languages.zig = {
  4642. 'comment': [
  4643. {
  4644. pattern: /\/\/[/!].*/,
  4645. alias: 'doc-comment'
  4646. },
  4647. /\/{2}.*/
  4648. ],
  4649. 'string': [
  4650. {
  4651. // "string" and c"string"
  4652. pattern: /(^|[^\\@])c?"(?:[^"\\\r\n]|\\.)*"/,
  4653. lookbehind: true,
  4654. greedy: true
  4655. },
  4656. {
  4657. // multiline strings and c-strings
  4658. pattern: /([\r\n])([ \t]+c?\\{2}).*(?:(?:\r\n?|\n)\2.*)*/,
  4659. lookbehind: true,
  4660. greedy: true
  4661. }
  4662. ],
  4663. 'char': {
  4664. // characters 'a', '\n', '\xFF', '\u{10FFFF}'
  4665. pattern: /(^|[^\\])'(?:[^'\\\r\n]|[\uD800-\uDFFF]{2}|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
  4666. lookbehind: true,
  4667. greedy: true
  4668. },
  4669. 'builtin': /\B@(?!\d)\w+(?=\s*\()/,
  4670. 'label': {
  4671. pattern: /(\b(?:break|continue)\s*:\s*)\w+\b|\b(?!\d)\w+\b(?=\s*:\s*(?:\{|while\b))/,
  4672. lookbehind: true
  4673. },
  4674. 'class-name': [
  4675. // const Foo = struct {};
  4676. /\b(?!\d)\w+(?=\s*=\s*(?:(?:extern|packed)\s+)?(?:enum|struct|union)\s*[({])/,
  4677. {
  4678. // const x: i32 = 9;
  4679. // var x: Bar;
  4680. // fn foo(x: bool, y: f32) void {}
  4681. pattern: RegExp(/(:\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?[=;,)])|<TYPE>(?=\s*(?:<ALIGN>\s*)?\{)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
  4682. lookbehind: true,
  4683. inside: null // see below
  4684. },
  4685. {
  4686. // extern fn foo(x: f64) f64; (optional alignment)
  4687. pattern: RegExp(/(\)\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?;)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
  4688. lookbehind: true,
  4689. inside: null // see below
  4690. }
  4691. ],
  4692. 'builtin-type': {
  4693. 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/,
  4694. alias: 'keyword'
  4695. },
  4696. 'keyword': keyword,
  4697. 'function': /\b(?!\d)\w+(?=\s*\()/,
  4698. '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/,
  4699. 'boolean': /\b(?:false|true)\b/,
  4700. 'operator': /\.[*?]|\.{2,3}|[-=]>|\*\*|\+\+|\|\||(?:<<|>>|[-+*]%|[-+*/%^&|<>!=])=?|[?~]/,
  4701. 'punctuation': /[.:,;(){}[\]]/
  4702. };
  4703. Prism.languages.zig['class-name'].forEach(function (obj) {
  4704. if (obj.inside === null) {
  4705. obj.inside = Prism.languages.zig;
  4706. }
  4707. });
  4708. }(Prism));