prism.js 194 KB

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