prism.js 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574
  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 = (typeof window !== 'undefined')
  5. ? window // if in browser
  6. : (
  7. (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
  8. ? self // if in worker
  9. : {} // if in node js
  10. );
  11. /**
  12. * Prism: Lightweight, robust, elegant syntax highlighting
  13. *
  14. * @license MIT <https://opensource.org/licenses/MIT>
  15. * @author Lea Verou <https://lea.verou.me>
  16. * @namespace
  17. * @public
  18. */
  19. var Prism = (function (_self) {
  20. // Private helper vars
  21. var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
  22. var uniqueId = 0;
  23. // The grammar object for plaintext
  24. var plainTextGrammar = {};
  25. var _ = {
  26. /**
  27. * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
  28. * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
  29. * additional languages or plugins yourself.
  30. *
  31. * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
  32. *
  33. * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
  34. * empty Prism object into the global scope before loading the Prism script like this:
  35. *
  36. * ```js
  37. * window.Prism = window.Prism || {};
  38. * Prism.manual = true;
  39. * // add a new <script> to load Prism's script
  40. * ```
  41. *
  42. * @default false
  43. * @type {boolean}
  44. * @memberof Prism
  45. * @public
  46. */
  47. manual: _self.Prism && _self.Prism.manual,
  48. /**
  49. * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
  50. * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
  51. * own worker, you don't want it to do this.
  52. *
  53. * By setting this value to `true`, Prism will not add its own listeners to the worker.
  54. *
  55. * You obviously have to change this value before Prism executes. To do this, you can add an
  56. * empty Prism object into the global scope before loading the Prism script like this:
  57. *
  58. * ```js
  59. * window.Prism = window.Prism || {};
  60. * Prism.disableWorkerMessageHandler = true;
  61. * // Load Prism's script
  62. * ```
  63. *
  64. * @default false
  65. * @type {boolean}
  66. * @memberof Prism
  67. * @public
  68. */
  69. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  70. /**
  71. * A namespace for utility methods.
  72. *
  73. * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
  74. * change or disappear at any time.
  75. *
  76. * @namespace
  77. * @memberof Prism
  78. */
  79. util: {
  80. encode: function encode(tokens) {
  81. if (tokens instanceof Token) {
  82. return new Token(tokens.type, encode(tokens.content), tokens.alias);
  83. } else if (Array.isArray(tokens)) {
  84. return tokens.map(encode);
  85. } else {
  86. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  87. }
  88. },
  89. /**
  90. * Returns the name of the type of the given value.
  91. *
  92. * @param {any} o
  93. * @returns {string}
  94. * @example
  95. * type(null) === 'Null'
  96. * type(undefined) === 'Undefined'
  97. * type(123) === 'Number'
  98. * type('foo') === 'String'
  99. * type(true) === 'Boolean'
  100. * type([1, 2]) === 'Array'
  101. * type({}) === 'Object'
  102. * type(String) === 'Function'
  103. * type(/abc+/) === 'RegExp'
  104. */
  105. type: function (o) {
  106. return Object.prototype.toString.call(o).slice(8, -1);
  107. },
  108. /**
  109. * Returns a unique number for the given object. Later calls will still return the same number.
  110. *
  111. * @param {Object} obj
  112. * @returns {number}
  113. */
  114. objId: function (obj) {
  115. if (!obj['__id']) {
  116. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  117. }
  118. return obj['__id'];
  119. },
  120. /**
  121. * Creates a deep clone of the given object.
  122. *
  123. * The main intended use of this function is to clone language definitions.
  124. *
  125. * @param {T} o
  126. * @param {Record<number, any>} [visited]
  127. * @returns {T}
  128. * @template T
  129. */
  130. clone: function deepClone(o, visited) {
  131. visited = visited || {};
  132. var clone; var id;
  133. switch (_.util.type(o)) {
  134. case 'Object':
  135. id = _.util.objId(o);
  136. if (visited[id]) {
  137. return visited[id];
  138. }
  139. clone = /** @type {Record<string, any>} */ ({});
  140. visited[id] = clone;
  141. for (var key in o) {
  142. if (o.hasOwnProperty(key)) {
  143. clone[key] = deepClone(o[key], visited);
  144. }
  145. }
  146. return /** @type {any} */ (clone);
  147. case 'Array':
  148. id = _.util.objId(o);
  149. if (visited[id]) {
  150. return visited[id];
  151. }
  152. clone = [];
  153. visited[id] = clone;
  154. (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
  155. clone[i] = deepClone(v, visited);
  156. });
  157. return /** @type {any} */ (clone);
  158. default:
  159. return o;
  160. }
  161. },
  162. /**
  163. * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
  164. *
  165. * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
  166. *
  167. * @param {Element} element
  168. * @returns {string}
  169. */
  170. getLanguage: function (element) {
  171. while (element) {
  172. var m = lang.exec(element.className);
  173. if (m) {
  174. return m[1].toLowerCase();
  175. }
  176. element = element.parentElement;
  177. }
  178. return 'none';
  179. },
  180. /**
  181. * Sets the Prism `language-xxxx` class of the given element.
  182. *
  183. * @param {Element} element
  184. * @param {string} language
  185. * @returns {void}
  186. */
  187. setLanguage: function (element, language) {
  188. // remove all `language-xxxx` classes
  189. // (this might leave behind a leading space)
  190. element.className = element.className.replace(RegExp(lang, 'gi'), '');
  191. // add the new `language-xxxx` class
  192. // (using `classList` will automatically clean up spaces for us)
  193. element.classList.add('language-' + language);
  194. },
  195. /**
  196. * Returns the script element that is currently executing.
  197. *
  198. * This does __not__ work for line script element.
  199. *
  200. * @returns {HTMLScriptElement | null}
  201. */
  202. currentScript: function () {
  203. if (typeof document === 'undefined') {
  204. return null;
  205. }
  206. if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
  207. return /** @type {any} */ (document.currentScript);
  208. }
  209. // IE11 workaround
  210. // we'll get the src of the current script by parsing IE11's error stack trace
  211. // this will not work for inline scripts
  212. try {
  213. throw new Error();
  214. } catch (err) {
  215. // Get file src url from stack. Specifically works with the format of stack traces in IE.
  216. // A stack will look like this:
  217. //
  218. // Error
  219. // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
  220. // at Global code (http://localhost/components/prism-core.js:606:1)
  221. var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
  222. if (src) {
  223. var scripts = document.getElementsByTagName('script');
  224. for (var i in scripts) {
  225. if (scripts[i].src == src) {
  226. return scripts[i];
  227. }
  228. }
  229. }
  230. return null;
  231. }
  232. },
  233. /**
  234. * Returns whether a given class is active for `element`.
  235. *
  236. * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
  237. * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
  238. * given class is just the given class with a `no-` prefix.
  239. *
  240. * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
  241. * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
  242. * ancestors have the given class or the negated version of it, then the default activation will be returned.
  243. *
  244. * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
  245. * version of it, the class is considered active.
  246. *
  247. * @param {Element} element
  248. * @param {string} className
  249. * @param {boolean} [defaultActivation=false]
  250. * @returns {boolean}
  251. */
  252. isActive: function (element, className, defaultActivation) {
  253. var no = 'no-' + className;
  254. while (element) {
  255. var classList = element.classList;
  256. if (classList.contains(className)) {
  257. return true;
  258. }
  259. if (classList.contains(no)) {
  260. return false;
  261. }
  262. element = element.parentElement;
  263. }
  264. return !!defaultActivation;
  265. }
  266. },
  267. /**
  268. * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
  269. *
  270. * @namespace
  271. * @memberof Prism
  272. * @public
  273. */
  274. languages: {
  275. /**
  276. * The grammar for plain, unformatted text.
  277. */
  278. plain: plainTextGrammar,
  279. plaintext: plainTextGrammar,
  280. text: plainTextGrammar,
  281. txt: plainTextGrammar,
  282. /**
  283. * Creates a deep copy of the language with the given id and appends the given tokens.
  284. *
  285. * If a token in `redef` also appears in the copied language, then the existing token in the copied language
  286. * will be overwritten at its original position.
  287. *
  288. * ## Best practices
  289. *
  290. * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
  291. * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
  292. * understand the language definition because, normally, the order of tokens matters in Prism grammars.
  293. *
  294. * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
  295. * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
  296. *
  297. * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
  298. * @param {Grammar} redef The new tokens to append.
  299. * @returns {Grammar} The new language created.
  300. * @public
  301. * @example
  302. * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
  303. * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
  304. * // at its original position
  305. * 'comment': { ... },
  306. * // CSS doesn't have a 'color' token, so this token will be appended
  307. * 'color': /\b(?:red|green|blue)\b/
  308. * });
  309. */
  310. extend: function (id, redef) {
  311. var lang = _.util.clone(_.languages[id]);
  312. for (var key in redef) {
  313. lang[key] = redef[key];
  314. }
  315. return lang;
  316. },
  317. /**
  318. * Inserts tokens _before_ another token in a language definition or any other grammar.
  319. *
  320. * ## Usage
  321. *
  322. * This helper method makes it easy to modify existing languages. For example, the CSS language definition
  323. * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
  324. * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
  325. * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
  326. * this:
  327. *
  328. * ```js
  329. * Prism.languages.markup.style = {
  330. * // token
  331. * };
  332. * ```
  333. *
  334. * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
  335. * before existing tokens. For the CSS example above, you would use it like this:
  336. *
  337. * ```js
  338. * Prism.languages.insertBefore('markup', 'cdata', {
  339. * 'style': {
  340. * // token
  341. * }
  342. * });
  343. * ```
  344. *
  345. * ## Special cases
  346. *
  347. * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
  348. * will be ignored.
  349. *
  350. * This behavior can be used to insert tokens after `before`:
  351. *
  352. * ```js
  353. * Prism.languages.insertBefore('markup', 'comment', {
  354. * 'comment': Prism.languages.markup.comment,
  355. * // tokens after 'comment'
  356. * });
  357. * ```
  358. *
  359. * ## Limitations
  360. *
  361. * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
  362. * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
  363. * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
  364. * deleting properties which is necessary to insert at arbitrary positions.
  365. *
  366. * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
  367. * Instead, it will create a new object and replace all references to the target object with the new one. This
  368. * can be done without temporarily deleting properties, so the iteration order is well-defined.
  369. *
  370. * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
  371. * you hold the target object in a variable, then the value of the variable will not change.
  372. *
  373. * ```js
  374. * var oldMarkup = Prism.languages.markup;
  375. * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
  376. *
  377. * assert(oldMarkup !== Prism.languages.markup);
  378. * assert(newMarkup === Prism.languages.markup);
  379. * ```
  380. *
  381. * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
  382. * object to be modified.
  383. * @param {string} before The key to insert before.
  384. * @param {Grammar} insert An object containing the key-value pairs to be inserted.
  385. * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
  386. * object to be modified.
  387. *
  388. * Defaults to `Prism.languages`.
  389. * @returns {Grammar} The new grammar object.
  390. * @public
  391. */
  392. insertBefore: function (inside, before, insert, root) {
  393. root = root || /** @type {any} */ (_.languages);
  394. var grammar = root[inside];
  395. /** @type {Grammar} */
  396. var ret = {};
  397. for (var token in grammar) {
  398. if (grammar.hasOwnProperty(token)) {
  399. if (token == before) {
  400. for (var newToken in insert) {
  401. if (insert.hasOwnProperty(newToken)) {
  402. ret[newToken] = insert[newToken];
  403. }
  404. }
  405. }
  406. // Do not insert token which also occur in insert. See #1525
  407. if (!insert.hasOwnProperty(token)) {
  408. ret[token] = grammar[token];
  409. }
  410. }
  411. }
  412. var old = root[inside];
  413. root[inside] = ret;
  414. // Update references in other language definitions
  415. _.languages.DFS(_.languages, function (key, value) {
  416. if (value === old && key != inside) {
  417. this[key] = ret;
  418. }
  419. });
  420. return ret;
  421. },
  422. // Traverse a language definition with Depth First Search
  423. DFS: function DFS(o, callback, type, visited) {
  424. visited = visited || {};
  425. var objId = _.util.objId;
  426. for (var i in o) {
  427. if (o.hasOwnProperty(i)) {
  428. callback.call(o, i, o[i], type || i);
  429. var property = o[i];
  430. var propertyType = _.util.type(property);
  431. if (propertyType === 'Object' && !visited[objId(property)]) {
  432. visited[objId(property)] = true;
  433. DFS(property, callback, null, visited);
  434. } else if (propertyType === 'Array' && !visited[objId(property)]) {
  435. visited[objId(property)] = true;
  436. DFS(property, callback, i, visited);
  437. }
  438. }
  439. }
  440. }
  441. },
  442. plugins: {},
  443. /**
  444. * This is the most high-level function in Prism’s API.
  445. * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
  446. * each one of them.
  447. *
  448. * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
  449. *
  450. * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
  451. * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
  452. * @memberof Prism
  453. * @public
  454. */
  455. highlightAll: function (async, callback) {
  456. _.highlightAllUnder(document, async, callback);
  457. },
  458. /**
  459. * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
  460. * {@link Prism.highlightElement} on each one of them.
  461. *
  462. * The following hooks will be run:
  463. * 1. `before-highlightall`
  464. * 2. `before-all-elements-highlight`
  465. * 3. All hooks of {@link Prism.highlightElement} for each element.
  466. *
  467. * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
  468. * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
  469. * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
  470. * @memberof Prism
  471. * @public
  472. */
  473. highlightAllUnder: function (container, async, callback) {
  474. var env = {
  475. callback: callback,
  476. container: container,
  477. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  478. };
  479. _.hooks.run('before-highlightall', env);
  480. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  481. _.hooks.run('before-all-elements-highlight', env);
  482. for (var i = 0, element; (element = env.elements[i++]);) {
  483. _.highlightElement(element, async === true, env.callback);
  484. }
  485. },
  486. /**
  487. * Highlights the code inside a single element.
  488. *
  489. * The following hooks will be run:
  490. * 1. `before-sanity-check`
  491. * 2. `before-highlight`
  492. * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
  493. * 4. `before-insert`
  494. * 5. `after-highlight`
  495. * 6. `complete`
  496. *
  497. * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
  498. * the element's language.
  499. *
  500. * @param {Element} element The element containing the code.
  501. * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
  502. * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
  503. * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
  504. * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
  505. *
  506. * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
  507. * asynchronous highlighting to work. You can build your own bundle on the
  508. * [Download page](https://prismjs.com/download.html).
  509. * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
  510. * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
  511. * @memberof Prism
  512. * @public
  513. */
  514. highlightElement: function (element, async, callback) {
  515. // Find language
  516. var language = _.util.getLanguage(element);
  517. var grammar = _.languages[language];
  518. // Set language on the element, if not present
  519. _.util.setLanguage(element, language);
  520. // Set language on the parent, for styling
  521. var parent = element.parentElement;
  522. if (parent && parent.nodeName.toLowerCase() === 'pre') {
  523. _.util.setLanguage(parent, language);
  524. }
  525. var code = element.textContent;
  526. var env = {
  527. element: element,
  528. language: language,
  529. grammar: grammar,
  530. code: code
  531. };
  532. function insertHighlightedCode(highlightedCode) {
  533. env.highlightedCode = highlightedCode;
  534. _.hooks.run('before-insert', env);
  535. env.element.innerHTML = env.highlightedCode;
  536. _.hooks.run('after-highlight', env);
  537. _.hooks.run('complete', env);
  538. callback && callback.call(env.element);
  539. }
  540. _.hooks.run('before-sanity-check', env);
  541. // plugins may change/add the parent/element
  542. parent = env.element.parentElement;
  543. if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
  544. parent.setAttribute('tabindex', '0');
  545. }
  546. if (!env.code) {
  547. _.hooks.run('complete', env);
  548. callback && callback.call(env.element);
  549. return;
  550. }
  551. _.hooks.run('before-highlight', env);
  552. if (!env.grammar) {
  553. insertHighlightedCode(_.util.encode(env.code));
  554. return;
  555. }
  556. if (async && _self.Worker) {
  557. var worker = new Worker(_.filename);
  558. worker.onmessage = function (evt) {
  559. insertHighlightedCode(evt.data);
  560. };
  561. worker.postMessage(JSON.stringify({
  562. language: env.language,
  563. code: env.code,
  564. immediateClose: true
  565. }));
  566. } else {
  567. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  568. }
  569. },
  570. /**
  571. * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
  572. * and the language definitions to use, and returns a string with the HTML produced.
  573. *
  574. * The following hooks will be run:
  575. * 1. `before-tokenize`
  576. * 2. `after-tokenize`
  577. * 3. `wrap`: On each {@link Token}.
  578. *
  579. * @param {string} text A string with the code to be highlighted.
  580. * @param {Grammar} grammar An object containing the tokens to use.
  581. *
  582. * Usually a language definition like `Prism.languages.markup`.
  583. * @param {string} language The name of the language definition passed to `grammar`.
  584. * @returns {string} The highlighted HTML.
  585. * @memberof Prism
  586. * @public
  587. * @example
  588. * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
  589. */
  590. highlight: function (text, grammar, language) {
  591. var env = {
  592. code: text,
  593. grammar: grammar,
  594. language: language
  595. };
  596. _.hooks.run('before-tokenize', env);
  597. if (!env.grammar) {
  598. throw new Error('The language "' + env.language + '" has no grammar.');
  599. }
  600. env.tokens = _.tokenize(env.code, env.grammar);
  601. _.hooks.run('after-tokenize', env);
  602. return Token.stringify(_.util.encode(env.tokens), env.language);
  603. },
  604. /**
  605. * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
  606. * and the language definitions to use, and returns an array with the tokenized code.
  607. *
  608. * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
  609. *
  610. * This method could be useful in other contexts as well, as a very crude parser.
  611. *
  612. * @param {string} text A string with the code to be highlighted.
  613. * @param {Grammar} grammar An object containing the tokens to use.
  614. *
  615. * Usually a language definition like `Prism.languages.markup`.
  616. * @returns {TokenStream} An array of strings and tokens, a token stream.
  617. * @memberof Prism
  618. * @public
  619. * @example
  620. * let code = `var foo = 0;`;
  621. * let tokens = Prism.tokenize(code, Prism.languages.javascript);
  622. * tokens.forEach(token => {
  623. * if (token instanceof Prism.Token && token.type === 'number') {
  624. * console.log(`Found numeric literal: ${token.content}`);
  625. * }
  626. * });
  627. */
  628. tokenize: function (text, grammar) {
  629. var rest = grammar.rest;
  630. if (rest) {
  631. for (var token in rest) {
  632. grammar[token] = rest[token];
  633. }
  634. delete grammar.rest;
  635. }
  636. var tokenList = new LinkedList();
  637. addAfter(tokenList, tokenList.head, text);
  638. matchGrammar(text, tokenList, grammar, tokenList.head, 0);
  639. return toArray(tokenList);
  640. },
  641. /**
  642. * @namespace
  643. * @memberof Prism
  644. * @public
  645. */
  646. hooks: {
  647. all: {},
  648. /**
  649. * Adds the given callback to the list of callbacks for the given hook.
  650. *
  651. * The callback will be invoked when the hook it is registered for is run.
  652. * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
  653. *
  654. * One callback function can be registered to multiple hooks and the same hook multiple times.
  655. *
  656. * @param {string} name The name of the hook.
  657. * @param {HookCallback} callback The callback function which is given environment variables.
  658. * @public
  659. */
  660. add: function (name, callback) {
  661. var hooks = _.hooks.all;
  662. hooks[name] = hooks[name] || [];
  663. hooks[name].push(callback);
  664. },
  665. /**
  666. * Runs a hook invoking all registered callbacks with the given environment variables.
  667. *
  668. * Callbacks will be invoked synchronously and in the order in which they were registered.
  669. *
  670. * @param {string} name The name of the hook.
  671. * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
  672. * @public
  673. */
  674. run: function (name, env) {
  675. var callbacks = _.hooks.all[name];
  676. if (!callbacks || !callbacks.length) {
  677. return;
  678. }
  679. for (var i = 0, callback; (callback = callbacks[i++]);) {
  680. callback(env);
  681. }
  682. }
  683. },
  684. Token: Token
  685. };
  686. _self.Prism = _;
  687. // Typescript note:
  688. // The following can be used to import the Token type in JSDoc:
  689. //
  690. // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
  691. /**
  692. * Creates a new token.
  693. *
  694. * @param {string} type See {@link Token#type type}
  695. * @param {string | TokenStream} content See {@link Token#content content}
  696. * @param {string|string[]} [alias] The alias(es) of the token.
  697. * @param {string} [matchedStr=""] A copy of the full string this token was created from.
  698. * @class
  699. * @global
  700. * @public
  701. */
  702. function Token(type, content, alias, matchedStr) {
  703. /**
  704. * The type of the token.
  705. *
  706. * This is usually the key of a pattern in a {@link Grammar}.
  707. *
  708. * @type {string}
  709. * @see GrammarToken
  710. * @public
  711. */
  712. this.type = type;
  713. /**
  714. * The strings or tokens contained by this token.
  715. *
  716. * This will be a token stream if the pattern matched also defined an `inside` grammar.
  717. *
  718. * @type {string | TokenStream}
  719. * @public
  720. */
  721. this.content = content;
  722. /**
  723. * The alias(es) of the token.
  724. *
  725. * @type {string|string[]}
  726. * @see GrammarToken
  727. * @public
  728. */
  729. this.alias = alias;
  730. // Copy of the full string this token was created from
  731. this.length = (matchedStr || '').length | 0;
  732. }
  733. /**
  734. * A token stream is an array of strings and {@link Token Token} objects.
  735. *
  736. * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
  737. * them.
  738. *
  739. * 1. No adjacent strings.
  740. * 2. No empty strings.
  741. *
  742. * The only exception here is the token stream that only contains the empty string and nothing else.
  743. *
  744. * @typedef {Array<string | Token>} TokenStream
  745. * @global
  746. * @public
  747. */
  748. /**
  749. * Converts the given token or token stream to an HTML representation.
  750. *
  751. * The following hooks will be run:
  752. * 1. `wrap`: On each {@link Token}.
  753. *
  754. * @param {string | Token | TokenStream} o The token or token stream to be converted.
  755. * @param {string} language The name of current language.
  756. * @returns {string} The HTML representation of the token or token stream.
  757. * @memberof Token
  758. * @static
  759. */
  760. Token.stringify = function stringify(o, language) {
  761. if (typeof o == 'string') {
  762. return o;
  763. }
  764. if (Array.isArray(o)) {
  765. var s = '';
  766. o.forEach(function (e) {
  767. s += stringify(e, language);
  768. });
  769. return s;
  770. }
  771. var env = {
  772. type: o.type,
  773. content: stringify(o.content, language),
  774. tag: 'span',
  775. classes: ['token', o.type],
  776. attributes: {},
  777. language: language
  778. };
  779. var aliases = o.alias;
  780. if (aliases) {
  781. if (Array.isArray(aliases)) {
  782. Array.prototype.push.apply(env.classes, aliases);
  783. } else {
  784. env.classes.push(aliases);
  785. }
  786. }
  787. _.hooks.run('wrap', env);
  788. var attributes = '';
  789. for (var name in env.attributes) {
  790. attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  791. }
  792. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
  793. };
  794. /**
  795. * @param {RegExp} pattern
  796. * @param {number} pos
  797. * @param {string} text
  798. * @param {boolean} lookbehind
  799. * @returns {RegExpExecArray | null}
  800. */
  801. function matchPattern(pattern, pos, text, lookbehind) {
  802. pattern.lastIndex = pos;
  803. var match = pattern.exec(text);
  804. if (match && lookbehind && match[1]) {
  805. // change the match to remove the text matched by the Prism lookbehind group
  806. var lookbehindLength = match[1].length;
  807. match.index += lookbehindLength;
  808. match[0] = match[0].slice(lookbehindLength);
  809. }
  810. return match;
  811. }
  812. /**
  813. * @param {string} text
  814. * @param {LinkedList<string | Token>} tokenList
  815. * @param {any} grammar
  816. * @param {LinkedListNode<string | Token>} startNode
  817. * @param {number} startPos
  818. * @param {RematchOptions} [rematch]
  819. * @returns {void}
  820. * @private
  821. *
  822. * @typedef RematchOptions
  823. * @property {string} cause
  824. * @property {number} reach
  825. */
  826. function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
  827. for (var token in grammar) {
  828. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  829. continue;
  830. }
  831. var patterns = grammar[token];
  832. patterns = Array.isArray(patterns) ? patterns : [patterns];
  833. for (var j = 0; j < patterns.length; ++j) {
  834. if (rematch && rematch.cause == token + ',' + j) {
  835. return;
  836. }
  837. var patternObj = patterns[j];
  838. var inside = patternObj.inside;
  839. var lookbehind = !!patternObj.lookbehind;
  840. var greedy = !!patternObj.greedy;
  841. var alias = patternObj.alias;
  842. if (greedy && !patternObj.pattern.global) {
  843. // Without the global flag, lastIndex won't work
  844. var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
  845. patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
  846. }
  847. /** @type {RegExp} */
  848. var pattern = patternObj.pattern || patternObj;
  849. for ( // iterate the token list and keep track of the current token/string position
  850. var currentNode = startNode.next, pos = startPos;
  851. currentNode !== tokenList.tail;
  852. pos += currentNode.value.length, currentNode = currentNode.next
  853. ) {
  854. if (rematch && pos >= rematch.reach) {
  855. break;
  856. }
  857. var str = currentNode.value;
  858. if (tokenList.length > text.length) {
  859. // Something went terribly wrong, ABORT, ABORT!
  860. return;
  861. }
  862. if (str instanceof Token) {
  863. continue;
  864. }
  865. var removeCount = 1; // this is the to parameter of removeBetween
  866. var match;
  867. if (greedy) {
  868. match = matchPattern(pattern, pos, text, lookbehind);
  869. if (!match || match.index >= text.length) {
  870. break;
  871. }
  872. var from = match.index;
  873. var to = match.index + match[0].length;
  874. var p = pos;
  875. // find the node that contains the match
  876. p += currentNode.value.length;
  877. while (from >= p) {
  878. currentNode = currentNode.next;
  879. p += currentNode.value.length;
  880. }
  881. // adjust pos (and p)
  882. p -= currentNode.value.length;
  883. pos = p;
  884. // the current node is a Token, then the match starts inside another Token, which is invalid
  885. if (currentNode.value instanceof Token) {
  886. continue;
  887. }
  888. // find the last node which is affected by this match
  889. for (
  890. var k = currentNode;
  891. k !== tokenList.tail && (p < to || typeof k.value === 'string');
  892. k = k.next
  893. ) {
  894. removeCount++;
  895. p += k.value.length;
  896. }
  897. removeCount--;
  898. // replace with the new match
  899. str = text.slice(pos, p);
  900. match.index -= pos;
  901. } else {
  902. match = matchPattern(pattern, 0, str, lookbehind);
  903. if (!match) {
  904. continue;
  905. }
  906. }
  907. // eslint-disable-next-line no-redeclare
  908. var from = match.index;
  909. var matchStr = match[0];
  910. var before = str.slice(0, from);
  911. var after = str.slice(from + matchStr.length);
  912. var reach = pos + str.length;
  913. if (rematch && reach > rematch.reach) {
  914. rematch.reach = reach;
  915. }
  916. var removeFrom = currentNode.prev;
  917. if (before) {
  918. removeFrom = addAfter(tokenList, removeFrom, before);
  919. pos += before.length;
  920. }
  921. removeRange(tokenList, removeFrom, removeCount);
  922. var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
  923. currentNode = addAfter(tokenList, removeFrom, wrapped);
  924. if (after) {
  925. addAfter(tokenList, currentNode, after);
  926. }
  927. if (removeCount > 1) {
  928. // at least one Token object was removed, so we have to do some rematching
  929. // this can only happen if the current pattern is greedy
  930. /** @type {RematchOptions} */
  931. var nestedRematch = {
  932. cause: token + ',' + j,
  933. reach: reach
  934. };
  935. matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
  936. // the reach might have been extended because of the rematching
  937. if (rematch && nestedRematch.reach > rematch.reach) {
  938. rematch.reach = nestedRematch.reach;
  939. }
  940. }
  941. }
  942. }
  943. }
  944. }
  945. /**
  946. * @typedef LinkedListNode
  947. * @property {T} value
  948. * @property {LinkedListNode<T> | null} prev The previous node.
  949. * @property {LinkedListNode<T> | null} next The next node.
  950. * @template T
  951. * @private
  952. */
  953. /**
  954. * @template T
  955. * @private
  956. */
  957. function LinkedList() {
  958. /** @type {LinkedListNode<T>} */
  959. var head = { value: null, prev: null, next: null };
  960. /** @type {LinkedListNode<T>} */
  961. var tail = { value: null, prev: head, next: null };
  962. head.next = tail;
  963. /** @type {LinkedListNode<T>} */
  964. this.head = head;
  965. /** @type {LinkedListNode<T>} */
  966. this.tail = tail;
  967. this.length = 0;
  968. }
  969. /**
  970. * Adds a new node with the given value to the list.
  971. *
  972. * @param {LinkedList<T>} list
  973. * @param {LinkedListNode<T>} node
  974. * @param {T} value
  975. * @returns {LinkedListNode<T>} The added node.
  976. * @template T
  977. */
  978. function addAfter(list, node, value) {
  979. // assumes that node != list.tail && values.length >= 0
  980. var next = node.next;
  981. var newNode = { value: value, prev: node, next: next };
  982. node.next = newNode;
  983. next.prev = newNode;
  984. list.length++;
  985. return newNode;
  986. }
  987. /**
  988. * Removes `count` nodes after the given node. The given node will not be removed.
  989. *
  990. * @param {LinkedList<T>} list
  991. * @param {LinkedListNode<T>} node
  992. * @param {number} count
  993. * @template T
  994. */
  995. function removeRange(list, node, count) {
  996. var next = node.next;
  997. for (var i = 0; i < count && next !== list.tail; i++) {
  998. next = next.next;
  999. }
  1000. node.next = next;
  1001. next.prev = node;
  1002. list.length -= i;
  1003. }
  1004. /**
  1005. * @param {LinkedList<T>} list
  1006. * @returns {T[]}
  1007. * @template T
  1008. */
  1009. function toArray(list) {
  1010. var array = [];
  1011. var node = list.head.next;
  1012. while (node !== list.tail) {
  1013. array.push(node.value);
  1014. node = node.next;
  1015. }
  1016. return array;
  1017. }
  1018. if (!_self.document) {
  1019. if (!_self.addEventListener) {
  1020. // in Node.js
  1021. return _;
  1022. }
  1023. if (!_.disableWorkerMessageHandler) {
  1024. // In worker
  1025. _self.addEventListener('message', function (evt) {
  1026. var message = JSON.parse(evt.data);
  1027. var lang = message.language;
  1028. var code = message.code;
  1029. var immediateClose = message.immediateClose;
  1030. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  1031. if (immediateClose) {
  1032. _self.close();
  1033. }
  1034. }, false);
  1035. }
  1036. return _;
  1037. }
  1038. // Get current script and highlight
  1039. var script = _.util.currentScript();
  1040. if (script) {
  1041. _.filename = script.src;
  1042. if (script.hasAttribute('data-manual')) {
  1043. _.manual = true;
  1044. }
  1045. }
  1046. function highlightAutomaticallyCallback() {
  1047. if (!_.manual) {
  1048. _.highlightAll();
  1049. }
  1050. }
  1051. if (!_.manual) {
  1052. // If the document state is "loading", then we'll use DOMContentLoaded.
  1053. // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
  1054. // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
  1055. // might take longer one animation frame to execute which can create a race condition where only some plugins have
  1056. // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
  1057. // See https://github.com/PrismJS/prism/issues/2102
  1058. var readyState = document.readyState;
  1059. if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
  1060. document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
  1061. } else {
  1062. if (window.requestAnimationFrame) {
  1063. window.requestAnimationFrame(highlightAutomaticallyCallback);
  1064. } else {
  1065. window.setTimeout(highlightAutomaticallyCallback, 16);
  1066. }
  1067. }
  1068. }
  1069. return _;
  1070. }(_self));
  1071. if (typeof module !== 'undefined' && module.exports) {
  1072. module.exports = Prism;
  1073. }
  1074. // hack for components to work correctly in node.js
  1075. if (typeof global !== 'undefined') {
  1076. global.Prism = Prism;
  1077. }
  1078. // some additional documentation/types
  1079. /**
  1080. * The expansion of a simple `RegExp` literal to support additional properties.
  1081. *
  1082. * @typedef GrammarToken
  1083. * @property {RegExp} pattern The regular expression of the token.
  1084. * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
  1085. * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
  1086. * @property {boolean} [greedy=false] Whether the token is greedy.
  1087. * @property {string|string[]} [alias] An optional alias or list of aliases.
  1088. * @property {Grammar} [inside] The nested grammar of this token.
  1089. *
  1090. * The `inside` grammar will be used to tokenize the text value of each token of this kind.
  1091. *
  1092. * This can be used to make nested and even recursive language definitions.
  1093. *
  1094. * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
  1095. * each another.
  1096. * @global
  1097. * @public
  1098. */
  1099. /**
  1100. * @typedef Grammar
  1101. * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
  1102. * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
  1103. * @global
  1104. * @public
  1105. */
  1106. /**
  1107. * A function which will invoked after an element was successfully highlighted.
  1108. *
  1109. * @callback HighlightCallback
  1110. * @param {Element} element The element successfully highlighted.
  1111. * @returns {void}
  1112. * @global
  1113. * @public
  1114. */
  1115. /**
  1116. * @callback HookCallback
  1117. * @param {Object<string, any>} env The environment variables of the hook.
  1118. * @returns {void}
  1119. * @global
  1120. * @public
  1121. */
  1122. ;
  1123. Prism.languages.markup = {
  1124. 'comment': {
  1125. pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
  1126. greedy: true
  1127. },
  1128. 'prolog': {
  1129. pattern: /<\?[\s\S]+?\?>/,
  1130. greedy: true
  1131. },
  1132. 'doctype': {
  1133. // https://www.w3.org/TR/xml/#NT-doctypedecl
  1134. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
  1135. greedy: true,
  1136. inside: {
  1137. 'internal-subset': {
  1138. pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
  1139. lookbehind: true,
  1140. greedy: true,
  1141. inside: null // see below
  1142. },
  1143. 'string': {
  1144. pattern: /"[^"]*"|'[^']*'/,
  1145. greedy: true
  1146. },
  1147. 'punctuation': /^<!|>$|[[\]]/,
  1148. 'doctype-tag': /^DOCTYPE/i,
  1149. 'name': /[^\s<>'"]+/
  1150. }
  1151. },
  1152. 'cdata': {
  1153. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1154. greedy: true
  1155. },
  1156. 'tag': {
  1157. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
  1158. greedy: true,
  1159. inside: {
  1160. 'tag': {
  1161. pattern: /^<\/?[^\s>\/]+/,
  1162. inside: {
  1163. 'punctuation': /^<\/?/,
  1164. 'namespace': /^[^\s>\/:]+:/
  1165. }
  1166. },
  1167. 'special-attr': [],
  1168. 'attr-value': {
  1169. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
  1170. inside: {
  1171. 'punctuation': [
  1172. {
  1173. pattern: /^=/,
  1174. alias: 'attr-equals'
  1175. },
  1176. {
  1177. pattern: /^(\s*)["']|["']$/,
  1178. lookbehind: true
  1179. }
  1180. ]
  1181. }
  1182. },
  1183. 'punctuation': /\/?>/,
  1184. 'attr-name': {
  1185. pattern: /[^\s>\/]+/,
  1186. inside: {
  1187. 'namespace': /^[^\s>\/:]+:/
  1188. }
  1189. }
  1190. }
  1191. },
  1192. 'entity': [
  1193. {
  1194. pattern: /&[\da-z]{1,8};/i,
  1195. alias: 'named-entity'
  1196. },
  1197. /&#x?[\da-f]{1,8};/i
  1198. ]
  1199. };
  1200. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
  1201. Prism.languages.markup['entity'];
  1202. Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
  1203. // Plugin to make entity title show the real entity, idea by Roman Komarov
  1204. Prism.hooks.add('wrap', function (env) {
  1205. if (env.type === 'entity') {
  1206. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  1207. }
  1208. });
  1209. Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
  1210. /**
  1211. * Adds an inlined language to markup.
  1212. *
  1213. * An example of an inlined language is CSS with `<style>` tags.
  1214. *
  1215. * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
  1216. * case insensitive.
  1217. * @param {string} lang The language key.
  1218. * @example
  1219. * addInlined('style', 'css');
  1220. */
  1221. value: function addInlined(tagName, lang) {
  1222. var includedCdataInside = {};
  1223. includedCdataInside['language-' + lang] = {
  1224. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  1225. lookbehind: true,
  1226. inside: Prism.languages[lang]
  1227. };
  1228. includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
  1229. var inside = {
  1230. 'included-cdata': {
  1231. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1232. inside: includedCdataInside
  1233. }
  1234. };
  1235. inside['language-' + lang] = {
  1236. pattern: /[\s\S]+/,
  1237. inside: Prism.languages[lang]
  1238. };
  1239. var def = {};
  1240. def[tagName] = {
  1241. pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
  1242. lookbehind: true,
  1243. greedy: true,
  1244. inside: inside
  1245. };
  1246. Prism.languages.insertBefore('markup', 'cdata', def);
  1247. }
  1248. });
  1249. Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
  1250. /**
  1251. * Adds an pattern to highlight languages embedded in HTML attributes.
  1252. *
  1253. * An example of an inlined language is CSS with `style` attributes.
  1254. *
  1255. * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
  1256. * case insensitive.
  1257. * @param {string} lang The language key.
  1258. * @example
  1259. * addAttribute('style', 'css');
  1260. */
  1261. value: function (attrName, lang) {
  1262. Prism.languages.markup.tag.inside['special-attr'].push({
  1263. pattern: RegExp(
  1264. /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
  1265. 'i'
  1266. ),
  1267. lookbehind: true,
  1268. inside: {
  1269. 'attr-name': /^[^\s=]+/,
  1270. 'attr-value': {
  1271. pattern: /=[\s\S]+/,
  1272. inside: {
  1273. 'value': {
  1274. pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
  1275. lookbehind: true,
  1276. alias: [lang, 'language-' + lang],
  1277. inside: Prism.languages[lang]
  1278. },
  1279. 'punctuation': [
  1280. {
  1281. pattern: /^=/,
  1282. alias: 'attr-equals'
  1283. },
  1284. /"|'/
  1285. ]
  1286. }
  1287. }
  1288. }
  1289. });
  1290. }
  1291. });
  1292. Prism.languages.html = Prism.languages.markup;
  1293. Prism.languages.mathml = Prism.languages.markup;
  1294. Prism.languages.svg = Prism.languages.markup;
  1295. Prism.languages.xml = Prism.languages.extend('markup', {});
  1296. Prism.languages.ssml = Prism.languages.xml;
  1297. Prism.languages.atom = Prism.languages.xml;
  1298. Prism.languages.rss = Prism.languages.xml;
  1299. (function (Prism) {
  1300. var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
  1301. Prism.languages.css = {
  1302. 'comment': /\/\*[\s\S]*?\*\//,
  1303. 'atrule': {
  1304. pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
  1305. inside: {
  1306. 'rule': /^@[\w-]+/,
  1307. 'selector-function-argument': {
  1308. pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
  1309. lookbehind: true,
  1310. alias: 'selector'
  1311. },
  1312. 'keyword': {
  1313. pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
  1314. lookbehind: true
  1315. }
  1316. // See rest below
  1317. }
  1318. },
  1319. 'url': {
  1320. // https://drafts.csswg.org/css-values-3/#urls
  1321. pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
  1322. greedy: true,
  1323. inside: {
  1324. 'function': /^url/i,
  1325. 'punctuation': /^\(|\)$/,
  1326. 'string': {
  1327. pattern: RegExp('^' + string.source + '$'),
  1328. alias: 'url'
  1329. }
  1330. }
  1331. },
  1332. 'selector': {
  1333. pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
  1334. lookbehind: true
  1335. },
  1336. 'string': {
  1337. pattern: string,
  1338. greedy: true
  1339. },
  1340. 'property': {
  1341. pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
  1342. lookbehind: true
  1343. },
  1344. 'important': /!important\b/i,
  1345. 'function': {
  1346. pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
  1347. lookbehind: true
  1348. },
  1349. 'punctuation': /[(){};:,]/
  1350. };
  1351. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  1352. var markup = Prism.languages.markup;
  1353. if (markup) {
  1354. markup.tag.addInlined('style', 'css');
  1355. markup.tag.addAttribute('style', 'css');
  1356. }
  1357. }(Prism));
  1358. Prism.languages.clike = {
  1359. 'comment': [
  1360. {
  1361. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  1362. lookbehind: true,
  1363. greedy: true
  1364. },
  1365. {
  1366. pattern: /(^|[^\\:])\/\/.*/,
  1367. lookbehind: true,
  1368. greedy: true
  1369. }
  1370. ],
  1371. 'string': {
  1372. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  1373. greedy: true
  1374. },
  1375. 'class-name': {
  1376. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
  1377. lookbehind: true,
  1378. inside: {
  1379. 'punctuation': /[.\\]/
  1380. }
  1381. },
  1382. 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
  1383. 'boolean': /\b(?:false|true)\b/,
  1384. 'function': /\b\w+(?=\()/,
  1385. 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
  1386. 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  1387. 'punctuation': /[{}[\];(),.:]/
  1388. };
  1389. Prism.languages.javascript = Prism.languages.extend('clike', {
  1390. 'class-name': [
  1391. Prism.languages.clike['class-name'],
  1392. {
  1393. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
  1394. lookbehind: true
  1395. }
  1396. ],
  1397. 'keyword': [
  1398. {
  1399. pattern: /((?:^|\})\s*)catch\b/,
  1400. lookbehind: true
  1401. },
  1402. {
  1403. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
  1404. lookbehind: true
  1405. },
  1406. ],
  1407. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  1408. 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  1409. 'number': {
  1410. pattern: RegExp(
  1411. /(^|[^\w$])/.source +
  1412. '(?:' +
  1413. (
  1414. // constant
  1415. /NaN|Infinity/.source +
  1416. '|' +
  1417. // binary integer
  1418. /0[bB][01]+(?:_[01]+)*n?/.source +
  1419. '|' +
  1420. // octal integer
  1421. /0[oO][0-7]+(?:_[0-7]+)*n?/.source +
  1422. '|' +
  1423. // hexadecimal integer
  1424. /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
  1425. '|' +
  1426. // decimal bigint
  1427. /\d+(?:_\d+)*n/.source +
  1428. '|' +
  1429. // decimal number (integer or float) but no bigint
  1430. /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
  1431. ) +
  1432. ')' +
  1433. /(?![\w$])/.source
  1434. ),
  1435. lookbehind: true
  1436. },
  1437. 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
  1438. });
  1439. Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
  1440. Prism.languages.insertBefore('javascript', 'keyword', {
  1441. 'regex': {
  1442. pattern: RegExp(
  1443. // lookbehind
  1444. // eslint-disable-next-line regexp/no-dupe-characters-character-class
  1445. /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
  1446. // Regex pattern:
  1447. // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
  1448. // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
  1449. // with the only syntax, so we have to define 2 different regex patterns.
  1450. /\//.source +
  1451. '(?:' +
  1452. /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
  1453. '|' +
  1454. // `v` flag syntax. This supports 3 levels of nested character classes.
  1455. /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
  1456. ')' +
  1457. // lookahead
  1458. /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
  1459. ),
  1460. lookbehind: true,
  1461. greedy: true,
  1462. inside: {
  1463. 'regex-source': {
  1464. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  1465. lookbehind: true,
  1466. alias: 'language-regex',
  1467. inside: Prism.languages.regex
  1468. },
  1469. 'regex-delimiter': /^\/|\/$/,
  1470. 'regex-flags': /^[a-z]+$/,
  1471. }
  1472. },
  1473. // This must be declared before keyword because we use "function" inside the look-forward
  1474. 'function-variable': {
  1475. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
  1476. alias: 'function'
  1477. },
  1478. 'parameter': [
  1479. {
  1480. pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
  1481. lookbehind: true,
  1482. inside: Prism.languages.javascript
  1483. },
  1484. {
  1485. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
  1486. lookbehind: true,
  1487. inside: Prism.languages.javascript
  1488. },
  1489. {
  1490. pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
  1491. lookbehind: true,
  1492. inside: Prism.languages.javascript
  1493. },
  1494. {
  1495. pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
  1496. lookbehind: true,
  1497. inside: Prism.languages.javascript
  1498. }
  1499. ],
  1500. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  1501. });
  1502. Prism.languages.insertBefore('javascript', 'string', {
  1503. 'hashbang': {
  1504. pattern: /^#!.*/,
  1505. greedy: true,
  1506. alias: 'comment'
  1507. },
  1508. 'template-string': {
  1509. pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
  1510. greedy: true,
  1511. inside: {
  1512. 'template-punctuation': {
  1513. pattern: /^`|`$/,
  1514. alias: 'string'
  1515. },
  1516. 'interpolation': {
  1517. pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
  1518. lookbehind: true,
  1519. inside: {
  1520. 'interpolation-punctuation': {
  1521. pattern: /^\$\{|\}$/,
  1522. alias: 'punctuation'
  1523. },
  1524. rest: Prism.languages.javascript
  1525. }
  1526. },
  1527. 'string': /[\s\S]+/
  1528. }
  1529. },
  1530. 'string-property': {
  1531. pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
  1532. lookbehind: true,
  1533. greedy: true,
  1534. alias: 'property'
  1535. }
  1536. });
  1537. Prism.languages.insertBefore('javascript', 'operator', {
  1538. 'literal-property': {
  1539. pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
  1540. lookbehind: true,
  1541. alias: 'property'
  1542. },
  1543. });
  1544. if (Prism.languages.markup) {
  1545. Prism.languages.markup.tag.addInlined('script', 'javascript');
  1546. // add attribute support for all DOM events.
  1547. // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
  1548. Prism.languages.markup.tag.addAttribute(
  1549. /on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
  1550. 'javascript'
  1551. );
  1552. }
  1553. Prism.languages.js = Prism.languages.javascript;
  1554. (function (Prism) {
  1555. // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
  1556. // + LC_ALL, RANDOM, REPLY, SECONDS.
  1557. // + make sure PS1..4 are here as they are not always set,
  1558. // - some useless things.
  1559. var envVars = '\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b';
  1560. var commandAfterHeredoc = {
  1561. pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
  1562. lookbehind: true,
  1563. alias: 'punctuation', // this looks reasonably well in all themes
  1564. inside: null // see below
  1565. };
  1566. var insideString = {
  1567. 'bash': commandAfterHeredoc,
  1568. 'environment': {
  1569. pattern: RegExp('\\$' + envVars),
  1570. alias: 'constant'
  1571. },
  1572. 'variable': [
  1573. // [0]: Arithmetic Environment
  1574. {
  1575. pattern: /\$?\(\([\s\S]+?\)\)/,
  1576. greedy: true,
  1577. inside: {
  1578. // If there is a $ sign at the beginning highlight $(( and )) as variable
  1579. 'variable': [
  1580. {
  1581. pattern: /(^\$\(\([\s\S]+)\)\)/,
  1582. lookbehind: true
  1583. },
  1584. /^\$\(\(/
  1585. ],
  1586. 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
  1587. // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
  1588. 'operator': /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
  1589. // If there is no $ sign at the beginning highlight (( and )) as punctuation
  1590. 'punctuation': /\(\(?|\)\)?|,|;/
  1591. }
  1592. },
  1593. // [1]: Command Substitution
  1594. {
  1595. pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
  1596. greedy: true,
  1597. inside: {
  1598. 'variable': /^\$\(|^`|\)$|`$/
  1599. }
  1600. },
  1601. // [2]: Brace expansion
  1602. {
  1603. pattern: /\$\{[^}]+\}/,
  1604. greedy: true,
  1605. inside: {
  1606. 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
  1607. 'punctuation': /[\[\]]/,
  1608. 'environment': {
  1609. pattern: RegExp('(\\{)' + envVars),
  1610. lookbehind: true,
  1611. alias: 'constant'
  1612. }
  1613. }
  1614. },
  1615. /\$(?:\w+|[#?*!@$])/
  1616. ],
  1617. // Escape sequences from echo and printf's manuals, and escaped quotes.
  1618. 'entity': /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/
  1619. };
  1620. Prism.languages.bash = {
  1621. 'shebang': {
  1622. pattern: /^#!\s*\/.*/,
  1623. alias: 'important'
  1624. },
  1625. 'comment': {
  1626. pattern: /(^|[^"{\\$])#.*/,
  1627. lookbehind: true
  1628. },
  1629. 'function-name': [
  1630. // a) function foo {
  1631. // b) foo() {
  1632. // c) function foo() {
  1633. // but not “foo {”
  1634. {
  1635. // a) and c)
  1636. pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
  1637. lookbehind: true,
  1638. alias: 'function'
  1639. },
  1640. {
  1641. // b)
  1642. pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/,
  1643. alias: 'function'
  1644. }
  1645. ],
  1646. // Highlight variable names as variables in for and select beginnings.
  1647. 'for-or-select': {
  1648. pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
  1649. alias: 'variable',
  1650. lookbehind: true
  1651. },
  1652. // Highlight variable names as variables in the left-hand part
  1653. // of assignments (“=” and “+=”).
  1654. 'assign-left': {
  1655. pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/,
  1656. inside: {
  1657. 'environment': {
  1658. pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars),
  1659. lookbehind: true,
  1660. alias: 'constant'
  1661. }
  1662. },
  1663. alias: 'variable',
  1664. lookbehind: true
  1665. },
  1666. // Highlight parameter names as variables
  1667. 'parameter': {
  1668. pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,
  1669. alias: 'variable',
  1670. lookbehind: true
  1671. },
  1672. 'string': [
  1673. // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
  1674. {
  1675. pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,
  1676. lookbehind: true,
  1677. greedy: true,
  1678. inside: insideString
  1679. },
  1680. // Here-document with quotes around the tag
  1681. // → No expansion (so no “inside”).
  1682. {
  1683. pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
  1684. lookbehind: true,
  1685. greedy: true,
  1686. inside: {
  1687. 'bash': commandAfterHeredoc
  1688. }
  1689. },
  1690. // “Normal” string
  1691. {
  1692. // https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
  1693. pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
  1694. lookbehind: true,
  1695. greedy: true,
  1696. inside: insideString
  1697. },
  1698. {
  1699. // https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html
  1700. pattern: /(^|[^$\\])'[^']*'/,
  1701. lookbehind: true,
  1702. greedy: true
  1703. },
  1704. {
  1705. // https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
  1706. pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
  1707. greedy: true,
  1708. inside: {
  1709. 'entity': insideString.entity
  1710. }
  1711. }
  1712. ],
  1713. 'environment': {
  1714. pattern: RegExp('\\$?' + envVars),
  1715. alias: 'constant'
  1716. },
  1717. 'variable': insideString.variable,
  1718. 'function': {
  1719. pattern: /(^|[\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;|&])/,
  1720. lookbehind: true
  1721. },
  1722. 'keyword': {
  1723. pattern: /(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,
  1724. lookbehind: true
  1725. },
  1726. // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
  1727. 'builtin': {
  1728. pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,
  1729. lookbehind: true,
  1730. // Alias added to make those easier to distinguish from strings.
  1731. alias: 'class-name'
  1732. },
  1733. 'boolean': {
  1734. pattern: /(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,
  1735. lookbehind: true
  1736. },
  1737. 'file-descriptor': {
  1738. pattern: /\B&\d\b/,
  1739. alias: 'important'
  1740. },
  1741. 'operator': {
  1742. // Lots of redirections here, but not just that.
  1743. pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,
  1744. inside: {
  1745. 'file-descriptor': {
  1746. pattern: /^\d/,
  1747. alias: 'important'
  1748. }
  1749. }
  1750. },
  1751. 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
  1752. 'number': {
  1753. pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
  1754. lookbehind: true
  1755. }
  1756. };
  1757. commandAfterHeredoc.inside = Prism.languages.bash;
  1758. /* Patterns in command substitution. */
  1759. var toBeCopied = [
  1760. 'comment',
  1761. 'function-name',
  1762. 'for-or-select',
  1763. 'assign-left',
  1764. 'parameter',
  1765. 'string',
  1766. 'environment',
  1767. 'function',
  1768. 'keyword',
  1769. 'builtin',
  1770. 'boolean',
  1771. 'file-descriptor',
  1772. 'operator',
  1773. 'punctuation',
  1774. 'number'
  1775. ];
  1776. var inside = insideString.variable[1].inside;
  1777. for (var i = 0; i < toBeCopied.length; i++) {
  1778. inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
  1779. }
  1780. Prism.languages.sh = Prism.languages.bash;
  1781. Prism.languages.shell = Prism.languages.bash;
  1782. }(Prism));
  1783. Prism.languages.c = Prism.languages.extend('clike', {
  1784. 'comment': {
  1785. pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
  1786. greedy: true
  1787. },
  1788. 'string': {
  1789. // https://en.cppreference.com/w/c/language/string_literal
  1790. pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
  1791. greedy: true
  1792. },
  1793. 'class-name': {
  1794. pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
  1795. lookbehind: true
  1796. },
  1797. 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
  1798. 'function': /\b[a-z_]\w*(?=\s*\()/i,
  1799. 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
  1800. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
  1801. });
  1802. Prism.languages.insertBefore('c', 'string', {
  1803. 'char': {
  1804. // https://en.cppreference.com/w/c/language/character_constant
  1805. pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
  1806. greedy: true
  1807. }
  1808. });
  1809. Prism.languages.insertBefore('c', 'string', {
  1810. 'macro': {
  1811. // allow for multiline macro definitions
  1812. // spaces after the # character compile fine with gcc
  1813. pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
  1814. lookbehind: true,
  1815. greedy: true,
  1816. alias: 'property',
  1817. inside: {
  1818. 'string': [
  1819. {
  1820. // highlight the path of the include statement as a string
  1821. pattern: /^(#\s*include\s*)<[^>]+>/,
  1822. lookbehind: true
  1823. },
  1824. Prism.languages.c['string']
  1825. ],
  1826. 'char': Prism.languages.c['char'],
  1827. 'comment': Prism.languages.c['comment'],
  1828. 'macro-name': [
  1829. {
  1830. pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
  1831. lookbehind: true
  1832. },
  1833. {
  1834. pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
  1835. lookbehind: true,
  1836. alias: 'function'
  1837. }
  1838. ],
  1839. // highlight macro directives as keywords
  1840. 'directive': {
  1841. pattern: /^(#\s*)[a-z]+/,
  1842. lookbehind: true,
  1843. alias: 'keyword'
  1844. },
  1845. 'directive-hash': /^#/,
  1846. 'punctuation': /##|\\(?=[\r\n])/,
  1847. 'expression': {
  1848. pattern: /\S[\s\S]*/,
  1849. inside: Prism.languages.c
  1850. }
  1851. }
  1852. }
  1853. });
  1854. Prism.languages.insertBefore('c', 'function', {
  1855. // highlight predefined macros as constants
  1856. 'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
  1857. });
  1858. delete Prism.languages.c['boolean'];
  1859. (function (Prism) {
  1860. var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
  1861. var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; });
  1862. Prism.languages.cpp = Prism.languages.extend('c', {
  1863. 'class-name': [
  1864. {
  1865. pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
  1866. .replace(/<keyword>/g, function () { return keyword.source; })),
  1867. lookbehind: true
  1868. },
  1869. // This is intended to capture the class name of method implementations like:
  1870. // void foo::bar() const {}
  1871. // However! The `foo` in the above example could also be a namespace, so we only capture the class name if
  1872. // it starts with an uppercase letter. This approximation should give decent results.
  1873. /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
  1874. // This will capture the class name before destructors like:
  1875. // Foo::~Foo() {}
  1876. /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
  1877. // This also intends to capture the class name of method implementations but here the class has template
  1878. // parameters, so it can't be a namespace (until C++ adds generic namespaces).
  1879. /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
  1880. ],
  1881. 'keyword': keyword,
  1882. 'number': {
  1883. pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
  1884. greedy: true
  1885. },
  1886. 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
  1887. 'boolean': /\b(?:false|true)\b/
  1888. });
  1889. Prism.languages.insertBefore('cpp', 'string', {
  1890. 'module': {
  1891. // https://en.cppreference.com/w/cpp/language/modules
  1892. pattern: RegExp(
  1893. /(\b(?:import|module)\s+)/.source +
  1894. '(?:' +
  1895. // header-name
  1896. /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
  1897. '|' +
  1898. // module name or partition or both
  1899. /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) +
  1900. ')'
  1901. ),
  1902. lookbehind: true,
  1903. greedy: true,
  1904. inside: {
  1905. 'string': /^[<"][\s\S]+/,
  1906. 'operator': /:/,
  1907. 'punctuation': /\./
  1908. }
  1909. },
  1910. 'raw-string': {
  1911. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  1912. alias: 'string',
  1913. greedy: true
  1914. }
  1915. });
  1916. Prism.languages.insertBefore('cpp', 'keyword', {
  1917. 'generic-function': {
  1918. pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
  1919. inside: {
  1920. 'function': /^\w+/,
  1921. 'generic': {
  1922. pattern: /<[\s\S]+/,
  1923. alias: 'class-name',
  1924. inside: Prism.languages.cpp
  1925. }
  1926. }
  1927. }
  1928. });
  1929. Prism.languages.insertBefore('cpp', 'operator', {
  1930. 'double-colon': {
  1931. pattern: /::/,
  1932. alias: 'punctuation'
  1933. }
  1934. });
  1935. Prism.languages.insertBefore('cpp', 'class-name', {
  1936. // the base clause is an optional list of parent classes
  1937. // https://en.cppreference.com/w/cpp/language/class
  1938. 'base-clause': {
  1939. pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
  1940. lookbehind: true,
  1941. greedy: true,
  1942. inside: Prism.languages.extend('cpp', {})
  1943. }
  1944. });
  1945. Prism.languages.insertBefore('inside', 'double-colon', {
  1946. // All untokenized words that are not namespaces should be class names
  1947. 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i
  1948. }, Prism.languages.cpp['base-clause']);
  1949. }(Prism));
  1950. Prism.languages.cmake = {
  1951. 'comment': /#.*/,
  1952. 'string': {
  1953. pattern: /"(?:[^\\"]|\\.)*"/,
  1954. greedy: true,
  1955. inside: {
  1956. 'interpolation': {
  1957. pattern: /\$\{(?:[^{}$]|\$\{[^{}$]*\})*\}/,
  1958. inside: {
  1959. 'punctuation': /\$\{|\}/,
  1960. 'variable': /\w+/
  1961. }
  1962. }
  1963. }
  1964. },
  1965. 'variable': /\b(?:CMAKE_\w+|\w+_(?:(?:BINARY|SOURCE)_DIR|DESCRIPTION|HOMEPAGE_URL|ROOT|VERSION(?:_MAJOR|_MINOR|_PATCH|_TWEAK)?)|(?:ANDROID|APPLE|BORLAND|BUILD_SHARED_LIBS|CACHE|CPACK_(?:ABSOLUTE_DESTINATION_FILES|COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY|ERROR_ON_ABSOLUTE_INSTALL_DESTINATION|INCLUDE_TOPLEVEL_DIRECTORY|INSTALL_DEFAULT_DIRECTORY_PERMISSIONS|INSTALL_SCRIPT|PACKAGING_INSTALL_PREFIX|SET_DESTDIR|WARN_ON_ABSOLUTE_INSTALL_DESTINATION)|CTEST_(?:BINARY_DIRECTORY|BUILD_COMMAND|BUILD_NAME|BZR_COMMAND|BZR_UPDATE_OPTIONS|CHANGE_ID|CHECKOUT_COMMAND|CONFIGURATION_TYPE|CONFIGURE_COMMAND|COVERAGE_COMMAND|COVERAGE_EXTRA_FLAGS|CURL_OPTIONS|CUSTOM_(?:COVERAGE_EXCLUDE|ERROR_EXCEPTION|ERROR_MATCH|ERROR_POST_CONTEXT|ERROR_PRE_CONTEXT|MAXIMUM_FAILED_TEST_OUTPUT_SIZE|MAXIMUM_NUMBER_OF_(?:ERRORS|WARNINGS)|MAXIMUM_PASSED_TEST_OUTPUT_SIZE|MEMCHECK_IGNORE|POST_MEMCHECK|POST_TEST|PRE_MEMCHECK|PRE_TEST|TESTS_IGNORE|WARNING_EXCEPTION|WARNING_MATCH)|CVS_CHECKOUT|CVS_COMMAND|CVS_UPDATE_OPTIONS|DROP_LOCATION|DROP_METHOD|DROP_SITE|DROP_SITE_CDASH|DROP_SITE_PASSWORD|DROP_SITE_USER|EXTRA_COVERAGE_GLOB|GIT_COMMAND|GIT_INIT_SUBMODULES|GIT_UPDATE_CUSTOM|GIT_UPDATE_OPTIONS|HG_COMMAND|HG_UPDATE_OPTIONS|LABELS_FOR_SUBPROJECTS|MEMORYCHECK_(?:COMMAND|COMMAND_OPTIONS|SANITIZER_OPTIONS|SUPPRESSIONS_FILE|TYPE)|NIGHTLY_START_TIME|P4_CLIENT|P4_COMMAND|P4_OPTIONS|P4_UPDATE_OPTIONS|RUN_CURRENT_SCRIPT|SCP_COMMAND|SITE|SOURCE_DIRECTORY|SUBMIT_URL|SVN_COMMAND|SVN_OPTIONS|SVN_UPDATE_OPTIONS|TEST_LOAD|TEST_TIMEOUT|TRIGGER_SITE|UPDATE_COMMAND|UPDATE_OPTIONS|UPDATE_VERSION_ONLY|USE_LAUNCHERS)|CYGWIN|ENV|EXECUTABLE_OUTPUT_PATH|GHS-MULTI|IOS|LIBRARY_OUTPUT_PATH|MINGW|MSVC(?:10|11|12|14|60|70|71|80|90|_IDE|_TOOLSET_VERSION|_VERSION)?|MSYS|PROJECT_NAME|UNIX|WIN32|WINCE|WINDOWS_PHONE|WINDOWS_STORE|XCODE))\b/,
  1966. 'property': /\b(?:cxx_\w+|(?:ARCHIVE_OUTPUT_(?:DIRECTORY|NAME)|COMPILE_DEFINITIONS|COMPILE_PDB_NAME|COMPILE_PDB_OUTPUT_DIRECTORY|EXCLUDE_FROM_DEFAULT_BUILD|IMPORTED_(?:IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_LANGUAGES|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|NO_SONAME|OBJECTS|SONAME)|INTERPROCEDURAL_OPTIMIZATION|LIBRARY_OUTPUT_DIRECTORY|LIBRARY_OUTPUT_NAME|LINK_FLAGS|LINK_INTERFACE_LIBRARIES|LINK_INTERFACE_MULTIPLICITY|LOCATION|MAP_IMPORTED_CONFIG|OSX_ARCHITECTURES|OUTPUT_NAME|PDB_NAME|PDB_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_DIRECTORY|RUNTIME_OUTPUT_NAME|STATIC_LIBRARY_FLAGS|VS_CSHARP|VS_DOTNET_REFERENCEPROP|VS_DOTNET_REFERENCE|VS_GLOBAL_SECTION_POST|VS_GLOBAL_SECTION_PRE|VS_GLOBAL|XCODE_ATTRIBUTE)_\w+|\w+_(?:CLANG_TIDY|COMPILER_LAUNCHER|CPPCHECK|CPPLINT|INCLUDE_WHAT_YOU_USE|OUTPUT_NAME|POSTFIX|VISIBILITY_PRESET)|ABSTRACT|ADDITIONAL_MAKE_CLEAN_FILES|ADVANCED|ALIASED_TARGET|ALLOW_DUPLICATE_CUSTOM_TARGETS|ANDROID_(?:ANT_ADDITIONAL_OPTIONS|API|API_MIN|ARCH|ASSETS_DIRECTORIES|GUI|JAR_DEPENDENCIES|NATIVE_LIB_DEPENDENCIES|NATIVE_LIB_DIRECTORIES|PROCESS_MAX|PROGUARD|PROGUARD_CONFIG_PATH|SECURE_PROPS_PATH|SKIP_ANT_STEP|STL_TYPE)|ARCHIVE_OUTPUT_DIRECTORY|ATTACHED_FILES|ATTACHED_FILES_ON_FAIL|AUTOGEN_(?:BUILD_DIR|ORIGIN_DEPENDS|PARALLEL|SOURCE_GROUP|TARGETS_FOLDER|TARGET_DEPENDS)|AUTOMOC|AUTOMOC_(?:COMPILER_PREDEFINES|DEPEND_FILTERS|EXECUTABLE|MACRO_NAMES|MOC_OPTIONS|SOURCE_GROUP|TARGETS_FOLDER)|AUTORCC|AUTORCC_EXECUTABLE|AUTORCC_OPTIONS|AUTORCC_SOURCE_GROUP|AUTOUIC|AUTOUIC_EXECUTABLE|AUTOUIC_OPTIONS|AUTOUIC_SEARCH_PATHS|BINARY_DIR|BUILDSYSTEM_TARGETS|BUILD_RPATH|BUILD_RPATH_USE_ORIGIN|BUILD_WITH_INSTALL_NAME_DIR|BUILD_WITH_INSTALL_RPATH|BUNDLE|BUNDLE_EXTENSION|CACHE_VARIABLES|CLEAN_NO_CUSTOM|COMMON_LANGUAGE_RUNTIME|COMPATIBLE_INTERFACE_(?:BOOL|NUMBER_MAX|NUMBER_MIN|STRING)|COMPILE_(?:DEFINITIONS|FEATURES|FLAGS|OPTIONS|PDB_NAME|PDB_OUTPUT_DIRECTORY)|COST|CPACK_DESKTOP_SHORTCUTS|CPACK_NEVER_OVERWRITE|CPACK_PERMANENT|CPACK_STARTUP_SHORTCUTS|CPACK_START_MENU_SHORTCUTS|CPACK_WIX_ACL|CROSSCOMPILING_EMULATOR|CUDA_EXTENSIONS|CUDA_PTX_COMPILATION|CUDA_RESOLVE_DEVICE_SYMBOLS|CUDA_SEPARABLE_COMPILATION|CUDA_STANDARD|CUDA_STANDARD_REQUIRED|CXX_EXTENSIONS|CXX_STANDARD|CXX_STANDARD_REQUIRED|C_EXTENSIONS|C_STANDARD|C_STANDARD_REQUIRED|DEBUG_CONFIGURATIONS|DEFINE_SYMBOL|DEFINITIONS|DEPENDS|DEPLOYMENT_ADDITIONAL_FILES|DEPLOYMENT_REMOTE_DIRECTORY|DISABLED|DISABLED_FEATURES|ECLIPSE_EXTRA_CPROJECT_CONTENTS|ECLIPSE_EXTRA_NATURES|ENABLED_FEATURES|ENABLED_LANGUAGES|ENABLE_EXPORTS|ENVIRONMENT|EXCLUDE_FROM_ALL|EXCLUDE_FROM_DEFAULT_BUILD|EXPORT_NAME|EXPORT_PROPERTIES|EXTERNAL_OBJECT|EchoString|FAIL_REGULAR_EXPRESSION|FIND_LIBRARY_USE_LIB32_PATHS|FIND_LIBRARY_USE_LIB64_PATHS|FIND_LIBRARY_USE_LIBX32_PATHS|FIND_LIBRARY_USE_OPENBSD_VERSIONING|FIXTURES_CLEANUP|FIXTURES_REQUIRED|FIXTURES_SETUP|FOLDER|FRAMEWORK|Fortran_FORMAT|Fortran_MODULE_DIRECTORY|GENERATED|GENERATOR_FILE_NAME|GENERATOR_IS_MULTI_CONFIG|GHS_INTEGRITY_APP|GHS_NO_SOURCE_GROUP_FILE|GLOBAL_DEPENDS_DEBUG_MODE|GLOBAL_DEPENDS_NO_CYCLES|GNUtoMS|HAS_CXX|HEADER_FILE_ONLY|HELPSTRING|IMPLICIT_DEPENDS_INCLUDE_TRANSFORM|IMPORTED|IMPORTED_(?:COMMON_LANGUAGE_RUNTIME|CONFIGURATIONS|GLOBAL|IMPLIB|LIBNAME|LINK_DEPENDENT_LIBRARIES|LINK_INTERFACE_(?:LANGUAGES|LIBRARIES|MULTIPLICITY)|LOCATION|NO_SONAME|OBJECTS|SONAME)|IMPORT_PREFIX|IMPORT_SUFFIX|INCLUDE_DIRECTORIES|INCLUDE_REGULAR_EXPRESSION|INSTALL_NAME_DIR|INSTALL_RPATH|INSTALL_RPATH_USE_LINK_PATH|INTERFACE_(?:AUTOUIC_OPTIONS|COMPILE_DEFINITIONS|COMPILE_FEATURES|COMPILE_OPTIONS|INCLUDE_DIRECTORIES|LINK_DEPENDS|LINK_DIRECTORIES|LINK_LIBRARIES|LINK_OPTIONS|POSITION_INDEPENDENT_CODE|SOURCES|SYSTEM_INCLUDE_DIRECTORIES)|INTERPROCEDURAL_OPTIMIZATION|IN_TRY_COMPILE|IOS_INSTALL_COMBINED|JOB_POOLS|JOB_POOL_COMPILE|JOB_POOL_LINK|KEEP_EXTENSION|LABELS|LANGUAGE|LIBRARY_OUTPUT_DIRECTORY|LINKER_LANGUAGE|LINK_(?:DEPENDS|DEPENDS_NO_SHARED|DIRECTORIES|FLAGS|INTERFACE_LIBRARIES|INTERFACE_MULTIPLICITY|LIBRARIES|OPTIONS|SEARCH_END_STATIC|SEARCH_START_STATIC|WHAT_YOU_USE)|LISTFILE_STACK|LOCATION|MACOSX_BUNDLE|MACOSX_BUNDLE_INFO_PLIST|MACOSX_FRAMEWORK_INFO_PLIST|MACOSX_PACKAGE_LOCATION|MACOSX_RPATH|MACROS|MANUALLY_ADDED_DEPENDENCIES|MEASUREMENT|MODIFIED|NAME|NO_SONAME|NO_SYSTEM_FROM_IMPORTED|OBJECT_DEPENDS|OBJECT_OUTPUTS|OSX_ARCHITECTURES|OUTPUT_NAME|PACKAGES_FOUND|PACKAGES_NOT_FOUND|PARENT_DIRECTORY|PASS_REGULAR_EXPRESSION|PDB_NAME|PDB_OUTPUT_DIRECTORY|POSITION_INDEPENDENT_CODE|POST_INSTALL_SCRIPT|PREDEFINED_TARGETS_FOLDER|PREFIX|PRE_INSTALL_SCRIPT|PRIVATE_HEADER|PROCESSORS|PROCESSOR_AFFINITY|PROJECT_LABEL|PUBLIC_HEADER|REPORT_UNDEFINED_PROPERTIES|REQUIRED_FILES|RESOURCE|RESOURCE_LOCK|RULE_LAUNCH_COMPILE|RULE_LAUNCH_CUSTOM|RULE_LAUNCH_LINK|RULE_MESSAGES|RUNTIME_OUTPUT_DIRECTORY|RUN_SERIAL|SKIP_AUTOGEN|SKIP_AUTOMOC|SKIP_AUTORCC|SKIP_AUTOUIC|SKIP_BUILD_RPATH|SKIP_RETURN_CODE|SOURCES|SOURCE_DIR|SOVERSION|STATIC_LIBRARY_FLAGS|STATIC_LIBRARY_OPTIONS|STRINGS|SUBDIRECTORIES|SUFFIX|SYMBOLIC|TARGET_ARCHIVES_MAY_BE_SHARED_LIBS|TARGET_MESSAGES|TARGET_SUPPORTS_SHARED_LIBS|TESTS|TEST_INCLUDE_FILE|TEST_INCLUDE_FILES|TIMEOUT|TIMEOUT_AFTER_MATCH|TYPE|USE_FOLDERS|VALUE|VARIABLES|VERSION|VISIBILITY_INLINES_HIDDEN|VS_(?:CONFIGURATION_TYPE|COPY_TO_OUT_DIR|DEBUGGER_(?:COMMAND|COMMAND_ARGUMENTS|ENVIRONMENT|WORKING_DIRECTORY)|DEPLOYMENT_CONTENT|DEPLOYMENT_LOCATION|DOTNET_REFERENCES|DOTNET_REFERENCES_COPY_LOCAL|INCLUDE_IN_VSIX|IOT_STARTUP_TASK|KEYWORD|RESOURCE_GENERATOR|SCC_AUXPATH|SCC_LOCALPATH|SCC_PROJECTNAME|SCC_PROVIDER|SDK_REFERENCES|SHADER_(?:DISABLE_OPTIMIZATIONS|ENABLE_DEBUG|ENTRYPOINT|FLAGS|MODEL|OBJECT_FILE_NAME|OUTPUT_HEADER_FILE|TYPE|VARIABLE_NAME)|STARTUP_PROJECT|TOOL_OVERRIDE|USER_PROPS|WINRT_COMPONENT|WINRT_EXTENSIONS|WINRT_REFERENCES|XAML_TYPE)|WILL_FAIL|WIN32_EXECUTABLE|WINDOWS_EXPORT_ALL_SYMBOLS|WORKING_DIRECTORY|WRAP_EXCLUDE|XCODE_(?:EMIT_EFFECTIVE_PLATFORM_NAME|EXPLICIT_FILE_TYPE|FILE_ATTRIBUTES|LAST_KNOWN_FILE_TYPE|PRODUCT_TYPE|SCHEME_(?:ADDRESS_SANITIZER|ADDRESS_SANITIZER_USE_AFTER_RETURN|ARGUMENTS|DISABLE_MAIN_THREAD_CHECKER|DYNAMIC_LIBRARY_LOADS|DYNAMIC_LINKER_API_USAGE|ENVIRONMENT|EXECUTABLE|GUARD_MALLOC|MAIN_THREAD_CHECKER_STOP|MALLOC_GUARD_EDGES|MALLOC_SCRIBBLE|MALLOC_STACK|THREAD_SANITIZER(?:_STOP)?|UNDEFINED_BEHAVIOUR_SANITIZER(?:_STOP)?|ZOMBIE_OBJECTS))|XCTEST)\b/,
  1967. 'keyword': /\b(?:add_compile_definitions|add_compile_options|add_custom_command|add_custom_target|add_definitions|add_dependencies|add_executable|add_library|add_link_options|add_subdirectory|add_test|aux_source_directory|break|build_command|build_name|cmake_host_system_information|cmake_minimum_required|cmake_parse_arguments|cmake_policy|configure_file|continue|create_test_sourcelist|ctest_build|ctest_configure|ctest_coverage|ctest_empty_binary_directory|ctest_memcheck|ctest_read_custom_files|ctest_run_script|ctest_sleep|ctest_start|ctest_submit|ctest_test|ctest_update|ctest_upload|define_property|else|elseif|enable_language|enable_testing|endforeach|endfunction|endif|endmacro|endwhile|exec_program|execute_process|export|export_library_dependencies|file|find_file|find_library|find_package|find_path|find_program|fltk_wrap_ui|foreach|function|get_cmake_property|get_directory_property|get_filename_component|get_property|get_source_file_property|get_target_property|get_test_property|if|include|include_directories|include_external_msproject|include_guard|include_regular_expression|install|install_files|install_programs|install_targets|link_directories|link_libraries|list|load_cache|load_command|macro|make_directory|mark_as_advanced|math|message|option|output_required_files|project|qt_wrap_cpp|qt_wrap_ui|remove|remove_definitions|return|separate_arguments|set|set_directory_properties|set_property|set_source_files_properties|set_target_properties|set_tests_properties|site_name|source_group|string|subdir_depends|subdirs|target_compile_definitions|target_compile_features|target_compile_options|target_include_directories|target_link_directories|target_link_libraries|target_link_options|target_sources|try_compile|try_run|unset|use_mangled_mesa|utility_source|variable_requires|variable_watch|while|write_file)(?=\s*\()\b/,
  1968. 'boolean': /\b(?:FALSE|OFF|ON|TRUE)\b/,
  1969. 'namespace': /\b(?:INTERFACE|PRIVATE|PROPERTIES|PUBLIC|SHARED|STATIC|TARGET_OBJECTS)\b/,
  1970. 'operator': /\b(?:AND|DEFINED|EQUAL|GREATER|LESS|MATCHES|NOT|OR|STREQUAL|STRGREATER|STRLESS|VERSION_EQUAL|VERSION_GREATER|VERSION_LESS)\b/,
  1971. 'inserted': {
  1972. pattern: /\b\w+::\w+\b/,
  1973. alias: 'class-name'
  1974. },
  1975. 'number': /\b\d+(?:\.\d+)*\b/,
  1976. 'function': /\b[a-z_]\w*(?=\s*\()\b/i,
  1977. 'punctuation': /[()>}]|\$[<{]/
  1978. };
  1979. (function (Prism) {
  1980. // Ignore comments starting with { to privilege string interpolation highlighting
  1981. var comment = /#(?!\{).+/;
  1982. var interpolation = {
  1983. pattern: /#\{[^}]+\}/,
  1984. alias: 'variable'
  1985. };
  1986. Prism.languages.coffeescript = Prism.languages.extend('javascript', {
  1987. 'comment': comment,
  1988. 'string': [
  1989. // Strings are multiline
  1990. {
  1991. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1992. greedy: true
  1993. },
  1994. {
  1995. // Strings are multiline
  1996. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1997. greedy: true,
  1998. inside: {
  1999. 'interpolation': interpolation
  2000. }
  2001. }
  2002. ],
  2003. 'keyword': /\b(?:and|break|by|catch|class|continue|debugger|delete|do|each|else|extend|extends|false|finally|for|if|in|instanceof|is|isnt|let|loop|namespace|new|no|not|null|of|off|on|or|own|return|super|switch|then|this|throw|true|try|typeof|undefined|unless|until|when|while|window|with|yes|yield)\b/,
  2004. 'class-member': {
  2005. pattern: /@(?!\d)\w+/,
  2006. alias: 'variable'
  2007. }
  2008. });
  2009. Prism.languages.insertBefore('coffeescript', 'comment', {
  2010. 'multiline-comment': {
  2011. pattern: /###[\s\S]+?###/,
  2012. alias: 'comment'
  2013. },
  2014. // Block regexp can contain comments and interpolation
  2015. 'block-regex': {
  2016. pattern: /\/{3}[\s\S]*?\/{3}/,
  2017. alias: 'regex',
  2018. inside: {
  2019. 'comment': comment,
  2020. 'interpolation': interpolation
  2021. }
  2022. }
  2023. });
  2024. Prism.languages.insertBefore('coffeescript', 'string', {
  2025. 'inline-javascript': {
  2026. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  2027. inside: {
  2028. 'delimiter': {
  2029. pattern: /^`|`$/,
  2030. alias: 'punctuation'
  2031. },
  2032. 'script': {
  2033. pattern: /[\s\S]+/,
  2034. alias: 'language-javascript',
  2035. inside: Prism.languages.javascript
  2036. }
  2037. }
  2038. },
  2039. // Block strings
  2040. 'multiline-string': [
  2041. {
  2042. pattern: /'''[\s\S]*?'''/,
  2043. greedy: true,
  2044. alias: 'string'
  2045. },
  2046. {
  2047. pattern: /"""[\s\S]*?"""/,
  2048. greedy: true,
  2049. alias: 'string',
  2050. inside: {
  2051. interpolation: interpolation
  2052. }
  2053. }
  2054. ]
  2055. });
  2056. Prism.languages.insertBefore('coffeescript', 'keyword', {
  2057. // Object property
  2058. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  2059. });
  2060. delete Prism.languages.coffeescript['template-string'];
  2061. Prism.languages.coffee = Prism.languages.coffeescript;
  2062. }(Prism));
  2063. /**
  2064. * Original by Samuel Flores
  2065. *
  2066. * Adds the following new token classes:
  2067. * constant, builtin, variable, symbol, regex
  2068. */
  2069. (function (Prism) {
  2070. Prism.languages.ruby = Prism.languages.extend('clike', {
  2071. 'comment': {
  2072. pattern: /#.*|^=begin\s[\s\S]*?^=end/m,
  2073. greedy: true
  2074. },
  2075. 'class-name': {
  2076. pattern: /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/,
  2077. lookbehind: true,
  2078. inside: {
  2079. 'punctuation': /[.\\]/
  2080. }
  2081. },
  2082. 'keyword': /\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/,
  2083. 'operator': /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/,
  2084. 'punctuation': /[(){}[\].,;]/,
  2085. });
  2086. Prism.languages.insertBefore('ruby', 'operator', {
  2087. 'double-colon': {
  2088. pattern: /::/,
  2089. alias: 'punctuation'
  2090. },
  2091. });
  2092. var interpolation = {
  2093. pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/,
  2094. lookbehind: true,
  2095. inside: {
  2096. 'content': {
  2097. pattern: /^(#\{)[\s\S]+(?=\}$)/,
  2098. lookbehind: true,
  2099. inside: Prism.languages.ruby
  2100. },
  2101. 'delimiter': {
  2102. pattern: /^#\{|\}$/,
  2103. alias: 'punctuation'
  2104. }
  2105. }
  2106. };
  2107. delete Prism.languages.ruby.function;
  2108. var percentExpression = '(?:' + [
  2109. /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  2110. /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source,
  2111. /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source,
  2112. /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source,
  2113. /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source
  2114. ].join('|') + ')';
  2115. var symbolName = /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source;
  2116. Prism.languages.insertBefore('ruby', 'keyword', {
  2117. 'regex-literal': [
  2118. {
  2119. pattern: RegExp(/%r/.source + percentExpression + /[egimnosux]{0,6}/.source),
  2120. greedy: true,
  2121. inside: {
  2122. 'interpolation': interpolation,
  2123. 'regex': /[\s\S]+/
  2124. }
  2125. },
  2126. {
  2127. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
  2128. lookbehind: true,
  2129. greedy: true,
  2130. inside: {
  2131. 'interpolation': interpolation,
  2132. 'regex': /[\s\S]+/
  2133. }
  2134. }
  2135. ],
  2136. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  2137. 'symbol': [
  2138. {
  2139. pattern: RegExp(/(^|[^:]):/.source + symbolName),
  2140. lookbehind: true,
  2141. greedy: true
  2142. },
  2143. {
  2144. pattern: RegExp(/([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source),
  2145. lookbehind: true,
  2146. greedy: true
  2147. },
  2148. ],
  2149. 'method-definition': {
  2150. pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/,
  2151. lookbehind: true,
  2152. inside: {
  2153. 'function': /\b\w+$/,
  2154. 'keyword': /^self\b/,
  2155. 'class-name': /^\w+/,
  2156. 'punctuation': /\./
  2157. }
  2158. }
  2159. });
  2160. Prism.languages.insertBefore('ruby', 'string', {
  2161. 'string-literal': [
  2162. {
  2163. pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression),
  2164. greedy: true,
  2165. inside: {
  2166. 'interpolation': interpolation,
  2167. 'string': /[\s\S]+/
  2168. }
  2169. },
  2170. {
  2171. pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
  2172. greedy: true,
  2173. inside: {
  2174. 'interpolation': interpolation,
  2175. 'string': /[\s\S]+/
  2176. }
  2177. },
  2178. {
  2179. pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  2180. alias: 'heredoc-string',
  2181. greedy: true,
  2182. inside: {
  2183. 'delimiter': {
  2184. pattern: /^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i,
  2185. inside: {
  2186. 'symbol': /\b\w+/,
  2187. 'punctuation': /^<<[-~]?/
  2188. }
  2189. },
  2190. 'interpolation': interpolation,
  2191. 'string': /[\s\S]+/
  2192. }
  2193. },
  2194. {
  2195. pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  2196. alias: 'heredoc-string',
  2197. greedy: true,
  2198. inside: {
  2199. 'delimiter': {
  2200. pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i,
  2201. inside: {
  2202. 'symbol': /\b\w+/,
  2203. 'punctuation': /^<<[-~]?'|'$/,
  2204. }
  2205. },
  2206. 'string': /[\s\S]+/
  2207. }
  2208. }
  2209. ],
  2210. 'command-literal': [
  2211. {
  2212. pattern: RegExp(/%x/.source + percentExpression),
  2213. greedy: true,
  2214. inside: {
  2215. 'interpolation': interpolation,
  2216. 'command': {
  2217. pattern: /[\s\S]+/,
  2218. alias: 'string'
  2219. }
  2220. }
  2221. },
  2222. {
  2223. pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/,
  2224. greedy: true,
  2225. inside: {
  2226. 'interpolation': interpolation,
  2227. 'command': {
  2228. pattern: /[\s\S]+/,
  2229. alias: 'string'
  2230. }
  2231. }
  2232. }
  2233. ]
  2234. });
  2235. delete Prism.languages.ruby.string;
  2236. Prism.languages.insertBefore('ruby', 'number', {
  2237. 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/,
  2238. 'constant': /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/
  2239. });
  2240. Prism.languages.rb = Prism.languages.ruby;
  2241. }(Prism));
  2242. (function (Prism) {
  2243. Prism.languages.crystal = Prism.languages.extend('ruby', {
  2244. 'keyword': [
  2245. /\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/,
  2246. {
  2247. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  2248. lookbehind: true
  2249. }
  2250. ],
  2251. 'number': /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[\da-fA-F_]*[\da-fA-F]|(?:\d(?:[\d_]*\d)?)(?:\.[\d_]*\d)?(?:[eE][+-]?[\d_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/,
  2252. 'operator': [
  2253. /->/,
  2254. Prism.languages.ruby.operator,
  2255. ],
  2256. 'punctuation': /[(){}[\].,;\\]/,
  2257. });
  2258. Prism.languages.insertBefore('crystal', 'string-literal', {
  2259. 'attribute': {
  2260. pattern: /@\[.*?\]/,
  2261. inside: {
  2262. 'delimiter': {
  2263. pattern: /^@\[|\]$/,
  2264. alias: 'punctuation'
  2265. },
  2266. 'attribute': {
  2267. pattern: /^(\s*)\w+/,
  2268. lookbehind: true,
  2269. alias: 'class-name'
  2270. },
  2271. 'args': {
  2272. pattern: /\S(?:[\s\S]*\S)?/,
  2273. inside: Prism.languages.crystal
  2274. },
  2275. }
  2276. },
  2277. 'expansion': {
  2278. pattern: /\{(?:\{.*?\}|%.*?%)\}/,
  2279. inside: {
  2280. 'content': {
  2281. pattern: /^(\{.)[\s\S]+(?=.\}$)/,
  2282. lookbehind: true,
  2283. inside: Prism.languages.crystal
  2284. },
  2285. 'delimiter': {
  2286. pattern: /^\{[\{%]|[\}%]\}$/,
  2287. alias: 'operator'
  2288. }
  2289. }
  2290. },
  2291. 'char': {
  2292. pattern: /'(?:[^\\\r\n]{1,2}|\\(?:.|u(?:[A-Fa-f0-9]{1,4}|\{[A-Fa-f0-9]{1,6}\})))'/,
  2293. greedy: true
  2294. }
  2295. });
  2296. }(Prism));
  2297. Prism.languages.d = Prism.languages.extend('clike', {
  2298. 'comment': [
  2299. {
  2300. // Shebang
  2301. pattern: /^\s*#!.+/,
  2302. greedy: true
  2303. },
  2304. {
  2305. pattern: RegExp(/(^|[^\\])/.source + '(?:' + [
  2306. // /+ comment +/
  2307. // Allow one level of nesting
  2308. /\/\+(?:\/\+(?:[^+]|\+(?!\/))*\+\/|(?!\/\+)[\s\S])*?\+\//.source,
  2309. // // comment
  2310. /\/\/.*/.source,
  2311. // /* comment */
  2312. /\/\*[\s\S]*?\*\//.source
  2313. ].join('|') + ')'),
  2314. lookbehind: true,
  2315. greedy: true
  2316. }
  2317. ],
  2318. 'string': [
  2319. {
  2320. pattern: RegExp([
  2321. // r"", x""
  2322. /\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/.source,
  2323. // q"[]", q"()", q"<>", q"{}"
  2324. /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/.source,
  2325. // q"IDENT
  2326. // ...
  2327. // IDENT"
  2328. /\bq"((?!\d)\w+)$[\s\S]*?^\1"/.source,
  2329. // q"//", q"||", etc.
  2330. // eslint-disable-next-line regexp/strict
  2331. /\bq"(.)[\s\S]*?\2"/.source,
  2332. // eslint-disable-next-line regexp/strict
  2333. /(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
  2334. ].join('|'), 'm'),
  2335. greedy: true
  2336. },
  2337. {
  2338. pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
  2339. greedy: true,
  2340. alias: 'token-string'
  2341. }
  2342. ],
  2343. // In order: $, keywords and special tokens, globally defined symbols
  2344. 'keyword': /\$|\b(?:__(?:(?:DATE|EOF|FILE|FUNCTION|LINE|MODULE|PRETTY_FUNCTION|TIMESTAMP|TIME|VENDOR|VERSION)__|gshared|parameters|traits|vector)|abstract|alias|align|asm|assert|auto|body|bool|break|byte|case|cast|catch|cdouble|cent|cfloat|char|class|const|continue|creal|dchar|debug|default|delegate|delete|deprecated|do|double|dstring|else|enum|export|extern|false|final|finally|float|for|foreach|foreach_reverse|function|goto|idouble|if|ifloat|immutable|import|inout|int|interface|invariant|ireal|lazy|long|macro|mixin|module|new|nothrow|null|out|override|package|pragma|private|protected|ptrdiff_t|public|pure|real|ref|return|scope|shared|short|size_t|static|string|struct|super|switch|synchronized|template|this|throw|true|try|typedef|typeid|typeof|ubyte|ucent|uint|ulong|union|unittest|ushort|version|void|volatile|wchar|while|with|wstring)\b/,
  2345. 'number': [
  2346. // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
  2347. // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
  2348. /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]{0,4}/i,
  2349. {
  2350. pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]{0,4}/i,
  2351. lookbehind: true
  2352. }
  2353. ],
  2354. 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
  2355. });
  2356. Prism.languages.insertBefore('d', 'string', {
  2357. // Characters
  2358. // 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
  2359. 'char': /'(?:\\(?:\W|\w+)|[^\\])'/
  2360. });
  2361. Prism.languages.insertBefore('d', 'keyword', {
  2362. 'property': /\B@\w*/
  2363. });
  2364. Prism.languages.insertBefore('d', 'function', {
  2365. 'register': {
  2366. // Iasm registers
  2367. pattern: /\b(?:[ABCD][LHX]|E?(?:BP|DI|SI|SP)|[BS]PL|[ECSDGF]S|CR[0234]|[DS]IL|DR[012367]|E[ABCD]X|X?MM[0-7]|R(?:1[0-5]|[89])[BWD]?|R[ABCD]X|R[BS]P|R[DS]I|TR[3-7]|XMM(?:1[0-5]|[89])|YMM(?:1[0-5]|\d))\b|\bST(?:\([0-7]\)|\b)/,
  2368. alias: 'variable'
  2369. }
  2370. });
  2371. (function (Prism) {
  2372. var keywords = [
  2373. /\b(?:async|sync|yield)\*/,
  2374. /\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/
  2375. ];
  2376. // Handles named imports, such as http.Client
  2377. var packagePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2378. // based on the dart naming conventions
  2379. var className = {
  2380. pattern: RegExp(packagePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2381. lookbehind: true,
  2382. inside: {
  2383. 'namespace': {
  2384. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2385. inside: {
  2386. 'punctuation': /\./
  2387. }
  2388. },
  2389. }
  2390. };
  2391. Prism.languages.dart = Prism.languages.extend('clike', {
  2392. 'class-name': [
  2393. className,
  2394. {
  2395. // variables and parameters
  2396. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2397. pattern: RegExp(packagePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source),
  2398. lookbehind: true,
  2399. inside: className.inside
  2400. }
  2401. ],
  2402. 'keyword': keywords,
  2403. 'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
  2404. });
  2405. Prism.languages.insertBefore('dart', 'string', {
  2406. 'string-literal': {
  2407. pattern: /r?(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\r\n])*\2(?!\2))/,
  2408. greedy: true,
  2409. inside: {
  2410. 'interpolation': {
  2411. pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
  2412. lookbehind: true,
  2413. inside: {
  2414. 'punctuation': /^\$\{?|\}$/,
  2415. 'expression': {
  2416. pattern: /[\s\S]+/,
  2417. inside: Prism.languages.dart
  2418. }
  2419. }
  2420. },
  2421. 'string': /[\s\S]+/
  2422. }
  2423. },
  2424. 'string': undefined
  2425. });
  2426. Prism.languages.insertBefore('dart', 'class-name', {
  2427. 'metadata': {
  2428. pattern: /@\w+/,
  2429. alias: 'function'
  2430. }
  2431. });
  2432. Prism.languages.insertBefore('dart', 'class-name', {
  2433. 'generics': {
  2434. pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
  2435. inside: {
  2436. 'class-name': className,
  2437. 'keyword': keywords,
  2438. 'punctuation': /[<>(),.:]/,
  2439. 'operator': /[?&|]/
  2440. }
  2441. },
  2442. });
  2443. }(Prism));
  2444. (function (Prism) {
  2445. Prism.languages.diff = {
  2446. 'coord': [
  2447. // Match all kinds of coord lines (prefixed by "+++", "---" or "***").
  2448. /^(?:\*{3}|-{3}|\+{3}).*$/m,
  2449. // Match "@@ ... @@" coord lines in unified diff.
  2450. /^@@.*@@$/m,
  2451. // Match coord lines in normal diff (starts with a number).
  2452. /^\d.*$/m
  2453. ]
  2454. // deleted, inserted, unchanged, diff
  2455. };
  2456. /**
  2457. * A map from the name of a block to its line prefix.
  2458. *
  2459. * @type {Object<string, string>}
  2460. */
  2461. var PREFIXES = {
  2462. 'deleted-sign': '-',
  2463. 'deleted-arrow': '<',
  2464. 'inserted-sign': '+',
  2465. 'inserted-arrow': '>',
  2466. 'unchanged': ' ',
  2467. 'diff': '!',
  2468. };
  2469. // add a token for each prefix
  2470. Object.keys(PREFIXES).forEach(function (name) {
  2471. var prefix = PREFIXES[name];
  2472. var alias = [];
  2473. if (!/^\w+$/.test(name)) { // "deleted-sign" -> "deleted"
  2474. alias.push(/\w+/.exec(name)[0]);
  2475. }
  2476. if (name === 'diff') {
  2477. alias.push('bold');
  2478. }
  2479. Prism.languages.diff[name] = {
  2480. pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'),
  2481. alias: alias,
  2482. inside: {
  2483. 'line': {
  2484. pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/,
  2485. lookbehind: true
  2486. },
  2487. 'prefix': {
  2488. pattern: /[\s\S]/,
  2489. alias: /\w+/.exec(name)[0]
  2490. }
  2491. }
  2492. };
  2493. });
  2494. // make prefixes available to Diff plugin
  2495. Object.defineProperty(Prism.languages.diff, 'PREFIXES', {
  2496. value: PREFIXES
  2497. });
  2498. }(Prism));
  2499. (function (Prism) {
  2500. /**
  2501. * Returns the placeholder for the given language id and index.
  2502. *
  2503. * @param {string} language
  2504. * @param {string|number} index
  2505. * @returns {string}
  2506. */
  2507. function getPlaceholder(language, index) {
  2508. return '___' + language.toUpperCase() + index + '___';
  2509. }
  2510. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  2511. buildPlaceholders: {
  2512. /**
  2513. * Tokenize all inline templating expressions matching `placeholderPattern`.
  2514. *
  2515. * If `replaceFilter` is provided, only matches of `placeholderPattern` for which `replaceFilter` returns
  2516. * `true` will be replaced.
  2517. *
  2518. * @param {object} env The environment of the `before-tokenize` hook.
  2519. * @param {string} language The language id.
  2520. * @param {RegExp} placeholderPattern The matches of this pattern will be replaced by placeholders.
  2521. * @param {(match: string) => boolean} [replaceFilter]
  2522. */
  2523. value: function (env, language, placeholderPattern, replaceFilter) {
  2524. if (env.language !== language) {
  2525. return;
  2526. }
  2527. var tokenStack = env.tokenStack = [];
  2528. env.code = env.code.replace(placeholderPattern, function (match) {
  2529. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  2530. return match;
  2531. }
  2532. var i = tokenStack.length;
  2533. var placeholder;
  2534. // Check for existing strings
  2535. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1) {
  2536. ++i;
  2537. }
  2538. // Create a sparse array
  2539. tokenStack[i] = match;
  2540. return placeholder;
  2541. });
  2542. // Switch the grammar to markup
  2543. env.grammar = Prism.languages.markup;
  2544. }
  2545. },
  2546. tokenizePlaceholders: {
  2547. /**
  2548. * Replace placeholders with proper tokens after tokenizing.
  2549. *
  2550. * @param {object} env The environment of the `after-tokenize` hook.
  2551. * @param {string} language The language id.
  2552. */
  2553. value: function (env, language) {
  2554. if (env.language !== language || !env.tokenStack) {
  2555. return;
  2556. }
  2557. // Switch the grammar back
  2558. env.grammar = Prism.languages[language];
  2559. var j = 0;
  2560. var keys = Object.keys(env.tokenStack);
  2561. function walkTokens(tokens) {
  2562. for (var i = 0; i < tokens.length; i++) {
  2563. // all placeholders are replaced already
  2564. if (j >= keys.length) {
  2565. break;
  2566. }
  2567. var token = tokens[i];
  2568. if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
  2569. var k = keys[j];
  2570. var t = env.tokenStack[k];
  2571. var s = typeof token === 'string' ? token : token.content;
  2572. var placeholder = getPlaceholder(language, k);
  2573. var index = s.indexOf(placeholder);
  2574. if (index > -1) {
  2575. ++j;
  2576. var before = s.substring(0, index);
  2577. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  2578. var after = s.substring(index + placeholder.length);
  2579. var replacement = [];
  2580. if (before) {
  2581. replacement.push.apply(replacement, walkTokens([before]));
  2582. }
  2583. replacement.push(middle);
  2584. if (after) {
  2585. replacement.push.apply(replacement, walkTokens([after]));
  2586. }
  2587. if (typeof token === 'string') {
  2588. tokens.splice.apply(tokens, [i, 1].concat(replacement));
  2589. } else {
  2590. token.content = replacement;
  2591. }
  2592. }
  2593. } else if (token.content /* && typeof token.content !== 'string' */) {
  2594. walkTokens(token.content);
  2595. }
  2596. }
  2597. return tokens;
  2598. }
  2599. walkTokens(env.tokens);
  2600. }
  2601. }
  2602. });
  2603. }(Prism));
  2604. // Django/Jinja2 syntax definition for Prism.js <http://prismjs.com> syntax highlighter.
  2605. // Mostly it works OK but can paint code incorrectly on complex html/template tag combinations.
  2606. (function (Prism) {
  2607. Prism.languages.django = {
  2608. 'comment': /^\{#[\s\S]*?#\}$/,
  2609. 'tag': {
  2610. pattern: /(^\{%[+-]?\s*)\w+/,
  2611. lookbehind: true,
  2612. alias: 'keyword'
  2613. },
  2614. 'delimiter': {
  2615. pattern: /^\{[{%][+-]?|[+-]?[}%]\}$/,
  2616. alias: 'punctuation'
  2617. },
  2618. 'string': {
  2619. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2620. greedy: true
  2621. },
  2622. 'filter': {
  2623. pattern: /(\|)\w+/,
  2624. lookbehind: true,
  2625. alias: 'function'
  2626. },
  2627. 'test': {
  2628. pattern: /(\bis\s+(?:not\s+)?)(?!not\b)\w+/,
  2629. lookbehind: true,
  2630. alias: 'function'
  2631. },
  2632. 'function': /\b[a-z_]\w+(?=\s*\()/i,
  2633. 'keyword': /\b(?:and|as|by|else|for|if|import|in|is|loop|not|or|recursive|with|without)\b/,
  2634. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  2635. 'number': /\b\d+(?:\.\d+)?\b/,
  2636. 'boolean': /[Ff]alse|[Nn]one|[Tt]rue/,
  2637. 'variable': /\b\w+\b/,
  2638. 'punctuation': /[{}[\](),.:;]/
  2639. };
  2640. var pattern = /\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}|\{#[\s\S]*?#\}/g;
  2641. var markupTemplating = Prism.languages['markup-templating'];
  2642. Prism.hooks.add('before-tokenize', function (env) {
  2643. markupTemplating.buildPlaceholders(env, 'django', pattern);
  2644. });
  2645. Prism.hooks.add('after-tokenize', function (env) {
  2646. markupTemplating.tokenizePlaceholders(env, 'django');
  2647. });
  2648. // Add an Jinja2 alias
  2649. Prism.languages.jinja2 = Prism.languages.django;
  2650. Prism.hooks.add('before-tokenize', function (env) {
  2651. markupTemplating.buildPlaceholders(env, 'jinja2', pattern);
  2652. });
  2653. Prism.hooks.add('after-tokenize', function (env) {
  2654. markupTemplating.tokenizePlaceholders(env, 'jinja2');
  2655. });
  2656. }(Prism));
  2657. Prism.languages.elixir = {
  2658. 'doc': {
  2659. pattern: /@(?:doc|moduledoc)\s+(?:("""|''')[\s\S]*?\1|("|')(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2)/,
  2660. inside: {
  2661. 'attribute': /^@\w+/,
  2662. 'string': /['"][\s\S]+/
  2663. }
  2664. },
  2665. 'comment': {
  2666. pattern: /#.*/,
  2667. greedy: true
  2668. },
  2669. // ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  2670. 'regex': {
  2671. pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
  2672. greedy: true
  2673. },
  2674. 'string': [
  2675. {
  2676. // ~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>
  2677. pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|#(?!\{)|[^#\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/,
  2678. greedy: true,
  2679. inside: {
  2680. // See interpolation below
  2681. }
  2682. },
  2683. {
  2684. pattern: /("""|''')[\s\S]*?\1/,
  2685. greedy: true,
  2686. inside: {
  2687. // See interpolation below
  2688. }
  2689. },
  2690. {
  2691. // Multi-line strings are allowed
  2692. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2693. greedy: true,
  2694. inside: {
  2695. // See interpolation below
  2696. }
  2697. }
  2698. ],
  2699. 'atom': {
  2700. // Look-behind prevents bad highlighting of the :: operator
  2701. pattern: /(^|[^:]):\w+/,
  2702. lookbehind: true,
  2703. alias: 'symbol'
  2704. },
  2705. 'module': {
  2706. pattern: /\b[A-Z]\w*\b/,
  2707. alias: 'class-name'
  2708. },
  2709. // Look-ahead prevents bad highlighting of the :: operator
  2710. 'attr-name': /\b\w+\??:(?!:)/,
  2711. 'argument': {
  2712. // Look-behind prevents bad highlighting of the && operator
  2713. pattern: /(^|[^&])&\d+/,
  2714. lookbehind: true,
  2715. alias: 'variable'
  2716. },
  2717. 'attribute': {
  2718. pattern: /@\w+/,
  2719. alias: 'variable'
  2720. },
  2721. 'function': /\b[_a-zA-Z]\w*[?!]?(?:(?=\s*(?:\.\s*)?\()|(?=\/\d))/,
  2722. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  2723. 'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|delegate|exception|impl|macro|module|n|np|p|protocol|struct)?|do|else|end|fn|for|if|import|not|or|quote|raise|require|rescue|try|unless|unquote|use|when)\b/,
  2724. 'boolean': /\b(?:false|nil|true)\b/,
  2725. 'operator': [
  2726. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  2727. {
  2728. // We don't want to match <<
  2729. pattern: /([^<])<(?!<)/,
  2730. lookbehind: true
  2731. },
  2732. {
  2733. // We don't want to match >>
  2734. pattern: /([^>])>(?!>)/,
  2735. lookbehind: true
  2736. }
  2737. ],
  2738. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  2739. };
  2740. Prism.languages.elixir.string.forEach(function (o) {
  2741. o.inside = {
  2742. 'interpolation': {
  2743. pattern: /#\{[^}]+\}/,
  2744. inside: {
  2745. 'delimiter': {
  2746. pattern: /^#\{|\}$/,
  2747. alias: 'punctuation'
  2748. },
  2749. rest: Prism.languages.elixir
  2750. }
  2751. }
  2752. };
  2753. });
  2754. Prism.languages.erlang = {
  2755. 'comment': /%.+/,
  2756. 'string': {
  2757. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  2758. greedy: true
  2759. },
  2760. 'quoted-function': {
  2761. pattern: /'(?:\\.|[^\\'\r\n])+'(?=\()/,
  2762. alias: 'function'
  2763. },
  2764. 'quoted-atom': {
  2765. pattern: /'(?:\\.|[^\\'\r\n])+'/,
  2766. alias: 'atom'
  2767. },
  2768. 'boolean': /\b(?:false|true)\b/,
  2769. 'keyword': /\b(?:after|begin|case|catch|end|fun|if|of|receive|try|when)\b/,
  2770. 'number': [
  2771. /\$\\?./,
  2772. /\b\d+#[a-z0-9]+/i,
  2773. /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i
  2774. ],
  2775. 'function': /\b[a-z][\w@]*(?=\()/,
  2776. 'variable': {
  2777. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  2778. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  2779. lookbehind: true
  2780. },
  2781. 'operator': [
  2782. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:and|andalso|band|bnot|bor|bsl|bsr|bxor|div|not|or|orelse|rem|xor)\b/,
  2783. {
  2784. // We don't want to match <<
  2785. pattern: /(^|[^<])<(?!<)/,
  2786. lookbehind: true
  2787. },
  2788. {
  2789. // We don't want to match >>
  2790. pattern: /(^|[^>])>(?!>)/,
  2791. lookbehind: true
  2792. }
  2793. ],
  2794. 'atom': /\b[a-z][\w@]*/,
  2795. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  2796. };
  2797. Prism.languages.go = Prism.languages.extend('clike', {
  2798. 'string': {
  2799. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,
  2800. lookbehind: true,
  2801. greedy: true
  2802. },
  2803. 'keyword': /\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
  2804. 'boolean': /\b(?:_|false|iota|nil|true)\b/,
  2805. 'number': [
  2806. // binary and octal integers
  2807. /\b0(?:b[01_]+|o[0-7_]+)i?\b/i,
  2808. // hexadecimal integers and floats
  2809. /\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,
  2810. // decimal integers and floats
  2811. /(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i
  2812. ],
  2813. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  2814. 'builtin': /\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/
  2815. });
  2816. Prism.languages.insertBefore('go', 'string', {
  2817. 'char': {
  2818. pattern: /'(?:\\.|[^'\\\r\n]){0,10}'/,
  2819. greedy: true
  2820. }
  2821. });
  2822. delete Prism.languages.go['class-name'];
  2823. (function (Prism) {
  2824. var interpolation = {
  2825. pattern: /((?:^|[^\\$])(?:\\{2})*)\$(?:\w+|\{[^{}]*\})/,
  2826. lookbehind: true,
  2827. inside: {
  2828. 'interpolation-punctuation': {
  2829. pattern: /^\$\{?|\}$/,
  2830. alias: 'punctuation'
  2831. },
  2832. 'expression': {
  2833. pattern: /[\s\S]+/,
  2834. inside: null // see below
  2835. }
  2836. }
  2837. };
  2838. Prism.languages.groovy = Prism.languages.extend('clike', {
  2839. 'string': {
  2840. // https://groovy-lang.org/syntax.html#_dollar_slashy_string
  2841. pattern: /'''(?:[^\\]|\\[\s\S])*?'''|'(?:\\.|[^\\'\r\n])*'/,
  2842. greedy: true
  2843. },
  2844. 'keyword': /\b(?:abstract|as|assert|boolean|break|byte|case|catch|char|class|const|continue|def|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|in|instanceof|int|interface|long|native|new|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|trait|transient|try|void|volatile|while)\b/,
  2845. 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
  2846. 'operator': {
  2847. pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
  2848. lookbehind: true
  2849. },
  2850. 'punctuation': /\.+|[{}[\];(),:$]/
  2851. });
  2852. Prism.languages.insertBefore('groovy', 'string', {
  2853. 'shebang': {
  2854. pattern: /#!.+/,
  2855. alias: 'comment',
  2856. greedy: true
  2857. },
  2858. 'interpolation-string': {
  2859. // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
  2860. // simple division (see JS regex), so find a fix maybe?
  2861. pattern: /"""(?:[^\\]|\\[\s\S])*?"""|(["/])(?:\\.|(?!\1)[^\\\r\n])*\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
  2862. greedy: true,
  2863. inside: {
  2864. 'interpolation': interpolation,
  2865. 'string': /[\s\S]+/
  2866. }
  2867. }
  2868. });
  2869. Prism.languages.insertBefore('groovy', 'punctuation', {
  2870. 'spock-block': /\b(?:and|cleanup|expect|given|setup|then|when|where):/
  2871. });
  2872. Prism.languages.insertBefore('groovy', 'function', {
  2873. 'annotation': {
  2874. pattern: /(^|[^.])@\w+/,
  2875. lookbehind: true,
  2876. alias: 'punctuation'
  2877. }
  2878. });
  2879. interpolation.inside.expression.inside = Prism.languages.groovy;
  2880. }(Prism));
  2881. (function (Prism) {
  2882. var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
  2883. // full package (optional) + parent classes (optional)
  2884. var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2885. // based on the java naming conventions
  2886. var className = {
  2887. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2888. lookbehind: true,
  2889. inside: {
  2890. 'namespace': {
  2891. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2892. inside: {
  2893. 'punctuation': /\./
  2894. }
  2895. },
  2896. 'punctuation': /\./
  2897. }
  2898. };
  2899. Prism.languages.java = Prism.languages.extend('clike', {
  2900. 'string': {
  2901. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
  2902. lookbehind: true,
  2903. greedy: true
  2904. },
  2905. 'class-name': [
  2906. className,
  2907. {
  2908. // variables, parameters, and constructor references
  2909. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2910. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),
  2911. lookbehind: true,
  2912. inside: className.inside
  2913. },
  2914. {
  2915. // class names based on keyword
  2916. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2917. pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source),
  2918. lookbehind: true,
  2919. inside: className.inside
  2920. }
  2921. ],
  2922. 'keyword': keywords,
  2923. 'function': [
  2924. Prism.languages.clike.function,
  2925. {
  2926. pattern: /(::\s*)[a-z_]\w*/,
  2927. lookbehind: true
  2928. }
  2929. ],
  2930. 'number': /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
  2931. 'operator': {
  2932. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  2933. lookbehind: true
  2934. },
  2935. 'constant': /\b[A-Z][A-Z_\d]+\b/
  2936. });
  2937. Prism.languages.insertBefore('java', 'string', {
  2938. 'triple-quoted-string': {
  2939. // http://openjdk.java.net/jeps/355#Description
  2940. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  2941. greedy: true,
  2942. alias: 'string'
  2943. },
  2944. 'char': {
  2945. pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
  2946. greedy: true
  2947. }
  2948. });
  2949. Prism.languages.insertBefore('java', 'class-name', {
  2950. 'annotation': {
  2951. pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
  2952. lookbehind: true,
  2953. alias: 'punctuation'
  2954. },
  2955. 'generics': {
  2956. pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
  2957. inside: {
  2958. 'class-name': className,
  2959. 'keyword': keywords,
  2960. 'punctuation': /[<>(),.:]/,
  2961. 'operator': /[?&|]/
  2962. }
  2963. },
  2964. 'import': [
  2965. {
  2966. pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source),
  2967. lookbehind: true,
  2968. inside: {
  2969. 'namespace': className.inside.namespace,
  2970. 'punctuation': /\./,
  2971. 'operator': /\*/,
  2972. 'class-name': /\w+/
  2973. }
  2974. },
  2975. {
  2976. pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source),
  2977. lookbehind: true,
  2978. alias: 'static',
  2979. inside: {
  2980. 'namespace': className.inside.namespace,
  2981. 'static': /\b\w+$/,
  2982. 'punctuation': /\./,
  2983. 'operator': /\*/,
  2984. 'class-name': /\w+/
  2985. }
  2986. }
  2987. ],
  2988. 'namespace': {
  2989. pattern: RegExp(
  2990. /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
  2991. .source.replace(/<keyword>/g, function () { return keywords.source; })),
  2992. lookbehind: true,
  2993. inside: {
  2994. 'punctuation': /\./,
  2995. }
  2996. }
  2997. });
  2998. }(Prism));
  2999. // https://www.json.org/json-en.html
  3000. Prism.languages.json = {
  3001. 'property': {
  3002. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
  3003. lookbehind: true,
  3004. greedy: true
  3005. },
  3006. 'string': {
  3007. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  3008. lookbehind: true,
  3009. greedy: true
  3010. },
  3011. 'comment': {
  3012. pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
  3013. greedy: true
  3014. },
  3015. 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
  3016. 'punctuation': /[{}[\],]/,
  3017. 'operator': /:/,
  3018. 'boolean': /\b(?:false|true)\b/,
  3019. 'null': {
  3020. pattern: /\bnull\b/,
  3021. alias: 'keyword'
  3022. }
  3023. };
  3024. Prism.languages.webmanifest = Prism.languages.json;
  3025. Prism.languages.julia = {
  3026. 'comment': {
  3027. // support one level of nested comments
  3028. // https://github.com/JuliaLang/julia/pull/6128
  3029. pattern: /(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/,
  3030. lookbehind: true
  3031. },
  3032. 'regex': {
  3033. // https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1
  3034. pattern: /r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/,
  3035. greedy: true
  3036. },
  3037. 'string': {
  3038. // https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1
  3039. // https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1
  3040. // https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1
  3041. pattern: /"""[\s\S]+?"""|(?:\b\w+)?"(?:\\.|[^"\\\r\n])*"|`(?:[^\\`\r\n]|\\.)*`/,
  3042. greedy: true
  3043. },
  3044. 'char': {
  3045. // https://docs.julialang.org/en/v1/manual/strings/#man-characters-1
  3046. pattern: /(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'/,
  3047. lookbehind: true,
  3048. greedy: true
  3049. },
  3050. 'keyword': /\b(?:abstract|baremodule|begin|bitstype|break|catch|ccall|const|continue|do|else|elseif|end|export|finally|for|function|global|if|immutable|import|importall|in|let|local|macro|module|print|println|quote|return|struct|try|type|typealias|using|while)\b/,
  3051. 'boolean': /\b(?:false|true)\b/,
  3052. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i,
  3053. // https://docs.julialang.org/en/v1/manual/mathematical-operations/
  3054. // https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1
  3055. 'operator': /&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/,
  3056. 'punctuation': /::?|[{}[\]();,.?]/,
  3057. // https://docs.julialang.org/en/v1/base/numbers/#Base.im
  3058. 'constant': /\b(?:(?:Inf|NaN)(?:16|32|64)?|im|pi)\b|[πℯ]/
  3059. };
  3060. (function (Prism) {
  3061. Prism.languages.kotlin = Prism.languages.extend('clike', {
  3062. 'keyword': {
  3063. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  3064. pattern: /(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|to|try|typealias|val|var|vararg|when|where|while)\b/,
  3065. lookbehind: true
  3066. },
  3067. 'function': [
  3068. {
  3069. pattern: /(?:`[^\r\n`]+`|\b\w+)(?=\s*\()/,
  3070. greedy: true
  3071. },
  3072. {
  3073. pattern: /(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/,
  3074. lookbehind: true,
  3075. greedy: true
  3076. }
  3077. ],
  3078. 'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
  3079. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  3080. });
  3081. delete Prism.languages.kotlin['class-name'];
  3082. var interpolationInside = {
  3083. 'interpolation-punctuation': {
  3084. pattern: /^\$\{?|\}$/,
  3085. alias: 'punctuation'
  3086. },
  3087. 'expression': {
  3088. pattern: /[\s\S]+/,
  3089. inside: Prism.languages.kotlin
  3090. }
  3091. };
  3092. Prism.languages.insertBefore('kotlin', 'string', {
  3093. // https://kotlinlang.org/spec/expressions.html#string-interpolation-expressions
  3094. 'string-literal': [
  3095. {
  3096. pattern: /"""(?:[^$]|\$(?:(?!\{)|\{[^{}]*\}))*?"""/,
  3097. alias: 'multiline',
  3098. inside: {
  3099. 'interpolation': {
  3100. pattern: /\$(?:[a-z_]\w*|\{[^{}]*\})/i,
  3101. inside: interpolationInside
  3102. },
  3103. 'string': /[\s\S]+/
  3104. }
  3105. },
  3106. {
  3107. pattern: /"(?:[^"\\\r\n$]|\\.|\$(?:(?!\{)|\{[^{}]*\}))*"/,
  3108. alias: 'singleline',
  3109. inside: {
  3110. 'interpolation': {
  3111. pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:[a-z_]\w*|\{[^{}]*\})/i,
  3112. lookbehind: true,
  3113. inside: interpolationInside
  3114. },
  3115. 'string': /[\s\S]+/
  3116. }
  3117. }
  3118. ],
  3119. 'char': {
  3120. // https://kotlinlang.org/spec/expressions.html#character-literals
  3121. pattern: /'(?:[^'\\\r\n]|\\(?:.|u[a-fA-F0-9]{0,4}))'/,
  3122. greedy: true
  3123. }
  3124. });
  3125. delete Prism.languages.kotlin['string'];
  3126. Prism.languages.insertBefore('kotlin', 'keyword', {
  3127. 'annotation': {
  3128. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  3129. alias: 'builtin'
  3130. }
  3131. });
  3132. Prism.languages.insertBefore('kotlin', 'function', {
  3133. 'label': {
  3134. pattern: /\b\w+@|@\w+\b/,
  3135. alias: 'symbol'
  3136. }
  3137. });
  3138. Prism.languages.kt = Prism.languages.kotlin;
  3139. Prism.languages.kts = Prism.languages.kotlin;
  3140. }(Prism));
  3141. (function (Prism) {
  3142. var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i;
  3143. var insideEqu = {
  3144. 'equation-command': {
  3145. pattern: funcPattern,
  3146. alias: 'regex'
  3147. }
  3148. };
  3149. Prism.languages.latex = {
  3150. 'comment': /%.*/,
  3151. // the verbatim environment prints whitespace to the document
  3152. 'cdata': {
  3153. pattern: /(\\begin\{((?:lstlisting|verbatim)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  3154. lookbehind: true
  3155. },
  3156. /*
  3157. * equations can be between $$ $$ or $ $ or \( \) or \[ \]
  3158. * (all are multiline)
  3159. */
  3160. 'equation': [
  3161. {
  3162. pattern: /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
  3163. inside: insideEqu,
  3164. alias: 'string'
  3165. },
  3166. {
  3167. pattern: /(\\begin\{((?:align|eqnarray|equation|gather|math|multline)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  3168. lookbehind: true,
  3169. inside: insideEqu,
  3170. alias: 'string'
  3171. }
  3172. ],
  3173. /*
  3174. * arguments which are keywords or references are highlighted
  3175. * as keywords
  3176. */
  3177. 'keyword': {
  3178. pattern: /(\\(?:begin|cite|documentclass|end|label|ref|usepackage)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  3179. lookbehind: true
  3180. },
  3181. 'url': {
  3182. pattern: /(\\url\{)[^}]+(?=\})/,
  3183. lookbehind: true
  3184. },
  3185. /*
  3186. * section or chapter headlines are highlighted as bold so that
  3187. * they stand out more
  3188. */
  3189. 'headline': {
  3190. pattern: /(\\(?:chapter|frametitle|paragraph|part|section|subparagraph|subsection|subsubparagraph|subsubsection|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  3191. lookbehind: true,
  3192. alias: 'class-name'
  3193. },
  3194. 'function': {
  3195. pattern: funcPattern,
  3196. alias: 'selector'
  3197. },
  3198. 'punctuation': /[[\]{}&]/
  3199. };
  3200. Prism.languages.tex = Prism.languages.latex;
  3201. Prism.languages.context = Prism.languages.latex;
  3202. }(Prism));
  3203. Prism.languages.lua = {
  3204. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  3205. // \z may be used to skip the following space
  3206. 'string': {
  3207. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  3208. greedy: true
  3209. },
  3210. 'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  3211. 'keyword': /\b(?:and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\b/,
  3212. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  3213. 'operator': [
  3214. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  3215. {
  3216. // Match ".." but don't break "..."
  3217. pattern: /(^|[^.])\.\.(?!\.)/,
  3218. lookbehind: true
  3219. }
  3220. ],
  3221. 'punctuation': /[\[\](){},;]|\.+|:+/
  3222. };
  3223. (function (Prism) {
  3224. // Allow only one line break
  3225. var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;
  3226. /**
  3227. * This function is intended for the creation of the bold or italic pattern.
  3228. *
  3229. * This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
  3230. *
  3231. * _Note:_ Keep in mind that this adds a capturing group.
  3232. *
  3233. * @param {string} pattern
  3234. * @returns {RegExp}
  3235. */
  3236. function createInline(pattern) {
  3237. pattern = pattern.replace(/<inner>/g, function () { return inner; });
  3238. return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')');
  3239. }
  3240. var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
  3241. var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g, function () { return tableCell; });
  3242. var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
  3243. Prism.languages.markdown = Prism.languages.extend('markup', {});
  3244. Prism.languages.insertBefore('markdown', 'prolog', {
  3245. 'front-matter-block': {
  3246. pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
  3247. lookbehind: true,
  3248. greedy: true,
  3249. inside: {
  3250. 'punctuation': /^---|---$/,
  3251. 'front-matter': {
  3252. pattern: /\S+(?:\s+\S+)*/,
  3253. alias: ['yaml', 'language-yaml'],
  3254. inside: Prism.languages.yaml
  3255. }
  3256. }
  3257. },
  3258. 'blockquote': {
  3259. // > ...
  3260. pattern: /^>(?:[\t ]*>)*/m,
  3261. alias: 'punctuation'
  3262. },
  3263. 'table': {
  3264. pattern: RegExp('^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm'),
  3265. inside: {
  3266. 'table-data-rows': {
  3267. pattern: RegExp('^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$'),
  3268. lookbehind: true,
  3269. inside: {
  3270. 'table-data': {
  3271. pattern: RegExp(tableCell),
  3272. inside: Prism.languages.markdown
  3273. },
  3274. 'punctuation': /\|/
  3275. }
  3276. },
  3277. 'table-line': {
  3278. pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'),
  3279. lookbehind: true,
  3280. inside: {
  3281. 'punctuation': /\||:?-{3,}:?/
  3282. }
  3283. },
  3284. 'table-header-row': {
  3285. pattern: RegExp('^' + tableRow + '$'),
  3286. inside: {
  3287. 'table-header': {
  3288. pattern: RegExp(tableCell),
  3289. alias: 'important',
  3290. inside: Prism.languages.markdown
  3291. },
  3292. 'punctuation': /\|/
  3293. }
  3294. }
  3295. }
  3296. },
  3297. 'code': [
  3298. {
  3299. // Prefixed by 4 spaces or 1 tab and preceded by an empty line
  3300. pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
  3301. lookbehind: true,
  3302. alias: 'keyword'
  3303. },
  3304. {
  3305. // ```optional language
  3306. // code block
  3307. // ```
  3308. pattern: /^```[\s\S]*?^```$/m,
  3309. greedy: true,
  3310. inside: {
  3311. 'code-block': {
  3312. pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
  3313. lookbehind: true
  3314. },
  3315. 'code-language': {
  3316. pattern: /^(```).+/,
  3317. lookbehind: true
  3318. },
  3319. 'punctuation': /```/
  3320. }
  3321. }
  3322. ],
  3323. 'title': [
  3324. {
  3325. // title 1
  3326. // =======
  3327. // title 2
  3328. // -------
  3329. pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
  3330. alias: 'important',
  3331. inside: {
  3332. punctuation: /==+$|--+$/
  3333. }
  3334. },
  3335. {
  3336. // # title 1
  3337. // ###### title 6
  3338. pattern: /(^\s*)#.+/m,
  3339. lookbehind: true,
  3340. alias: 'important',
  3341. inside: {
  3342. punctuation: /^#+|#+$/
  3343. }
  3344. }
  3345. ],
  3346. 'hr': {
  3347. // ***
  3348. // ---
  3349. // * * *
  3350. // -----------
  3351. pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
  3352. lookbehind: true,
  3353. alias: 'punctuation'
  3354. },
  3355. 'list': {
  3356. // * item
  3357. // + item
  3358. // - item
  3359. // 1. item
  3360. pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
  3361. lookbehind: true,
  3362. alias: 'punctuation'
  3363. },
  3364. 'url-reference': {
  3365. // [id]: http://example.com "Optional title"
  3366. // [id]: http://example.com 'Optional title'
  3367. // [id]: http://example.com (Optional title)
  3368. // [id]: <http://example.com> "Optional title"
  3369. pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
  3370. inside: {
  3371. 'variable': {
  3372. pattern: /^(!?\[)[^\]]+/,
  3373. lookbehind: true
  3374. },
  3375. 'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
  3376. 'punctuation': /^[\[\]!:]|[<>]/
  3377. },
  3378. alias: 'url'
  3379. },
  3380. 'bold': {
  3381. // **strong**
  3382. // __strong__
  3383. // allow one nested instance of italic text using the same delimiter
  3384. pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
  3385. lookbehind: true,
  3386. greedy: true,
  3387. inside: {
  3388. 'content': {
  3389. pattern: /(^..)[\s\S]+(?=..$)/,
  3390. lookbehind: true,
  3391. inside: {} // see below
  3392. },
  3393. 'punctuation': /\*\*|__/
  3394. }
  3395. },
  3396. 'italic': {
  3397. // *em*
  3398. // _em_
  3399. // allow one nested instance of bold text using the same delimiter
  3400. pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
  3401. lookbehind: true,
  3402. greedy: true,
  3403. inside: {
  3404. 'content': {
  3405. pattern: /(^.)[\s\S]+(?=.$)/,
  3406. lookbehind: true,
  3407. inside: {} // see below
  3408. },
  3409. 'punctuation': /[*_]/
  3410. }
  3411. },
  3412. 'strike': {
  3413. // ~~strike through~~
  3414. // ~strike~
  3415. // eslint-disable-next-line regexp/strict
  3416. pattern: createInline(/(~~?)(?:(?!~)<inner>)+\2/.source),
  3417. lookbehind: true,
  3418. greedy: true,
  3419. inside: {
  3420. 'content': {
  3421. pattern: /(^~~?)[\s\S]+(?=\1$)/,
  3422. lookbehind: true,
  3423. inside: {} // see below
  3424. },
  3425. 'punctuation': /~~?/
  3426. }
  3427. },
  3428. 'code-snippet': {
  3429. // `code`
  3430. // ``code``
  3431. pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,
  3432. lookbehind: true,
  3433. greedy: true,
  3434. alias: ['code', 'keyword']
  3435. },
  3436. 'url': {
  3437. // [example](http://example.com "Optional title")
  3438. // [example][id]
  3439. // [example] [id]
  3440. pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\])<inner>)+\])/.source),
  3441. lookbehind: true,
  3442. greedy: true,
  3443. inside: {
  3444. 'operator': /^!/,
  3445. 'content': {
  3446. pattern: /(^\[)[^\]]+(?=\])/,
  3447. lookbehind: true,
  3448. inside: {} // see below
  3449. },
  3450. 'variable': {
  3451. pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/,
  3452. lookbehind: true
  3453. },
  3454. 'url': {
  3455. pattern: /(^\]\()[^\s)]+/,
  3456. lookbehind: true
  3457. },
  3458. 'string': {
  3459. pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,
  3460. lookbehind: true
  3461. }
  3462. }
  3463. }
  3464. });
  3465. ['url', 'bold', 'italic', 'strike'].forEach(function (token) {
  3466. ['url', 'bold', 'italic', 'strike', 'code-snippet'].forEach(function (inside) {
  3467. if (token !== inside) {
  3468. Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
  3469. }
  3470. });
  3471. });
  3472. Prism.hooks.add('after-tokenize', function (env) {
  3473. if (env.language !== 'markdown' && env.language !== 'md') {
  3474. return;
  3475. }
  3476. function walkTokens(tokens) {
  3477. if (!tokens || typeof tokens === 'string') {
  3478. return;
  3479. }
  3480. for (var i = 0, l = tokens.length; i < l; i++) {
  3481. var token = tokens[i];
  3482. if (token.type !== 'code') {
  3483. walkTokens(token.content);
  3484. continue;
  3485. }
  3486. /*
  3487. * Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
  3488. * is optional. But the grammar is defined so that there is only one case we have to handle:
  3489. *
  3490. * token.content = [
  3491. * <span class="punctuation">```</span>,
  3492. * <span class="code-language">xxxx</span>,
  3493. * '\n', // exactly one new lines (\r or \n or \r\n)
  3494. * <span class="code-block">...</span>,
  3495. * '\n', // exactly one new lines again
  3496. * <span class="punctuation">```</span>
  3497. * ];
  3498. */
  3499. var codeLang = token.content[1];
  3500. var codeBlock = token.content[3];
  3501. if (codeLang && codeBlock &&
  3502. codeLang.type === 'code-language' && codeBlock.type === 'code-block' &&
  3503. typeof codeLang.content === 'string') {
  3504. // this might be a language that Prism does not support
  3505. // do some replacements to support C++, C#, and F#
  3506. var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp');
  3507. // only use the first word
  3508. lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase();
  3509. var alias = 'language-' + lang;
  3510. // add alias
  3511. if (!codeBlock.alias) {
  3512. codeBlock.alias = [alias];
  3513. } else if (typeof codeBlock.alias === 'string') {
  3514. codeBlock.alias = [codeBlock.alias, alias];
  3515. } else {
  3516. codeBlock.alias.push(alias);
  3517. }
  3518. }
  3519. }
  3520. }
  3521. walkTokens(env.tokens);
  3522. });
  3523. Prism.hooks.add('wrap', function (env) {
  3524. if (env.type !== 'code-block') {
  3525. return;
  3526. }
  3527. var codeLang = '';
  3528. for (var i = 0, l = env.classes.length; i < l; i++) {
  3529. var cls = env.classes[i];
  3530. var match = /language-(.+)/.exec(cls);
  3531. if (match) {
  3532. codeLang = match[1];
  3533. break;
  3534. }
  3535. }
  3536. var grammar = Prism.languages[codeLang];
  3537. if (!grammar) {
  3538. if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) {
  3539. var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16);
  3540. env.attributes['id'] = id;
  3541. Prism.plugins.autoloader.loadLanguages(codeLang, function () {
  3542. var ele = document.getElementById(id);
  3543. if (ele) {
  3544. ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
  3545. }
  3546. });
  3547. }
  3548. } else {
  3549. env.content = Prism.highlight(textContent(env.content), grammar, codeLang);
  3550. }
  3551. });
  3552. var tagPattern = RegExp(Prism.languages.markup.tag.pattern.source, 'gi');
  3553. /**
  3554. * A list of known entity names.
  3555. *
  3556. * This will always be incomplete to save space. The current list is the one used by lowdash's unescape function.
  3557. *
  3558. * @see {@link https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/unescape.js#L2}
  3559. */
  3560. var KNOWN_ENTITY_NAMES = {
  3561. 'amp': '&',
  3562. 'lt': '<',
  3563. 'gt': '>',
  3564. 'quot': '"',
  3565. };
  3566. // IE 11 doesn't support `String.fromCodePoint`
  3567. var fromCodePoint = String.fromCodePoint || String.fromCharCode;
  3568. /**
  3569. * Returns the text content of a given HTML source code string.
  3570. *
  3571. * @param {string} html
  3572. * @returns {string}
  3573. */
  3574. function textContent(html) {
  3575. // remove all tags
  3576. var text = html.replace(tagPattern, '');
  3577. // decode known entities
  3578. text = text.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi, function (m, code) {
  3579. code = code.toLowerCase();
  3580. if (code[0] === '#') {
  3581. var value;
  3582. if (code[1] === 'x') {
  3583. value = parseInt(code.slice(2), 16);
  3584. } else {
  3585. value = Number(code.slice(1));
  3586. }
  3587. return fromCodePoint(value);
  3588. } else {
  3589. var known = KNOWN_ENTITY_NAMES[code];
  3590. if (known) {
  3591. return known;
  3592. }
  3593. // unable to decode
  3594. return m;
  3595. }
  3596. });
  3597. return text;
  3598. }
  3599. Prism.languages.md = Prism.languages.markdown;
  3600. }(Prism));
  3601. Prism.languages.matlab = {
  3602. 'comment': [
  3603. /%\{[\s\S]*?\}%/,
  3604. /%.+/
  3605. ],
  3606. 'string': {
  3607. pattern: /\B'(?:''|[^'\r\n])*'/,
  3608. greedy: true
  3609. },
  3610. // FIXME We could handle imaginary numbers as a whole
  3611. 'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[eE][+-]?\d+)?(?:[ij])?|\b[ij]\b/,
  3612. 'keyword': /\b(?:NaN|break|case|catch|continue|else|elseif|end|for|function|if|inf|otherwise|parfor|pause|pi|return|switch|try|while)\b/,
  3613. 'function': /\b(?!\d)\w+(?=\s*\()/,
  3614. 'operator': /\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,
  3615. 'punctuation': /\.{3}|[.,;\[\](){}!]/
  3616. };
  3617. (function (Prism) {
  3618. var variable = /\$(?:\w[a-z\d]*(?:_[^\x00-\x1F\s"'\\()$]*)?|\{[^}\s"'\\]+\})/i;
  3619. Prism.languages.nginx = {
  3620. 'comment': {
  3621. pattern: /(^|[\s{};])#.*/,
  3622. lookbehind: true,
  3623. greedy: true
  3624. },
  3625. 'directive': {
  3626. pattern: /(^|\s)\w(?:[^;{}"'\\\s]|\\.|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\s+(?:#.*(?!.)|(?![#\s])))*?(?=\s*[;{])/,
  3627. lookbehind: true,
  3628. greedy: true,
  3629. inside: {
  3630. 'string': {
  3631. pattern: /((?:^|[^\\])(?:\\\\)*)(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/,
  3632. lookbehind: true,
  3633. greedy: true,
  3634. inside: {
  3635. 'escape': {
  3636. pattern: /\\["'\\nrt]/,
  3637. alias: 'entity'
  3638. },
  3639. 'variable': variable
  3640. }
  3641. },
  3642. 'comment': {
  3643. pattern: /(\s)#.*/,
  3644. lookbehind: true,
  3645. greedy: true
  3646. },
  3647. 'keyword': {
  3648. pattern: /^\S+/,
  3649. greedy: true
  3650. },
  3651. // other patterns
  3652. 'boolean': {
  3653. pattern: /(\s)(?:off|on)(?!\S)/,
  3654. lookbehind: true
  3655. },
  3656. 'number': {
  3657. pattern: /(\s)\d+[a-z]*(?!\S)/i,
  3658. lookbehind: true
  3659. },
  3660. 'variable': variable
  3661. }
  3662. },
  3663. 'punctuation': /[{};]/
  3664. };
  3665. }(Prism));
  3666. Prism.languages.nim = {
  3667. 'comment': {
  3668. pattern: /#.*/,
  3669. greedy: true
  3670. },
  3671. 'string': {
  3672. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  3673. pattern: /(?:\b(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")/,
  3674. greedy: true
  3675. },
  3676. 'char': {
  3677. // Character literals are handled specifically to prevent issues with numeric type suffixes
  3678. pattern: /'(?:\\(?:\d+|x[\da-fA-F]{0,2}|.)|[^'])'/,
  3679. greedy: true
  3680. },
  3681. 'function': {
  3682. pattern: /(?:(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  3683. greedy: true,
  3684. inside: {
  3685. 'operator': /\*$/
  3686. }
  3687. },
  3688. // We don't want to highlight operators (and anything really) inside backticks
  3689. 'identifier': {
  3690. pattern: /`[^`\r\n]+`/,
  3691. greedy: true,
  3692. inside: {
  3693. 'punctuation': /`/
  3694. }
  3695. },
  3696. // The negative look ahead prevents wrong highlighting of the .. operator
  3697. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  3698. 'keyword': /\b(?:addr|as|asm|atomic|bind|block|break|case|cast|concept|const|continue|converter|defer|discard|distinct|do|elif|else|end|enum|except|export|finally|for|from|func|generic|if|import|include|interface|iterator|let|macro|method|mixin|nil|object|out|proc|ptr|raise|ref|return|static|template|try|tuple|type|using|var|when|while|with|without|yield)\b/,
  3699. 'operator': {
  3700. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  3701. // but allow the slice operator .. to take precedence over them
  3702. // One can define his own operators in Nim so all combination of operators might be an operator.
  3703. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|in|is|isnot|mod|not|notin|of|or|shl|shr|xor)\b)/m,
  3704. lookbehind: true
  3705. },
  3706. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  3707. };
  3708. Prism.languages.nix = {
  3709. 'comment': {
  3710. pattern: /\/\*[\s\S]*?\*\/|#.*/,
  3711. greedy: true
  3712. },
  3713. 'string': {
  3714. pattern: /"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,
  3715. greedy: true,
  3716. inside: {
  3717. 'interpolation': {
  3718. // The lookbehind ensures the ${} is not preceded by \ or ''
  3719. pattern: /(^|(?:^|(?!'').)[^\\])\$\{(?:[^{}]|\{[^}]*\})*\}/,
  3720. lookbehind: true,
  3721. inside: null // see below
  3722. }
  3723. }
  3724. },
  3725. 'url': [
  3726. /\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,
  3727. {
  3728. pattern: /([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,
  3729. lookbehind: true
  3730. }
  3731. ],
  3732. 'antiquotation': {
  3733. pattern: /\$(?=\{)/,
  3734. alias: 'important'
  3735. },
  3736. 'number': /\b\d+\b/,
  3737. 'keyword': /\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,
  3738. 'function': /\b(?:abort|add|all|any|attrNames|attrValues|baseNameOf|compareVersions|concatLists|currentSystem|deepSeq|derivation|dirOf|div|elem(?:At)?|fetch(?:Tarball|url)|filter(?:Source)?|fromJSON|genList|getAttr|getEnv|hasAttr|hashString|head|import|intersectAttrs|is(?:Attrs|Bool|Function|Int|List|Null|String)|length|lessThan|listToAttrs|map|mul|parseDrvName|pathExists|read(?:Dir|File)|removeAttrs|replaceStrings|seq|sort|stringLength|sub(?:string)?|tail|throw|to(?:File|JSON|Path|String|XML)|trace|typeOf)\b|\bfoldl'\B/,
  3739. 'boolean': /\b(?:false|true)\b/,
  3740. 'operator': /[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,
  3741. 'punctuation': /[{}()[\].,:;]/
  3742. };
  3743. Prism.languages.nix.string.inside.interpolation.inside = Prism.languages.nix;
  3744. // https://ocaml.org/manual/lex.html
  3745. Prism.languages.ocaml = {
  3746. 'comment': {
  3747. pattern: /\(\*[\s\S]*?\*\)/,
  3748. greedy: true
  3749. },
  3750. 'char': {
  3751. pattern: /'(?:[^\\\r\n']|\\(?:.|[ox]?[0-9a-f]{1,3}))'/i,
  3752. greedy: true
  3753. },
  3754. 'string': [
  3755. {
  3756. pattern: /"(?:\\(?:[\s\S]|\r\n)|[^\\\r\n"])*"/,
  3757. greedy: true
  3758. },
  3759. {
  3760. pattern: /\{([a-z_]*)\|[\s\S]*?\|\1\}/,
  3761. greedy: true
  3762. }
  3763. ],
  3764. 'number': [
  3765. // binary and octal
  3766. /\b(?:0b[01][01_]*|0o[0-7][0-7_]*)\b/i,
  3767. // hexadecimal
  3768. /\b0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]*)?(?:p[+-]?\d[\d_]*)?(?!\w)/i,
  3769. // decimal
  3770. /\b\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?\d[\d_]*)?(?!\w)/i,
  3771. ],
  3772. 'directive': {
  3773. pattern: /\B#\w+/,
  3774. alias: 'property'
  3775. },
  3776. 'label': {
  3777. pattern: /\B~\w+/,
  3778. alias: 'property'
  3779. },
  3780. 'type-variable': {
  3781. pattern: /\B'\w+/,
  3782. alias: 'function'
  3783. },
  3784. 'variant': {
  3785. pattern: /`\w+/,
  3786. alias: 'symbol'
  3787. },
  3788. // For the list of keywords and operators,
  3789. // see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
  3790. 'keyword': /\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|nonrec|object|of|open|private|rec|sig|struct|then|to|try|type|val|value|virtual|when|where|while|with)\b/,
  3791. 'boolean': /\b(?:false|true)\b/,
  3792. 'operator-like-punctuation': {
  3793. pattern: /\[[<>|]|[>|]\]|\{<|>\}/,
  3794. alias: 'punctuation'
  3795. },
  3796. // Custom operators are allowed
  3797. 'operator': /\.[.~]|:[=>]|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
  3798. 'punctuation': /;;|::|[(){}\[\].,:;#]|\b_\b/
  3799. };
  3800. (function (Prism) {
  3801. var brackets = /(?:\((?:[^()\\]|\\[\s\S])*\)|\{(?:[^{}\\]|\\[\s\S])*\}|\[(?:[^[\]\\]|\\[\s\S])*\]|<(?:[^<>\\]|\\[\s\S])*>)/.source;
  3802. Prism.languages.perl = {
  3803. 'comment': [
  3804. {
  3805. // POD
  3806. pattern: /(^\s*)=\w[\s\S]*?=cut.*/m,
  3807. lookbehind: true,
  3808. greedy: true
  3809. },
  3810. {
  3811. pattern: /(^|[^\\$])#.*/,
  3812. lookbehind: true,
  3813. greedy: true
  3814. }
  3815. ],
  3816. // TODO Could be nice to handle Heredoc too.
  3817. 'string': [
  3818. {
  3819. pattern: RegExp(
  3820. /\b(?:q|qq|qw|qx)(?![a-zA-Z0-9])\s*/.source +
  3821. '(?:' +
  3822. [
  3823. // q/.../
  3824. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  3825. // q a...a
  3826. // eslint-disable-next-line regexp/strict
  3827. /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3828. // q(...)
  3829. // q{...}
  3830. // q[...]
  3831. // q<...>
  3832. brackets,
  3833. ].join('|') +
  3834. ')'
  3835. ),
  3836. greedy: true
  3837. },
  3838. // "...", `...`
  3839. {
  3840. pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  3841. greedy: true
  3842. },
  3843. // '...'
  3844. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  3845. {
  3846. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  3847. greedy: true
  3848. }
  3849. ],
  3850. 'regex': [
  3851. {
  3852. pattern: RegExp(
  3853. /\b(?:m|qr)(?![a-zA-Z0-9])\s*/.source +
  3854. '(?:' +
  3855. [
  3856. // m/.../
  3857. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  3858. // m a...a
  3859. // eslint-disable-next-line regexp/strict
  3860. /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3861. // m(...)
  3862. // m{...}
  3863. // m[...]
  3864. // m<...>
  3865. brackets,
  3866. ].join('|') +
  3867. ')' +
  3868. /[msixpodualngc]*/.source
  3869. ),
  3870. greedy: true
  3871. },
  3872. // The lookbehinds prevent -s from breaking
  3873. {
  3874. pattern: RegExp(
  3875. /(^|[^-])\b(?:s|tr|y)(?![a-zA-Z0-9])\s*/.source +
  3876. '(?:' +
  3877. [
  3878. // s/.../.../
  3879. // eslint-disable-next-line regexp/strict
  3880. /([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3881. // s a...a...a
  3882. // eslint-disable-next-line regexp/strict
  3883. /([a-zA-Z0-9])(?:(?!\3)[^\\]|\\[\s\S])*\3(?:(?!\3)[^\\]|\\[\s\S])*\3/.source,
  3884. // s(...)(...)
  3885. // s{...}{...}
  3886. // s[...][...]
  3887. // s<...><...>
  3888. // s(...)[...]
  3889. brackets + /\s*/.source + brackets,
  3890. ].join('|') +
  3891. ')' +
  3892. /[msixpodualngcer]*/.source
  3893. ),
  3894. lookbehind: true,
  3895. greedy: true
  3896. },
  3897. // /.../
  3898. // The look-ahead tries to prevent two divisions on
  3899. // the same line from being highlighted as regex.
  3900. // This does not support multi-line regex.
  3901. {
  3902. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|x|xor)\b))/,
  3903. greedy: true
  3904. }
  3905. ],
  3906. // FIXME Not sure about the handling of ::, ', and #
  3907. 'variable': [
  3908. // ${^POSTMATCH}
  3909. /[&*$@%]\{\^[A-Z]+\}/,
  3910. // $^V
  3911. /[&*$@%]\^[A-Z_]/,
  3912. // ${...}
  3913. /[&*$@%]#?(?=\{)/,
  3914. // $foo
  3915. /[&*$@%]#?(?:(?:::)*'?(?!\d)[\w$]+(?![\w$]))+(?:::)*/,
  3916. // $1
  3917. /[&*$@%]\d+/,
  3918. // $_, @_, %!
  3919. // The negative lookahead prevents from breaking the %= operator
  3920. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  3921. ],
  3922. 'filehandle': {
  3923. // <>, <FOO>, _
  3924. pattern: /<(?![<=])\S*?>|\b_\b/,
  3925. alias: 'symbol'
  3926. },
  3927. 'v-string': {
  3928. // v1.2, 1.2.3
  3929. pattern: /v\d+(?:\.\d+)*|\d+(?:\.\d+){2,}/,
  3930. alias: 'string'
  3931. },
  3932. 'function': {
  3933. pattern: /(\bsub[ \t]+)\w+/,
  3934. lookbehind: true
  3935. },
  3936. 'keyword': /\b(?:any|break|continue|default|delete|die|do|else|elsif|eval|for|foreach|given|goto|if|last|local|my|next|our|package|print|redo|require|return|say|state|sub|switch|undef|unless|until|use|when|while)\b/,
  3937. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)\b/,
  3938. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)\b/,
  3939. 'punctuation': /[{}[\];(),:]/
  3940. };
  3941. }(Prism));
  3942. /**
  3943. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  3944. * Modified by Miles Johnson: http://milesj.me
  3945. * Rewritten by Tom Pavelec
  3946. *
  3947. * Supports PHP 5.3 - 8.0
  3948. */
  3949. (function (Prism) {
  3950. var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
  3951. var constant = [
  3952. {
  3953. pattern: /\b(?:false|true)\b/i,
  3954. alias: 'boolean'
  3955. },
  3956. {
  3957. pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
  3958. greedy: true,
  3959. lookbehind: true,
  3960. },
  3961. {
  3962. pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
  3963. greedy: true,
  3964. lookbehind: true,
  3965. },
  3966. /\b(?:null)\b/i,
  3967. /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
  3968. ];
  3969. var number = /\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i;
  3970. var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
  3971. var punctuation = /[{}\[\](),:;]/;
  3972. Prism.languages.php = {
  3973. 'delimiter': {
  3974. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  3975. alias: 'important'
  3976. },
  3977. 'comment': comment,
  3978. 'variable': /\$+(?:\w+\b|(?=\{))/,
  3979. 'package': {
  3980. pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3981. lookbehind: true,
  3982. inside: {
  3983. 'punctuation': /\\/
  3984. }
  3985. },
  3986. 'class-name-definition': {
  3987. pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
  3988. lookbehind: true,
  3989. alias: 'class-name'
  3990. },
  3991. 'function-definition': {
  3992. pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
  3993. lookbehind: true,
  3994. alias: 'function'
  3995. },
  3996. 'keyword': [
  3997. {
  3998. pattern: /(\(\s*)\b(?:array|bool|boolean|float|int|integer|object|string)\b(?=\s*\))/i,
  3999. alias: 'type-casting',
  4000. greedy: true,
  4001. lookbehind: true
  4002. },
  4003. {
  4004. pattern: /([(,?]\s*)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string)\b(?=\s*\$)/i,
  4005. alias: 'type-hint',
  4006. greedy: true,
  4007. lookbehind: true
  4008. },
  4009. {
  4010. pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i,
  4011. alias: 'return-type',
  4012. greedy: true,
  4013. lookbehind: true
  4014. },
  4015. {
  4016. pattern: /\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i,
  4017. alias: 'type-declaration',
  4018. greedy: true
  4019. },
  4020. {
  4021. pattern: /(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i,
  4022. alias: 'type-declaration',
  4023. greedy: true,
  4024. lookbehind: true
  4025. },
  4026. {
  4027. pattern: /\b(?:parent|self|static)(?=\s*::)/i,
  4028. alias: 'static-context',
  4029. greedy: true
  4030. },
  4031. {
  4032. // yield from
  4033. pattern: /(\byield\s+)from\b/i,
  4034. lookbehind: true
  4035. },
  4036. // `class` is always a keyword unlike other keywords
  4037. /\bclass\b/i,
  4038. {
  4039. // https://www.php.net/manual/en/reserved.keywords.php
  4040. //
  4041. // keywords cannot be preceded by "->"
  4042. // the complex lookbehind means `(?<!(?:->|::)\s*)`
  4043. pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|never|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i,
  4044. lookbehind: true
  4045. }
  4046. ],
  4047. 'argument-name': {
  4048. pattern: /([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i,
  4049. lookbehind: true
  4050. },
  4051. 'class-name': [
  4052. {
  4053. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
  4054. greedy: true,
  4055. lookbehind: true
  4056. },
  4057. {
  4058. pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
  4059. greedy: true,
  4060. lookbehind: true
  4061. },
  4062. {
  4063. pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
  4064. greedy: true
  4065. },
  4066. {
  4067. pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
  4068. alias: 'class-name-fully-qualified',
  4069. greedy: true,
  4070. lookbehind: true,
  4071. inside: {
  4072. 'punctuation': /\\/
  4073. }
  4074. },
  4075. {
  4076. pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
  4077. alias: 'class-name-fully-qualified',
  4078. greedy: true,
  4079. inside: {
  4080. 'punctuation': /\\/
  4081. }
  4082. },
  4083. {
  4084. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  4085. alias: 'class-name-fully-qualified',
  4086. greedy: true,
  4087. lookbehind: true,
  4088. inside: {
  4089. 'punctuation': /\\/
  4090. }
  4091. },
  4092. {
  4093. pattern: /\b[a-z_]\w*(?=\s*\$)/i,
  4094. alias: 'type-declaration',
  4095. greedy: true
  4096. },
  4097. {
  4098. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  4099. alias: ['class-name-fully-qualified', 'type-declaration'],
  4100. greedy: true,
  4101. inside: {
  4102. 'punctuation': /\\/
  4103. }
  4104. },
  4105. {
  4106. pattern: /\b[a-z_]\w*(?=\s*::)/i,
  4107. alias: 'static-context',
  4108. greedy: true
  4109. },
  4110. {
  4111. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
  4112. alias: ['class-name-fully-qualified', 'static-context'],
  4113. greedy: true,
  4114. inside: {
  4115. 'punctuation': /\\/
  4116. }
  4117. },
  4118. {
  4119. pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
  4120. alias: 'type-hint',
  4121. greedy: true,
  4122. lookbehind: true
  4123. },
  4124. {
  4125. pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  4126. alias: ['class-name-fully-qualified', 'type-hint'],
  4127. greedy: true,
  4128. lookbehind: true,
  4129. inside: {
  4130. 'punctuation': /\\/
  4131. }
  4132. },
  4133. {
  4134. pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
  4135. alias: 'return-type',
  4136. greedy: true,
  4137. lookbehind: true
  4138. },
  4139. {
  4140. pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  4141. alias: ['class-name-fully-qualified', 'return-type'],
  4142. greedy: true,
  4143. lookbehind: true,
  4144. inside: {
  4145. 'punctuation': /\\/
  4146. }
  4147. }
  4148. ],
  4149. 'constant': constant,
  4150. 'function': {
  4151. pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
  4152. lookbehind: true,
  4153. inside: {
  4154. 'punctuation': /\\/
  4155. }
  4156. },
  4157. 'property': {
  4158. pattern: /(->\s*)\w+/,
  4159. lookbehind: true
  4160. },
  4161. 'number': number,
  4162. 'operator': operator,
  4163. 'punctuation': punctuation
  4164. };
  4165. var string_interpolation = {
  4166. pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
  4167. lookbehind: true,
  4168. inside: Prism.languages.php
  4169. };
  4170. var string = [
  4171. {
  4172. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  4173. alias: 'nowdoc-string',
  4174. greedy: true,
  4175. inside: {
  4176. 'delimiter': {
  4177. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  4178. alias: 'symbol',
  4179. inside: {
  4180. 'punctuation': /^<<<'?|[';]$/
  4181. }
  4182. }
  4183. }
  4184. },
  4185. {
  4186. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  4187. alias: 'heredoc-string',
  4188. greedy: true,
  4189. inside: {
  4190. 'delimiter': {
  4191. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  4192. alias: 'symbol',
  4193. inside: {
  4194. 'punctuation': /^<<<"?|[";]$/
  4195. }
  4196. },
  4197. 'interpolation': string_interpolation
  4198. }
  4199. },
  4200. {
  4201. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  4202. alias: 'backtick-quoted-string',
  4203. greedy: true
  4204. },
  4205. {
  4206. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  4207. alias: 'single-quoted-string',
  4208. greedy: true
  4209. },
  4210. {
  4211. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  4212. alias: 'double-quoted-string',
  4213. greedy: true,
  4214. inside: {
  4215. 'interpolation': string_interpolation
  4216. }
  4217. }
  4218. ];
  4219. Prism.languages.insertBefore('php', 'variable', {
  4220. 'string': string,
  4221. 'attribute': {
  4222. pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,
  4223. greedy: true,
  4224. inside: {
  4225. 'attribute-content': {
  4226. pattern: /^(#\[)[\s\S]+(?=\]$)/,
  4227. lookbehind: true,
  4228. // inside can appear subset of php
  4229. inside: {
  4230. 'comment': comment,
  4231. 'string': string,
  4232. 'attribute-class-name': [
  4233. {
  4234. pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
  4235. alias: 'class-name',
  4236. greedy: true,
  4237. lookbehind: true
  4238. },
  4239. {
  4240. pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
  4241. alias: [
  4242. 'class-name',
  4243. 'class-name-fully-qualified'
  4244. ],
  4245. greedy: true,
  4246. lookbehind: true,
  4247. inside: {
  4248. 'punctuation': /\\/
  4249. }
  4250. }
  4251. ],
  4252. 'constant': constant,
  4253. 'number': number,
  4254. 'operator': operator,
  4255. 'punctuation': punctuation
  4256. }
  4257. },
  4258. 'delimiter': {
  4259. pattern: /^#\[|\]$/,
  4260. alias: 'punctuation'
  4261. }
  4262. }
  4263. },
  4264. });
  4265. Prism.hooks.add('before-tokenize', function (env) {
  4266. if (!/<\?/.test(env.code)) {
  4267. return;
  4268. }
  4269. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g;
  4270. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  4271. });
  4272. Prism.hooks.add('after-tokenize', function (env) {
  4273. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  4274. });
  4275. }(Prism));
  4276. Prism.languages.python = {
  4277. 'comment': {
  4278. pattern: /(^|[^\\])#.*/,
  4279. lookbehind: true,
  4280. greedy: true
  4281. },
  4282. 'string-interpolation': {
  4283. pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  4284. greedy: true,
  4285. inside: {
  4286. 'interpolation': {
  4287. // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
  4288. pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
  4289. lookbehind: true,
  4290. inside: {
  4291. 'format-spec': {
  4292. pattern: /(:)[^:(){}]+(?=\}$)/,
  4293. lookbehind: true
  4294. },
  4295. 'conversion-option': {
  4296. pattern: /![sra](?=[:}]$)/,
  4297. alias: 'punctuation'
  4298. },
  4299. rest: null
  4300. }
  4301. },
  4302. 'string': /[\s\S]+/
  4303. }
  4304. },
  4305. 'triple-quoted-string': {
  4306. pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
  4307. greedy: true,
  4308. alias: 'string'
  4309. },
  4310. 'string': {
  4311. pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  4312. greedy: true
  4313. },
  4314. 'function': {
  4315. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  4316. lookbehind: true
  4317. },
  4318. 'class-name': {
  4319. pattern: /(\bclass\s+)\w+/i,
  4320. lookbehind: true
  4321. },
  4322. 'decorator': {
  4323. pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
  4324. lookbehind: true,
  4325. alias: ['annotation', 'punctuation'],
  4326. inside: {
  4327. 'punctuation': /\./
  4328. }
  4329. },
  4330. 'keyword': /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
  4331. 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
  4332. 'boolean': /\b(?:False|None|True)\b/,
  4333. 'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
  4334. 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  4335. 'punctuation': /[{}[\];(),.:]/
  4336. };
  4337. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  4338. Prism.languages.py = Prism.languages.python;
  4339. (function (Prism) {
  4340. var jsString = /"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*'/.source;
  4341. var jsComment = /\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))*\*\//.source;
  4342. var jsExpr = /(?:[^\\()[\]{}"'/]|<string>|\/(?![*/])|<comment>|\(<expr>*\)|\[<expr>*\]|\{<expr>*\}|\\[\s\S])/
  4343. .source.replace(/<string>/g, function () { return jsString; }).replace(/<comment>/g, function () { return jsComment; });
  4344. // the pattern will blow up, so only a few iterations
  4345. for (var i = 0; i < 2; i++) {
  4346. jsExpr = jsExpr.replace(/<expr>/g, function () { return jsExpr; });
  4347. }
  4348. jsExpr = jsExpr.replace(/<expr>/g, '[^\\s\\S]');
  4349. Prism.languages.qml = {
  4350. 'comment': {
  4351. pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
  4352. greedy: true
  4353. },
  4354. 'javascript-function': {
  4355. pattern: RegExp(/((?:^|;)[ \t]*)function\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*\(<js>*\)\s*\{<js>*\}/.source.replace(/<js>/g, function () { return jsExpr; }), 'm'),
  4356. lookbehind: true,
  4357. greedy: true,
  4358. alias: 'language-javascript',
  4359. inside: Prism.languages.javascript
  4360. },
  4361. 'class-name': {
  4362. pattern: /((?:^|[:;])[ \t]*)(?!\d)\w+(?=[ \t]*\{|[ \t]+on\b)/m,
  4363. lookbehind: true
  4364. },
  4365. 'property': [
  4366. {
  4367. pattern: /((?:^|[;{])[ \t]*)(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  4368. lookbehind: true
  4369. },
  4370. {
  4371. pattern: /((?:^|[;{])[ \t]*)property[ \t]+(?!\d)\w+(?:\.\w+)*[ \t]+(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  4372. lookbehind: true,
  4373. inside: {
  4374. 'keyword': /^property/,
  4375. 'property': /\w+(?:\.\w+)*/
  4376. }
  4377. }
  4378. ],
  4379. 'javascript-expression': {
  4380. pattern: RegExp(/(:[ \t]*)(?![\s;}[])(?:(?!$|[;}])<js>)+/.source.replace(/<js>/g, function () { return jsExpr; }), 'm'),
  4381. lookbehind: true,
  4382. greedy: true,
  4383. alias: 'language-javascript',
  4384. inside: Prism.languages.javascript
  4385. },
  4386. 'string': {
  4387. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  4388. greedy: true
  4389. },
  4390. 'keyword': /\b(?:as|import|on)\b/,
  4391. 'punctuation': /[{}[\]:;,]/
  4392. };
  4393. }(Prism));
  4394. Prism.languages.r = {
  4395. 'comment': /#.*/,
  4396. 'string': {
  4397. pattern: /(['"])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  4398. greedy: true
  4399. },
  4400. 'percent-operator': {
  4401. // Includes user-defined operators
  4402. // and %%, %*%, %/%, %in%, %o%, %x%
  4403. pattern: /%[^%\s]*%/,
  4404. alias: 'operator'
  4405. },
  4406. 'boolean': /\b(?:FALSE|TRUE)\b/,
  4407. 'ellipsis': /\.\.(?:\.|\d+)/,
  4408. 'number': [
  4409. /\b(?:Inf|NaN)\b/,
  4410. /(?:\b0x[\dA-Fa-f]+(?:\.\d*)?|\b\d+(?:\.\d*)?|\B\.\d+)(?:[EePp][+-]?\d+)?[iL]?/
  4411. ],
  4412. 'keyword': /\b(?:NA|NA_character_|NA_complex_|NA_integer_|NA_real_|NULL|break|else|for|function|if|in|next|repeat|while)\b/,
  4413. 'operator': /->?>?|<(?:=|<?-)?|[>=!]=?|::?|&&?|\|\|?|[+*\/^$@~]/,
  4414. 'punctuation': /[(){}\[\],;]/
  4415. };
  4416. (function (Prism) {
  4417. var javascript = Prism.util.clone(Prism.languages.javascript);
  4418. var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
  4419. var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
  4420. var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
  4421. /**
  4422. * @param {string} source
  4423. * @param {string} [flags]
  4424. */
  4425. function re(source, flags) {
  4426. source = source
  4427. .replace(/<S>/g, function () { return space; })
  4428. .replace(/<BRACES>/g, function () { return braces; })
  4429. .replace(/<SPREAD>/g, function () { return spread; });
  4430. return RegExp(source, flags);
  4431. }
  4432. spread = re(spread).source;
  4433. Prism.languages.jsx = Prism.languages.extend('markup', javascript);
  4434. Prism.languages.jsx.tag.pattern = re(
  4435. /<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
  4436. );
  4437. Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/;
  4438. Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/;
  4439. Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
  4440. Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
  4441. Prism.languages.insertBefore('inside', 'attr-name', {
  4442. 'spread': {
  4443. pattern: re(/<SPREAD>/.source),
  4444. inside: Prism.languages.jsx
  4445. }
  4446. }, Prism.languages.jsx.tag);
  4447. Prism.languages.insertBefore('inside', 'special-attr', {
  4448. 'script': {
  4449. // Allow for two levels of nesting
  4450. pattern: re(/=<BRACES>/.source),
  4451. alias: 'language-javascript',
  4452. inside: {
  4453. 'script-punctuation': {
  4454. pattern: /^=(?=\{)/,
  4455. alias: 'punctuation'
  4456. },
  4457. rest: Prism.languages.jsx
  4458. },
  4459. }
  4460. }, Prism.languages.jsx.tag);
  4461. // The following will handle plain text inside tags
  4462. var stringifyToken = function (token) {
  4463. if (!token) {
  4464. return '';
  4465. }
  4466. if (typeof token === 'string') {
  4467. return token;
  4468. }
  4469. if (typeof token.content === 'string') {
  4470. return token.content;
  4471. }
  4472. return token.content.map(stringifyToken).join('');
  4473. };
  4474. var walkTokens = function (tokens) {
  4475. var openedTags = [];
  4476. for (var i = 0; i < tokens.length; i++) {
  4477. var token = tokens[i];
  4478. var notTagNorBrace = false;
  4479. if (typeof token !== 'string') {
  4480. if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
  4481. // We found a tag, now find its kind
  4482. if (token.content[0].content[0].content === '</') {
  4483. // Closing tag
  4484. if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
  4485. // Pop matching opening tag
  4486. openedTags.pop();
  4487. }
  4488. } else {
  4489. if (token.content[token.content.length - 1].content === '/>') {
  4490. // Autoclosed tag, ignore
  4491. } else {
  4492. // Opening tag
  4493. openedTags.push({
  4494. tagName: stringifyToken(token.content[0].content[1]),
  4495. openedBraces: 0
  4496. });
  4497. }
  4498. }
  4499. } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
  4500. // Here we might have entered a JSX context inside a tag
  4501. openedTags[openedTags.length - 1].openedBraces++;
  4502. } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
  4503. // Here we might have left a JSX context inside a tag
  4504. openedTags[openedTags.length - 1].openedBraces--;
  4505. } else {
  4506. notTagNorBrace = true;
  4507. }
  4508. }
  4509. if (notTagNorBrace || typeof token === 'string') {
  4510. if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
  4511. // Here we are inside a tag, and not inside a JSX context.
  4512. // That's plain text: drop any tokens matched.
  4513. var plainText = stringifyToken(token);
  4514. // And merge text with adjacent text
  4515. if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
  4516. plainText += stringifyToken(tokens[i + 1]);
  4517. tokens.splice(i + 1, 1);
  4518. }
  4519. if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
  4520. plainText = stringifyToken(tokens[i - 1]) + plainText;
  4521. tokens.splice(i - 1, 1);
  4522. i--;
  4523. }
  4524. tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
  4525. }
  4526. }
  4527. if (token.content && typeof token.content !== 'string') {
  4528. walkTokens(token.content);
  4529. }
  4530. }
  4531. };
  4532. Prism.hooks.add('after-tokenize', function (env) {
  4533. if (env.language !== 'jsx' && env.language !== 'tsx') {
  4534. return;
  4535. }
  4536. walkTokens(env.tokens);
  4537. });
  4538. }(Prism));
  4539. (function (Prism) {
  4540. var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
  4541. for (var i = 0; i < 2; i++) {
  4542. // support 4 levels of nested comments
  4543. multilineComment = multilineComment.replace(/<self>/g, function () { return multilineComment; });
  4544. }
  4545. multilineComment = multilineComment.replace(/<self>/g, function () { return /[^\s\S]/.source; });
  4546. Prism.languages.rust = {
  4547. 'comment': [
  4548. {
  4549. pattern: RegExp(/(^|[^\\])/.source + multilineComment),
  4550. lookbehind: true,
  4551. greedy: true
  4552. },
  4553. {
  4554. pattern: /(^|[^\\:])\/\/.*/,
  4555. lookbehind: true,
  4556. greedy: true
  4557. }
  4558. ],
  4559. 'string': {
  4560. pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
  4561. greedy: true
  4562. },
  4563. 'char': {
  4564. pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
  4565. greedy: true
  4566. },
  4567. 'attribute': {
  4568. pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
  4569. greedy: true,
  4570. alias: 'attr-name',
  4571. inside: {
  4572. 'string': null // see below
  4573. }
  4574. },
  4575. // Closure params should not be confused with bitwise OR |
  4576. 'closure-params': {
  4577. pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
  4578. lookbehind: true,
  4579. greedy: true,
  4580. inside: {
  4581. 'closure-punctuation': {
  4582. pattern: /^\||\|$/,
  4583. alias: 'punctuation'
  4584. },
  4585. rest: null // see below
  4586. }
  4587. },
  4588. 'lifetime-annotation': {
  4589. pattern: /'\w+/,
  4590. alias: 'symbol'
  4591. },
  4592. 'fragment-specifier': {
  4593. pattern: /(\$\w+:)[a-z]+/,
  4594. lookbehind: true,
  4595. alias: 'punctuation'
  4596. },
  4597. 'variable': /\$\w+/,
  4598. 'function-definition': {
  4599. pattern: /(\bfn\s+)\w+/,
  4600. lookbehind: true,
  4601. alias: 'function'
  4602. },
  4603. 'type-definition': {
  4604. pattern: /(\b(?:enum|struct|trait|type|union)\s+)\w+/,
  4605. lookbehind: true,
  4606. alias: 'class-name'
  4607. },
  4608. 'module-declaration': [
  4609. {
  4610. pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
  4611. lookbehind: true,
  4612. alias: 'namespace'
  4613. },
  4614. {
  4615. pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
  4616. lookbehind: true,
  4617. alias: 'namespace',
  4618. inside: {
  4619. 'punctuation': /::/
  4620. }
  4621. }
  4622. ],
  4623. 'keyword': [
  4624. // https://github.com/rust-lang/reference/blob/master/src/keywords.md
  4625. /\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/,
  4626. // primitives and str
  4627. // https://doc.rust-lang.org/stable/rust-by-example/primitives.html
  4628. /\b(?:bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/
  4629. ],
  4630. // functions can technically start with an upper-case letter, but this will introduce a lot of false positives
  4631. // and Rust's naming conventions recommend snake_case anyway.
  4632. // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
  4633. 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
  4634. 'macro': {
  4635. pattern: /\b\w+!/,
  4636. alias: 'property'
  4637. },
  4638. 'constant': /\b[A-Z_][A-Z_\d]+\b/,
  4639. 'class-name': /\b[A-Z]\w*\b/,
  4640. 'namespace': {
  4641. pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
  4642. inside: {
  4643. 'punctuation': /::/
  4644. }
  4645. },
  4646. // Hex, oct, bin, dec numbers with visual separators and type suffix
  4647. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/,
  4648. 'boolean': /\b(?:false|true)\b/,
  4649. 'punctuation': /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
  4650. 'operator': /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
  4651. };
  4652. Prism.languages.rust['closure-params'].inside.rest = Prism.languages.rust;
  4653. Prism.languages.rust['attribute'].inside['string'] = Prism.languages.rust['string'];
  4654. }(Prism));
  4655. Prism.languages.scss = Prism.languages.extend('css', {
  4656. 'comment': {
  4657. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  4658. lookbehind: true
  4659. },
  4660. 'atrule': {
  4661. pattern: /@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,
  4662. inside: {
  4663. 'rule': /@[\w-]+/
  4664. // See rest below
  4665. }
  4666. },
  4667. // url, compassified
  4668. 'url': /(?:[-a-z]+-)?url(?=\()/i,
  4669. // CSS selector regex is not appropriate for Sass
  4670. // since there can be lot more things (var, @ directive, nesting..)
  4671. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  4672. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  4673. // 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
  4674. // can "pass" as a selector- e.g: proper#{$erty})
  4675. // this one was hard to do, so please be careful if you edit this one :)
  4676. 'selector': {
  4677. // Initial look-ahead is used to prevent matching of blank selectors
  4678. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,
  4679. inside: {
  4680. 'parent': {
  4681. pattern: /&/,
  4682. alias: 'important'
  4683. },
  4684. 'placeholder': /%[-\w]+/,
  4685. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4686. }
  4687. },
  4688. 'property': {
  4689. pattern: /(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,
  4690. inside: {
  4691. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4692. }
  4693. }
  4694. });
  4695. Prism.languages.insertBefore('scss', 'atrule', {
  4696. 'keyword': [
  4697. /@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,
  4698. {
  4699. pattern: /( )(?:from|through)(?= )/,
  4700. lookbehind: true
  4701. }
  4702. ]
  4703. });
  4704. Prism.languages.insertBefore('scss', 'important', {
  4705. // var and interpolated vars
  4706. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4707. });
  4708. Prism.languages.insertBefore('scss', 'function', {
  4709. 'module-modifier': {
  4710. pattern: /\b(?:as|hide|show|with)\b/i,
  4711. alias: 'keyword'
  4712. },
  4713. 'placeholder': {
  4714. pattern: /%[-\w]+/,
  4715. alias: 'selector'
  4716. },
  4717. 'statement': {
  4718. pattern: /\B!(?:default|optional)\b/i,
  4719. alias: 'keyword'
  4720. },
  4721. 'boolean': /\b(?:false|true)\b/,
  4722. 'null': {
  4723. pattern: /\bnull\b/,
  4724. alias: 'keyword'
  4725. },
  4726. 'operator': {
  4727. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,
  4728. lookbehind: true
  4729. }
  4730. });
  4731. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;
  4732. Prism.languages.scala = Prism.languages.extend('java', {
  4733. 'triple-quoted-string': {
  4734. pattern: /"""[\s\S]*?"""/,
  4735. greedy: true,
  4736. alias: 'string'
  4737. },
  4738. 'string': {
  4739. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  4740. greedy: true
  4741. },
  4742. 'keyword': /<-|=>|\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/,
  4743. 'number': /\b0x(?:[\da-f]*\.)?[\da-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e\d+)?[dfl]?/i,
  4744. 'builtin': /\b(?:Any|AnyRef|AnyVal|Boolean|Byte|Char|Double|Float|Int|Long|Nothing|Short|String|Unit)\b/,
  4745. 'symbol': /'[^\d\s\\]\w*/
  4746. });
  4747. Prism.languages.insertBefore('scala', 'triple-quoted-string', {
  4748. 'string-interpolation': {
  4749. pattern: /\b[a-z]\w*(?:"""(?:[^$]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*?"""|"(?:[^$"\r\n]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*")/i,
  4750. greedy: true,
  4751. inside: {
  4752. 'id': {
  4753. pattern: /^\w+/,
  4754. greedy: true,
  4755. alias: 'function'
  4756. },
  4757. 'escape': {
  4758. pattern: /\\\$"|\$[$"]/,
  4759. greedy: true,
  4760. alias: 'symbol'
  4761. },
  4762. 'interpolation': {
  4763. pattern: /\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
  4764. greedy: true,
  4765. inside: {
  4766. 'punctuation': /^\$\{?|\}$/,
  4767. 'expression': {
  4768. pattern: /[\s\S]+/,
  4769. inside: Prism.languages.scala
  4770. }
  4771. }
  4772. },
  4773. 'string': /[\s\S]+/
  4774. }
  4775. }
  4776. });
  4777. delete Prism.languages.scala['class-name'];
  4778. delete Prism.languages.scala['function'];
  4779. delete Prism.languages.scala['constant'];
  4780. (function (Prism) {
  4781. // CAREFUL!
  4782. // The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
  4783. var strings = [
  4784. // normal string
  4785. /"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/.source,
  4786. /'[^']*'/.source,
  4787. /\$'(?:[^'\\]|\\[\s\S])*'/.source,
  4788. // here doc
  4789. // 2 capturing groups
  4790. /<<-?\s*(["']?)(\w+)\1\s[\s\S]*?[\r\n]\2/.source
  4791. ].join('|');
  4792. Prism.languages['shell-session'] = {
  4793. 'command': {
  4794. pattern: RegExp(
  4795. // user info
  4796. /^/.source +
  4797. '(?:' +
  4798. (
  4799. // <user> ":" ( <path> )?
  4800. /[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+(?::[^\0-\x1F$#%*?"<>:;|]+)?/.source +
  4801. '|' +
  4802. // <path>
  4803. // Since the path pattern is quite general, we will require it to start with a special character to
  4804. // prevent false positives.
  4805. /[/~.][^\0-\x1F$#%*?"<>@:;|]*/.source
  4806. ) +
  4807. ')?' +
  4808. // shell symbol
  4809. /[$#%](?=\s)/.source +
  4810. // bash command
  4811. /(?:[^\\\r\n \t'"<$]|[ \t](?:(?!#)|#.*$)|\\(?:[^\r]|\r\n?)|\$(?!')|<(?!<)|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
  4812. 'm'
  4813. ),
  4814. greedy: true,
  4815. inside: {
  4816. 'info': {
  4817. // foo@bar:~/files$ exit
  4818. // foo@bar$ exit
  4819. // ~/files$ exit
  4820. pattern: /^[^#$%]+/,
  4821. alias: 'punctuation',
  4822. inside: {
  4823. 'user': /^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,
  4824. 'punctuation': /:/,
  4825. 'path': /[\s\S]+/
  4826. }
  4827. },
  4828. 'bash': {
  4829. pattern: /(^[$#%]\s*)\S[\s\S]*/,
  4830. lookbehind: true,
  4831. alias: 'language-bash',
  4832. inside: Prism.languages.bash
  4833. },
  4834. 'shell-symbol': {
  4835. pattern: /^[$#%]/,
  4836. alias: 'important'
  4837. }
  4838. }
  4839. },
  4840. 'output': /.(?:.*(?:[\r\n]|.$))*/
  4841. };
  4842. Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
  4843. }(Prism));
  4844. Prism.languages.sql = {
  4845. 'comment': {
  4846. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  4847. lookbehind: true
  4848. },
  4849. 'variable': [
  4850. {
  4851. pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
  4852. greedy: true
  4853. },
  4854. /@[\w.$]+/
  4855. ],
  4856. 'string': {
  4857. pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
  4858. greedy: true,
  4859. lookbehind: true
  4860. },
  4861. 'identifier': {
  4862. pattern: /(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,
  4863. greedy: true,
  4864. lookbehind: true,
  4865. inside: {
  4866. 'punctuation': /^`|`$/
  4867. }
  4868. },
  4869. 'function': /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i, // Should we highlight user defined functions too?
  4870. 'keyword': /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:COL|_INSERT)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:ING|S)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
  4871. 'boolean': /\b(?:FALSE|NULL|TRUE)\b/i,
  4872. 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
  4873. 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  4874. 'punctuation': /[;[\]()`,.]/
  4875. };
  4876. (function (Prism) {
  4877. Prism.languages.typescript = Prism.languages.extend('javascript', {
  4878. 'class-name': {
  4879. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
  4880. lookbehind: true,
  4881. greedy: true,
  4882. inside: null // see below
  4883. },
  4884. 'builtin': /\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/,
  4885. });
  4886. // The keywords TypeScript adds to JavaScript
  4887. Prism.languages.typescript.keyword.push(
  4888. /\b(?:abstract|declare|is|keyof|readonly|require)\b/,
  4889. // keywords that have to be followed by an identifier
  4890. /\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
  4891. // This is for `import type *, {}`
  4892. /\btype\b(?=\s*(?:[\{*]|$))/
  4893. );
  4894. // doesn't work with TS because TS is too complex
  4895. delete Prism.languages.typescript['parameter'];
  4896. delete Prism.languages.typescript['literal-property'];
  4897. // a version of typescript specifically for highlighting types
  4898. var typeInside = Prism.languages.extend('typescript', {});
  4899. delete typeInside['class-name'];
  4900. Prism.languages.typescript['class-name'].inside = typeInside;
  4901. Prism.languages.insertBefore('typescript', 'function', {
  4902. 'decorator': {
  4903. pattern: /@[$\w\xA0-\uFFFF]+/,
  4904. inside: {
  4905. 'at': {
  4906. pattern: /^@/,
  4907. alias: 'operator'
  4908. },
  4909. 'function': /^[\s\S]+/
  4910. }
  4911. },
  4912. 'generic-function': {
  4913. // e.g. foo<T extends "bar" | "baz">( ...
  4914. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
  4915. greedy: true,
  4916. inside: {
  4917. 'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
  4918. 'generic': {
  4919. pattern: /<[\s\S]+/, // everything after the first <
  4920. alias: 'class-name',
  4921. inside: typeInside
  4922. }
  4923. }
  4924. }
  4925. });
  4926. Prism.languages.ts = Prism.languages.typescript;
  4927. }(Prism));
  4928. (function (Prism) {
  4929. // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
  4930. // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
  4931. var anchorOrAlias = /[*&][^\s[\]{},]+/;
  4932. // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
  4933. var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
  4934. // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
  4935. var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
  4936. + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
  4937. // https://yaml.org/spec/1.2/spec.html#ns-plain(n,c)
  4938. // This is a simplified version that doesn't support "#" and multiline keys
  4939. // All these long scarry character classes are simplified versions of YAML's characters
  4940. var plainKey = /(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*/.source
  4941. .replace(/<PLAIN>/g, function () { return /[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source; });
  4942. var string = /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;
  4943. /**
  4944. *
  4945. * @param {string} value
  4946. * @param {string} [flags]
  4947. * @returns {RegExp}
  4948. */
  4949. function createValuePattern(value, flags) {
  4950. flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
  4951. var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source
  4952. .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
  4953. return RegExp(pattern, flags);
  4954. }
  4955. Prism.languages.yaml = {
  4956. 'scalar': {
  4957. pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source
  4958. .replace(/<<prop>>/g, function () { return properties; })),
  4959. lookbehind: true,
  4960. alias: 'string'
  4961. },
  4962. 'comment': /#.*/,
  4963. 'key': {
  4964. pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\s*:\s)/.source
  4965. .replace(/<<prop>>/g, function () { return properties; })
  4966. .replace(/<<key>>/g, function () { return '(?:' + plainKey + '|' + string + ')'; })),
  4967. lookbehind: true,
  4968. greedy: true,
  4969. alias: 'atrule'
  4970. },
  4971. 'directive': {
  4972. pattern: /(^[ \t]*)%.+/m,
  4973. lookbehind: true,
  4974. alias: 'important'
  4975. },
  4976. 'datetime': {
  4977. pattern: createValuePattern(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?))?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),
  4978. lookbehind: true,
  4979. alias: 'number'
  4980. },
  4981. 'boolean': {
  4982. pattern: createValuePattern(/false|true/.source, 'i'),
  4983. lookbehind: true,
  4984. alias: 'important'
  4985. },
  4986. 'null': {
  4987. pattern: createValuePattern(/null|~/.source, 'i'),
  4988. lookbehind: true,
  4989. alias: 'important'
  4990. },
  4991. 'string': {
  4992. pattern: createValuePattern(string),
  4993. lookbehind: true,
  4994. greedy: true
  4995. },
  4996. 'number': {
  4997. pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
  4998. lookbehind: true
  4999. },
  5000. 'tag': tag,
  5001. 'important': anchorOrAlias,
  5002. 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
  5003. };
  5004. Prism.languages.yml = Prism.languages.yaml;
  5005. }(Prism));
  5006. (function (Prism) {
  5007. function literal(str) {
  5008. return function () { return str; };
  5009. }
  5010. var keyword = /\b(?:align|allowzero|and|anyframe|anytype|asm|async|await|break|cancel|catch|comptime|const|continue|defer|else|enum|errdefer|error|export|extern|fn|for|if|inline|linksection|nakedcc|noalias|nosuspend|null|or|orelse|packed|promise|pub|resume|return|stdcallcc|struct|suspend|switch|test|threadlocal|try|undefined|union|unreachable|usingnamespace|var|volatile|while)\b/;
  5011. var IDENTIFIER = '\\b(?!' + keyword.source + ')(?!\\d)\\w+\\b';
  5012. var ALIGN = /align\s*\((?:[^()]|\([^()]*\))*\)/.source;
  5013. var PREFIX_TYPE_OP = /(?:\?|\bpromise->|(?:\[[^[\]]*\]|\*(?!\*)|\*\*)(?:\s*<ALIGN>|\s*const\b|\s*volatile\b|\s*allowzero\b)*)/.source.replace(/<ALIGN>/g, literal(ALIGN));
  5014. var SUFFIX_EXPR = /(?:\bpromise\b|(?:\berror\.)?<ID>(?:\.<ID>)*(?!\s+<ID>))/.source.replace(/<ID>/g, literal(IDENTIFIER));
  5015. var TYPE = '(?!\\s)(?:!?\\s*(?:' + PREFIX_TYPE_OP + '\\s*)*' + SUFFIX_EXPR + ')+';
  5016. /*
  5017. * A simplified grammar for Zig compile time type literals:
  5018. *
  5019. * TypeExpr = ( "!"? PREFIX_TYPE_OP* SUFFIX_EXPR )+
  5020. *
  5021. * SUFFIX_EXPR = ( \b "promise" \b | ( \b "error" "." )? IDENTIFIER ( "." IDENTIFIER )* (?! \s+ IDENTIFIER ) )
  5022. *
  5023. * PREFIX_TYPE_OP = "?"
  5024. * | \b "promise" "->"
  5025. * | ( "[" [^\[\]]* "]" | "*" | "**" ) ( ALIGN | "const" \b | "volatile" \b | "allowzero" \b )*
  5026. *
  5027. * ALIGN = "align" "(" ( [^()] | "(" [^()]* ")" )* ")"
  5028. *
  5029. * IDENTIFIER = \b (?! KEYWORD ) [a-zA-Z_] \w* \b
  5030. *
  5031. */
  5032. Prism.languages.zig = {
  5033. 'comment': [
  5034. {
  5035. pattern: /\/\/[/!].*/,
  5036. alias: 'doc-comment'
  5037. },
  5038. /\/{2}.*/
  5039. ],
  5040. 'string': [
  5041. {
  5042. // "string" and c"string"
  5043. pattern: /(^|[^\\@])c?"(?:[^"\\\r\n]|\\.)*"/,
  5044. lookbehind: true,
  5045. greedy: true
  5046. },
  5047. {
  5048. // multiline strings and c-strings
  5049. pattern: /([\r\n])([ \t]+c?\\{2}).*(?:(?:\r\n?|\n)\2.*)*/,
  5050. lookbehind: true,
  5051. greedy: true
  5052. }
  5053. ],
  5054. 'char': {
  5055. // characters 'a', '\n', '\xFF', '\u{10FFFF}'
  5056. pattern: /(^|[^\\])'(?:[^'\\\r\n]|[\uD800-\uDFFF]{2}|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
  5057. lookbehind: true,
  5058. greedy: true
  5059. },
  5060. 'builtin': /\B@(?!\d)\w+(?=\s*\()/,
  5061. 'label': {
  5062. pattern: /(\b(?:break|continue)\s*:\s*)\w+\b|\b(?!\d)\w+\b(?=\s*:\s*(?:\{|while\b))/,
  5063. lookbehind: true
  5064. },
  5065. 'class-name': [
  5066. // const Foo = struct {};
  5067. /\b(?!\d)\w+(?=\s*=\s*(?:(?:extern|packed)\s+)?(?:enum|struct|union)\s*[({])/,
  5068. {
  5069. // const x: i32 = 9;
  5070. // var x: Bar;
  5071. // fn foo(x: bool, y: f32) void {}
  5072. pattern: RegExp(/(:\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?[=;,)])|<TYPE>(?=\s*(?:<ALIGN>\s*)?\{)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
  5073. lookbehind: true,
  5074. inside: null // see below
  5075. },
  5076. {
  5077. // extern fn foo(x: f64) f64; (optional alignment)
  5078. pattern: RegExp(/(\)\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?;)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
  5079. lookbehind: true,
  5080. inside: null // see below
  5081. }
  5082. ],
  5083. 'builtin-type': {
  5084. pattern: /\b(?:anyerror|bool|c_u?(?:int|long|longlong|short)|c_longdouble|c_void|comptime_(?:float|int)|f(?:16|32|64|128)|[iu](?:8|16|32|64|128|size)|noreturn|type|void)\b/,
  5085. alias: 'keyword'
  5086. },
  5087. 'keyword': keyword,
  5088. 'function': /\b(?!\d)\w+(?=\s*\()/,
  5089. 'number': /\b(?:0b[01]+|0o[0-7]+|0x[a-fA-F\d]+(?:\.[a-fA-F\d]*)?(?:[pP][+-]?[a-fA-F\d]+)?|\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)\b/,
  5090. 'boolean': /\b(?:false|true)\b/,
  5091. 'operator': /\.[*?]|\.{2,3}|[-=]>|\*\*|\+\+|\|\||(?:<<|>>|[-+*]%|[-+*/%^&|<>!=])=?|[?~]/,
  5092. 'punctuation': /[.:,;(){}[\]]/
  5093. };
  5094. Prism.languages.zig['class-name'].forEach(function (obj) {
  5095. if (obj.inside === null) {
  5096. obj.inside = Prism.languages.zig;
  5097. }
  5098. });
  5099. }(Prism));