prism.js 152 KB

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