prism.js 180 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698
  1. /* PrismJS 1.30.0
  2. https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+cmake+coffeescript+crystal+d+dart+diff+django+dot+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+tcl+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 (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 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. // https://www.graphviz.org/doc/info/lang.html
  2658. (function (Prism) {
  2659. var ID = '(?:' + [
  2660. // an identifier
  2661. /[a-zA-Z_\x80-\uFFFF][\w\x80-\uFFFF]*/.source,
  2662. // a number
  2663. /-?(?:\.\d+|\d+(?:\.\d*)?)/.source,
  2664. // a double-quoted string
  2665. /"[^"\\]*(?:\\[\s\S][^"\\]*)*"/.source,
  2666. // HTML-like string
  2667. /<(?:[^<>]|(?!<!--)<(?:[^<>"']|"[^"]*"|'[^']*')+>|<!--(?:[^-]|-(?!->))*-->)*>/.source
  2668. ].join('|') + ')';
  2669. var IDInside = {
  2670. 'markup': {
  2671. pattern: /(^<)[\s\S]+(?=>$)/,
  2672. lookbehind: true,
  2673. alias: ['language-markup', 'language-html', 'language-xml'],
  2674. inside: Prism.languages.markup
  2675. }
  2676. };
  2677. /**
  2678. * @param {string} source
  2679. * @param {string} flags
  2680. * @returns {RegExp}
  2681. */
  2682. function withID(source, flags) {
  2683. return RegExp(source.replace(/<ID>/g, function () { return ID; }), flags);
  2684. }
  2685. Prism.languages.dot = {
  2686. 'comment': {
  2687. pattern: /\/\/.*|\/\*[\s\S]*?\*\/|^#.*/m,
  2688. greedy: true
  2689. },
  2690. 'graph-name': {
  2691. pattern: withID(/(\b(?:digraph|graph|subgraph)[ \t\r\n]+)<ID>/.source, 'i'),
  2692. lookbehind: true,
  2693. greedy: true,
  2694. alias: 'class-name',
  2695. inside: IDInside
  2696. },
  2697. 'attr-value': {
  2698. pattern: withID(/(=[ \t\r\n]*)<ID>/.source),
  2699. lookbehind: true,
  2700. greedy: true,
  2701. inside: IDInside
  2702. },
  2703. 'attr-name': {
  2704. pattern: withID(/([\[;, \t\r\n])<ID>(?=[ \t\r\n]*=)/.source),
  2705. lookbehind: true,
  2706. greedy: true,
  2707. inside: IDInside
  2708. },
  2709. 'keyword': /\b(?:digraph|edge|graph|node|strict|subgraph)\b/i,
  2710. 'compass-point': {
  2711. pattern: /(:[ \t\r\n]*)(?:[ewc_]|[ns][ew]?)(?![\w\x80-\uFFFF])/,
  2712. lookbehind: true,
  2713. alias: 'builtin'
  2714. },
  2715. 'node': {
  2716. pattern: withID(/(^|[^-.\w\x80-\uFFFF\\])<ID>/.source),
  2717. lookbehind: true,
  2718. greedy: true,
  2719. inside: IDInside
  2720. },
  2721. 'operator': /[=:]|-[->]/,
  2722. 'punctuation': /[\[\]{};,]/
  2723. };
  2724. Prism.languages.gv = Prism.languages.dot;
  2725. }(Prism));
  2726. Prism.languages.elixir = {
  2727. 'doc': {
  2728. pattern: /@(?:doc|moduledoc)\s+(?:("""|''')[\s\S]*?\1|("|')(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2)/,
  2729. inside: {
  2730. 'attribute': /^@\w+/,
  2731. 'string': /['"][\s\S]+/
  2732. }
  2733. },
  2734. 'comment': {
  2735. pattern: /#.*/,
  2736. greedy: true
  2737. },
  2738. // ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  2739. 'regex': {
  2740. pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
  2741. greedy: true
  2742. },
  2743. 'string': [
  2744. {
  2745. // ~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>
  2746. pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|#(?!\{)|[^#\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/,
  2747. greedy: true,
  2748. inside: {
  2749. // See interpolation below
  2750. }
  2751. },
  2752. {
  2753. pattern: /("""|''')[\s\S]*?\1/,
  2754. greedy: true,
  2755. inside: {
  2756. // See interpolation below
  2757. }
  2758. },
  2759. {
  2760. // Multi-line strings are allowed
  2761. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2762. greedy: true,
  2763. inside: {
  2764. // See interpolation below
  2765. }
  2766. }
  2767. ],
  2768. 'atom': {
  2769. // Look-behind prevents bad highlighting of the :: operator
  2770. pattern: /(^|[^:]):\w+/,
  2771. lookbehind: true,
  2772. alias: 'symbol'
  2773. },
  2774. 'module': {
  2775. pattern: /\b[A-Z]\w*\b/,
  2776. alias: 'class-name'
  2777. },
  2778. // Look-ahead prevents bad highlighting of the :: operator
  2779. 'attr-name': /\b\w+\??:(?!:)/,
  2780. 'argument': {
  2781. // Look-behind prevents bad highlighting of the && operator
  2782. pattern: /(^|[^&])&\d+/,
  2783. lookbehind: true,
  2784. alias: 'variable'
  2785. },
  2786. 'attribute': {
  2787. pattern: /@\w+/,
  2788. alias: 'variable'
  2789. },
  2790. 'function': /\b[_a-zA-Z]\w*[?!]?(?:(?=\s*(?:\.\s*)?\()|(?=\/\d))/,
  2791. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  2792. '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/,
  2793. 'boolean': /\b(?:false|nil|true)\b/,
  2794. 'operator': [
  2795. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  2796. {
  2797. // We don't want to match <<
  2798. pattern: /([^<])<(?!<)/,
  2799. lookbehind: true
  2800. },
  2801. {
  2802. // We don't want to match >>
  2803. pattern: /([^>])>(?!>)/,
  2804. lookbehind: true
  2805. }
  2806. ],
  2807. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  2808. };
  2809. Prism.languages.elixir.string.forEach(function (o) {
  2810. o.inside = {
  2811. 'interpolation': {
  2812. pattern: /#\{[^}]+\}/,
  2813. inside: {
  2814. 'delimiter': {
  2815. pattern: /^#\{|\}$/,
  2816. alias: 'punctuation'
  2817. },
  2818. rest: Prism.languages.elixir
  2819. }
  2820. }
  2821. };
  2822. });
  2823. Prism.languages.erlang = {
  2824. 'comment': /%.+/,
  2825. 'string': {
  2826. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  2827. greedy: true
  2828. },
  2829. 'quoted-function': {
  2830. pattern: /'(?:\\.|[^\\'\r\n])+'(?=\()/,
  2831. alias: 'function'
  2832. },
  2833. 'quoted-atom': {
  2834. pattern: /'(?:\\.|[^\\'\r\n])+'/,
  2835. alias: 'atom'
  2836. },
  2837. 'boolean': /\b(?:false|true)\b/,
  2838. 'keyword': /\b(?:after|begin|case|catch|end|fun|if|of|receive|try|when)\b/,
  2839. 'number': [
  2840. /\$\\?./,
  2841. /\b\d+#[a-z0-9]+/i,
  2842. /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i
  2843. ],
  2844. 'function': /\b[a-z][\w@]*(?=\()/,
  2845. 'variable': {
  2846. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  2847. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  2848. lookbehind: true
  2849. },
  2850. 'operator': [
  2851. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:and|andalso|band|bnot|bor|bsl|bsr|bxor|div|not|or|orelse|rem|xor)\b/,
  2852. {
  2853. // We don't want to match <<
  2854. pattern: /(^|[^<])<(?!<)/,
  2855. lookbehind: true
  2856. },
  2857. {
  2858. // We don't want to match >>
  2859. pattern: /(^|[^>])>(?!>)/,
  2860. lookbehind: true
  2861. }
  2862. ],
  2863. 'atom': /\b[a-z][\w@]*/,
  2864. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  2865. };
  2866. Prism.languages.go = Prism.languages.extend('clike', {
  2867. 'string': {
  2868. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,
  2869. lookbehind: true,
  2870. greedy: true
  2871. },
  2872. '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/,
  2873. 'boolean': /\b(?:_|false|iota|nil|true)\b/,
  2874. 'number': [
  2875. // binary and octal integers
  2876. /\b0(?:b[01_]+|o[0-7_]+)i?\b/i,
  2877. // hexadecimal integers and floats
  2878. /\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,
  2879. // decimal integers and floats
  2880. /(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i
  2881. ],
  2882. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  2883. '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/
  2884. });
  2885. Prism.languages.insertBefore('go', 'string', {
  2886. 'char': {
  2887. pattern: /'(?:\\.|[^'\\\r\n]){0,10}'/,
  2888. greedy: true
  2889. }
  2890. });
  2891. delete Prism.languages.go['class-name'];
  2892. (function (Prism) {
  2893. var interpolation = {
  2894. pattern: /((?:^|[^\\$])(?:\\{2})*)\$(?:\w+|\{[^{}]*\})/,
  2895. lookbehind: true,
  2896. inside: {
  2897. 'interpolation-punctuation': {
  2898. pattern: /^\$\{?|\}$/,
  2899. alias: 'punctuation'
  2900. },
  2901. 'expression': {
  2902. pattern: /[\s\S]+/,
  2903. inside: null // see below
  2904. }
  2905. }
  2906. };
  2907. Prism.languages.groovy = Prism.languages.extend('clike', {
  2908. 'string': {
  2909. // https://groovy-lang.org/syntax.html#_dollar_slashy_string
  2910. pattern: /'''(?:[^\\]|\\[\s\S])*?'''|'(?:\\.|[^\\'\r\n])*'/,
  2911. greedy: true
  2912. },
  2913. '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/,
  2914. 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
  2915. 'operator': {
  2916. pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
  2917. lookbehind: true
  2918. },
  2919. 'punctuation': /\.+|[{}[\];(),:$]/
  2920. });
  2921. Prism.languages.insertBefore('groovy', 'string', {
  2922. 'shebang': {
  2923. pattern: /#!.+/,
  2924. alias: 'comment',
  2925. greedy: true
  2926. },
  2927. 'interpolation-string': {
  2928. // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
  2929. // simple division (see JS regex), so find a fix maybe?
  2930. pattern: /"""(?:[^\\]|\\[\s\S])*?"""|(["/])(?:\\.|(?!\1)[^\\\r\n])*\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
  2931. greedy: true,
  2932. inside: {
  2933. 'interpolation': interpolation,
  2934. 'string': /[\s\S]+/
  2935. }
  2936. }
  2937. });
  2938. Prism.languages.insertBefore('groovy', 'punctuation', {
  2939. 'spock-block': /\b(?:and|cleanup|expect|given|setup|then|when|where):/
  2940. });
  2941. Prism.languages.insertBefore('groovy', 'function', {
  2942. 'annotation': {
  2943. pattern: /(^|[^.])@\w+/,
  2944. lookbehind: true,
  2945. alias: 'punctuation'
  2946. }
  2947. });
  2948. interpolation.inside.expression.inside = Prism.languages.groovy;
  2949. }(Prism));
  2950. (function (Prism) {
  2951. 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/;
  2952. // full package (optional) + parent classes (optional)
  2953. var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2954. // based on the java naming conventions
  2955. var className = {
  2956. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2957. lookbehind: true,
  2958. inside: {
  2959. 'namespace': {
  2960. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2961. inside: {
  2962. 'punctuation': /\./
  2963. }
  2964. },
  2965. 'punctuation': /\./
  2966. }
  2967. };
  2968. Prism.languages.java = Prism.languages.extend('clike', {
  2969. 'string': {
  2970. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
  2971. lookbehind: true,
  2972. greedy: true
  2973. },
  2974. 'class-name': [
  2975. className,
  2976. {
  2977. // variables, parameters, and constructor references
  2978. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2979. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),
  2980. lookbehind: true,
  2981. inside: className.inside
  2982. },
  2983. {
  2984. // class names based on keyword
  2985. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2986. pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source),
  2987. lookbehind: true,
  2988. inside: className.inside
  2989. }
  2990. ],
  2991. 'keyword': keywords,
  2992. 'function': [
  2993. Prism.languages.clike.function,
  2994. {
  2995. pattern: /(::\s*)[a-z_]\w*/,
  2996. lookbehind: true
  2997. }
  2998. ],
  2999. '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,
  3000. 'operator': {
  3001. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  3002. lookbehind: true
  3003. },
  3004. 'constant': /\b[A-Z][A-Z_\d]+\b/
  3005. });
  3006. Prism.languages.insertBefore('java', 'string', {
  3007. 'triple-quoted-string': {
  3008. // http://openjdk.java.net/jeps/355#Description
  3009. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  3010. greedy: true,
  3011. alias: 'string'
  3012. },
  3013. 'char': {
  3014. pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
  3015. greedy: true
  3016. }
  3017. });
  3018. Prism.languages.insertBefore('java', 'class-name', {
  3019. 'annotation': {
  3020. pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
  3021. lookbehind: true,
  3022. alias: 'punctuation'
  3023. },
  3024. 'generics': {
  3025. pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
  3026. inside: {
  3027. 'class-name': className,
  3028. 'keyword': keywords,
  3029. 'punctuation': /[<>(),.:]/,
  3030. 'operator': /[?&|]/
  3031. }
  3032. },
  3033. 'import': [
  3034. {
  3035. pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source),
  3036. lookbehind: true,
  3037. inside: {
  3038. 'namespace': className.inside.namespace,
  3039. 'punctuation': /\./,
  3040. 'operator': /\*/,
  3041. 'class-name': /\w+/
  3042. }
  3043. },
  3044. {
  3045. pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source),
  3046. lookbehind: true,
  3047. alias: 'static',
  3048. inside: {
  3049. 'namespace': className.inside.namespace,
  3050. 'static': /\b\w+$/,
  3051. 'punctuation': /\./,
  3052. 'operator': /\*/,
  3053. 'class-name': /\w+/
  3054. }
  3055. }
  3056. ],
  3057. 'namespace': {
  3058. pattern: RegExp(
  3059. /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
  3060. .source.replace(/<keyword>/g, function () { return keywords.source; })),
  3061. lookbehind: true,
  3062. inside: {
  3063. 'punctuation': /\./,
  3064. }
  3065. }
  3066. });
  3067. }(Prism));
  3068. // https://www.json.org/json-en.html
  3069. Prism.languages.json = {
  3070. 'property': {
  3071. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
  3072. lookbehind: true,
  3073. greedy: true
  3074. },
  3075. 'string': {
  3076. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  3077. lookbehind: true,
  3078. greedy: true
  3079. },
  3080. 'comment': {
  3081. pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
  3082. greedy: true
  3083. },
  3084. 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
  3085. 'punctuation': /[{}[\],]/,
  3086. 'operator': /:/,
  3087. 'boolean': /\b(?:false|true)\b/,
  3088. 'null': {
  3089. pattern: /\bnull\b/,
  3090. alias: 'keyword'
  3091. }
  3092. };
  3093. Prism.languages.webmanifest = Prism.languages.json;
  3094. Prism.languages.julia = {
  3095. 'comment': {
  3096. // support one level of nested comments
  3097. // https://github.com/JuliaLang/julia/pull/6128
  3098. pattern: /(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/,
  3099. lookbehind: true
  3100. },
  3101. 'regex': {
  3102. // https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1
  3103. pattern: /r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/,
  3104. greedy: true
  3105. },
  3106. 'string': {
  3107. // https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1
  3108. // https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1
  3109. // https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1
  3110. pattern: /"""[\s\S]+?"""|(?:\b\w+)?"(?:\\.|[^"\\\r\n])*"|`(?:[^\\`\r\n]|\\.)*`/,
  3111. greedy: true
  3112. },
  3113. 'char': {
  3114. // https://docs.julialang.org/en/v1/manual/strings/#man-characters-1
  3115. pattern: /(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'/,
  3116. lookbehind: true,
  3117. greedy: true
  3118. },
  3119. '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/,
  3120. 'boolean': /\b(?:false|true)\b/,
  3121. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i,
  3122. // https://docs.julialang.org/en/v1/manual/mathematical-operations/
  3123. // https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1
  3124. 'operator': /&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/,
  3125. 'punctuation': /::?|[{}[\]();,.?]/,
  3126. // https://docs.julialang.org/en/v1/base/numbers/#Base.im
  3127. 'constant': /\b(?:(?:Inf|NaN)(?:16|32|64)?|im|pi)\b|[πℯ]/
  3128. };
  3129. (function (Prism) {
  3130. Prism.languages.kotlin = Prism.languages.extend('clike', {
  3131. 'keyword': {
  3132. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  3133. 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/,
  3134. lookbehind: true
  3135. },
  3136. 'function': [
  3137. {
  3138. pattern: /(?:`[^\r\n`]+`|\b\w+)(?=\s*\()/,
  3139. greedy: true
  3140. },
  3141. {
  3142. pattern: /(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/,
  3143. lookbehind: true,
  3144. greedy: true
  3145. }
  3146. ],
  3147. 'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
  3148. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  3149. });
  3150. delete Prism.languages.kotlin['class-name'];
  3151. var interpolationInside = {
  3152. 'interpolation-punctuation': {
  3153. pattern: /^\$\{?|\}$/,
  3154. alias: 'punctuation'
  3155. },
  3156. 'expression': {
  3157. pattern: /[\s\S]+/,
  3158. inside: Prism.languages.kotlin
  3159. }
  3160. };
  3161. Prism.languages.insertBefore('kotlin', 'string', {
  3162. // https://kotlinlang.org/spec/expressions.html#string-interpolation-expressions
  3163. 'string-literal': [
  3164. {
  3165. pattern: /"""(?:[^$]|\$(?:(?!\{)|\{[^{}]*\}))*?"""/,
  3166. alias: 'multiline',
  3167. inside: {
  3168. 'interpolation': {
  3169. pattern: /\$(?:[a-z_]\w*|\{[^{}]*\})/i,
  3170. inside: interpolationInside
  3171. },
  3172. 'string': /[\s\S]+/
  3173. }
  3174. },
  3175. {
  3176. pattern: /"(?:[^"\\\r\n$]|\\.|\$(?:(?!\{)|\{[^{}]*\}))*"/,
  3177. alias: 'singleline',
  3178. inside: {
  3179. 'interpolation': {
  3180. pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:[a-z_]\w*|\{[^{}]*\})/i,
  3181. lookbehind: true,
  3182. inside: interpolationInside
  3183. },
  3184. 'string': /[\s\S]+/
  3185. }
  3186. }
  3187. ],
  3188. 'char': {
  3189. // https://kotlinlang.org/spec/expressions.html#character-literals
  3190. pattern: /'(?:[^'\\\r\n]|\\(?:.|u[a-fA-F0-9]{0,4}))'/,
  3191. greedy: true
  3192. }
  3193. });
  3194. delete Prism.languages.kotlin['string'];
  3195. Prism.languages.insertBefore('kotlin', 'keyword', {
  3196. 'annotation': {
  3197. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  3198. alias: 'builtin'
  3199. }
  3200. });
  3201. Prism.languages.insertBefore('kotlin', 'function', {
  3202. 'label': {
  3203. pattern: /\b\w+@|@\w+\b/,
  3204. alias: 'symbol'
  3205. }
  3206. });
  3207. Prism.languages.kt = Prism.languages.kotlin;
  3208. Prism.languages.kts = Prism.languages.kotlin;
  3209. }(Prism));
  3210. (function (Prism) {
  3211. var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i;
  3212. var insideEqu = {
  3213. 'equation-command': {
  3214. pattern: funcPattern,
  3215. alias: 'regex'
  3216. }
  3217. };
  3218. Prism.languages.latex = {
  3219. 'comment': /%.*/,
  3220. // the verbatim environment prints whitespace to the document
  3221. 'cdata': {
  3222. pattern: /(\\begin\{((?:lstlisting|verbatim)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  3223. lookbehind: true
  3224. },
  3225. /*
  3226. * equations can be between $$ $$ or $ $ or \( \) or \[ \]
  3227. * (all are multiline)
  3228. */
  3229. 'equation': [
  3230. {
  3231. pattern: /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/,
  3232. inside: insideEqu,
  3233. alias: 'string'
  3234. },
  3235. {
  3236. pattern: /(\\begin\{((?:align|eqnarray|equation|gather|math|multline)\*?)\})[\s\S]*?(?=\\end\{\2\})/,
  3237. lookbehind: true,
  3238. inside: insideEqu,
  3239. alias: 'string'
  3240. }
  3241. ],
  3242. /*
  3243. * arguments which are keywords or references are highlighted
  3244. * as keywords
  3245. */
  3246. 'keyword': {
  3247. pattern: /(\\(?:begin|cite|documentclass|end|label|ref|usepackage)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  3248. lookbehind: true
  3249. },
  3250. 'url': {
  3251. pattern: /(\\url\{)[^}]+(?=\})/,
  3252. lookbehind: true
  3253. },
  3254. /*
  3255. * section or chapter headlines are highlighted as bold so that
  3256. * they stand out more
  3257. */
  3258. 'headline': {
  3259. pattern: /(\\(?:chapter|frametitle|paragraph|part|section|subparagraph|subsection|subsubparagraph|subsubsection|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
  3260. lookbehind: true,
  3261. alias: 'class-name'
  3262. },
  3263. 'function': {
  3264. pattern: funcPattern,
  3265. alias: 'selector'
  3266. },
  3267. 'punctuation': /[[\]{}&]/
  3268. };
  3269. Prism.languages.tex = Prism.languages.latex;
  3270. Prism.languages.context = Prism.languages.latex;
  3271. }(Prism));
  3272. Prism.languages.lua = {
  3273. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  3274. // \z may be used to skip the following space
  3275. 'string': {
  3276. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  3277. greedy: true
  3278. },
  3279. 'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  3280. '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/,
  3281. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  3282. 'operator': [
  3283. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  3284. {
  3285. // Match ".." but don't break "..."
  3286. pattern: /(^|[^.])\.\.(?!\.)/,
  3287. lookbehind: true
  3288. }
  3289. ],
  3290. 'punctuation': /[\[\](){},;]|\.+|:+/
  3291. };
  3292. (function (Prism) {
  3293. // Allow only one line break
  3294. var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;
  3295. /**
  3296. * This function is intended for the creation of the bold or italic pattern.
  3297. *
  3298. * This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
  3299. *
  3300. * _Note:_ Keep in mind that this adds a capturing group.
  3301. *
  3302. * @param {string} pattern
  3303. * @returns {RegExp}
  3304. */
  3305. function createInline(pattern) {
  3306. pattern = pattern.replace(/<inner>/g, function () { return inner; });
  3307. return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')');
  3308. }
  3309. var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
  3310. var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g, function () { return tableCell; });
  3311. var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
  3312. Prism.languages.markdown = Prism.languages.extend('markup', {});
  3313. Prism.languages.insertBefore('markdown', 'prolog', {
  3314. 'front-matter-block': {
  3315. pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
  3316. lookbehind: true,
  3317. greedy: true,
  3318. inside: {
  3319. 'punctuation': /^---|---$/,
  3320. 'front-matter': {
  3321. pattern: /\S+(?:\s+\S+)*/,
  3322. alias: ['yaml', 'language-yaml'],
  3323. inside: Prism.languages.yaml
  3324. }
  3325. }
  3326. },
  3327. 'blockquote': {
  3328. // > ...
  3329. pattern: /^>(?:[\t ]*>)*/m,
  3330. alias: 'punctuation'
  3331. },
  3332. 'table': {
  3333. pattern: RegExp('^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm'),
  3334. inside: {
  3335. 'table-data-rows': {
  3336. pattern: RegExp('^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$'),
  3337. lookbehind: true,
  3338. inside: {
  3339. 'table-data': {
  3340. pattern: RegExp(tableCell),
  3341. inside: Prism.languages.markdown
  3342. },
  3343. 'punctuation': /\|/
  3344. }
  3345. },
  3346. 'table-line': {
  3347. pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'),
  3348. lookbehind: true,
  3349. inside: {
  3350. 'punctuation': /\||:?-{3,}:?/
  3351. }
  3352. },
  3353. 'table-header-row': {
  3354. pattern: RegExp('^' + tableRow + '$'),
  3355. inside: {
  3356. 'table-header': {
  3357. pattern: RegExp(tableCell),
  3358. alias: 'important',
  3359. inside: Prism.languages.markdown
  3360. },
  3361. 'punctuation': /\|/
  3362. }
  3363. }
  3364. }
  3365. },
  3366. 'code': [
  3367. {
  3368. // Prefixed by 4 spaces or 1 tab and preceded by an empty line
  3369. pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
  3370. lookbehind: true,
  3371. alias: 'keyword'
  3372. },
  3373. {
  3374. // ```optional language
  3375. // code block
  3376. // ```
  3377. pattern: /^```[\s\S]*?^```$/m,
  3378. greedy: true,
  3379. inside: {
  3380. 'code-block': {
  3381. pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
  3382. lookbehind: true
  3383. },
  3384. 'code-language': {
  3385. pattern: /^(```).+/,
  3386. lookbehind: true
  3387. },
  3388. 'punctuation': /```/
  3389. }
  3390. }
  3391. ],
  3392. 'title': [
  3393. {
  3394. // title 1
  3395. // =======
  3396. // title 2
  3397. // -------
  3398. pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
  3399. alias: 'important',
  3400. inside: {
  3401. punctuation: /==+$|--+$/
  3402. }
  3403. },
  3404. {
  3405. // # title 1
  3406. // ###### title 6
  3407. pattern: /(^\s*)#.+/m,
  3408. lookbehind: true,
  3409. alias: 'important',
  3410. inside: {
  3411. punctuation: /^#+|#+$/
  3412. }
  3413. }
  3414. ],
  3415. 'hr': {
  3416. // ***
  3417. // ---
  3418. // * * *
  3419. // -----------
  3420. pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
  3421. lookbehind: true,
  3422. alias: 'punctuation'
  3423. },
  3424. 'list': {
  3425. // * item
  3426. // + item
  3427. // - item
  3428. // 1. item
  3429. pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
  3430. lookbehind: true,
  3431. alias: 'punctuation'
  3432. },
  3433. 'url-reference': {
  3434. // [id]: http://example.com "Optional title"
  3435. // [id]: http://example.com 'Optional title'
  3436. // [id]: http://example.com (Optional title)
  3437. // [id]: <http://example.com> "Optional title"
  3438. pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
  3439. inside: {
  3440. 'variable': {
  3441. pattern: /^(!?\[)[^\]]+/,
  3442. lookbehind: true
  3443. },
  3444. 'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
  3445. 'punctuation': /^[\[\]!:]|[<>]/
  3446. },
  3447. alias: 'url'
  3448. },
  3449. 'bold': {
  3450. // **strong**
  3451. // __strong__
  3452. // allow one nested instance of italic text using the same delimiter
  3453. pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
  3454. lookbehind: true,
  3455. greedy: true,
  3456. inside: {
  3457. 'content': {
  3458. pattern: /(^..)[\s\S]+(?=..$)/,
  3459. lookbehind: true,
  3460. inside: {} // see below
  3461. },
  3462. 'punctuation': /\*\*|__/
  3463. }
  3464. },
  3465. 'italic': {
  3466. // *em*
  3467. // _em_
  3468. // allow one nested instance of bold text using the same delimiter
  3469. pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
  3470. lookbehind: true,
  3471. greedy: true,
  3472. inside: {
  3473. 'content': {
  3474. pattern: /(^.)[\s\S]+(?=.$)/,
  3475. lookbehind: true,
  3476. inside: {} // see below
  3477. },
  3478. 'punctuation': /[*_]/
  3479. }
  3480. },
  3481. 'strike': {
  3482. // ~~strike through~~
  3483. // ~strike~
  3484. // eslint-disable-next-line regexp/strict
  3485. pattern: createInline(/(~~?)(?:(?!~)<inner>)+\2/.source),
  3486. lookbehind: true,
  3487. greedy: true,
  3488. inside: {
  3489. 'content': {
  3490. pattern: /(^~~?)[\s\S]+(?=\1$)/,
  3491. lookbehind: true,
  3492. inside: {} // see below
  3493. },
  3494. 'punctuation': /~~?/
  3495. }
  3496. },
  3497. 'code-snippet': {
  3498. // `code`
  3499. // ``code``
  3500. pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,
  3501. lookbehind: true,
  3502. greedy: true,
  3503. alias: ['code', 'keyword']
  3504. },
  3505. 'url': {
  3506. // [example](http://example.com "Optional title")
  3507. // [example][id]
  3508. // [example] [id]
  3509. pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\])<inner>)+\])/.source),
  3510. lookbehind: true,
  3511. greedy: true,
  3512. inside: {
  3513. 'operator': /^!/,
  3514. 'content': {
  3515. pattern: /(^\[)[^\]]+(?=\])/,
  3516. lookbehind: true,
  3517. inside: {} // see below
  3518. },
  3519. 'variable': {
  3520. pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/,
  3521. lookbehind: true
  3522. },
  3523. 'url': {
  3524. pattern: /(^\]\()[^\s)]+/,
  3525. lookbehind: true
  3526. },
  3527. 'string': {
  3528. pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,
  3529. lookbehind: true
  3530. }
  3531. }
  3532. }
  3533. });
  3534. ['url', 'bold', 'italic', 'strike'].forEach(function (token) {
  3535. ['url', 'bold', 'italic', 'strike', 'code-snippet'].forEach(function (inside) {
  3536. if (token !== inside) {
  3537. Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
  3538. }
  3539. });
  3540. });
  3541. Prism.hooks.add('after-tokenize', function (env) {
  3542. if (env.language !== 'markdown' && env.language !== 'md') {
  3543. return;
  3544. }
  3545. function walkTokens(tokens) {
  3546. if (!tokens || typeof tokens === 'string') {
  3547. return;
  3548. }
  3549. for (var i = 0, l = tokens.length; i < l; i++) {
  3550. var token = tokens[i];
  3551. if (token.type !== 'code') {
  3552. walkTokens(token.content);
  3553. continue;
  3554. }
  3555. /*
  3556. * Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
  3557. * is optional. But the grammar is defined so that there is only one case we have to handle:
  3558. *
  3559. * token.content = [
  3560. * <span class="punctuation">```</span>,
  3561. * <span class="code-language">xxxx</span>,
  3562. * '\n', // exactly one new lines (\r or \n or \r\n)
  3563. * <span class="code-block">...</span>,
  3564. * '\n', // exactly one new lines again
  3565. * <span class="punctuation">```</span>
  3566. * ];
  3567. */
  3568. var codeLang = token.content[1];
  3569. var codeBlock = token.content[3];
  3570. if (codeLang && codeBlock &&
  3571. codeLang.type === 'code-language' && codeBlock.type === 'code-block' &&
  3572. typeof codeLang.content === 'string') {
  3573. // this might be a language that Prism does not support
  3574. // do some replacements to support C++, C#, and F#
  3575. var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp');
  3576. // only use the first word
  3577. lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase();
  3578. var alias = 'language-' + lang;
  3579. // add alias
  3580. if (!codeBlock.alias) {
  3581. codeBlock.alias = [alias];
  3582. } else if (typeof codeBlock.alias === 'string') {
  3583. codeBlock.alias = [codeBlock.alias, alias];
  3584. } else {
  3585. codeBlock.alias.push(alias);
  3586. }
  3587. }
  3588. }
  3589. }
  3590. walkTokens(env.tokens);
  3591. });
  3592. Prism.hooks.add('wrap', function (env) {
  3593. if (env.type !== 'code-block') {
  3594. return;
  3595. }
  3596. var codeLang = '';
  3597. for (var i = 0, l = env.classes.length; i < l; i++) {
  3598. var cls = env.classes[i];
  3599. var match = /language-(.+)/.exec(cls);
  3600. if (match) {
  3601. codeLang = match[1];
  3602. break;
  3603. }
  3604. }
  3605. var grammar = Prism.languages[codeLang];
  3606. if (!grammar) {
  3607. if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) {
  3608. var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16);
  3609. env.attributes['id'] = id;
  3610. Prism.plugins.autoloader.loadLanguages(codeLang, function () {
  3611. var ele = document.getElementById(id);
  3612. if (ele) {
  3613. ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
  3614. }
  3615. });
  3616. }
  3617. } else {
  3618. env.content = Prism.highlight(textContent(env.content), grammar, codeLang);
  3619. }
  3620. });
  3621. var tagPattern = RegExp(Prism.languages.markup.tag.pattern.source, 'gi');
  3622. /**
  3623. * A list of known entity names.
  3624. *
  3625. * This will always be incomplete to save space. The current list is the one used by lowdash's unescape function.
  3626. *
  3627. * @see {@link https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/unescape.js#L2}
  3628. */
  3629. var KNOWN_ENTITY_NAMES = {
  3630. 'amp': '&',
  3631. 'lt': '<',
  3632. 'gt': '>',
  3633. 'quot': '"',
  3634. };
  3635. // IE 11 doesn't support `String.fromCodePoint`
  3636. var fromCodePoint = String.fromCodePoint || String.fromCharCode;
  3637. /**
  3638. * Returns the text content of a given HTML source code string.
  3639. *
  3640. * @param {string} html
  3641. * @returns {string}
  3642. */
  3643. function textContent(html) {
  3644. // remove all tags
  3645. var text = html.replace(tagPattern, '');
  3646. // decode known entities
  3647. text = text.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi, function (m, code) {
  3648. code = code.toLowerCase();
  3649. if (code[0] === '#') {
  3650. var value;
  3651. if (code[1] === 'x') {
  3652. value = parseInt(code.slice(2), 16);
  3653. } else {
  3654. value = Number(code.slice(1));
  3655. }
  3656. return fromCodePoint(value);
  3657. } else {
  3658. var known = KNOWN_ENTITY_NAMES[code];
  3659. if (known) {
  3660. return known;
  3661. }
  3662. // unable to decode
  3663. return m;
  3664. }
  3665. });
  3666. return text;
  3667. }
  3668. Prism.languages.md = Prism.languages.markdown;
  3669. }(Prism));
  3670. Prism.languages.matlab = {
  3671. 'comment': [
  3672. /%\{[\s\S]*?\}%/,
  3673. /%.+/
  3674. ],
  3675. 'string': {
  3676. pattern: /\B'(?:''|[^'\r\n])*'/,
  3677. greedy: true
  3678. },
  3679. // FIXME We could handle imaginary numbers as a whole
  3680. 'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[eE][+-]?\d+)?(?:[ij])?|\b[ij]\b/,
  3681. 'keyword': /\b(?:NaN|break|case|catch|continue|else|elseif|end|for|function|if|inf|otherwise|parfor|pause|pi|return|switch|try|while)\b/,
  3682. 'function': /\b(?!\d)\w+(?=\s*\()/,
  3683. 'operator': /\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,
  3684. 'punctuation': /\.{3}|[.,;\[\](){}!]/
  3685. };
  3686. (function (Prism) {
  3687. var variable = /\$(?:\w[a-z\d]*(?:_[^\x00-\x1F\s"'\\()$]*)?|\{[^}\s"'\\]+\})/i;
  3688. Prism.languages.nginx = {
  3689. 'comment': {
  3690. pattern: /(^|[\s{};])#.*/,
  3691. lookbehind: true,
  3692. greedy: true
  3693. },
  3694. 'directive': {
  3695. pattern: /(^|\s)\w(?:[^;{}"'\\\s]|\\.|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\s+(?:#.*(?!.)|(?![#\s])))*?(?=\s*[;{])/,
  3696. lookbehind: true,
  3697. greedy: true,
  3698. inside: {
  3699. 'string': {
  3700. pattern: /((?:^|[^\\])(?:\\\\)*)(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/,
  3701. lookbehind: true,
  3702. greedy: true,
  3703. inside: {
  3704. 'escape': {
  3705. pattern: /\\["'\\nrt]/,
  3706. alias: 'entity'
  3707. },
  3708. 'variable': variable
  3709. }
  3710. },
  3711. 'comment': {
  3712. pattern: /(\s)#.*/,
  3713. lookbehind: true,
  3714. greedy: true
  3715. },
  3716. 'keyword': {
  3717. pattern: /^\S+/,
  3718. greedy: true
  3719. },
  3720. // other patterns
  3721. 'boolean': {
  3722. pattern: /(\s)(?:off|on)(?!\S)/,
  3723. lookbehind: true
  3724. },
  3725. 'number': {
  3726. pattern: /(\s)\d+[a-z]*(?!\S)/i,
  3727. lookbehind: true
  3728. },
  3729. 'variable': variable
  3730. }
  3731. },
  3732. 'punctuation': /[{};]/
  3733. };
  3734. }(Prism));
  3735. Prism.languages.nim = {
  3736. 'comment': {
  3737. pattern: /#.*/,
  3738. greedy: true
  3739. },
  3740. 'string': {
  3741. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  3742. pattern: /(?:\b(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")/,
  3743. greedy: true
  3744. },
  3745. 'char': {
  3746. // Character literals are handled specifically to prevent issues with numeric type suffixes
  3747. pattern: /'(?:\\(?:\d+|x[\da-fA-F]{0,2}|.)|[^'])'/,
  3748. greedy: true
  3749. },
  3750. 'function': {
  3751. pattern: /(?:(?!\d)(?:\w|\\x[89a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  3752. greedy: true,
  3753. inside: {
  3754. 'operator': /\*$/
  3755. }
  3756. },
  3757. // We don't want to highlight operators (and anything really) inside backticks
  3758. 'identifier': {
  3759. pattern: /`[^`\r\n]+`/,
  3760. greedy: true,
  3761. inside: {
  3762. 'punctuation': /`/
  3763. }
  3764. },
  3765. // The negative look ahead prevents wrong highlighting of the .. operator
  3766. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  3767. '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/,
  3768. 'operator': {
  3769. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  3770. // but allow the slice operator .. to take precedence over them
  3771. // One can define his own operators in Nim so all combination of operators might be an operator.
  3772. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|in|is|isnot|mod|not|notin|of|or|shl|shr|xor)\b)/m,
  3773. lookbehind: true
  3774. },
  3775. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  3776. };
  3777. Prism.languages.nix = {
  3778. 'comment': {
  3779. pattern: /\/\*[\s\S]*?\*\/|#.*/,
  3780. greedy: true
  3781. },
  3782. 'string': {
  3783. pattern: /"(?:[^"\\]|\\[\s\S])*"|''(?:(?!'')[\s\S]|''(?:'|\\|\$\{))*''/,
  3784. greedy: true,
  3785. inside: {
  3786. 'interpolation': {
  3787. // The lookbehind ensures the ${} is not preceded by \ or ''
  3788. pattern: /(^|(?:^|(?!'').)[^\\])\$\{(?:[^{}]|\{[^}]*\})*\}/,
  3789. lookbehind: true,
  3790. inside: null // see below
  3791. }
  3792. }
  3793. },
  3794. 'url': [
  3795. /\b(?:[a-z]{3,7}:\/\/)[\w\-+%~\/.:#=?&]+/,
  3796. {
  3797. pattern: /([^\/])(?:[\w\-+%~.:#=?&]*(?!\/\/)[\w\-+%~\/.:#=?&])?(?!\/\/)\/[\w\-+%~\/.:#=?&]*/,
  3798. lookbehind: true
  3799. }
  3800. ],
  3801. 'antiquotation': {
  3802. pattern: /\$(?=\{)/,
  3803. alias: 'important'
  3804. },
  3805. 'number': /\b\d+\b/,
  3806. 'keyword': /\b(?:assert|builtins|else|if|in|inherit|let|null|or|then|with)\b/,
  3807. '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/,
  3808. 'boolean': /\b(?:false|true)\b/,
  3809. 'operator': /[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]/,
  3810. 'punctuation': /[{}()[\].,:;]/
  3811. };
  3812. Prism.languages.nix.string.inside.interpolation.inside = Prism.languages.nix;
  3813. // https://ocaml.org/manual/lex.html
  3814. Prism.languages.ocaml = {
  3815. 'comment': {
  3816. pattern: /\(\*[\s\S]*?\*\)/,
  3817. greedy: true
  3818. },
  3819. 'char': {
  3820. pattern: /'(?:[^\\\r\n']|\\(?:.|[ox]?[0-9a-f]{1,3}))'/i,
  3821. greedy: true
  3822. },
  3823. 'string': [
  3824. {
  3825. pattern: /"(?:\\(?:[\s\S]|\r\n)|[^\\\r\n"])*"/,
  3826. greedy: true
  3827. },
  3828. {
  3829. pattern: /\{([a-z_]*)\|[\s\S]*?\|\1\}/,
  3830. greedy: true
  3831. }
  3832. ],
  3833. 'number': [
  3834. // binary and octal
  3835. /\b(?:0b[01][01_]*|0o[0-7][0-7_]*)\b/i,
  3836. // hexadecimal
  3837. /\b0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]*)?(?:p[+-]?\d[\d_]*)?(?!\w)/i,
  3838. // decimal
  3839. /\b\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?\d[\d_]*)?(?!\w)/i,
  3840. ],
  3841. 'directive': {
  3842. pattern: /\B#\w+/,
  3843. alias: 'property'
  3844. },
  3845. 'label': {
  3846. pattern: /\B~\w+/,
  3847. alias: 'property'
  3848. },
  3849. 'type-variable': {
  3850. pattern: /\B'\w+/,
  3851. alias: 'function'
  3852. },
  3853. 'variant': {
  3854. pattern: /`\w+/,
  3855. alias: 'symbol'
  3856. },
  3857. // For the list of keywords and operators,
  3858. // see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
  3859. '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/,
  3860. 'boolean': /\b(?:false|true)\b/,
  3861. 'operator-like-punctuation': {
  3862. pattern: /\[[<>|]|[>|]\]|\{<|>\}/,
  3863. alias: 'punctuation'
  3864. },
  3865. // Custom operators are allowed
  3866. 'operator': /\.[.~]|:[=>]|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
  3867. 'punctuation': /;;|::|[(){}\[\].,:;#]|\b_\b/
  3868. };
  3869. (function (Prism) {
  3870. var brackets = /(?:\((?:[^()\\]|\\[\s\S])*\)|\{(?:[^{}\\]|\\[\s\S])*\}|\[(?:[^[\]\\]|\\[\s\S])*\]|<(?:[^<>\\]|\\[\s\S])*>)/.source;
  3871. Prism.languages.perl = {
  3872. 'comment': [
  3873. {
  3874. // POD
  3875. pattern: /(^\s*)=\w[\s\S]*?=cut.*/m,
  3876. lookbehind: true,
  3877. greedy: true
  3878. },
  3879. {
  3880. pattern: /(^|[^\\$])#.*/,
  3881. lookbehind: true,
  3882. greedy: true
  3883. }
  3884. ],
  3885. // TODO Could be nice to handle Heredoc too.
  3886. 'string': [
  3887. {
  3888. pattern: RegExp(
  3889. /\b(?:q|qq|qw|qx)(?![a-zA-Z0-9])\s*/.source +
  3890. '(?:' +
  3891. [
  3892. // q/.../
  3893. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  3894. // q a...a
  3895. // eslint-disable-next-line regexp/strict
  3896. /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3897. // q(...)
  3898. // q{...}
  3899. // q[...]
  3900. // q<...>
  3901. brackets,
  3902. ].join('|') +
  3903. ')'
  3904. ),
  3905. greedy: true
  3906. },
  3907. // "...", `...`
  3908. {
  3909. pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  3910. greedy: true
  3911. },
  3912. // '...'
  3913. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  3914. {
  3915. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  3916. greedy: true
  3917. }
  3918. ],
  3919. 'regex': [
  3920. {
  3921. pattern: RegExp(
  3922. /\b(?:m|qr)(?![a-zA-Z0-9])\s*/.source +
  3923. '(?:' +
  3924. [
  3925. // m/.../
  3926. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  3927. // m a...a
  3928. // eslint-disable-next-line regexp/strict
  3929. /([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3930. // m(...)
  3931. // m{...}
  3932. // m[...]
  3933. // m<...>
  3934. brackets,
  3935. ].join('|') +
  3936. ')' +
  3937. /[msixpodualngc]*/.source
  3938. ),
  3939. greedy: true
  3940. },
  3941. // The lookbehinds prevent -s from breaking
  3942. {
  3943. pattern: RegExp(
  3944. /(^|[^-])\b(?:s|tr|y)(?![a-zA-Z0-9])\s*/.source +
  3945. '(?:' +
  3946. [
  3947. // s/.../.../
  3948. // eslint-disable-next-line regexp/strict
  3949. /([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2/.source,
  3950. // s a...a...a
  3951. // eslint-disable-next-line regexp/strict
  3952. /([a-zA-Z0-9])(?:(?!\3)[^\\]|\\[\s\S])*\3(?:(?!\3)[^\\]|\\[\s\S])*\3/.source,
  3953. // s(...)(...)
  3954. // s{...}{...}
  3955. // s[...][...]
  3956. // s<...><...>
  3957. // s(...)[...]
  3958. brackets + /\s*/.source + brackets,
  3959. ].join('|') +
  3960. ')' +
  3961. /[msixpodualngcer]*/.source
  3962. ),
  3963. lookbehind: true,
  3964. greedy: true
  3965. },
  3966. // /.../
  3967. // The look-ahead tries to prevent two divisions on
  3968. // the same line from being highlighted as regex.
  3969. // This does not support multi-line regex.
  3970. {
  3971. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|x|xor)\b))/,
  3972. greedy: true
  3973. }
  3974. ],
  3975. // FIXME Not sure about the handling of ::, ', and #
  3976. 'variable': [
  3977. // ${^POSTMATCH}
  3978. /[&*$@%]\{\^[A-Z]+\}/,
  3979. // $^V
  3980. /[&*$@%]\^[A-Z_]/,
  3981. // ${...}
  3982. /[&*$@%]#?(?=\{)/,
  3983. // $foo
  3984. /[&*$@%]#?(?:(?:::)*'?(?!\d)[\w$]+(?![\w$]))+(?:::)*/,
  3985. // $1
  3986. /[&*$@%]\d+/,
  3987. // $_, @_, %!
  3988. // The negative lookahead prevents from breaking the %= operator
  3989. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  3990. ],
  3991. 'filehandle': {
  3992. // <>, <FOO>, _
  3993. pattern: /<(?![<=])\S*?>|\b_\b/,
  3994. alias: 'symbol'
  3995. },
  3996. 'v-string': {
  3997. // v1.2, 1.2.3
  3998. pattern: /v\d+(?:\.\d+)*|\d+(?:\.\d+){2,}/,
  3999. alias: 'string'
  4000. },
  4001. 'function': {
  4002. pattern: /(\bsub[ \t]+)\w+/,
  4003. lookbehind: true
  4004. },
  4005. '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/,
  4006. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)\b/,
  4007. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)\b/,
  4008. 'punctuation': /[{}[\];(),:]/
  4009. };
  4010. }(Prism));
  4011. /**
  4012. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  4013. * Modified by Miles Johnson: http://milesj.me
  4014. * Rewritten by Tom Pavelec
  4015. *
  4016. * Supports PHP 5.3 - 8.0
  4017. */
  4018. (function (Prism) {
  4019. var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
  4020. var constant = [
  4021. {
  4022. pattern: /\b(?:false|true)\b/i,
  4023. alias: 'boolean'
  4024. },
  4025. {
  4026. pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
  4027. greedy: true,
  4028. lookbehind: true,
  4029. },
  4030. {
  4031. pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
  4032. greedy: true,
  4033. lookbehind: true,
  4034. },
  4035. /\b(?:null)\b/i,
  4036. /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
  4037. ];
  4038. 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;
  4039. var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
  4040. var punctuation = /[{}\[\](),:;]/;
  4041. Prism.languages.php = {
  4042. 'delimiter': {
  4043. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  4044. alias: 'important'
  4045. },
  4046. 'comment': comment,
  4047. 'variable': /\$+(?:\w+\b|(?=\{))/,
  4048. 'package': {
  4049. pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  4050. lookbehind: true,
  4051. inside: {
  4052. 'punctuation': /\\/
  4053. }
  4054. },
  4055. 'class-name-definition': {
  4056. pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
  4057. lookbehind: true,
  4058. alias: 'class-name'
  4059. },
  4060. 'function-definition': {
  4061. pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
  4062. lookbehind: true,
  4063. alias: 'function'
  4064. },
  4065. 'keyword': [
  4066. {
  4067. pattern: /(\(\s*)\b(?:array|bool|boolean|float|int|integer|object|string)\b(?=\s*\))/i,
  4068. alias: 'type-casting',
  4069. greedy: true,
  4070. lookbehind: true
  4071. },
  4072. {
  4073. pattern: /([(,?]\s*)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string)\b(?=\s*\$)/i,
  4074. alias: 'type-hint',
  4075. greedy: true,
  4076. lookbehind: true
  4077. },
  4078. {
  4079. pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i,
  4080. alias: 'return-type',
  4081. greedy: true,
  4082. lookbehind: true
  4083. },
  4084. {
  4085. pattern: /\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i,
  4086. alias: 'type-declaration',
  4087. greedy: true
  4088. },
  4089. {
  4090. pattern: /(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i,
  4091. alias: 'type-declaration',
  4092. greedy: true,
  4093. lookbehind: true
  4094. },
  4095. {
  4096. pattern: /\b(?:parent|self|static)(?=\s*::)/i,
  4097. alias: 'static-context',
  4098. greedy: true
  4099. },
  4100. {
  4101. // yield from
  4102. pattern: /(\byield\s+)from\b/i,
  4103. lookbehind: true
  4104. },
  4105. // `class` is always a keyword unlike other keywords
  4106. /\bclass\b/i,
  4107. {
  4108. // https://www.php.net/manual/en/reserved.keywords.php
  4109. //
  4110. // keywords cannot be preceded by "->"
  4111. // the complex lookbehind means `(?<!(?:->|::)\s*)`
  4112. 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,
  4113. lookbehind: true
  4114. }
  4115. ],
  4116. 'argument-name': {
  4117. pattern: /([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i,
  4118. lookbehind: true
  4119. },
  4120. 'class-name': [
  4121. {
  4122. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
  4123. greedy: true,
  4124. lookbehind: true
  4125. },
  4126. {
  4127. pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
  4128. greedy: true,
  4129. lookbehind: true
  4130. },
  4131. {
  4132. pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
  4133. greedy: true
  4134. },
  4135. {
  4136. pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
  4137. alias: 'class-name-fully-qualified',
  4138. greedy: true,
  4139. lookbehind: true,
  4140. inside: {
  4141. 'punctuation': /\\/
  4142. }
  4143. },
  4144. {
  4145. pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
  4146. alias: 'class-name-fully-qualified',
  4147. greedy: true,
  4148. inside: {
  4149. 'punctuation': /\\/
  4150. }
  4151. },
  4152. {
  4153. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  4154. alias: 'class-name-fully-qualified',
  4155. greedy: true,
  4156. lookbehind: true,
  4157. inside: {
  4158. 'punctuation': /\\/
  4159. }
  4160. },
  4161. {
  4162. pattern: /\b[a-z_]\w*(?=\s*\$)/i,
  4163. alias: 'type-declaration',
  4164. greedy: true
  4165. },
  4166. {
  4167. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  4168. alias: ['class-name-fully-qualified', 'type-declaration'],
  4169. greedy: true,
  4170. inside: {
  4171. 'punctuation': /\\/
  4172. }
  4173. },
  4174. {
  4175. pattern: /\b[a-z_]\w*(?=\s*::)/i,
  4176. alias: 'static-context',
  4177. greedy: true
  4178. },
  4179. {
  4180. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
  4181. alias: ['class-name-fully-qualified', 'static-context'],
  4182. greedy: true,
  4183. inside: {
  4184. 'punctuation': /\\/
  4185. }
  4186. },
  4187. {
  4188. pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
  4189. alias: 'type-hint',
  4190. greedy: true,
  4191. lookbehind: true
  4192. },
  4193. {
  4194. pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  4195. alias: ['class-name-fully-qualified', 'type-hint'],
  4196. greedy: true,
  4197. lookbehind: true,
  4198. inside: {
  4199. 'punctuation': /\\/
  4200. }
  4201. },
  4202. {
  4203. pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
  4204. alias: 'return-type',
  4205. greedy: true,
  4206. lookbehind: true
  4207. },
  4208. {
  4209. pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  4210. alias: ['class-name-fully-qualified', 'return-type'],
  4211. greedy: true,
  4212. lookbehind: true,
  4213. inside: {
  4214. 'punctuation': /\\/
  4215. }
  4216. }
  4217. ],
  4218. 'constant': constant,
  4219. 'function': {
  4220. pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
  4221. lookbehind: true,
  4222. inside: {
  4223. 'punctuation': /\\/
  4224. }
  4225. },
  4226. 'property': {
  4227. pattern: /(->\s*)\w+/,
  4228. lookbehind: true
  4229. },
  4230. 'number': number,
  4231. 'operator': operator,
  4232. 'punctuation': punctuation
  4233. };
  4234. var string_interpolation = {
  4235. pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
  4236. lookbehind: true,
  4237. inside: Prism.languages.php
  4238. };
  4239. var string = [
  4240. {
  4241. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  4242. alias: 'nowdoc-string',
  4243. greedy: true,
  4244. inside: {
  4245. 'delimiter': {
  4246. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  4247. alias: 'symbol',
  4248. inside: {
  4249. 'punctuation': /^<<<'?|[';]$/
  4250. }
  4251. }
  4252. }
  4253. },
  4254. {
  4255. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  4256. alias: 'heredoc-string',
  4257. greedy: true,
  4258. inside: {
  4259. 'delimiter': {
  4260. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  4261. alias: 'symbol',
  4262. inside: {
  4263. 'punctuation': /^<<<"?|[";]$/
  4264. }
  4265. },
  4266. 'interpolation': string_interpolation
  4267. }
  4268. },
  4269. {
  4270. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  4271. alias: 'backtick-quoted-string',
  4272. greedy: true
  4273. },
  4274. {
  4275. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  4276. alias: 'single-quoted-string',
  4277. greedy: true
  4278. },
  4279. {
  4280. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  4281. alias: 'double-quoted-string',
  4282. greedy: true,
  4283. inside: {
  4284. 'interpolation': string_interpolation
  4285. }
  4286. }
  4287. ];
  4288. Prism.languages.insertBefore('php', 'variable', {
  4289. 'string': string,
  4290. 'attribute': {
  4291. pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,
  4292. greedy: true,
  4293. inside: {
  4294. 'attribute-content': {
  4295. pattern: /^(#\[)[\s\S]+(?=\]$)/,
  4296. lookbehind: true,
  4297. // inside can appear subset of php
  4298. inside: {
  4299. 'comment': comment,
  4300. 'string': string,
  4301. 'attribute-class-name': [
  4302. {
  4303. pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
  4304. alias: 'class-name',
  4305. greedy: true,
  4306. lookbehind: true
  4307. },
  4308. {
  4309. pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
  4310. alias: [
  4311. 'class-name',
  4312. 'class-name-fully-qualified'
  4313. ],
  4314. greedy: true,
  4315. lookbehind: true,
  4316. inside: {
  4317. 'punctuation': /\\/
  4318. }
  4319. }
  4320. ],
  4321. 'constant': constant,
  4322. 'number': number,
  4323. 'operator': operator,
  4324. 'punctuation': punctuation
  4325. }
  4326. },
  4327. 'delimiter': {
  4328. pattern: /^#\[|\]$/,
  4329. alias: 'punctuation'
  4330. }
  4331. }
  4332. },
  4333. });
  4334. Prism.hooks.add('before-tokenize', function (env) {
  4335. if (!/<\?/.test(env.code)) {
  4336. return;
  4337. }
  4338. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g;
  4339. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  4340. });
  4341. Prism.hooks.add('after-tokenize', function (env) {
  4342. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  4343. });
  4344. }(Prism));
  4345. Prism.languages.python = {
  4346. 'comment': {
  4347. pattern: /(^|[^\\])#.*/,
  4348. lookbehind: true,
  4349. greedy: true
  4350. },
  4351. 'string-interpolation': {
  4352. pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  4353. greedy: true,
  4354. inside: {
  4355. 'interpolation': {
  4356. // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
  4357. pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
  4358. lookbehind: true,
  4359. inside: {
  4360. 'format-spec': {
  4361. pattern: /(:)[^:(){}]+(?=\}$)/,
  4362. lookbehind: true
  4363. },
  4364. 'conversion-option': {
  4365. pattern: /![sra](?=[:}]$)/,
  4366. alias: 'punctuation'
  4367. },
  4368. rest: null
  4369. }
  4370. },
  4371. 'string': /[\s\S]+/
  4372. }
  4373. },
  4374. 'triple-quoted-string': {
  4375. pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
  4376. greedy: true,
  4377. alias: 'string'
  4378. },
  4379. 'string': {
  4380. pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  4381. greedy: true
  4382. },
  4383. 'function': {
  4384. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  4385. lookbehind: true
  4386. },
  4387. 'class-name': {
  4388. pattern: /(\bclass\s+)\w+/i,
  4389. lookbehind: true
  4390. },
  4391. 'decorator': {
  4392. pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
  4393. lookbehind: true,
  4394. alias: ['annotation', 'punctuation'],
  4395. inside: {
  4396. 'punctuation': /\./
  4397. }
  4398. },
  4399. '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/,
  4400. '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/,
  4401. 'boolean': /\b(?:False|None|True)\b/,
  4402. '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,
  4403. 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  4404. 'punctuation': /[{}[\];(),.:]/
  4405. };
  4406. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  4407. Prism.languages.py = Prism.languages.python;
  4408. (function (Prism) {
  4409. var jsString = /"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*'/.source;
  4410. var jsComment = /\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))*\*\//.source;
  4411. var jsExpr = /(?:[^\\()[\]{}"'/]|<string>|\/(?![*/])|<comment>|\(<expr>*\)|\[<expr>*\]|\{<expr>*\}|\\[\s\S])/
  4412. .source.replace(/<string>/g, function () { return jsString; }).replace(/<comment>/g, function () { return jsComment; });
  4413. // the pattern will blow up, so only a few iterations
  4414. for (var i = 0; i < 2; i++) {
  4415. jsExpr = jsExpr.replace(/<expr>/g, function () { return jsExpr; });
  4416. }
  4417. jsExpr = jsExpr.replace(/<expr>/g, '[^\\s\\S]');
  4418. Prism.languages.qml = {
  4419. 'comment': {
  4420. pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
  4421. greedy: true
  4422. },
  4423. 'javascript-function': {
  4424. 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'),
  4425. lookbehind: true,
  4426. greedy: true,
  4427. alias: 'language-javascript',
  4428. inside: Prism.languages.javascript
  4429. },
  4430. 'class-name': {
  4431. pattern: /((?:^|[:;])[ \t]*)(?!\d)\w+(?=[ \t]*\{|[ \t]+on\b)/m,
  4432. lookbehind: true
  4433. },
  4434. 'property': [
  4435. {
  4436. pattern: /((?:^|[;{])[ \t]*)(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  4437. lookbehind: true
  4438. },
  4439. {
  4440. pattern: /((?:^|[;{])[ \t]*)property[ \t]+(?!\d)\w+(?:\.\w+)*[ \t]+(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  4441. lookbehind: true,
  4442. inside: {
  4443. 'keyword': /^property/,
  4444. 'property': /\w+(?:\.\w+)*/
  4445. }
  4446. }
  4447. ],
  4448. 'javascript-expression': {
  4449. pattern: RegExp(/(:[ \t]*)(?![\s;}[])(?:(?!$|[;}])<js>)+/.source.replace(/<js>/g, function () { return jsExpr; }), 'm'),
  4450. lookbehind: true,
  4451. greedy: true,
  4452. alias: 'language-javascript',
  4453. inside: Prism.languages.javascript
  4454. },
  4455. 'string': {
  4456. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  4457. greedy: true
  4458. },
  4459. 'keyword': /\b(?:as|import|on)\b/,
  4460. 'punctuation': /[{}[\]:;,]/
  4461. };
  4462. }(Prism));
  4463. Prism.languages.r = {
  4464. 'comment': /#.*/,
  4465. 'string': {
  4466. pattern: /(['"])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  4467. greedy: true
  4468. },
  4469. 'percent-operator': {
  4470. // Includes user-defined operators
  4471. // and %%, %*%, %/%, %in%, %o%, %x%
  4472. pattern: /%[^%\s]*%/,
  4473. alias: 'operator'
  4474. },
  4475. 'boolean': /\b(?:FALSE|TRUE)\b/,
  4476. 'ellipsis': /\.\.(?:\.|\d+)/,
  4477. 'number': [
  4478. /\b(?:Inf|NaN)\b/,
  4479. /(?:\b0x[\dA-Fa-f]+(?:\.\d*)?|\b\d+(?:\.\d*)?|\B\.\d+)(?:[EePp][+-]?\d+)?[iL]?/
  4480. ],
  4481. 'keyword': /\b(?:NA|NA_character_|NA_complex_|NA_integer_|NA_real_|NULL|break|else|for|function|if|in|next|repeat|while)\b/,
  4482. 'operator': /->?>?|<(?:=|<?-)?|[>=!]=?|::?|&&?|\|\|?|[+*\/^$@~]/,
  4483. 'punctuation': /[(){}\[\],;]/
  4484. };
  4485. (function (Prism) {
  4486. var javascript = Prism.util.clone(Prism.languages.javascript);
  4487. var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
  4488. var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
  4489. var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
  4490. /**
  4491. * @param {string} source
  4492. * @param {string} [flags]
  4493. */
  4494. function re(source, flags) {
  4495. source = source
  4496. .replace(/<S>/g, function () { return space; })
  4497. .replace(/<BRACES>/g, function () { return braces; })
  4498. .replace(/<SPREAD>/g, function () { return spread; });
  4499. return RegExp(source, flags);
  4500. }
  4501. spread = re(spread).source;
  4502. Prism.languages.jsx = Prism.languages.extend('markup', javascript);
  4503. Prism.languages.jsx.tag.pattern = re(
  4504. /<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
  4505. );
  4506. Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/;
  4507. Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/;
  4508. Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
  4509. Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
  4510. Prism.languages.insertBefore('inside', 'attr-name', {
  4511. 'spread': {
  4512. pattern: re(/<SPREAD>/.source),
  4513. inside: Prism.languages.jsx
  4514. }
  4515. }, Prism.languages.jsx.tag);
  4516. Prism.languages.insertBefore('inside', 'special-attr', {
  4517. 'script': {
  4518. // Allow for two levels of nesting
  4519. pattern: re(/=<BRACES>/.source),
  4520. alias: 'language-javascript',
  4521. inside: {
  4522. 'script-punctuation': {
  4523. pattern: /^=(?=\{)/,
  4524. alias: 'punctuation'
  4525. },
  4526. rest: Prism.languages.jsx
  4527. },
  4528. }
  4529. }, Prism.languages.jsx.tag);
  4530. // The following will handle plain text inside tags
  4531. var stringifyToken = function (token) {
  4532. if (!token) {
  4533. return '';
  4534. }
  4535. if (typeof token === 'string') {
  4536. return token;
  4537. }
  4538. if (typeof token.content === 'string') {
  4539. return token.content;
  4540. }
  4541. return token.content.map(stringifyToken).join('');
  4542. };
  4543. var walkTokens = function (tokens) {
  4544. var openedTags = [];
  4545. for (var i = 0; i < tokens.length; i++) {
  4546. var token = tokens[i];
  4547. var notTagNorBrace = false;
  4548. if (typeof token !== 'string') {
  4549. if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
  4550. // We found a tag, now find its kind
  4551. if (token.content[0].content[0].content === '</') {
  4552. // Closing tag
  4553. if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
  4554. // Pop matching opening tag
  4555. openedTags.pop();
  4556. }
  4557. } else {
  4558. if (token.content[token.content.length - 1].content === '/>') {
  4559. // Autoclosed tag, ignore
  4560. } else {
  4561. // Opening tag
  4562. openedTags.push({
  4563. tagName: stringifyToken(token.content[0].content[1]),
  4564. openedBraces: 0
  4565. });
  4566. }
  4567. }
  4568. } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
  4569. // Here we might have entered a JSX context inside a tag
  4570. openedTags[openedTags.length - 1].openedBraces++;
  4571. } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
  4572. // Here we might have left a JSX context inside a tag
  4573. openedTags[openedTags.length - 1].openedBraces--;
  4574. } else {
  4575. notTagNorBrace = true;
  4576. }
  4577. }
  4578. if (notTagNorBrace || typeof token === 'string') {
  4579. if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
  4580. // Here we are inside a tag, and not inside a JSX context.
  4581. // That's plain text: drop any tokens matched.
  4582. var plainText = stringifyToken(token);
  4583. // And merge text with adjacent text
  4584. if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
  4585. plainText += stringifyToken(tokens[i + 1]);
  4586. tokens.splice(i + 1, 1);
  4587. }
  4588. if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
  4589. plainText = stringifyToken(tokens[i - 1]) + plainText;
  4590. tokens.splice(i - 1, 1);
  4591. i--;
  4592. }
  4593. tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
  4594. }
  4595. }
  4596. if (token.content && typeof token.content !== 'string') {
  4597. walkTokens(token.content);
  4598. }
  4599. }
  4600. };
  4601. Prism.hooks.add('after-tokenize', function (env) {
  4602. if (env.language !== 'jsx' && env.language !== 'tsx') {
  4603. return;
  4604. }
  4605. walkTokens(env.tokens);
  4606. });
  4607. }(Prism));
  4608. (function (Prism) {
  4609. var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
  4610. for (var i = 0; i < 2; i++) {
  4611. // support 4 levels of nested comments
  4612. multilineComment = multilineComment.replace(/<self>/g, function () { return multilineComment; });
  4613. }
  4614. multilineComment = multilineComment.replace(/<self>/g, function () { return /[^\s\S]/.source; });
  4615. Prism.languages.rust = {
  4616. 'comment': [
  4617. {
  4618. pattern: RegExp(/(^|[^\\])/.source + multilineComment),
  4619. lookbehind: true,
  4620. greedy: true
  4621. },
  4622. {
  4623. pattern: /(^|[^\\:])\/\/.*/,
  4624. lookbehind: true,
  4625. greedy: true
  4626. }
  4627. ],
  4628. 'string': {
  4629. pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
  4630. greedy: true
  4631. },
  4632. 'char': {
  4633. pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
  4634. greedy: true
  4635. },
  4636. 'attribute': {
  4637. pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
  4638. greedy: true,
  4639. alias: 'attr-name',
  4640. inside: {
  4641. 'string': null // see below
  4642. }
  4643. },
  4644. // Closure params should not be confused with bitwise OR |
  4645. 'closure-params': {
  4646. pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
  4647. lookbehind: true,
  4648. greedy: true,
  4649. inside: {
  4650. 'closure-punctuation': {
  4651. pattern: /^\||\|$/,
  4652. alias: 'punctuation'
  4653. },
  4654. rest: null // see below
  4655. }
  4656. },
  4657. 'lifetime-annotation': {
  4658. pattern: /'\w+/,
  4659. alias: 'symbol'
  4660. },
  4661. 'fragment-specifier': {
  4662. pattern: /(\$\w+:)[a-z]+/,
  4663. lookbehind: true,
  4664. alias: 'punctuation'
  4665. },
  4666. 'variable': /\$\w+/,
  4667. 'function-definition': {
  4668. pattern: /(\bfn\s+)\w+/,
  4669. lookbehind: true,
  4670. alias: 'function'
  4671. },
  4672. 'type-definition': {
  4673. pattern: /(\b(?:enum|struct|trait|type|union)\s+)\w+/,
  4674. lookbehind: true,
  4675. alias: 'class-name'
  4676. },
  4677. 'module-declaration': [
  4678. {
  4679. pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
  4680. lookbehind: true,
  4681. alias: 'namespace'
  4682. },
  4683. {
  4684. pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
  4685. lookbehind: true,
  4686. alias: 'namespace',
  4687. inside: {
  4688. 'punctuation': /::/
  4689. }
  4690. }
  4691. ],
  4692. 'keyword': [
  4693. // https://github.com/rust-lang/reference/blob/master/src/keywords.md
  4694. /\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/,
  4695. // primitives and str
  4696. // https://doc.rust-lang.org/stable/rust-by-example/primitives.html
  4697. /\b(?:bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/
  4698. ],
  4699. // functions can technically start with an upper-case letter, but this will introduce a lot of false positives
  4700. // and Rust's naming conventions recommend snake_case anyway.
  4701. // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
  4702. 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
  4703. 'macro': {
  4704. pattern: /\b\w+!/,
  4705. alias: 'property'
  4706. },
  4707. 'constant': /\b[A-Z_][A-Z_\d]+\b/,
  4708. 'class-name': /\b[A-Z]\w*\b/,
  4709. 'namespace': {
  4710. pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
  4711. inside: {
  4712. 'punctuation': /::/
  4713. }
  4714. },
  4715. // Hex, oct, bin, dec numbers with visual separators and type suffix
  4716. '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/,
  4717. 'boolean': /\b(?:false|true)\b/,
  4718. 'punctuation': /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
  4719. 'operator': /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
  4720. };
  4721. Prism.languages.rust['closure-params'].inside.rest = Prism.languages.rust;
  4722. Prism.languages.rust['attribute'].inside['string'] = Prism.languages.rust['string'];
  4723. }(Prism));
  4724. Prism.languages.scss = Prism.languages.extend('css', {
  4725. 'comment': {
  4726. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  4727. lookbehind: true
  4728. },
  4729. 'atrule': {
  4730. pattern: /@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,
  4731. inside: {
  4732. 'rule': /@[\w-]+/
  4733. // See rest below
  4734. }
  4735. },
  4736. // url, compassified
  4737. 'url': /(?:[-a-z]+-)?url(?=\()/i,
  4738. // CSS selector regex is not appropriate for Sass
  4739. // since there can be lot more things (var, @ directive, nesting..)
  4740. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  4741. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  4742. // 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
  4743. // can "pass" as a selector- e.g: proper#{$erty})
  4744. // this one was hard to do, so please be careful if you edit this one :)
  4745. 'selector': {
  4746. // Initial look-ahead is used to prevent matching of blank selectors
  4747. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]))/,
  4748. inside: {
  4749. 'parent': {
  4750. pattern: /&/,
  4751. alias: 'important'
  4752. },
  4753. 'placeholder': /%[-\w]+/,
  4754. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4755. }
  4756. },
  4757. 'property': {
  4758. pattern: /(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,
  4759. inside: {
  4760. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4761. }
  4762. }
  4763. });
  4764. Prism.languages.insertBefore('scss', 'atrule', {
  4765. 'keyword': [
  4766. /@(?:content|debug|each|else(?: if)?|extend|for|forward|function|if|import|include|mixin|return|use|warn|while)\b/i,
  4767. {
  4768. pattern: /( )(?:from|through)(?= )/,
  4769. lookbehind: true
  4770. }
  4771. ]
  4772. });
  4773. Prism.languages.insertBefore('scss', 'important', {
  4774. // var and interpolated vars
  4775. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  4776. });
  4777. Prism.languages.insertBefore('scss', 'function', {
  4778. 'module-modifier': {
  4779. pattern: /\b(?:as|hide|show|with)\b/i,
  4780. alias: 'keyword'
  4781. },
  4782. 'placeholder': {
  4783. pattern: /%[-\w]+/,
  4784. alias: 'selector'
  4785. },
  4786. 'statement': {
  4787. pattern: /\B!(?:default|optional)\b/i,
  4788. alias: 'keyword'
  4789. },
  4790. 'boolean': /\b(?:false|true)\b/,
  4791. 'null': {
  4792. pattern: /\bnull\b/,
  4793. alias: 'keyword'
  4794. },
  4795. 'operator': {
  4796. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|not|or)(?=\s)/,
  4797. lookbehind: true
  4798. }
  4799. });
  4800. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;
  4801. Prism.languages.scala = Prism.languages.extend('java', {
  4802. 'triple-quoted-string': {
  4803. pattern: /"""[\s\S]*?"""/,
  4804. greedy: true,
  4805. alias: 'string'
  4806. },
  4807. 'string': {
  4808. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  4809. greedy: true
  4810. },
  4811. '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/,
  4812. 'number': /\b0x(?:[\da-f]*\.)?[\da-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e\d+)?[dfl]?/i,
  4813. 'builtin': /\b(?:Any|AnyRef|AnyVal|Boolean|Byte|Char|Double|Float|Int|Long|Nothing|Short|String|Unit)\b/,
  4814. 'symbol': /'[^\d\s\\]\w*/
  4815. });
  4816. Prism.languages.insertBefore('scala', 'triple-quoted-string', {
  4817. 'string-interpolation': {
  4818. pattern: /\b[a-z]\w*(?:"""(?:[^$]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*?"""|"(?:[^$"\r\n]|\$(?:[^{]|\{(?:[^{}]|\{[^{}]*\})*\}))*")/i,
  4819. greedy: true,
  4820. inside: {
  4821. 'id': {
  4822. pattern: /^\w+/,
  4823. greedy: true,
  4824. alias: 'function'
  4825. },
  4826. 'escape': {
  4827. pattern: /\\\$"|\$[$"]/,
  4828. greedy: true,
  4829. alias: 'symbol'
  4830. },
  4831. 'interpolation': {
  4832. pattern: /\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
  4833. greedy: true,
  4834. inside: {
  4835. 'punctuation': /^\$\{?|\}$/,
  4836. 'expression': {
  4837. pattern: /[\s\S]+/,
  4838. inside: Prism.languages.scala
  4839. }
  4840. }
  4841. },
  4842. 'string': /[\s\S]+/
  4843. }
  4844. }
  4845. });
  4846. delete Prism.languages.scala['class-name'];
  4847. delete Prism.languages.scala['function'];
  4848. delete Prism.languages.scala['constant'];
  4849. (function (Prism) {
  4850. // CAREFUL!
  4851. // The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
  4852. var strings = [
  4853. // normal string
  4854. /"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/.source,
  4855. /'[^']*'/.source,
  4856. /\$'(?:[^'\\]|\\[\s\S])*'/.source,
  4857. // here doc
  4858. // 2 capturing groups
  4859. /<<-?\s*(["']?)(\w+)\1\s[\s\S]*?[\r\n]\2/.source
  4860. ].join('|');
  4861. Prism.languages['shell-session'] = {
  4862. 'command': {
  4863. pattern: RegExp(
  4864. // user info
  4865. /^/.source +
  4866. '(?:' +
  4867. (
  4868. // <user> ":" ( <path> )?
  4869. /[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+(?::[^\0-\x1F$#%*?"<>:;|]+)?/.source +
  4870. '|' +
  4871. // <path>
  4872. // Since the path pattern is quite general, we will require it to start with a special character to
  4873. // prevent false positives.
  4874. /[/~.][^\0-\x1F$#%*?"<>@:;|]*/.source
  4875. ) +
  4876. ')?' +
  4877. // shell symbol
  4878. /[$#%](?=\s)/.source +
  4879. // bash command
  4880. /(?:[^\\\r\n \t'"<$]|[ \t](?:(?!#)|#.*$)|\\(?:[^\r]|\r\n?)|\$(?!')|<(?!<)|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
  4881. 'm'
  4882. ),
  4883. greedy: true,
  4884. inside: {
  4885. 'info': {
  4886. // foo@bar:~/files$ exit
  4887. // foo@bar$ exit
  4888. // ~/files$ exit
  4889. pattern: /^[^#$%]+/,
  4890. alias: 'punctuation',
  4891. inside: {
  4892. 'user': /^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,
  4893. 'punctuation': /:/,
  4894. 'path': /[\s\S]+/
  4895. }
  4896. },
  4897. 'bash': {
  4898. pattern: /(^[$#%]\s*)\S[\s\S]*/,
  4899. lookbehind: true,
  4900. alias: 'language-bash',
  4901. inside: Prism.languages.bash
  4902. },
  4903. 'shell-symbol': {
  4904. pattern: /^[$#%]/,
  4905. alias: 'important'
  4906. }
  4907. }
  4908. },
  4909. 'output': /.(?:.*(?:[\r\n]|.$))*/
  4910. };
  4911. Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
  4912. }(Prism));
  4913. Prism.languages.sql = {
  4914. 'comment': {
  4915. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  4916. lookbehind: true
  4917. },
  4918. 'variable': [
  4919. {
  4920. pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
  4921. greedy: true
  4922. },
  4923. /@[\w.$]+/
  4924. ],
  4925. 'string': {
  4926. pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
  4927. greedy: true,
  4928. lookbehind: true
  4929. },
  4930. 'identifier': {
  4931. pattern: /(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,
  4932. greedy: true,
  4933. lookbehind: true,
  4934. inside: {
  4935. 'punctuation': /^`|`$/
  4936. }
  4937. },
  4938. '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?
  4939. '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,
  4940. 'boolean': /\b(?:FALSE|NULL|TRUE)\b/i,
  4941. 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
  4942. 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  4943. 'punctuation': /[;[\]()`,.]/
  4944. };
  4945. Prism.languages.tcl = {
  4946. 'comment': {
  4947. pattern: /(^|[^\\])#.*/,
  4948. lookbehind: true
  4949. },
  4950. 'string': {
  4951. pattern: /"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*"/,
  4952. greedy: true
  4953. },
  4954. 'variable': [
  4955. {
  4956. pattern: /(\$)(?:::)?(?:[a-zA-Z0-9]+::)*\w+/,
  4957. lookbehind: true
  4958. },
  4959. {
  4960. pattern: /(\$)\{[^}]+\}/,
  4961. lookbehind: true
  4962. },
  4963. {
  4964. pattern: /(^[\t ]*set[ \t]+)(?:::)?(?:[a-zA-Z0-9]+::)*\w+/m,
  4965. lookbehind: true
  4966. }
  4967. ],
  4968. 'function': {
  4969. pattern: /(^[\t ]*proc[ \t]+)\S+/m,
  4970. lookbehind: true
  4971. },
  4972. 'builtin': [
  4973. {
  4974. pattern: /(^[\t ]*)(?:break|class|continue|error|eval|exit|for|foreach|if|proc|return|switch|while)\b/m,
  4975. lookbehind: true
  4976. },
  4977. /\b(?:else|elseif)\b/
  4978. ],
  4979. 'scope': {
  4980. pattern: /(^[\t ]*)(?:global|upvar|variable)\b/m,
  4981. lookbehind: true,
  4982. alias: 'constant'
  4983. },
  4984. 'keyword': {
  4985. pattern: /(^[\t ]*|\[)(?:Safe_Base|Tcl|after|append|apply|array|auto_(?:execok|import|load|mkindex|qualify|reset)|automkindex_old|bgerror|binary|catch|cd|chan|clock|close|concat|dde|dict|encoding|eof|exec|expr|fblocked|fconfigure|fcopy|file(?:event|name)?|flush|gets|glob|history|http|incr|info|interp|join|lappend|lassign|lindex|linsert|list|llength|load|lrange|lrepeat|lreplace|lreverse|lsearch|lset|lsort|math(?:func|op)|memory|msgcat|namespace|open|package|parray|pid|pkg_mkIndex|platform|puts|pwd|re_syntax|read|refchan|regexp|registry|regsub|rename|scan|seek|set|socket|source|split|string|subst|tcl(?:_endOfWord|_findLibrary|startOf(?:Next|Previous)Word|test|vars|wordBreak(?:After|Before))|tell|time|tm|trace|unknown|unload|unset|update|uplevel|vwait)\b/m,
  4986. lookbehind: true
  4987. },
  4988. 'operator': /!=?|\*\*?|==|&&?|\|\|?|<[=<]?|>[=>]?|[-+~\/%?^]|\b(?:eq|in|ne|ni)\b/,
  4989. 'punctuation': /[{}()\[\]]/
  4990. };
  4991. (function (Prism) {
  4992. Prism.languages.typescript = Prism.languages.extend('javascript', {
  4993. 'class-name': {
  4994. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
  4995. lookbehind: true,
  4996. greedy: true,
  4997. inside: null // see below
  4998. },
  4999. 'builtin': /\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/,
  5000. });
  5001. // The keywords TypeScript adds to JavaScript
  5002. Prism.languages.typescript.keyword.push(
  5003. /\b(?:abstract|declare|is|keyof|readonly|require)\b/,
  5004. // keywords that have to be followed by an identifier
  5005. /\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,
  5006. // This is for `import type *, {}`
  5007. /\btype\b(?=\s*(?:[\{*]|$))/
  5008. );
  5009. // doesn't work with TS because TS is too complex
  5010. delete Prism.languages.typescript['parameter'];
  5011. delete Prism.languages.typescript['literal-property'];
  5012. // a version of typescript specifically for highlighting types
  5013. var typeInside = Prism.languages.extend('typescript', {});
  5014. delete typeInside['class-name'];
  5015. Prism.languages.typescript['class-name'].inside = typeInside;
  5016. Prism.languages.insertBefore('typescript', 'function', {
  5017. 'decorator': {
  5018. pattern: /@[$\w\xA0-\uFFFF]+/,
  5019. inside: {
  5020. 'at': {
  5021. pattern: /^@/,
  5022. alias: 'operator'
  5023. },
  5024. 'function': /^[\s\S]+/
  5025. }
  5026. },
  5027. 'generic-function': {
  5028. // e.g. foo<T extends "bar" | "baz">( ...
  5029. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
  5030. greedy: true,
  5031. inside: {
  5032. 'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
  5033. 'generic': {
  5034. pattern: /<[\s\S]+/, // everything after the first <
  5035. alias: 'class-name',
  5036. inside: typeInside
  5037. }
  5038. }
  5039. }
  5040. });
  5041. Prism.languages.ts = Prism.languages.typescript;
  5042. }(Prism));
  5043. (function (Prism) {
  5044. // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
  5045. // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
  5046. var anchorOrAlias = /[*&][^\s[\]{},]+/;
  5047. // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
  5048. var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
  5049. // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
  5050. var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
  5051. + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
  5052. // https://yaml.org/spec/1.2/spec.html#ns-plain(n,c)
  5053. // This is a simplified version that doesn't support "#" and multiline keys
  5054. // All these long scarry character classes are simplified versions of YAML's characters
  5055. var plainKey = /(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*/.source
  5056. .replace(/<PLAIN>/g, function () { return /[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source; });
  5057. var string = /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;
  5058. /**
  5059. *
  5060. * @param {string} value
  5061. * @param {string} [flags]
  5062. * @returns {RegExp}
  5063. */
  5064. function createValuePattern(value, flags) {
  5065. flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
  5066. var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|\]|\}|(?:[\r\n]\s*)?#))/.source
  5067. .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
  5068. return RegExp(pattern, flags);
  5069. }
  5070. Prism.languages.yaml = {
  5071. 'scalar': {
  5072. pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source
  5073. .replace(/<<prop>>/g, function () { return properties; })),
  5074. lookbehind: true,
  5075. alias: 'string'
  5076. },
  5077. 'comment': /#.*/,
  5078. 'key': {
  5079. pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\s*:\s)/.source
  5080. .replace(/<<prop>>/g, function () { return properties; })
  5081. .replace(/<<key>>/g, function () { return '(?:' + plainKey + '|' + string + ')'; })),
  5082. lookbehind: true,
  5083. greedy: true,
  5084. alias: 'atrule'
  5085. },
  5086. 'directive': {
  5087. pattern: /(^[ \t]*)%.+/m,
  5088. lookbehind: true,
  5089. alias: 'important'
  5090. },
  5091. 'datetime': {
  5092. 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),
  5093. lookbehind: true,
  5094. alias: 'number'
  5095. },
  5096. 'boolean': {
  5097. pattern: createValuePattern(/false|true/.source, 'i'),
  5098. lookbehind: true,
  5099. alias: 'important'
  5100. },
  5101. 'null': {
  5102. pattern: createValuePattern(/null|~/.source, 'i'),
  5103. lookbehind: true,
  5104. alias: 'important'
  5105. },
  5106. 'string': {
  5107. pattern: createValuePattern(string),
  5108. lookbehind: true,
  5109. greedy: true
  5110. },
  5111. 'number': {
  5112. pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
  5113. lookbehind: true
  5114. },
  5115. 'tag': tag,
  5116. 'important': anchorOrAlias,
  5117. 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
  5118. };
  5119. Prism.languages.yml = Prism.languages.yaml;
  5120. }(Prism));
  5121. (function (Prism) {
  5122. function literal(str) {
  5123. return function () { return str; };
  5124. }
  5125. 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/;
  5126. var IDENTIFIER = '\\b(?!' + keyword.source + ')(?!\\d)\\w+\\b';
  5127. var ALIGN = /align\s*\((?:[^()]|\([^()]*\))*\)/.source;
  5128. var PREFIX_TYPE_OP = /(?:\?|\bpromise->|(?:\[[^[\]]*\]|\*(?!\*)|\*\*)(?:\s*<ALIGN>|\s*const\b|\s*volatile\b|\s*allowzero\b)*)/.source.replace(/<ALIGN>/g, literal(ALIGN));
  5129. var SUFFIX_EXPR = /(?:\bpromise\b|(?:\berror\.)?<ID>(?:\.<ID>)*(?!\s+<ID>))/.source.replace(/<ID>/g, literal(IDENTIFIER));
  5130. var TYPE = '(?!\\s)(?:!?\\s*(?:' + PREFIX_TYPE_OP + '\\s*)*' + SUFFIX_EXPR + ')+';
  5131. /*
  5132. * A simplified grammar for Zig compile time type literals:
  5133. *
  5134. * TypeExpr = ( "!"? PREFIX_TYPE_OP* SUFFIX_EXPR )+
  5135. *
  5136. * SUFFIX_EXPR = ( \b "promise" \b | ( \b "error" "." )? IDENTIFIER ( "." IDENTIFIER )* (?! \s+ IDENTIFIER ) )
  5137. *
  5138. * PREFIX_TYPE_OP = "?"
  5139. * | \b "promise" "->"
  5140. * | ( "[" [^\[\]]* "]" | "*" | "**" ) ( ALIGN | "const" \b | "volatile" \b | "allowzero" \b )*
  5141. *
  5142. * ALIGN = "align" "(" ( [^()] | "(" [^()]* ")" )* ")"
  5143. *
  5144. * IDENTIFIER = \b (?! KEYWORD ) [a-zA-Z_] \w* \b
  5145. *
  5146. */
  5147. Prism.languages.zig = {
  5148. 'comment': [
  5149. {
  5150. pattern: /\/\/[/!].*/,
  5151. alias: 'doc-comment'
  5152. },
  5153. /\/{2}.*/
  5154. ],
  5155. 'string': [
  5156. {
  5157. // "string" and c"string"
  5158. pattern: /(^|[^\\@])c?"(?:[^"\\\r\n]|\\.)*"/,
  5159. lookbehind: true,
  5160. greedy: true
  5161. },
  5162. {
  5163. // multiline strings and c-strings
  5164. pattern: /([\r\n])([ \t]+c?\\{2}).*(?:(?:\r\n?|\n)\2.*)*/,
  5165. lookbehind: true,
  5166. greedy: true
  5167. }
  5168. ],
  5169. 'char': {
  5170. // characters 'a', '\n', '\xFF', '\u{10FFFF}'
  5171. pattern: /(^|[^\\])'(?:[^'\\\r\n]|[\uD800-\uDFFF]{2}|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
  5172. lookbehind: true,
  5173. greedy: true
  5174. },
  5175. 'builtin': /\B@(?!\d)\w+(?=\s*\()/,
  5176. 'label': {
  5177. pattern: /(\b(?:break|continue)\s*:\s*)\w+\b|\b(?!\d)\w+\b(?=\s*:\s*(?:\{|while\b))/,
  5178. lookbehind: true
  5179. },
  5180. 'class-name': [
  5181. // const Foo = struct {};
  5182. /\b(?!\d)\w+(?=\s*=\s*(?:(?:extern|packed)\s+)?(?:enum|struct|union)\s*[({])/,
  5183. {
  5184. // const x: i32 = 9;
  5185. // var x: Bar;
  5186. // fn foo(x: bool, y: f32) void {}
  5187. pattern: RegExp(/(:\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?[=;,)])|<TYPE>(?=\s*(?:<ALIGN>\s*)?\{)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
  5188. lookbehind: true,
  5189. inside: null // see below
  5190. },
  5191. {
  5192. // extern fn foo(x: f64) f64; (optional alignment)
  5193. pattern: RegExp(/(\)\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?;)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
  5194. lookbehind: true,
  5195. inside: null // see below
  5196. }
  5197. ],
  5198. 'builtin-type': {
  5199. 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/,
  5200. alias: 'keyword'
  5201. },
  5202. 'keyword': keyword,
  5203. 'function': /\b(?!\d)\w+(?=\s*\()/,
  5204. '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/,
  5205. 'boolean': /\b(?:false|true)\b/,
  5206. 'operator': /\.[*?]|\.{2,3}|[-=]>|\*\*|\+\+|\|\||(?:<<|>>|[-+*]%|[-+*/%^&|<>!=])=?|[?~]/,
  5207. 'punctuation': /[.:,;(){}[\]]/
  5208. };
  5209. Prism.languages.zig['class-name'].forEach(function (obj) {
  5210. if (obj.inside === null) {
  5211. obj.inside = Prism.languages.zig;
  5212. }
  5213. });
  5214. }(Prism));