prism.js 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205
  1. /* PrismJS 1.23.0
  2. https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+cpp+coffeescript+crystal+d+dart+diff+django+elixir+erlang+go+groovy+java+json+julia+kotlin+lua+markup-templating+matlab+nginx+nim+ocaml+perl+php+python+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. var _ = {
  24. /**
  25. * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
  26. * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
  27. * additional languages or plugins yourself.
  28. *
  29. * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
  30. *
  31. * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
  32. * empty Prism object into the global scope before loading the Prism script like this:
  33. *
  34. * ```js
  35. * window.Prism = window.Prism || {};
  36. * Prism.manual = true;
  37. * // add a new <script> to load Prism's script
  38. * ```
  39. *
  40. * @default false
  41. * @type {boolean}
  42. * @memberof Prism
  43. * @public
  44. */
  45. manual: _self.Prism && _self.Prism.manual,
  46. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  47. /**
  48. * A namespace for utility methods.
  49. *
  50. * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
  51. * change or disappear at any time.
  52. *
  53. * @namespace
  54. * @memberof Prism
  55. */
  56. util: {
  57. encode: function encode(tokens) {
  58. if (tokens instanceof Token) {
  59. return new Token(tokens.type, encode(tokens.content), tokens.alias);
  60. } else if (Array.isArray(tokens)) {
  61. return tokens.map(encode);
  62. } else {
  63. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  64. }
  65. },
  66. /**
  67. * Returns the name of the type of the given value.
  68. *
  69. * @param {any} o
  70. * @returns {string}
  71. * @example
  72. * type(null) === 'Null'
  73. * type(undefined) === 'Undefined'
  74. * type(123) === 'Number'
  75. * type('foo') === 'String'
  76. * type(true) === 'Boolean'
  77. * type([1, 2]) === 'Array'
  78. * type({}) === 'Object'
  79. * type(String) === 'Function'
  80. * type(/abc+/) === 'RegExp'
  81. */
  82. type: function (o) {
  83. return Object.prototype.toString.call(o).slice(8, -1);
  84. },
  85. /**
  86. * Returns a unique number for the given object. Later calls will still return the same number.
  87. *
  88. * @param {Object} obj
  89. * @returns {number}
  90. */
  91. objId: function (obj) {
  92. if (!obj['__id']) {
  93. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  94. }
  95. return obj['__id'];
  96. },
  97. /**
  98. * Creates a deep clone of the given object.
  99. *
  100. * The main intended use of this function is to clone language definitions.
  101. *
  102. * @param {T} o
  103. * @param {Record<number, any>} [visited]
  104. * @returns {T}
  105. * @template T
  106. */
  107. clone: function deepClone(o, visited) {
  108. visited = visited || {};
  109. var clone, id;
  110. switch (_.util.type(o)) {
  111. case 'Object':
  112. id = _.util.objId(o);
  113. if (visited[id]) {
  114. return visited[id];
  115. }
  116. clone = /** @type {Record<string, any>} */ ({});
  117. visited[id] = clone;
  118. for (var key in o) {
  119. if (o.hasOwnProperty(key)) {
  120. clone[key] = deepClone(o[key], visited);
  121. }
  122. }
  123. return /** @type {any} */ (clone);
  124. case 'Array':
  125. id = _.util.objId(o);
  126. if (visited[id]) {
  127. return visited[id];
  128. }
  129. clone = [];
  130. visited[id] = clone;
  131. (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
  132. clone[i] = deepClone(v, visited);
  133. });
  134. return /** @type {any} */ (clone);
  135. default:
  136. return o;
  137. }
  138. },
  139. /**
  140. * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
  141. *
  142. * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
  143. *
  144. * @param {Element} element
  145. * @returns {string}
  146. */
  147. getLanguage: function (element) {
  148. while (element && !lang.test(element.className)) {
  149. element = element.parentElement;
  150. }
  151. if (element) {
  152. return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
  153. }
  154. return 'none';
  155. },
  156. /**
  157. * Returns the script element that is currently executing.
  158. *
  159. * This does __not__ work for line script element.
  160. *
  161. * @returns {HTMLScriptElement | null}
  162. */
  163. currentScript: function () {
  164. if (typeof document === 'undefined') {
  165. return null;
  166. }
  167. if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
  168. return /** @type {any} */ (document.currentScript);
  169. }
  170. // IE11 workaround
  171. // we'll get the src of the current script by parsing IE11's error stack trace
  172. // this will not work for inline scripts
  173. try {
  174. throw new Error();
  175. } catch (err) {
  176. // Get file src url from stack. Specifically works with the format of stack traces in IE.
  177. // A stack will look like this:
  178. //
  179. // Error
  180. // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
  181. // at Global code (http://localhost/components/prism-core.js:606:1)
  182. var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
  183. if (src) {
  184. var scripts = document.getElementsByTagName('script');
  185. for (var i in scripts) {
  186. if (scripts[i].src == src) {
  187. return scripts[i];
  188. }
  189. }
  190. }
  191. return null;
  192. }
  193. },
  194. /**
  195. * Returns whether a given class is active for `element`.
  196. *
  197. * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
  198. * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
  199. * given class is just the given class with a `no-` prefix.
  200. *
  201. * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
  202. * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
  203. * ancestors have the given class or the negated version of it, then the default activation will be returned.
  204. *
  205. * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
  206. * version of it, the class is considered active.
  207. *
  208. * @param {Element} element
  209. * @param {string} className
  210. * @param {boolean} [defaultActivation=false]
  211. * @returns {boolean}
  212. */
  213. isActive: function (element, className, defaultActivation) {
  214. var no = 'no-' + className;
  215. while (element) {
  216. var classList = element.classList;
  217. if (classList.contains(className)) {
  218. return true;
  219. }
  220. if (classList.contains(no)) {
  221. return false;
  222. }
  223. element = element.parentElement;
  224. }
  225. return !!defaultActivation;
  226. }
  227. },
  228. /**
  229. * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
  230. *
  231. * @namespace
  232. * @memberof Prism
  233. * @public
  234. */
  235. languages: {
  236. /**
  237. * Creates a deep copy of the language with the given id and appends the given tokens.
  238. *
  239. * If a token in `redef` also appears in the copied language, then the existing token in the copied language
  240. * will be overwritten at its original position.
  241. *
  242. * ## Best practices
  243. *
  244. * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
  245. * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
  246. * understand the language definition because, normally, the order of tokens matters in Prism grammars.
  247. *
  248. * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
  249. * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
  250. *
  251. * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
  252. * @param {Grammar} redef The new tokens to append.
  253. * @returns {Grammar} The new language created.
  254. * @public
  255. * @example
  256. * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
  257. * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
  258. * // at its original position
  259. * 'comment': { ... },
  260. * // CSS doesn't have a 'color' token, so this token will be appended
  261. * 'color': /\b(?:red|green|blue)\b/
  262. * });
  263. */
  264. extend: function (id, redef) {
  265. var lang = _.util.clone(_.languages[id]);
  266. for (var key in redef) {
  267. lang[key] = redef[key];
  268. }
  269. return lang;
  270. },
  271. /**
  272. * Inserts tokens _before_ another token in a language definition or any other grammar.
  273. *
  274. * ## Usage
  275. *
  276. * This helper method makes it easy to modify existing languages. For example, the CSS language definition
  277. * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
  278. * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
  279. * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
  280. * this:
  281. *
  282. * ```js
  283. * Prism.languages.markup.style = {
  284. * // token
  285. * };
  286. * ```
  287. *
  288. * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
  289. * before existing tokens. For the CSS example above, you would use it like this:
  290. *
  291. * ```js
  292. * Prism.languages.insertBefore('markup', 'cdata', {
  293. * 'style': {
  294. * // token
  295. * }
  296. * });
  297. * ```
  298. *
  299. * ## Special cases
  300. *
  301. * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
  302. * will be ignored.
  303. *
  304. * This behavior can be used to insert tokens after `before`:
  305. *
  306. * ```js
  307. * Prism.languages.insertBefore('markup', 'comment', {
  308. * 'comment': Prism.languages.markup.comment,
  309. * // tokens after 'comment'
  310. * });
  311. * ```
  312. *
  313. * ## Limitations
  314. *
  315. * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
  316. * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
  317. * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
  318. * deleting properties which is necessary to insert at arbitrary positions.
  319. *
  320. * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
  321. * Instead, it will create a new object and replace all references to the target object with the new one. This
  322. * can be done without temporarily deleting properties, so the iteration order is well-defined.
  323. *
  324. * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
  325. * you hold the target object in a variable, then the value of the variable will not change.
  326. *
  327. * ```js
  328. * var oldMarkup = Prism.languages.markup;
  329. * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
  330. *
  331. * assert(oldMarkup !== Prism.languages.markup);
  332. * assert(newMarkup === Prism.languages.markup);
  333. * ```
  334. *
  335. * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
  336. * object to be modified.
  337. * @param {string} before The key to insert before.
  338. * @param {Grammar} insert An object containing the key-value pairs to be inserted.
  339. * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
  340. * object to be modified.
  341. *
  342. * Defaults to `Prism.languages`.
  343. * @returns {Grammar} The new grammar object.
  344. * @public
  345. */
  346. insertBefore: function (inside, before, insert, root) {
  347. root = root || /** @type {any} */ (_.languages);
  348. var grammar = root[inside];
  349. /** @type {Grammar} */
  350. var ret = {};
  351. for (var token in grammar) {
  352. if (grammar.hasOwnProperty(token)) {
  353. if (token == before) {
  354. for (var newToken in insert) {
  355. if (insert.hasOwnProperty(newToken)) {
  356. ret[newToken] = insert[newToken];
  357. }
  358. }
  359. }
  360. // Do not insert token which also occur in insert. See #1525
  361. if (!insert.hasOwnProperty(token)) {
  362. ret[token] = grammar[token];
  363. }
  364. }
  365. }
  366. var old = root[inside];
  367. root[inside] = ret;
  368. // Update references in other language definitions
  369. _.languages.DFS(_.languages, function(key, value) {
  370. if (value === old && key != inside) {
  371. this[key] = ret;
  372. }
  373. });
  374. return ret;
  375. },
  376. // Traverse a language definition with Depth First Search
  377. DFS: function DFS(o, callback, type, visited) {
  378. visited = visited || {};
  379. var objId = _.util.objId;
  380. for (var i in o) {
  381. if (o.hasOwnProperty(i)) {
  382. callback.call(o, i, o[i], type || i);
  383. var property = o[i],
  384. propertyType = _.util.type(property);
  385. if (propertyType === 'Object' && !visited[objId(property)]) {
  386. visited[objId(property)] = true;
  387. DFS(property, callback, null, visited);
  388. }
  389. else if (propertyType === 'Array' && !visited[objId(property)]) {
  390. visited[objId(property)] = true;
  391. DFS(property, callback, i, visited);
  392. }
  393. }
  394. }
  395. }
  396. },
  397. plugins: {},
  398. /**
  399. * This is the most high-level function in Prism’s API.
  400. * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
  401. * each one of them.
  402. *
  403. * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
  404. *
  405. * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
  406. * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
  407. * @memberof Prism
  408. * @public
  409. */
  410. highlightAll: function(async, callback) {
  411. _.highlightAllUnder(document, async, callback);
  412. },
  413. /**
  414. * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
  415. * {@link Prism.highlightElement} on each one of them.
  416. *
  417. * The following hooks will be run:
  418. * 1. `before-highlightall`
  419. * 2. `before-all-elements-highlight`
  420. * 3. All hooks of {@link Prism.highlightElement} for each element.
  421. *
  422. * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
  423. * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
  424. * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
  425. * @memberof Prism
  426. * @public
  427. */
  428. highlightAllUnder: function(container, async, callback) {
  429. var env = {
  430. callback: callback,
  431. container: container,
  432. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  433. };
  434. _.hooks.run('before-highlightall', env);
  435. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  436. _.hooks.run('before-all-elements-highlight', env);
  437. for (var i = 0, element; element = env.elements[i++];) {
  438. _.highlightElement(element, async === true, env.callback);
  439. }
  440. },
  441. /**
  442. * Highlights the code inside a single element.
  443. *
  444. * The following hooks will be run:
  445. * 1. `before-sanity-check`
  446. * 2. `before-highlight`
  447. * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
  448. * 4. `before-insert`
  449. * 5. `after-highlight`
  450. * 6. `complete`
  451. *
  452. * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
  453. * the element's language.
  454. *
  455. * @param {Element} element The element containing the code.
  456. * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
  457. * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
  458. * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
  459. * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
  460. *
  461. * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
  462. * asynchronous highlighting to work. You can build your own bundle on the
  463. * [Download page](https://prismjs.com/download.html).
  464. * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
  465. * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
  466. * @memberof Prism
  467. * @public
  468. */
  469. highlightElement: function(element, async, callback) {
  470. // Find language
  471. var language = _.util.getLanguage(element);
  472. var grammar = _.languages[language];
  473. // Set language on the element, if not present
  474. element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  475. // Set language on the parent, for styling
  476. var parent = element.parentElement;
  477. if (parent && parent.nodeName.toLowerCase() === 'pre') {
  478. parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
  479. }
  480. var code = element.textContent;
  481. var env = {
  482. element: element,
  483. language: language,
  484. grammar: grammar,
  485. code: code
  486. };
  487. function insertHighlightedCode(highlightedCode) {
  488. env.highlightedCode = highlightedCode;
  489. _.hooks.run('before-insert', env);
  490. env.element.innerHTML = env.highlightedCode;
  491. _.hooks.run('after-highlight', env);
  492. _.hooks.run('complete', env);
  493. callback && callback.call(env.element);
  494. }
  495. _.hooks.run('before-sanity-check', env);
  496. if (!env.code) {
  497. _.hooks.run('complete', env);
  498. callback && callback.call(env.element);
  499. return;
  500. }
  501. _.hooks.run('before-highlight', env);
  502. if (!env.grammar) {
  503. insertHighlightedCode(_.util.encode(env.code));
  504. return;
  505. }
  506. if (async && _self.Worker) {
  507. var worker = new Worker(_.filename);
  508. worker.onmessage = function(evt) {
  509. insertHighlightedCode(evt.data);
  510. };
  511. worker.postMessage(JSON.stringify({
  512. language: env.language,
  513. code: env.code,
  514. immediateClose: true
  515. }));
  516. }
  517. else {
  518. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  519. }
  520. },
  521. /**
  522. * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
  523. * and the language definitions to use, and returns a string with the HTML produced.
  524. *
  525. * The following hooks will be run:
  526. * 1. `before-tokenize`
  527. * 2. `after-tokenize`
  528. * 3. `wrap`: On each {@link Token}.
  529. *
  530. * @param {string} text A string with the code to be highlighted.
  531. * @param {Grammar} grammar An object containing the tokens to use.
  532. *
  533. * Usually a language definition like `Prism.languages.markup`.
  534. * @param {string} language The name of the language definition passed to `grammar`.
  535. * @returns {string} The highlighted HTML.
  536. * @memberof Prism
  537. * @public
  538. * @example
  539. * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
  540. */
  541. highlight: function (text, grammar, language) {
  542. var env = {
  543. code: text,
  544. grammar: grammar,
  545. language: language
  546. };
  547. _.hooks.run('before-tokenize', env);
  548. env.tokens = _.tokenize(env.code, env.grammar);
  549. _.hooks.run('after-tokenize', env);
  550. return Token.stringify(_.util.encode(env.tokens), env.language);
  551. },
  552. /**
  553. * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
  554. * and the language definitions to use, and returns an array with the tokenized code.
  555. *
  556. * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
  557. *
  558. * This method could be useful in other contexts as well, as a very crude parser.
  559. *
  560. * @param {string} text A string with the code to be highlighted.
  561. * @param {Grammar} grammar An object containing the tokens to use.
  562. *
  563. * Usually a language definition like `Prism.languages.markup`.
  564. * @returns {TokenStream} An array of strings and tokens, a token stream.
  565. * @memberof Prism
  566. * @public
  567. * @example
  568. * let code = `var foo = 0;`;
  569. * let tokens = Prism.tokenize(code, Prism.languages.javascript);
  570. * tokens.forEach(token => {
  571. * if (token instanceof Prism.Token && token.type === 'number') {
  572. * console.log(`Found numeric literal: ${token.content}`);
  573. * }
  574. * });
  575. */
  576. tokenize: function(text, grammar) {
  577. var rest = grammar.rest;
  578. if (rest) {
  579. for (var token in rest) {
  580. grammar[token] = rest[token];
  581. }
  582. delete grammar.rest;
  583. }
  584. var tokenList = new LinkedList();
  585. addAfter(tokenList, tokenList.head, text);
  586. matchGrammar(text, tokenList, grammar, tokenList.head, 0);
  587. return toArray(tokenList);
  588. },
  589. /**
  590. * @namespace
  591. * @memberof Prism
  592. * @public
  593. */
  594. hooks: {
  595. all: {},
  596. /**
  597. * Adds the given callback to the list of callbacks for the given hook.
  598. *
  599. * The callback will be invoked when the hook it is registered for is run.
  600. * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
  601. *
  602. * One callback function can be registered to multiple hooks and the same hook multiple times.
  603. *
  604. * @param {string} name The name of the hook.
  605. * @param {HookCallback} callback The callback function which is given environment variables.
  606. * @public
  607. */
  608. add: function (name, callback) {
  609. var hooks = _.hooks.all;
  610. hooks[name] = hooks[name] || [];
  611. hooks[name].push(callback);
  612. },
  613. /**
  614. * Runs a hook invoking all registered callbacks with the given environment variables.
  615. *
  616. * Callbacks will be invoked synchronously and in the order in which they were registered.
  617. *
  618. * @param {string} name The name of the hook.
  619. * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
  620. * @public
  621. */
  622. run: function (name, env) {
  623. var callbacks = _.hooks.all[name];
  624. if (!callbacks || !callbacks.length) {
  625. return;
  626. }
  627. for (var i=0, callback; callback = callbacks[i++];) {
  628. callback(env);
  629. }
  630. }
  631. },
  632. Token: Token
  633. };
  634. _self.Prism = _;
  635. // Typescript note:
  636. // The following can be used to import the Token type in JSDoc:
  637. //
  638. // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
  639. /**
  640. * Creates a new token.
  641. *
  642. * @param {string} type See {@link Token#type type}
  643. * @param {string | TokenStream} content See {@link Token#content content}
  644. * @param {string|string[]} [alias] The alias(es) of the token.
  645. * @param {string} [matchedStr=""] A copy of the full string this token was created from.
  646. * @class
  647. * @global
  648. * @public
  649. */
  650. function Token(type, content, alias, matchedStr) {
  651. /**
  652. * The type of the token.
  653. *
  654. * This is usually the key of a pattern in a {@link Grammar}.
  655. *
  656. * @type {string}
  657. * @see GrammarToken
  658. * @public
  659. */
  660. this.type = type;
  661. /**
  662. * The strings or tokens contained by this token.
  663. *
  664. * This will be a token stream if the pattern matched also defined an `inside` grammar.
  665. *
  666. * @type {string | TokenStream}
  667. * @public
  668. */
  669. this.content = content;
  670. /**
  671. * The alias(es) of the token.
  672. *
  673. * @type {string|string[]}
  674. * @see GrammarToken
  675. * @public
  676. */
  677. this.alias = alias;
  678. // Copy of the full string this token was created from
  679. this.length = (matchedStr || '').length | 0;
  680. }
  681. /**
  682. * A token stream is an array of strings and {@link Token Token} objects.
  683. *
  684. * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
  685. * them.
  686. *
  687. * 1. No adjacent strings.
  688. * 2. No empty strings.
  689. *
  690. * The only exception here is the token stream that only contains the empty string and nothing else.
  691. *
  692. * @typedef {Array<string | Token>} TokenStream
  693. * @global
  694. * @public
  695. */
  696. /**
  697. * Converts the given token or token stream to an HTML representation.
  698. *
  699. * The following hooks will be run:
  700. * 1. `wrap`: On each {@link Token}.
  701. *
  702. * @param {string | Token | TokenStream} o The token or token stream to be converted.
  703. * @param {string} language The name of current language.
  704. * @returns {string} The HTML representation of the token or token stream.
  705. * @memberof Token
  706. * @static
  707. */
  708. Token.stringify = function stringify(o, language) {
  709. if (typeof o == 'string') {
  710. return o;
  711. }
  712. if (Array.isArray(o)) {
  713. var s = '';
  714. o.forEach(function (e) {
  715. s += stringify(e, language);
  716. });
  717. return s;
  718. }
  719. var env = {
  720. type: o.type,
  721. content: stringify(o.content, language),
  722. tag: 'span',
  723. classes: ['token', o.type],
  724. attributes: {},
  725. language: language
  726. };
  727. var aliases = o.alias;
  728. if (aliases) {
  729. if (Array.isArray(aliases)) {
  730. Array.prototype.push.apply(env.classes, aliases);
  731. } else {
  732. env.classes.push(aliases);
  733. }
  734. }
  735. _.hooks.run('wrap', env);
  736. var attributes = '';
  737. for (var name in env.attributes) {
  738. attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  739. }
  740. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
  741. };
  742. /**
  743. * @param {RegExp} pattern
  744. * @param {number} pos
  745. * @param {string} text
  746. * @param {boolean} lookbehind
  747. * @returns {RegExpExecArray | null}
  748. */
  749. function matchPattern(pattern, pos, text, lookbehind) {
  750. pattern.lastIndex = pos;
  751. var match = pattern.exec(text);
  752. if (match && lookbehind && match[1]) {
  753. // change the match to remove the text matched by the Prism lookbehind group
  754. var lookbehindLength = match[1].length;
  755. match.index += lookbehindLength;
  756. match[0] = match[0].slice(lookbehindLength);
  757. }
  758. return match;
  759. }
  760. /**
  761. * @param {string} text
  762. * @param {LinkedList<string | Token>} tokenList
  763. * @param {any} grammar
  764. * @param {LinkedListNode<string | Token>} startNode
  765. * @param {number} startPos
  766. * @param {RematchOptions} [rematch]
  767. * @returns {void}
  768. * @private
  769. *
  770. * @typedef RematchOptions
  771. * @property {string} cause
  772. * @property {number} reach
  773. */
  774. function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
  775. for (var token in grammar) {
  776. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  777. continue;
  778. }
  779. var patterns = grammar[token];
  780. patterns = Array.isArray(patterns) ? patterns : [patterns];
  781. for (var j = 0; j < patterns.length; ++j) {
  782. if (rematch && rematch.cause == token + ',' + j) {
  783. return;
  784. }
  785. var patternObj = patterns[j],
  786. inside = patternObj.inside,
  787. lookbehind = !!patternObj.lookbehind,
  788. greedy = !!patternObj.greedy,
  789. alias = patternObj.alias;
  790. if (greedy && !patternObj.pattern.global) {
  791. // Without the global flag, lastIndex won't work
  792. var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
  793. patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
  794. }
  795. /** @type {RegExp} */
  796. var pattern = patternObj.pattern || patternObj;
  797. for ( // iterate the token list and keep track of the current token/string position
  798. var currentNode = startNode.next, pos = startPos;
  799. currentNode !== tokenList.tail;
  800. pos += currentNode.value.length, currentNode = currentNode.next
  801. ) {
  802. if (rematch && pos >= rematch.reach) {
  803. break;
  804. }
  805. var str = currentNode.value;
  806. if (tokenList.length > text.length) {
  807. // Something went terribly wrong, ABORT, ABORT!
  808. return;
  809. }
  810. if (str instanceof Token) {
  811. continue;
  812. }
  813. var removeCount = 1; // this is the to parameter of removeBetween
  814. var match;
  815. if (greedy) {
  816. match = matchPattern(pattern, pos, text, lookbehind);
  817. if (!match) {
  818. break;
  819. }
  820. var from = match.index;
  821. var to = match.index + match[0].length;
  822. var p = pos;
  823. // find the node that contains the match
  824. p += currentNode.value.length;
  825. while (from >= p) {
  826. currentNode = currentNode.next;
  827. p += currentNode.value.length;
  828. }
  829. // adjust pos (and p)
  830. p -= currentNode.value.length;
  831. pos = p;
  832. // the current node is a Token, then the match starts inside another Token, which is invalid
  833. if (currentNode.value instanceof Token) {
  834. continue;
  835. }
  836. // find the last node which is affected by this match
  837. for (
  838. var k = currentNode;
  839. k !== tokenList.tail && (p < to || typeof k.value === 'string');
  840. k = k.next
  841. ) {
  842. removeCount++;
  843. p += k.value.length;
  844. }
  845. removeCount--;
  846. // replace with the new match
  847. str = text.slice(pos, p);
  848. match.index -= pos;
  849. } else {
  850. match = matchPattern(pattern, 0, str, lookbehind);
  851. if (!match) {
  852. continue;
  853. }
  854. }
  855. var from = match.index,
  856. matchStr = match[0],
  857. before = str.slice(0, from),
  858. after = str.slice(from + matchStr.length);
  859. var reach = pos + str.length;
  860. if (rematch && reach > rematch.reach) {
  861. rematch.reach = reach;
  862. }
  863. var removeFrom = currentNode.prev;
  864. if (before) {
  865. removeFrom = addAfter(tokenList, removeFrom, before);
  866. pos += before.length;
  867. }
  868. removeRange(tokenList, removeFrom, removeCount);
  869. var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
  870. currentNode = addAfter(tokenList, removeFrom, wrapped);
  871. if (after) {
  872. addAfter(tokenList, currentNode, after);
  873. }
  874. if (removeCount > 1) {
  875. // at least one Token object was removed, so we have to do some rematching
  876. // this can only happen if the current pattern is greedy
  877. /** @type {RematchOptions} */
  878. var nestedRematch = {
  879. cause: token + ',' + j,
  880. reach: reach
  881. };
  882. matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
  883. // the reach might have been extended because of the rematching
  884. if (rematch && nestedRematch.reach > rematch.reach) {
  885. rematch.reach = nestedRematch.reach;
  886. }
  887. }
  888. }
  889. }
  890. }
  891. }
  892. /**
  893. * @typedef LinkedListNode
  894. * @property {T} value
  895. * @property {LinkedListNode<T> | null} prev The previous node.
  896. * @property {LinkedListNode<T> | null} next The next node.
  897. * @template T
  898. * @private
  899. */
  900. /**
  901. * @template T
  902. * @private
  903. */
  904. function LinkedList() {
  905. /** @type {LinkedListNode<T>} */
  906. var head = { value: null, prev: null, next: null };
  907. /** @type {LinkedListNode<T>} */
  908. var tail = { value: null, prev: head, next: null };
  909. head.next = tail;
  910. /** @type {LinkedListNode<T>} */
  911. this.head = head;
  912. /** @type {LinkedListNode<T>} */
  913. this.tail = tail;
  914. this.length = 0;
  915. }
  916. /**
  917. * Adds a new node with the given value to the list.
  918. * @param {LinkedList<T>} list
  919. * @param {LinkedListNode<T>} node
  920. * @param {T} value
  921. * @returns {LinkedListNode<T>} The added node.
  922. * @template T
  923. */
  924. function addAfter(list, node, value) {
  925. // assumes that node != list.tail && values.length >= 0
  926. var next = node.next;
  927. var newNode = { value: value, prev: node, next: next };
  928. node.next = newNode;
  929. next.prev = newNode;
  930. list.length++;
  931. return newNode;
  932. }
  933. /**
  934. * Removes `count` nodes after the given node. The given node will not be removed.
  935. * @param {LinkedList<T>} list
  936. * @param {LinkedListNode<T>} node
  937. * @param {number} count
  938. * @template T
  939. */
  940. function removeRange(list, node, count) {
  941. var next = node.next;
  942. for (var i = 0; i < count && next !== list.tail; i++) {
  943. next = next.next;
  944. }
  945. node.next = next;
  946. next.prev = node;
  947. list.length -= i;
  948. }
  949. /**
  950. * @param {LinkedList<T>} list
  951. * @returns {T[]}
  952. * @template T
  953. */
  954. function toArray(list) {
  955. var array = [];
  956. var node = list.head.next;
  957. while (node !== list.tail) {
  958. array.push(node.value);
  959. node = node.next;
  960. }
  961. return array;
  962. }
  963. if (!_self.document) {
  964. if (!_self.addEventListener) {
  965. // in Node.js
  966. return _;
  967. }
  968. if (!_.disableWorkerMessageHandler) {
  969. // In worker
  970. _self.addEventListener('message', function (evt) {
  971. var message = JSON.parse(evt.data),
  972. lang = message.language,
  973. code = message.code,
  974. immediateClose = message.immediateClose;
  975. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  976. if (immediateClose) {
  977. _self.close();
  978. }
  979. }, false);
  980. }
  981. return _;
  982. }
  983. // Get current script and highlight
  984. var script = _.util.currentScript();
  985. if (script) {
  986. _.filename = script.src;
  987. if (script.hasAttribute('data-manual')) {
  988. _.manual = true;
  989. }
  990. }
  991. function highlightAutomaticallyCallback() {
  992. if (!_.manual) {
  993. _.highlightAll();
  994. }
  995. }
  996. if (!_.manual) {
  997. // If the document state is "loading", then we'll use DOMContentLoaded.
  998. // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
  999. // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
  1000. // might take longer one animation frame to execute which can create a race condition where only some plugins have
  1001. // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
  1002. // See https://github.com/PrismJS/prism/issues/2102
  1003. var readyState = document.readyState;
  1004. if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
  1005. document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
  1006. } else {
  1007. if (window.requestAnimationFrame) {
  1008. window.requestAnimationFrame(highlightAutomaticallyCallback);
  1009. } else {
  1010. window.setTimeout(highlightAutomaticallyCallback, 16);
  1011. }
  1012. }
  1013. }
  1014. return _;
  1015. })(_self);
  1016. if (typeof module !== 'undefined' && module.exports) {
  1017. module.exports = Prism;
  1018. }
  1019. // hack for components to work correctly in node.js
  1020. if (typeof global !== 'undefined') {
  1021. global.Prism = Prism;
  1022. }
  1023. // some additional documentation/types
  1024. /**
  1025. * The expansion of a simple `RegExp` literal to support additional properties.
  1026. *
  1027. * @typedef GrammarToken
  1028. * @property {RegExp} pattern The regular expression of the token.
  1029. * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
  1030. * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
  1031. * @property {boolean} [greedy=false] Whether the token is greedy.
  1032. * @property {string|string[]} [alias] An optional alias or list of aliases.
  1033. * @property {Grammar} [inside] The nested grammar of this token.
  1034. *
  1035. * The `inside` grammar will be used to tokenize the text value of each token of this kind.
  1036. *
  1037. * This can be used to make nested and even recursive language definitions.
  1038. *
  1039. * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
  1040. * each another.
  1041. * @global
  1042. * @public
  1043. */
  1044. /**
  1045. * @typedef Grammar
  1046. * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
  1047. * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
  1048. * @global
  1049. * @public
  1050. */
  1051. /**
  1052. * A function which will invoked after an element was successfully highlighted.
  1053. *
  1054. * @callback HighlightCallback
  1055. * @param {Element} element The element successfully highlighted.
  1056. * @returns {void}
  1057. * @global
  1058. * @public
  1059. */
  1060. /**
  1061. * @callback HookCallback
  1062. * @param {Object<string, any>} env The environment variables of the hook.
  1063. * @returns {void}
  1064. * @global
  1065. * @public
  1066. */
  1067. ;
  1068. Prism.languages.markup = {
  1069. 'comment': /<!--[\s\S]*?-->/,
  1070. 'prolog': /<\?[\s\S]+?\?>/,
  1071. 'doctype': {
  1072. // https://www.w3.org/TR/xml/#NT-doctypedecl
  1073. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
  1074. greedy: true,
  1075. inside: {
  1076. 'internal-subset': {
  1077. pattern: /(\[)[\s\S]+(?=\]>$)/,
  1078. lookbehind: true,
  1079. greedy: true,
  1080. inside: null // see below
  1081. },
  1082. 'string': {
  1083. pattern: /"[^"]*"|'[^']*'/,
  1084. greedy: true
  1085. },
  1086. 'punctuation': /^<!|>$|[[\]]/,
  1087. 'doctype-tag': /^DOCTYPE/,
  1088. 'name': /[^\s<>'"]+/
  1089. }
  1090. },
  1091. 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
  1092. 'tag': {
  1093. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
  1094. greedy: true,
  1095. inside: {
  1096. 'tag': {
  1097. pattern: /^<\/?[^\s>\/]+/,
  1098. inside: {
  1099. 'punctuation': /^<\/?/,
  1100. 'namespace': /^[^\s>\/:]+:/
  1101. }
  1102. },
  1103. 'attr-value': {
  1104. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
  1105. inside: {
  1106. 'punctuation': [
  1107. {
  1108. pattern: /^=/,
  1109. alias: 'attr-equals'
  1110. },
  1111. /"|'/
  1112. ]
  1113. }
  1114. },
  1115. 'punctuation': /\/?>/,
  1116. 'attr-name': {
  1117. pattern: /[^\s>\/]+/,
  1118. inside: {
  1119. 'namespace': /^[^\s>\/:]+:/
  1120. }
  1121. }
  1122. }
  1123. },
  1124. 'entity': [
  1125. {
  1126. pattern: /&[\da-z]{1,8};/i,
  1127. alias: 'named-entity'
  1128. },
  1129. /&#x?[\da-f]{1,8};/i
  1130. ]
  1131. };
  1132. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
  1133. Prism.languages.markup['entity'];
  1134. Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
  1135. // Plugin to make entity title show the real entity, idea by Roman Komarov
  1136. Prism.hooks.add('wrap', function (env) {
  1137. if (env.type === 'entity') {
  1138. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  1139. }
  1140. });
  1141. Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
  1142. /**
  1143. * Adds an inlined language to markup.
  1144. *
  1145. * An example of an inlined language is CSS with `<style>` tags.
  1146. *
  1147. * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
  1148. * case insensitive.
  1149. * @param {string} lang The language key.
  1150. * @example
  1151. * addInlined('style', 'css');
  1152. */
  1153. value: function addInlined(tagName, lang) {
  1154. var includedCdataInside = {};
  1155. includedCdataInside['language-' + lang] = {
  1156. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  1157. lookbehind: true,
  1158. inside: Prism.languages[lang]
  1159. };
  1160. includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
  1161. var inside = {
  1162. 'included-cdata': {
  1163. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1164. inside: includedCdataInside
  1165. }
  1166. };
  1167. inside['language-' + lang] = {
  1168. pattern: /[\s\S]+/,
  1169. inside: Prism.languages[lang]
  1170. };
  1171. var def = {};
  1172. def[tagName] = {
  1173. pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
  1174. lookbehind: true,
  1175. greedy: true,
  1176. inside: inside
  1177. };
  1178. Prism.languages.insertBefore('markup', 'cdata', def);
  1179. }
  1180. });
  1181. Prism.languages.html = Prism.languages.markup;
  1182. Prism.languages.mathml = Prism.languages.markup;
  1183. Prism.languages.svg = Prism.languages.markup;
  1184. Prism.languages.xml = Prism.languages.extend('markup', {});
  1185. Prism.languages.ssml = Prism.languages.xml;
  1186. Prism.languages.atom = Prism.languages.xml;
  1187. Prism.languages.rss = Prism.languages.xml;
  1188. (function (Prism) {
  1189. var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
  1190. Prism.languages.css = {
  1191. 'comment': /\/\*[\s\S]*?\*\//,
  1192. 'atrule': {
  1193. pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
  1194. inside: {
  1195. 'rule': /^@[\w-]+/,
  1196. 'selector-function-argument': {
  1197. pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
  1198. lookbehind: true,
  1199. alias: 'selector'
  1200. },
  1201. 'keyword': {
  1202. pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
  1203. lookbehind: true
  1204. }
  1205. // See rest below
  1206. }
  1207. },
  1208. 'url': {
  1209. // https://drafts.csswg.org/css-values-3/#urls
  1210. pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
  1211. greedy: true,
  1212. inside: {
  1213. 'function': /^url/i,
  1214. 'punctuation': /^\(|\)$/,
  1215. 'string': {
  1216. pattern: RegExp('^' + string.source + '$'),
  1217. alias: 'url'
  1218. }
  1219. }
  1220. },
  1221. 'selector': RegExp('[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
  1222. 'string': {
  1223. pattern: string,
  1224. greedy: true
  1225. },
  1226. 'property': /(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
  1227. 'important': /!important\b/i,
  1228. 'function': /[-a-z0-9]+(?=\()/i,
  1229. 'punctuation': /[(){};:,]/
  1230. };
  1231. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  1232. var markup = Prism.languages.markup;
  1233. if (markup) {
  1234. markup.tag.addInlined('style', 'css');
  1235. Prism.languages.insertBefore('inside', 'attr-value', {
  1236. 'style-attr': {
  1237. pattern: /(^|["'\s])style\s*=\s*(?:"[^"]*"|'[^']*')/i,
  1238. lookbehind: true,
  1239. inside: {
  1240. 'attr-value': {
  1241. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
  1242. inside: {
  1243. 'style': {
  1244. pattern: /(["'])[\s\S]+(?=["']$)/,
  1245. lookbehind: true,
  1246. alias: 'language-css',
  1247. inside: Prism.languages.css
  1248. },
  1249. 'punctuation': [
  1250. {
  1251. pattern: /^=/,
  1252. alias: 'attr-equals'
  1253. },
  1254. /"|'/
  1255. ]
  1256. }
  1257. },
  1258. 'attr-name': /^style/i
  1259. }
  1260. }
  1261. }, markup.tag);
  1262. }
  1263. }(Prism));
  1264. Prism.languages.clike = {
  1265. 'comment': [
  1266. {
  1267. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  1268. lookbehind: true,
  1269. greedy: true
  1270. },
  1271. {
  1272. pattern: /(^|[^\\:])\/\/.*/,
  1273. lookbehind: true,
  1274. greedy: true
  1275. }
  1276. ],
  1277. 'string': {
  1278. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  1279. greedy: true
  1280. },
  1281. 'class-name': {
  1282. pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
  1283. lookbehind: true,
  1284. inside: {
  1285. 'punctuation': /[.\\]/
  1286. }
  1287. },
  1288. 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
  1289. 'boolean': /\b(?:true|false)\b/,
  1290. 'function': /\w+(?=\()/,
  1291. 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
  1292. 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  1293. 'punctuation': /[{}[\];(),.:]/
  1294. };
  1295. Prism.languages.javascript = Prism.languages.extend('clike', {
  1296. 'class-name': [
  1297. Prism.languages.clike['class-name'],
  1298. {
  1299. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:prototype|constructor))/,
  1300. lookbehind: true
  1301. }
  1302. ],
  1303. 'keyword': [
  1304. {
  1305. pattern: /((?:^|})\s*)catch\b/,
  1306. lookbehind: true
  1307. },
  1308. {
  1309. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|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/,
  1310. lookbehind: true
  1311. },
  1312. ],
  1313. // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
  1314. 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  1315. 'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
  1316. 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
  1317. });
  1318. Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
  1319. Prism.languages.insertBefore('javascript', 'keyword', {
  1320. 'regex': {
  1321. pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
  1322. lookbehind: true,
  1323. greedy: true,
  1324. inside: {
  1325. 'regex-source': {
  1326. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  1327. lookbehind: true,
  1328. alias: 'language-regex',
  1329. inside: Prism.languages.regex
  1330. },
  1331. 'regex-flags': /[a-z]+$/,
  1332. 'regex-delimiter': /^\/|\/$/
  1333. }
  1334. },
  1335. // This must be declared before keyword because we use "function" inside the look-forward
  1336. 'function-variable': {
  1337. 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*=>))/,
  1338. alias: 'function'
  1339. },
  1340. 'parameter': [
  1341. {
  1342. pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
  1343. lookbehind: true,
  1344. inside: Prism.languages.javascript
  1345. },
  1346. {
  1347. pattern: /(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
  1348. inside: Prism.languages.javascript
  1349. },
  1350. {
  1351. pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
  1352. lookbehind: true,
  1353. inside: Prism.languages.javascript
  1354. },
  1355. {
  1356. 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*\{)/,
  1357. lookbehind: true,
  1358. inside: Prism.languages.javascript
  1359. }
  1360. ],
  1361. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  1362. });
  1363. Prism.languages.insertBefore('javascript', 'string', {
  1364. 'template-string': {
  1365. pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
  1366. greedy: true,
  1367. inside: {
  1368. 'template-punctuation': {
  1369. pattern: /^`|`$/,
  1370. alias: 'string'
  1371. },
  1372. 'interpolation': {
  1373. pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
  1374. lookbehind: true,
  1375. inside: {
  1376. 'interpolation-punctuation': {
  1377. pattern: /^\${|}$/,
  1378. alias: 'punctuation'
  1379. },
  1380. rest: Prism.languages.javascript
  1381. }
  1382. },
  1383. 'string': /[\s\S]+/
  1384. }
  1385. }
  1386. });
  1387. if (Prism.languages.markup) {
  1388. Prism.languages.markup.tag.addInlined('script', 'javascript');
  1389. }
  1390. Prism.languages.js = Prism.languages.javascript;
  1391. (function(Prism) {
  1392. // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
  1393. // + LC_ALL, RANDOM, REPLY, SECONDS.
  1394. // + make sure PS1..4 are here as they are not always set,
  1395. // - some useless things.
  1396. 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';
  1397. var commandAfterHeredoc = {
  1398. pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
  1399. lookbehind: true,
  1400. alias: 'punctuation', // this looks reasonably well in all themes
  1401. inside: null // see below
  1402. };
  1403. var insideString = {
  1404. 'bash': commandAfterHeredoc,
  1405. 'environment': {
  1406. pattern: RegExp("\\$" + envVars),
  1407. alias: 'constant'
  1408. },
  1409. 'variable': [
  1410. // [0]: Arithmetic Environment
  1411. {
  1412. pattern: /\$?\(\([\s\S]+?\)\)/,
  1413. greedy: true,
  1414. inside: {
  1415. // If there is a $ sign at the beginning highlight $(( and )) as variable
  1416. 'variable': [
  1417. {
  1418. pattern: /(^\$\(\([\s\S]+)\)\)/,
  1419. lookbehind: true
  1420. },
  1421. /^\$\(\(/
  1422. ],
  1423. 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
  1424. // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
  1425. 'operator': /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
  1426. // If there is no $ sign at the beginning highlight (( and )) as punctuation
  1427. 'punctuation': /\(\(?|\)\)?|,|;/
  1428. }
  1429. },
  1430. // [1]: Command Substitution
  1431. {
  1432. pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
  1433. greedy: true,
  1434. inside: {
  1435. 'variable': /^\$\(|^`|\)$|`$/
  1436. }
  1437. },
  1438. // [2]: Brace expansion
  1439. {
  1440. pattern: /\$\{[^}]+\}/,
  1441. greedy: true,
  1442. inside: {
  1443. 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
  1444. 'punctuation': /[\[\]]/,
  1445. 'environment': {
  1446. pattern: RegExp("(\\{)" + envVars),
  1447. lookbehind: true,
  1448. alias: 'constant'
  1449. }
  1450. }
  1451. },
  1452. /\$(?:\w+|[#?*!@$])/
  1453. ],
  1454. // Escape sequences from echo and printf's manuals, and escaped quotes.
  1455. 'entity': /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})/
  1456. };
  1457. Prism.languages.bash = {
  1458. 'shebang': {
  1459. pattern: /^#!\s*\/.*/,
  1460. alias: 'important'
  1461. },
  1462. 'comment': {
  1463. pattern: /(^|[^"{\\$])#.*/,
  1464. lookbehind: true
  1465. },
  1466. 'function-name': [
  1467. // a) function foo {
  1468. // b) foo() {
  1469. // c) function foo() {
  1470. // but not “foo {”
  1471. {
  1472. // a) and c)
  1473. pattern: /(\bfunction\s+)\w+(?=(?:\s*\(?:\s*\))?\s*\{)/,
  1474. lookbehind: true,
  1475. alias: 'function'
  1476. },
  1477. {
  1478. // b)
  1479. pattern: /\b\w+(?=\s*\(\s*\)\s*\{)/,
  1480. alias: 'function'
  1481. }
  1482. ],
  1483. // Highlight variable names as variables in for and select beginnings.
  1484. 'for-or-select': {
  1485. pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
  1486. alias: 'variable',
  1487. lookbehind: true
  1488. },
  1489. // Highlight variable names as variables in the left-hand part
  1490. // of assignments (“=” and “+=”).
  1491. 'assign-left': {
  1492. pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
  1493. inside: {
  1494. 'environment': {
  1495. pattern: RegExp("(^|[\\s;|&]|[<>]\\()" + envVars),
  1496. lookbehind: true,
  1497. alias: 'constant'
  1498. }
  1499. },
  1500. alias: 'variable',
  1501. lookbehind: true
  1502. },
  1503. 'string': [
  1504. // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
  1505. {
  1506. pattern: /((?:^|[^<])<<-?\s*)(\w+?)\s[\s\S]*?(?:\r?\n|\r)\2/,
  1507. lookbehind: true,
  1508. greedy: true,
  1509. inside: insideString
  1510. },
  1511. // Here-document with quotes around the tag
  1512. // → No expansion (so no “inside”).
  1513. {
  1514. pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
  1515. lookbehind: true,
  1516. greedy: true,
  1517. inside: {
  1518. 'bash': commandAfterHeredoc
  1519. }
  1520. },
  1521. // “Normal” string
  1522. {
  1523. pattern: /(^|[^\\](?:\\\\)*)(["'])(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|(?!\2)[^\\`$])*\2/,
  1524. lookbehind: true,
  1525. greedy: true,
  1526. inside: insideString
  1527. }
  1528. ],
  1529. 'environment': {
  1530. pattern: RegExp("\\$?" + envVars),
  1531. alias: 'constant'
  1532. },
  1533. 'variable': insideString.variable,
  1534. 'function': {
  1535. pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|aptitude|apt-cache|apt-get|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;|&])/,
  1536. lookbehind: true
  1537. },
  1538. 'keyword': {
  1539. pattern: /(^|[\s;|&]|[<>]\()(?:if|then|else|elif|fi|for|while|in|case|esac|function|select|do|done|until)(?=$|[)\s;|&])/,
  1540. lookbehind: true
  1541. },
  1542. // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
  1543. 'builtin': {
  1544. pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|break|cd|continue|eval|exec|exit|export|getopts|hash|pwd|readonly|return|shift|test|times|trap|umask|unset|alias|bind|builtin|caller|command|declare|echo|enable|help|let|local|logout|mapfile|printf|read|readarray|source|type|typeset|ulimit|unalias|set|shopt)(?=$|[)\s;|&])/,
  1545. lookbehind: true,
  1546. // Alias added to make those easier to distinguish from strings.
  1547. alias: 'class-name'
  1548. },
  1549. 'boolean': {
  1550. pattern: /(^|[\s;|&]|[<>]\()(?:true|false)(?=$|[)\s;|&])/,
  1551. lookbehind: true
  1552. },
  1553. 'file-descriptor': {
  1554. pattern: /\B&\d\b/,
  1555. alias: 'important'
  1556. },
  1557. 'operator': {
  1558. // Lots of redirections here, but not just that.
  1559. pattern: /\d?<>|>\||\+=|==?|!=?|=~|<<[<-]?|[&\d]?>>|\d?[<>]&?|&[>&]?|\|[&|]?|<=?|>=?/,
  1560. inside: {
  1561. 'file-descriptor': {
  1562. pattern: /^\d/,
  1563. alias: 'important'
  1564. }
  1565. }
  1566. },
  1567. 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
  1568. 'number': {
  1569. pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
  1570. lookbehind: true
  1571. }
  1572. };
  1573. commandAfterHeredoc.inside = Prism.languages.bash;
  1574. /* Patterns in command substitution. */
  1575. var toBeCopied = [
  1576. 'comment',
  1577. 'function-name',
  1578. 'for-or-select',
  1579. 'assign-left',
  1580. 'string',
  1581. 'environment',
  1582. 'function',
  1583. 'keyword',
  1584. 'builtin',
  1585. 'boolean',
  1586. 'file-descriptor',
  1587. 'operator',
  1588. 'punctuation',
  1589. 'number'
  1590. ];
  1591. var inside = insideString.variable[1].inside;
  1592. for(var i = 0; i < toBeCopied.length; i++) {
  1593. inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
  1594. }
  1595. Prism.languages.shell = Prism.languages.bash;
  1596. })(Prism);
  1597. Prism.languages.c = Prism.languages.extend('clike', {
  1598. 'comment': {
  1599. pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
  1600. greedy: true
  1601. },
  1602. 'class-name': {
  1603. pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
  1604. lookbehind: true
  1605. },
  1606. 'keyword': /\b(?:__attribute__|_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
  1607. 'function': /[a-z_]\w*(?=\s*\()/i,
  1608. 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
  1609. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
  1610. });
  1611. Prism.languages.insertBefore('c', 'string', {
  1612. 'macro': {
  1613. // allow for multiline macro definitions
  1614. // spaces after the # character compile fine with gcc
  1615. pattern: /(^\s*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
  1616. lookbehind: true,
  1617. greedy: true,
  1618. alias: 'property',
  1619. inside: {
  1620. 'string': [
  1621. {
  1622. // highlight the path of the include statement as a string
  1623. pattern: /^(#\s*include\s*)<[^>]+>/,
  1624. lookbehind: true
  1625. },
  1626. Prism.languages.c['string']
  1627. ],
  1628. 'comment': Prism.languages.c['comment'],
  1629. 'macro-name': [
  1630. {
  1631. pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
  1632. lookbehind: true
  1633. },
  1634. {
  1635. pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
  1636. lookbehind: true,
  1637. alias: 'function'
  1638. }
  1639. ],
  1640. // highlight macro directives as keywords
  1641. 'directive': {
  1642. pattern: /^(#\s*)[a-z]+/,
  1643. lookbehind: true,
  1644. alias: 'keyword'
  1645. },
  1646. 'directive-hash': /^#/,
  1647. 'punctuation': /##|\\(?=[\r\n])/,
  1648. 'expression': {
  1649. pattern: /\S[\s\S]*/,
  1650. inside: Prism.languages.c
  1651. }
  1652. }
  1653. },
  1654. // highlight predefined macros as constants
  1655. 'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
  1656. });
  1657. delete Prism.languages.c['boolean'];
  1658. (function (Prism) {
  1659. var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|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|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
  1660. Prism.languages.cpp = Prism.languages.extend('c', {
  1661. 'class-name': [
  1662. {
  1663. pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
  1664. .replace(/<keyword>/g, function () { return keyword.source; })),
  1665. lookbehind: true
  1666. },
  1667. // This is intended to capture the class name of method implementations like:
  1668. // void foo::bar() const {}
  1669. // However! The `foo` in the above example could also be a namespace, so we only capture the class name if
  1670. // it starts with an uppercase letter. This approximation should give decent results.
  1671. /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
  1672. // This will capture the class name before destructors like:
  1673. // Foo::~Foo() {}
  1674. /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
  1675. // This also intends to capture the class name of method implementations but here the class has template
  1676. // parameters, so it can't be a namespace (until C++ adds generic namespaces).
  1677. /\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
  1678. ],
  1679. 'keyword': keyword,
  1680. 'number': {
  1681. pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
  1682. greedy: true
  1683. },
  1684. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
  1685. 'boolean': /\b(?:true|false)\b/
  1686. });
  1687. Prism.languages.insertBefore('cpp', 'string', {
  1688. 'raw-string': {
  1689. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  1690. alias: 'string',
  1691. greedy: true
  1692. }
  1693. });
  1694. Prism.languages.insertBefore('cpp', 'class-name', {
  1695. // the base clause is an optional list of parent classes
  1696. // https://en.cppreference.com/w/cpp/language/class
  1697. 'base-clause': {
  1698. pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
  1699. lookbehind: true,
  1700. greedy: true,
  1701. inside: Prism.languages.extend('cpp', {})
  1702. }
  1703. });
  1704. Prism.languages.insertBefore('inside', 'operator', {
  1705. // All untokenized words that are not namespaces should be class names
  1706. 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i
  1707. }, Prism.languages.cpp['base-clause']);
  1708. }(Prism));
  1709. (function(Prism) {
  1710. // Ignore comments starting with { to privilege string interpolation highlighting
  1711. var comment = /#(?!\{).+/,
  1712. interpolation = {
  1713. pattern: /#\{[^}]+\}/,
  1714. alias: 'variable'
  1715. };
  1716. Prism.languages.coffeescript = Prism.languages.extend('javascript', {
  1717. 'comment': comment,
  1718. 'string': [
  1719. // Strings are multiline
  1720. {
  1721. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1722. greedy: true
  1723. },
  1724. {
  1725. // Strings are multiline
  1726. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1727. greedy: true,
  1728. inside: {
  1729. 'interpolation': interpolation
  1730. }
  1731. }
  1732. ],
  1733. '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/,
  1734. 'class-member': {
  1735. pattern: /@(?!\d)\w+/,
  1736. alias: 'variable'
  1737. }
  1738. });
  1739. Prism.languages.insertBefore('coffeescript', 'comment', {
  1740. 'multiline-comment': {
  1741. pattern: /###[\s\S]+?###/,
  1742. alias: 'comment'
  1743. },
  1744. // Block regexp can contain comments and interpolation
  1745. 'block-regex': {
  1746. pattern: /\/{3}[\s\S]*?\/{3}/,
  1747. alias: 'regex',
  1748. inside: {
  1749. 'comment': comment,
  1750. 'interpolation': interpolation
  1751. }
  1752. }
  1753. });
  1754. Prism.languages.insertBefore('coffeescript', 'string', {
  1755. 'inline-javascript': {
  1756. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  1757. inside: {
  1758. 'delimiter': {
  1759. pattern: /^`|`$/,
  1760. alias: 'punctuation'
  1761. },
  1762. 'script': {
  1763. pattern: /[\s\S]+/,
  1764. alias: 'language-javascript',
  1765. inside: Prism.languages.javascript
  1766. }
  1767. }
  1768. },
  1769. // Block strings
  1770. 'multiline-string': [
  1771. {
  1772. pattern: /'''[\s\S]*?'''/,
  1773. greedy: true,
  1774. alias: 'string'
  1775. },
  1776. {
  1777. pattern: /"""[\s\S]*?"""/,
  1778. greedy: true,
  1779. alias: 'string',
  1780. inside: {
  1781. interpolation: interpolation
  1782. }
  1783. }
  1784. ]
  1785. });
  1786. Prism.languages.insertBefore('coffeescript', 'keyword', {
  1787. // Object property
  1788. 'property': /(?!\d)\w+(?=\s*:(?!:))/
  1789. });
  1790. delete Prism.languages.coffeescript['template-string'];
  1791. Prism.languages.coffee = Prism.languages.coffeescript;
  1792. }(Prism));
  1793. /**
  1794. * Original by Samuel Flores
  1795. *
  1796. * Adds the following new token classes:
  1797. * constant, builtin, variable, symbol, regex
  1798. */
  1799. (function (Prism) {
  1800. Prism.languages.ruby = Prism.languages.extend('clike', {
  1801. 'comment': [
  1802. /#.*/,
  1803. {
  1804. pattern: /^=begin\s[\s\S]*?^=end/m,
  1805. greedy: true
  1806. }
  1807. ],
  1808. 'class-name': {
  1809. pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
  1810. lookbehind: true,
  1811. inside: {
  1812. 'punctuation': /[.\\]/
  1813. }
  1814. },
  1815. 'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/
  1816. });
  1817. var interpolation = {
  1818. pattern: /#\{[^}]+\}/,
  1819. inside: {
  1820. 'delimiter': {
  1821. pattern: /^#\{|\}$/,
  1822. alias: 'tag'
  1823. },
  1824. rest: Prism.languages.ruby
  1825. }
  1826. };
  1827. delete Prism.languages.ruby.function;
  1828. Prism.languages.insertBefore('ruby', 'keyword', {
  1829. 'regex': [
  1830. {
  1831. pattern: RegExp(/%r/.source + '(?:' + [
  1832. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/.source,
  1833. /\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/.source,
  1834. // Here we need to specifically allow interpolation
  1835. /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/.source,
  1836. /\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/.source,
  1837. /<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/.source
  1838. ].join('|') + ')'),
  1839. greedy: true,
  1840. inside: {
  1841. 'interpolation': interpolation
  1842. }
  1843. },
  1844. {
  1845. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[gim]{0,3}(?=\s*(?:$|[\r\n,.;})]))/,
  1846. lookbehind: true,
  1847. greedy: true
  1848. }
  1849. ],
  1850. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  1851. 'symbol': {
  1852. pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
  1853. lookbehind: true
  1854. },
  1855. 'method-definition': {
  1856. pattern: /(\bdef\s+)[\w.]+/,
  1857. lookbehind: true,
  1858. inside: {
  1859. 'function': /\w+$/,
  1860. rest: Prism.languages.ruby
  1861. }
  1862. }
  1863. });
  1864. Prism.languages.insertBefore('ruby', 'number', {
  1865. 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|Fixnum|Float|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
  1866. 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
  1867. });
  1868. Prism.languages.ruby.string = [
  1869. {
  1870. pattern: RegExp(/%[qQiIwWxs]?/.source + '(?:' + [
  1871. /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  1872. /\((?:[^()\\]|\\[\s\S])*\)/.source,
  1873. // Here we need to specifically allow interpolation
  1874. /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
  1875. /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
  1876. /<(?:[^<>\\]|\\[\s\S])*>/.source
  1877. ].join('|') + ')'),
  1878. greedy: true,
  1879. inside: {
  1880. 'interpolation': interpolation
  1881. }
  1882. },
  1883. {
  1884. pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
  1885. greedy: true,
  1886. inside: {
  1887. 'interpolation': interpolation
  1888. }
  1889. }
  1890. ];
  1891. Prism.languages.rb = Prism.languages.ruby;
  1892. }(Prism));
  1893. (function(Prism) {
  1894. Prism.languages.crystal = Prism.languages.extend('ruby', {
  1895. keyword: [
  1896. /\b(?: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|rescue|return|require|select|self|sizeof|struct|super|then|type|typeof|uninitialized|union|unless|until|when|while|with|yield|__DIR__|__END_LINE__|__FILE__|__LINE__)\b/,
  1897. {
  1898. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  1899. lookbehind: true
  1900. }
  1901. ],
  1902. 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/
  1903. });
  1904. Prism.languages.insertBefore('crystal', 'string', {
  1905. attribute: {
  1906. pattern: /@\[.+?\]/,
  1907. alias: 'attr-name',
  1908. inside: {
  1909. delimiter: {
  1910. pattern: /^@\[|\]$/,
  1911. alias: 'tag'
  1912. },
  1913. rest: Prism.languages.crystal
  1914. }
  1915. },
  1916. expansion: [
  1917. {
  1918. pattern: /\{\{.+?\}\}/,
  1919. inside: {
  1920. delimiter: {
  1921. pattern: /^\{\{|\}\}$/,
  1922. alias: 'tag'
  1923. },
  1924. rest: Prism.languages.crystal
  1925. }
  1926. },
  1927. {
  1928. pattern: /\{%.+?%\}/,
  1929. inside: {
  1930. delimiter: {
  1931. pattern: /^\{%|%\}$/,
  1932. alias: 'tag'
  1933. },
  1934. rest: Prism.languages.crystal
  1935. }
  1936. }
  1937. ]
  1938. });
  1939. }(Prism));
  1940. Prism.languages.d = Prism.languages.extend('clike', {
  1941. 'comment': [
  1942. {
  1943. // Shebang
  1944. pattern: /^\s*#!.+/,
  1945. greedy: true
  1946. },
  1947. {
  1948. pattern: RegExp(/(^|[^\\])/.source + '(?:' + [
  1949. // /+ comment +/
  1950. // Allow one level of nesting
  1951. /\/\+(?:\/\+(?:[^+]|\+(?!\/))*\+\/|(?!\/\+)[\s\S])*?\+\//.source,
  1952. // // comment
  1953. /\/\/.*/.source,
  1954. // /* comment */
  1955. /\/\*[\s\S]*?\*\//.source
  1956. ].join('|') + ')'),
  1957. lookbehind: true,
  1958. greedy: true
  1959. }
  1960. ],
  1961. 'string': [
  1962. {
  1963. pattern: RegExp([
  1964. // r"", x""
  1965. /\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/.source,
  1966. // q"[]", q"()", q"<>", q"{}"
  1967. /\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/.source,
  1968. // q"IDENT
  1969. // ...
  1970. // IDENT"
  1971. /\bq"((?!\d)\w+)$[\s\S]*?^\1"/.source,
  1972. // q"//", q"||", etc.
  1973. /\bq"(.)[\s\S]*?\2"/.source,
  1974. // Characters
  1975. // 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
  1976. /'(?:\\(?:\W|\w+)|[^\\])'/.source,
  1977. /(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
  1978. ].join('|'), 'm'),
  1979. greedy: true
  1980. },
  1981. {
  1982. pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
  1983. greedy: true,
  1984. alias: 'token-string'
  1985. }
  1986. ],
  1987. // In order: $, keywords and special tokens, globally defined symbols
  1988. 'keyword': /\$|\b(?: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|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|public|pure|real|ref|return|scope|shared|short|static|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|__(?:(?:FILE|MODULE|LINE|FUNCTION|PRETTY_FUNCTION|DATE|EOF|TIME|TIMESTAMP|VENDOR|VERSION)__|gshared|traits|vector|parameters)|string|wstring|dstring|size_t|ptrdiff_t)\b/,
  1989. 'number': [
  1990. // The lookbehind and the negative look-ahead try to prevent bad highlighting of the .. operator
  1991. // Hexadecimal numbers must be handled separately to avoid problems with exponent "e"
  1992. /\b0x\.?[a-f\d_]+(?:(?!\.\.)\.[a-f\d_]*)?(?:p[+-]?[a-f\d_]+)?[ulfi]{0,4}/i,
  1993. {
  1994. pattern: /((?:\.\.)?)(?:\b0b\.?|\b|\.)\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:e[+-]?\d[\d_]*)?[ulfi]{0,4}/i,
  1995. lookbehind: true
  1996. }
  1997. ],
  1998. 'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
  1999. });
  2000. Prism.languages.insertBefore('d', 'keyword', {
  2001. 'property': /\B@\w*/
  2002. });
  2003. Prism.languages.insertBefore('d', 'function', {
  2004. 'register': {
  2005. // Iasm registers
  2006. pattern: /\b(?:[ABCD][LHX]|E[ABCD]X|E?(?:BP|SP|DI|SI)|[ECSDGF]S|CR[0234]|DR[012367]|TR[3-7]|X?MM[0-7]|R[ABCD]X|[BS]PL|R[BS]P|[DS]IL|R[DS]I|R(?:[89]|1[0-5])[BWD]?|XMM(?:[89]|1[0-5])|YMM(?:1[0-5]|\d))\b|\bST(?:\([0-7]\)|\b)/,
  2007. alias: 'variable'
  2008. }
  2009. });
  2010. Prism.languages.dart = Prism.languages.extend('clike', {
  2011. 'string': [
  2012. {
  2013. pattern: /r?("""|''')[\s\S]*?\1/,
  2014. greedy: true
  2015. },
  2016. {
  2017. pattern: /r?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2018. greedy: true
  2019. }
  2020. ],
  2021. 'keyword': [
  2022. /\b(?:async|sync|yield)\*/,
  2023. /\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extension|external|extends|factory|final|finally|for|Function|get|hide|if|implements|interface|import|in|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/
  2024. ],
  2025. 'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
  2026. });
  2027. Prism.languages.insertBefore('dart','function',{
  2028. 'metadata': {
  2029. pattern: /@\w+/,
  2030. alias: 'symbol'
  2031. }
  2032. });
  2033. (function (Prism) {
  2034. Prism.languages.diff = {
  2035. 'coord': [
  2036. // Match all kinds of coord lines (prefixed by "+++", "---" or "***").
  2037. /^(?:\*{3}|-{3}|\+{3}).*$/m,
  2038. // Match "@@ ... @@" coord lines in unified diff.
  2039. /^@@.*@@$/m,
  2040. // Match coord lines in normal diff (starts with a number).
  2041. /^\d.*$/m
  2042. ]
  2043. // deleted, inserted, unchanged, diff
  2044. };
  2045. /**
  2046. * A map from the name of a block to its line prefix.
  2047. *
  2048. * @type {Object<string, string>}
  2049. */
  2050. var PREFIXES = {
  2051. 'deleted-sign': '-',
  2052. 'deleted-arrow': '<',
  2053. 'inserted-sign': '+',
  2054. 'inserted-arrow': '>',
  2055. 'unchanged': ' ',
  2056. 'diff': '!',
  2057. };
  2058. // add a token for each prefix
  2059. Object.keys(PREFIXES).forEach(function (name) {
  2060. var prefix = PREFIXES[name];
  2061. var alias = [];
  2062. if (!/^\w+$/.test(name)) { // "deleted-sign" -> "deleted"
  2063. alias.push(/\w+/.exec(name)[0]);
  2064. }
  2065. if (name === "diff") {
  2066. alias.push("bold");
  2067. }
  2068. Prism.languages.diff[name] = {
  2069. pattern: RegExp('^(?:[' + prefix + '].*(?:\r\n?|\n|(?![\\s\\S])))+', 'm'),
  2070. alias: alias,
  2071. inside: {
  2072. 'line': {
  2073. pattern: /(.)(?=[\s\S]).*(?:\r\n?|\n)?/,
  2074. lookbehind: true
  2075. },
  2076. 'prefix': {
  2077. pattern: /[\s\S]/,
  2078. alias: /\w+/.exec(name)[0]
  2079. }
  2080. }
  2081. };
  2082. });
  2083. // make prefixes available to Diff plugin
  2084. Object.defineProperty(Prism.languages.diff, 'PREFIXES', {
  2085. value: PREFIXES
  2086. });
  2087. }(Prism));
  2088. (function (Prism) {
  2089. /**
  2090. * Returns the placeholder for the given language id and index.
  2091. *
  2092. * @param {string} language
  2093. * @param {string|number} index
  2094. * @returns {string}
  2095. */
  2096. function getPlaceholder(language, index) {
  2097. return '___' + language.toUpperCase() + index + '___';
  2098. }
  2099. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  2100. buildPlaceholders: {
  2101. /**
  2102. * Tokenize all inline templating expressions matching `placeholderPattern`.
  2103. *
  2104. * If `replaceFilter` is provided, only matches of `placeholderPattern` for which `replaceFilter` returns
  2105. * `true` will be replaced.
  2106. *
  2107. * @param {object} env The environment of the `before-tokenize` hook.
  2108. * @param {string} language The language id.
  2109. * @param {RegExp} placeholderPattern The matches of this pattern will be replaced by placeholders.
  2110. * @param {(match: string) => boolean} [replaceFilter]
  2111. */
  2112. value: function (env, language, placeholderPattern, replaceFilter) {
  2113. if (env.language !== language) {
  2114. return;
  2115. }
  2116. var tokenStack = env.tokenStack = [];
  2117. env.code = env.code.replace(placeholderPattern, function (match) {
  2118. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  2119. return match;
  2120. }
  2121. var i = tokenStack.length;
  2122. var placeholder;
  2123. // Check for existing strings
  2124. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1)
  2125. ++i;
  2126. // Create a sparse array
  2127. tokenStack[i] = match;
  2128. return placeholder;
  2129. });
  2130. // Switch the grammar to markup
  2131. env.grammar = Prism.languages.markup;
  2132. }
  2133. },
  2134. tokenizePlaceholders: {
  2135. /**
  2136. * Replace placeholders with proper tokens after tokenizing.
  2137. *
  2138. * @param {object} env The environment of the `after-tokenize` hook.
  2139. * @param {string} language The language id.
  2140. */
  2141. value: function (env, language) {
  2142. if (env.language !== language || !env.tokenStack) {
  2143. return;
  2144. }
  2145. // Switch the grammar back
  2146. env.grammar = Prism.languages[language];
  2147. var j = 0;
  2148. var keys = Object.keys(env.tokenStack);
  2149. function walkTokens(tokens) {
  2150. for (var i = 0; i < tokens.length; i++) {
  2151. // all placeholders are replaced already
  2152. if (j >= keys.length) {
  2153. break;
  2154. }
  2155. var token = tokens[i];
  2156. if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
  2157. var k = keys[j];
  2158. var t = env.tokenStack[k];
  2159. var s = typeof token === 'string' ? token : token.content;
  2160. var placeholder = getPlaceholder(language, k);
  2161. var index = s.indexOf(placeholder);
  2162. if (index > -1) {
  2163. ++j;
  2164. var before = s.substring(0, index);
  2165. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  2166. var after = s.substring(index + placeholder.length);
  2167. var replacement = [];
  2168. if (before) {
  2169. replacement.push.apply(replacement, walkTokens([before]));
  2170. }
  2171. replacement.push(middle);
  2172. if (after) {
  2173. replacement.push.apply(replacement, walkTokens([after]));
  2174. }
  2175. if (typeof token === 'string') {
  2176. tokens.splice.apply(tokens, [i, 1].concat(replacement));
  2177. } else {
  2178. token.content = replacement;
  2179. }
  2180. }
  2181. } else if (token.content /* && typeof token.content !== 'string' */) {
  2182. walkTokens(token.content);
  2183. }
  2184. }
  2185. return tokens;
  2186. }
  2187. walkTokens(env.tokens);
  2188. }
  2189. }
  2190. });
  2191. }(Prism));
  2192. // Django/Jinja2 syntax definition for Prism.js <http://prismjs.com> syntax highlighter.
  2193. // Mostly it works OK but can paint code incorrectly on complex html/template tag combinations.
  2194. (function (Prism) {
  2195. Prism.languages.django = {
  2196. 'comment': /^{#[\s\S]*?#}$/,
  2197. 'tag': {
  2198. pattern: /(^{%[+-]?\s*)\w+/,
  2199. lookbehind: true,
  2200. alias: 'keyword'
  2201. },
  2202. 'delimiter': {
  2203. pattern: /^{[{%][+-]?|[+-]?[}%]}$/,
  2204. alias: 'punctuation'
  2205. },
  2206. 'string': {
  2207. pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2208. greedy: true
  2209. },
  2210. 'filter': {
  2211. pattern: /(\|)\w+/,
  2212. lookbehind: true,
  2213. alias: 'function'
  2214. },
  2215. 'test': {
  2216. pattern: /(\bis\s+(?:not\s+)?)(?!not\b)\w+/,
  2217. lookbehind: true,
  2218. alias: 'function'
  2219. },
  2220. 'function': /\b[a-z_]\w+(?=\s*\()/i,
  2221. 'keyword': /\b(?:and|as|by|else|for|if|import|in|is|loop|not|or|recursive|with|without)\b/,
  2222. 'operator': /[-+*/%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  2223. 'number': /\b\d+(?:\.\d+)?\b/,
  2224. 'boolean': /[Tt]rue|[Ff]alse|[Nn]one/,
  2225. 'variable': /\b\w+?\b/,
  2226. 'punctuation': /[{}[\](),.:;]/
  2227. };
  2228. var pattern = /{{[\s\S]*?}}|{%[\s\S]*?%}|{#[\s\S]*?#}/g;
  2229. var markupTemplating = Prism.languages['markup-templating'];
  2230. Prism.hooks.add('before-tokenize', function (env) {
  2231. markupTemplating.buildPlaceholders(env, 'django', pattern);
  2232. });
  2233. Prism.hooks.add('after-tokenize', function (env) {
  2234. markupTemplating.tokenizePlaceholders(env, 'django');
  2235. });
  2236. // Add an Jinja2 alias
  2237. Prism.languages.jinja2 = Prism.languages.django;
  2238. Prism.hooks.add('before-tokenize', function (env) {
  2239. markupTemplating.buildPlaceholders(env, 'jinja2', pattern);
  2240. });
  2241. Prism.hooks.add('after-tokenize', function (env) {
  2242. markupTemplating.tokenizePlaceholders(env, 'jinja2');
  2243. });
  2244. })(Prism);
  2245. Prism.languages.elixir = {
  2246. 'comment': /#.*/m,
  2247. // ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
  2248. 'regex': {
  2249. pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
  2250. greedy: true
  2251. },
  2252. 'string': [
  2253. {
  2254. // ~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>
  2255. pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|#(?!\{)|[^#\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/,
  2256. greedy: true,
  2257. inside: {
  2258. // See interpolation below
  2259. }
  2260. },
  2261. {
  2262. pattern: /("""|''')[\s\S]*?\1/,
  2263. greedy: true,
  2264. inside: {
  2265. // See interpolation below
  2266. }
  2267. },
  2268. {
  2269. // Multi-line strings are allowed
  2270. pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  2271. greedy: true,
  2272. inside: {
  2273. // See interpolation below
  2274. }
  2275. }
  2276. ],
  2277. 'atom': {
  2278. // Look-behind prevents bad highlighting of the :: operator
  2279. pattern: /(^|[^:]):\w+/,
  2280. lookbehind: true,
  2281. alias: 'symbol'
  2282. },
  2283. // Look-ahead prevents bad highlighting of the :: operator
  2284. 'attr-name': /\w+\??:(?!:)/,
  2285. 'capture': {
  2286. // Look-behind prevents bad highlighting of the && operator
  2287. pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
  2288. lookbehind: true,
  2289. alias: 'function'
  2290. },
  2291. 'argument': {
  2292. // Look-behind prevents bad highlighting of the && operator
  2293. pattern: /(^|[^&])&\d+/,
  2294. lookbehind: true,
  2295. alias: 'variable'
  2296. },
  2297. 'attribute': {
  2298. pattern: /@\w+/,
  2299. alias: 'variable'
  2300. },
  2301. 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
  2302. 'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct|delegate)?|do|else|end|fn|for|if|import|not|or|require|rescue|try|unless|use|when)\b/,
  2303. 'boolean': /\b(?:true|false|nil)\b/,
  2304. 'operator': [
  2305. /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
  2306. {
  2307. // We don't want to match <<
  2308. pattern: /([^<])<(?!<)/,
  2309. lookbehind: true
  2310. },
  2311. {
  2312. // We don't want to match >>
  2313. pattern: /([^>])>(?!>)/,
  2314. lookbehind: true
  2315. }
  2316. ],
  2317. 'punctuation': /<<|>>|[.,%\[\]{}()]/
  2318. };
  2319. Prism.languages.insertBefore('elixir', 'keyword', {
  2320. 'module': {
  2321. pattern: /\b(defmodule\s)[A-Z][\w.\\]+/,
  2322. lookbehind: true,
  2323. alias: 'class-name'
  2324. },
  2325. 'function': {
  2326. pattern: /\b(defp?\s)[\w.\\]+/,
  2327. lookbehind: true
  2328. }
  2329. });
  2330. Prism.languages.elixir.string.forEach(function(o) {
  2331. o.inside = {
  2332. 'interpolation': {
  2333. pattern: /#\{[^}]+\}/,
  2334. inside: {
  2335. 'delimiter': {
  2336. pattern: /^#\{|\}$/,
  2337. alias: 'punctuation'
  2338. },
  2339. rest: Prism.languages.elixir
  2340. }
  2341. }
  2342. };
  2343. });
  2344. Prism.languages.erlang = {
  2345. 'comment': /%.+/,
  2346. 'string': {
  2347. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  2348. greedy: true
  2349. },
  2350. 'quoted-function': {
  2351. pattern: /'(?:\\.|[^\\'\r\n])+'(?=\()/,
  2352. alias: 'function'
  2353. },
  2354. 'quoted-atom': {
  2355. pattern: /'(?:\\.|[^\\'\r\n])+'/,
  2356. alias: 'atom'
  2357. },
  2358. 'boolean': /\b(?:true|false)\b/,
  2359. 'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
  2360. 'number': [
  2361. /\$\\?./,
  2362. /\d+#[a-z0-9]+/i,
  2363. /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i
  2364. ],
  2365. 'function': /\b[a-z][\w@]*(?=\()/,
  2366. 'variable': {
  2367. // Look-behind is used to prevent wrong highlighting of atoms containing "@"
  2368. pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
  2369. lookbehind: true
  2370. },
  2371. 'operator': [
  2372. /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,
  2373. {
  2374. // We don't want to match <<
  2375. pattern: /(^|[^<])<(?!<)/,
  2376. lookbehind: true
  2377. },
  2378. {
  2379. // We don't want to match >>
  2380. pattern: /(^|[^>])>(?!>)/,
  2381. lookbehind: true
  2382. }
  2383. ],
  2384. 'atom': /\b[a-z][\w@]*/,
  2385. 'punctuation': /[()[\]{}:;,.#|]|<<|>>/
  2386. };
  2387. Prism.languages.go = Prism.languages.extend('clike', {
  2388. 'string': {
  2389. pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
  2390. greedy: true
  2391. },
  2392. '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/,
  2393. 'boolean': /\b(?:_|iota|nil|true|false)\b/,
  2394. 'number': /(?:\b0x[a-f\d]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[-+]?\d+)?)i?/i,
  2395. 'operator': /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
  2396. 'builtin': /\b(?:bool|byte|complex(?:64|128)|error|float(?:32|64)|rune|string|u?int(?:8|16|32|64)?|uintptr|append|cap|close|complex|copy|delete|imag|len|make|new|panic|print(?:ln)?|real|recover)\b/
  2397. });
  2398. delete Prism.languages.go['class-name'];
  2399. Prism.languages.groovy = Prism.languages.extend('clike', {
  2400. 'string': [
  2401. {
  2402. // https://groovy-lang.org/syntax.html#_dollar_slashy_string
  2403. pattern: /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
  2404. greedy: true
  2405. },
  2406. {
  2407. // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
  2408. // simple division (see JS regex), so find a fix maybe?
  2409. pattern: /(["'/])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  2410. greedy: true
  2411. }
  2412. ],
  2413. 'keyword': /\b(?:as|def|in|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|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/,
  2414. 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?[\d]+)?)[glidf]?\b/i,
  2415. 'operator': {
  2416. pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
  2417. lookbehind: true
  2418. },
  2419. 'punctuation': /\.+|[{}[\];(),:$]/
  2420. });
  2421. Prism.languages.insertBefore('groovy', 'string', {
  2422. 'shebang': {
  2423. pattern: /#!.+/,
  2424. alias: 'comment'
  2425. }
  2426. });
  2427. Prism.languages.insertBefore('groovy', 'punctuation', {
  2428. 'spock-block': /\b(?:setup|given|when|then|and|cleanup|expect|where):/
  2429. });
  2430. Prism.languages.insertBefore('groovy', 'function', {
  2431. 'annotation': {
  2432. pattern: /(^|[^.])@\w+/,
  2433. lookbehind: true,
  2434. alias: 'punctuation'
  2435. }
  2436. });
  2437. // Handle string interpolation
  2438. Prism.hooks.add('wrap', function(env) {
  2439. if (env.language === 'groovy' && env.type === 'string') {
  2440. var delimiter = env.content[0];
  2441. if (delimiter != "'") {
  2442. var pattern = /([^\\])(?:\$(?:\{.*?\}|[\w.]+))/;
  2443. if (delimiter === '$') {
  2444. pattern = /([^\$])(?:\$(?:\{.*?\}|[\w.]+))/;
  2445. }
  2446. // To prevent double HTML-encoding we have to decode env.content first
  2447. env.content = env.content.replace(/&lt;/g, '<').replace(/&amp;/g, '&');
  2448. env.content = Prism.highlight(env.content, {
  2449. 'expression': {
  2450. pattern: pattern,
  2451. lookbehind: true,
  2452. inside: Prism.languages.groovy
  2453. }
  2454. });
  2455. env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
  2456. }
  2457. }
  2458. });
  2459. (function (Prism) {
  2460. 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/;
  2461. // full package (optional) + parent classes (optional)
  2462. var classNamePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  2463. // based on the java naming conventions
  2464. var className = {
  2465. pattern: RegExp(classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  2466. lookbehind: true,
  2467. inside: {
  2468. 'namespace': {
  2469. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  2470. inside: {
  2471. 'punctuation': /\./
  2472. }
  2473. },
  2474. 'punctuation': /\./
  2475. }
  2476. };
  2477. Prism.languages.java = Prism.languages.extend('clike', {
  2478. 'class-name': [
  2479. className,
  2480. {
  2481. // variables and parameters
  2482. // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
  2483. pattern: RegExp(classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=())])/.source),
  2484. lookbehind: true,
  2485. inside: className.inside
  2486. }
  2487. ],
  2488. 'keyword': keywords,
  2489. 'function': [
  2490. Prism.languages.clike.function,
  2491. {
  2492. pattern: /(\:\:\s*)[a-z_]\w*/,
  2493. lookbehind: true
  2494. }
  2495. ],
  2496. '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,
  2497. 'operator': {
  2498. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  2499. lookbehind: true
  2500. }
  2501. });
  2502. Prism.languages.insertBefore('java', 'string', {
  2503. 'triple-quoted-string': {
  2504. // http://openjdk.java.net/jeps/355#Description
  2505. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  2506. greedy: true,
  2507. alias: 'string'
  2508. }
  2509. });
  2510. Prism.languages.insertBefore('java', 'class-name', {
  2511. 'annotation': {
  2512. pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
  2513. lookbehind: true,
  2514. alias: 'punctuation'
  2515. },
  2516. 'generics': {
  2517. pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
  2518. inside: {
  2519. 'class-name': className,
  2520. 'keyword': keywords,
  2521. 'punctuation': /[<>(),.:]/,
  2522. 'operator': /[?&|]/
  2523. }
  2524. },
  2525. 'namespace': {
  2526. pattern: RegExp(
  2527. /(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
  2528. .source.replace(/<keyword>/g, function () { return keywords.source; })),
  2529. lookbehind: true,
  2530. inside: {
  2531. 'punctuation': /\./,
  2532. }
  2533. }
  2534. });
  2535. }(Prism));
  2536. // https://www.json.org/json-en.html
  2537. Prism.languages.json = {
  2538. 'property': {
  2539. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
  2540. lookbehind: true,
  2541. greedy: true
  2542. },
  2543. 'string': {
  2544. pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
  2545. lookbehind: true,
  2546. greedy: true
  2547. },
  2548. 'comment': {
  2549. pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
  2550. greedy: true
  2551. },
  2552. 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
  2553. 'punctuation': /[{}[\],]/,
  2554. 'operator': /:/,
  2555. 'boolean': /\b(?:true|false)\b/,
  2556. 'null': {
  2557. pattern: /\bnull\b/,
  2558. alias: 'keyword'
  2559. }
  2560. };
  2561. Prism.languages.webmanifest = Prism.languages.json;
  2562. Prism.languages.julia = {
  2563. 'comment': {
  2564. // support one level of nested comments
  2565. // https://github.com/JuliaLang/julia/pull/6128
  2566. pattern: /(^|[^\\])(?:#=(?:[^#=]|=(?!#)|#(?!=)|#=(?:[^#=]|=(?!#)|#(?!=))*=#)*=#|#.*)/,
  2567. lookbehind: true
  2568. },
  2569. 'regex': {
  2570. // https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1
  2571. pattern: /r"(?:\\.|[^"\\\r\n])*"[imsx]{0,4}/,
  2572. greedy: true
  2573. },
  2574. 'string': {
  2575. // https://docs.julialang.org/en/v1/manual/strings/#man-characters-1
  2576. // https://docs.julialang.org/en/v1/manual/strings/#String-Basics-1
  2577. // https://docs.julialang.org/en/v1/manual/strings/#non-standard-string-literals-1
  2578. // https://docs.julialang.org/en/v1/manual/running-external-programs/#Running-External-Programs-1
  2579. pattern: /"""[\s\S]+?"""|\w*"(?:\\.|[^"\\\r\n])*"|(^|[^\w'])'(?:\\[^\r\n][^'\r\n]*|[^\\\r\n])'|`(?:[^\\`\r\n]|\\.)*`/,
  2580. lookbehind: true,
  2581. greedy: true
  2582. },
  2583. '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/,
  2584. 'boolean': /\b(?:true|false)\b/,
  2585. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[box])?(?:[\da-f]+(?:_[\da-f]+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[efp][+-]?\d+(?:_\d+)*)?j?/i,
  2586. // https://docs.julialang.org/en/v1/manual/mathematical-operations/
  2587. // https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1
  2588. 'operator': /&&|\|\||[-+*^%÷⊻&$\\]=?|\/[\/=]?|!=?=?|\|[=>]?|<(?:<=?|[=:|])?|>(?:=|>>?=?)?|==?=?|[~≠≤≥'√∛]/,
  2589. 'punctuation': /::?|[{}[\]();,.?]/,
  2590. // https://docs.julialang.org/en/v1/base/numbers/#Base.im
  2591. 'constant': /\b(?:(?:NaN|Inf)(?:16|32|64)?|im|pi)\b|[πℯ]/
  2592. };
  2593. (function (Prism) {
  2594. Prism.languages.kotlin = Prism.languages.extend('clike', {
  2595. 'keyword': {
  2596. // The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
  2597. 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/,
  2598. lookbehind: true
  2599. },
  2600. 'function': [
  2601. {
  2602. pattern: /(?:`[^\r\n`]+`|\w+)(?=\s*\()/,
  2603. greedy: true
  2604. },
  2605. {
  2606. pattern: /(\.)(?:`[^\r\n`]+`|\w+)(?=\s*\{)/,
  2607. lookbehind: true,
  2608. greedy: true
  2609. }
  2610. ],
  2611. 'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
  2612. 'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
  2613. });
  2614. delete Prism.languages.kotlin["class-name"];
  2615. Prism.languages.insertBefore('kotlin', 'string', {
  2616. 'raw-string': {
  2617. pattern: /("""|''')[\s\S]*?\1/,
  2618. alias: 'string'
  2619. // See interpolation below
  2620. }
  2621. });
  2622. Prism.languages.insertBefore('kotlin', 'keyword', {
  2623. 'annotation': {
  2624. pattern: /\B@(?:\w+:)?(?:[A-Z]\w*|\[[^\]]+\])/,
  2625. alias: 'builtin'
  2626. }
  2627. });
  2628. Prism.languages.insertBefore('kotlin', 'function', {
  2629. 'label': {
  2630. pattern: /\w+@|@\w+/,
  2631. alias: 'symbol'
  2632. }
  2633. });
  2634. var interpolation = [
  2635. {
  2636. pattern: /\$\{[^}]+\}/,
  2637. inside: {
  2638. 'delimiter': {
  2639. pattern: /^\$\{|\}$/,
  2640. alias: 'variable'
  2641. },
  2642. rest: Prism.languages.kotlin
  2643. }
  2644. },
  2645. {
  2646. pattern: /\$\w+/,
  2647. alias: 'variable'
  2648. }
  2649. ];
  2650. Prism.languages.kotlin['string'].inside = Prism.languages.kotlin['raw-string'].inside = {
  2651. interpolation: interpolation
  2652. };
  2653. Prism.languages.kt = Prism.languages.kotlin;
  2654. Prism.languages.kts = Prism.languages.kotlin;
  2655. }(Prism));
  2656. Prism.languages.lua = {
  2657. 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
  2658. // \z may be used to skip the following space
  2659. 'string': {
  2660. pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
  2661. greedy: true
  2662. },
  2663. 'number': /\b0x[a-f\d]+(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
  2664. '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/,
  2665. 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
  2666. 'operator': [
  2667. /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
  2668. {
  2669. // Match ".." but don't break "..."
  2670. pattern: /(^|[^.])\.\.(?!\.)/,
  2671. lookbehind: true
  2672. }
  2673. ],
  2674. 'punctuation': /[\[\](){},;]|\.+|:+/
  2675. };
  2676. Prism.languages.matlab = {
  2677. 'comment': [
  2678. /%\{[\s\S]*?\}%/,
  2679. /%.+/
  2680. ],
  2681. 'string': {
  2682. pattern: /\B'(?:''|[^'\r\n])*'/,
  2683. greedy: true
  2684. },
  2685. // FIXME We could handle imaginary numbers as a whole
  2686. 'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[eE][+-]?\d+)?(?:[ij])?|\b[ij]\b/,
  2687. 'keyword': /\b(?:break|case|catch|continue|else|elseif|end|for|function|if|inf|NaN|otherwise|parfor|pause|pi|return|switch|try|while)\b/,
  2688. 'function': /(?!\d)\w+(?=\s*\()/,
  2689. 'operator': /\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,
  2690. 'punctuation': /\.{3}|[.,;\[\](){}!]/
  2691. };
  2692. Prism.languages.nginx = Prism.languages.extend('clike', {
  2693. 'comment': {
  2694. pattern: /(^|[^"{\\])#.*/,
  2695. lookbehind: true
  2696. },
  2697. 'keyword': /\b(?:CONTENT_|DOCUMENT_|GATEWAY_|HTTP_|HTTPS|if_not_empty|PATH_|QUERY_|REDIRECT_|REMOTE_|REQUEST_|SCGI|SCRIPT_|SERVER_|http|events|accept_mutex|accept_mutex_delay|access_log|add_after_body|add_before_body|add_header|addition_types|aio|alias|allow|ancient_browser|ancient_browser_value|auth|auth_basic|auth_basic_user_file|auth_http|auth_http_header|auth_http_timeout|autoindex|autoindex_exact_size|autoindex_localtime|break|charset|charset_map|charset_types|chunked_transfer_encoding|client_body_buffer_size|client_body_in_file_only|client_body_in_single_buffer|client_body_temp_path|client_body_timeout|client_header_buffer_size|client_header_timeout|client_max_body_size|connection_pool_size|create_full_put_path|daemon|dav_access|dav_methods|debug_connection|debug_points|default_type|deny|devpoll_changes|devpoll_events|directio|directio_alignment|disable_symlinks|empty_gif|env|epoll_events|error_log|error_page|expires|fastcgi_buffer_size|fastcgi_buffers|fastcgi_busy_buffers_size|fastcgi_cache|fastcgi_cache_bypass|fastcgi_cache_key|fastcgi_cache_lock|fastcgi_cache_lock_timeout|fastcgi_cache_methods|fastcgi_cache_min_uses|fastcgi_cache_path|fastcgi_cache_purge|fastcgi_cache_use_stale|fastcgi_cache_valid|fastcgi_connect_timeout|fastcgi_hide_header|fastcgi_ignore_client_abort|fastcgi_ignore_headers|fastcgi_index|fastcgi_intercept_errors|fastcgi_keep_conn|fastcgi_max_temp_file_size|fastcgi_next_upstream|fastcgi_no_cache|fastcgi_param|fastcgi_pass|fastcgi_pass_header|fastcgi_read_timeout|fastcgi_redirect_errors|fastcgi_send_timeout|fastcgi_split_path_info|fastcgi_store|fastcgi_store_access|fastcgi_temp_file_write_size|fastcgi_temp_path|flv|geo|geoip_city|geoip_country|google_perftools_profiles|gzip|gzip_buffers|gzip_comp_level|gzip_disable|gzip_http_version|gzip_min_length|gzip_proxied|gzip_static|gzip_types|gzip_vary|if|if_modified_since|ignore_invalid_headers|image_filter|image_filter_buffer|image_filter_jpeg_quality|image_filter_sharpen|image_filter_transparency|imap_capabilities|imap_client_buffer|include|index|internal|ip_hash|keepalive|keepalive_disable|keepalive_requests|keepalive_timeout|kqueue_changes|kqueue_events|large_client_header_buffers|limit_conn|limit_conn_log_level|limit_conn_zone|limit_except|limit_rate|limit_rate_after|limit_req|limit_req_log_level|limit_req_zone|limit_zone|lingering_close|lingering_time|lingering_timeout|listen|location|lock_file|log_format|log_format_combined|log_not_found|log_subrequest|map|map_hash_bucket_size|map_hash_max_size|master_process|max_ranges|memcached_buffer_size|memcached_connect_timeout|memcached_next_upstream|memcached_pass|memcached_read_timeout|memcached_send_timeout|merge_slashes|min_delete_depth|modern_browser|modern_browser_value|mp4|mp4_buffer_size|mp4_max_buffer_size|msie_padding|msie_refresh|multi_accept|open_file_cache|open_file_cache_errors|open_file_cache_min_uses|open_file_cache_valid|open_log_file_cache|optimize_server_names|override_charset|pcre_jit|perl|perl_modules|perl_require|perl_set|pid|pop3_auth|pop3_capabilities|port_in_redirect|post_action|postpone_output|protocol|proxy|proxy_buffer|proxy_buffer_size|proxy_buffering|proxy_buffers|proxy_busy_buffers_size|proxy_cache|proxy_cache_bypass|proxy_cache_key|proxy_cache_lock|proxy_cache_lock_timeout|proxy_cache_methods|proxy_cache_min_uses|proxy_cache_path|proxy_cache_use_stale|proxy_cache_valid|proxy_connect_timeout|proxy_cookie_domain|proxy_cookie_path|proxy_headers_hash_bucket_size|proxy_headers_hash_max_size|proxy_hide_header|proxy_http_version|proxy_ignore_client_abort|proxy_ignore_headers|proxy_intercept_errors|proxy_max_temp_file_size|proxy_method|proxy_next_upstream|proxy_no_cache|proxy_pass|proxy_pass_error_message|proxy_pass_header|proxy_pass_request_body|proxy_pass_request_headers|proxy_read_timeout|proxy_redirect|proxy_redirect_errors|proxy_send_lowat|proxy_send_timeout|proxy_set_body|proxy_set_header|proxy_ssl_session_reuse|proxy_store|proxy_store_access|proxy_temp_file_write_size|proxy_temp_path|proxy_timeout|proxy_upstream_fail_timeout|proxy_upstream_max_fails|random_index|read_ahead|real_ip_header|recursive_error_pages|request_pool_size|reset_timedout_connection|resolver|resolver_timeout|return|rewrite|root|rtsig_overflow_events|rtsig_overflow_test|rtsig_overflow_threshold|rtsig_signo|satisfy|satisfy_any|secure_link_secret|send_lowat|send_timeout|sendfile|sendfile_max_chunk|server|server_name|server_name_in_redirect|server_names_hash_bucket_size|server_names_hash_max_size|server_tokens|set|set_real_ip_from|smtp_auth|smtp_capabilities|so_keepalive|source_charset|split_clients|ssi|ssi_silent_errors|ssi_types|ssi_value_length|ssl|ssl_certificate|ssl_certificate_key|ssl_ciphers|ssl_client_certificate|ssl_crl|ssl_dhparam|ssl_engine|ssl_prefer_server_ciphers|ssl_protocols|ssl_session_cache|ssl_session_timeout|ssl_verify_client|ssl_verify_depth|starttls|stub_status|sub_filter|sub_filter_once|sub_filter_types|tcp_nodelay|tcp_nopush|timeout|timer_resolution|try_files|types|types_hash_bucket_size|types_hash_max_size|underscores_in_headers|uninitialized_variable_warn|upstream|use|user|userid|userid_domain|userid_expires|userid_name|userid_p3p|userid_path|userid_service|valid_referers|variables_hash_bucket_size|variables_hash_max_size|worker_connections|worker_cpu_affinity|worker_priority|worker_processes|worker_rlimit_core|worker_rlimit_nofile|worker_rlimit_sigpending|working_directory|xclient|xml_entities|xslt_entities|xslt_stylesheet|xslt_types|ssl_session_tickets|ssl_stapling|ssl_stapling_verify|ssl_ecdh_curve|ssl_trusted_certificate|more_set_headers|ssl_early_data)\b/i
  2698. });
  2699. Prism.languages.insertBefore('nginx', 'keyword', {
  2700. 'variable': /\$[a-z_]+/i
  2701. });
  2702. Prism.languages.nim = {
  2703. 'comment': /#.*/,
  2704. // Double-quoted strings can be prefixed by an identifier (Generalized raw string literals)
  2705. // Character literals are handled specifically to prevent issues with numeric type suffixes
  2706. 'string': {
  2707. pattern: /(?:(?:\b(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+)?(?:"""[\s\S]*?"""(?!")|"(?:\\[\s\S]|""|[^"\\])*")|'(?:\\(?:\d+|x[\da-fA-F]{2}|.)|[^'])')/,
  2708. greedy: true
  2709. },
  2710. // The negative look ahead prevents wrong highlighting of the .. operator
  2711. 'number': /\b(?:0[xXoObB][\da-fA-F_]+|\d[\d_]*(?:(?!\.\.)\.[\d_]*)?(?:[eE][+-]?\d[\d_]*)?)(?:'?[iuf]\d*)?/,
  2712. '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/,
  2713. 'function': {
  2714. pattern: /(?:(?!\d)(?:\w|\\x[8-9a-fA-F][0-9a-fA-F])+|`[^`\r\n]+`)\*?(?:\[[^\]]+\])?(?=\s*\()/,
  2715. inside: {
  2716. 'operator': /\*$/
  2717. }
  2718. },
  2719. // We don't want to highlight operators inside backticks
  2720. 'ignore': {
  2721. pattern: /`[^`\r\n]+`/,
  2722. inside: {
  2723. 'punctuation': /`/
  2724. }
  2725. },
  2726. 'operator': {
  2727. // Look behind and look ahead prevent wrong highlighting of punctuations [. .] {. .} (. .)
  2728. // but allow the slice operator .. to take precedence over them
  2729. // One can define his own operators in Nim so all combination of operators might be an operator.
  2730. pattern: /(^|[({\[](?=\.\.)|(?![({\[]\.).)(?:(?:[=+\-*\/<>@$~&%|!?^:\\]|\.\.|\.(?![)}\]]))+|\b(?:and|div|of|or|in|is|isnot|mod|not|notin|shl|shr|xor)\b)/m,
  2731. lookbehind: true
  2732. },
  2733. 'punctuation': /[({\[]\.|\.[)}\]]|[`(){}\[\],:]/
  2734. };
  2735. Prism.languages.ocaml = {
  2736. 'comment': /\(\*[\s\S]*?\*\)/,
  2737. 'string': [
  2738. {
  2739. pattern: /"(?:\\.|[^\\\r\n"])*"/,
  2740. greedy: true
  2741. },
  2742. {
  2743. pattern: /(['`])(?:\\(?:\d+|x[\da-f]+|.)|(?!\1)[^\\\r\n])\1/i,
  2744. greedy: true
  2745. }
  2746. ],
  2747. 'number': /\b(?:0x[\da-f][\da-f_]+|(?:0[bo])?\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?[\d_]+)?)/i,
  2748. 'directive': {
  2749. pattern: /\B#\w+/,
  2750. alias: 'important'
  2751. },
  2752. 'label': {
  2753. pattern: /\B~\w+/,
  2754. alias: 'function'
  2755. },
  2756. 'type-variable': {
  2757. pattern: /\B'\w+/,
  2758. alias: 'function'
  2759. },
  2760. 'variant': {
  2761. pattern: /`\w+/,
  2762. alias: 'variable'
  2763. },
  2764. 'module': {
  2765. pattern: /\b[A-Z]\w+/,
  2766. alias: 'variable'
  2767. },
  2768. // For the list of keywords and operators,
  2769. // see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
  2770. '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/,
  2771. 'boolean': /\b(?:false|true)\b/,
  2772. // Custom operators are allowed
  2773. 'operator': /:=|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
  2774. 'punctuation': /[(){}\[\]|.,:;]|\b_\b/
  2775. };
  2776. Prism.languages.perl = {
  2777. 'comment': [
  2778. {
  2779. // POD
  2780. pattern: /(^\s*)=\w[\s\S]*?=cut.*/m,
  2781. lookbehind: true
  2782. },
  2783. {
  2784. pattern: /(^|[^\\$])#.*/,
  2785. lookbehind: true
  2786. }
  2787. ],
  2788. // TODO Could be nice to handle Heredoc too.
  2789. 'string': [
  2790. // q/.../
  2791. {
  2792. pattern: /\b(?:q|qq|qx|qw)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  2793. greedy: true
  2794. },
  2795. // q a...a
  2796. {
  2797. pattern: /\b(?:q|qq|qx|qw)\s+([a-zA-Z0-9])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  2798. greedy: true
  2799. },
  2800. // q(...)
  2801. {
  2802. pattern: /\b(?:q|qq|qx|qw)\s*\((?:[^()\\]|\\[\s\S])*\)/,
  2803. greedy: true
  2804. },
  2805. // q{...}
  2806. {
  2807. pattern: /\b(?:q|qq|qx|qw)\s*\{(?:[^{}\\]|\\[\s\S])*\}/,
  2808. greedy: true
  2809. },
  2810. // q[...]
  2811. {
  2812. pattern: /\b(?:q|qq|qx|qw)\s*\[(?:[^[\]\\]|\\[\s\S])*\]/,
  2813. greedy: true
  2814. },
  2815. // q<...>
  2816. {
  2817. pattern: /\b(?:q|qq|qx|qw)\s*<(?:[^<>\\]|\\[\s\S])*>/,
  2818. greedy: true
  2819. },
  2820. // "...", `...`
  2821. {
  2822. pattern: /("|`)(?:(?!\1)[^\\]|\\[\s\S])*\1/,
  2823. greedy: true
  2824. },
  2825. // '...'
  2826. // FIXME Multi-line single-quoted strings are not supported as they would break variables containing '
  2827. {
  2828. pattern: /'(?:[^'\\\r\n]|\\.)*'/,
  2829. greedy: true
  2830. }
  2831. ],
  2832. 'regex': [
  2833. // m/.../
  2834. {
  2835. pattern: /\b(?:m|qr)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[msixpodualngc]*/,
  2836. greedy: true
  2837. },
  2838. // m a...a
  2839. {
  2840. pattern: /\b(?:m|qr)\s+([a-zA-Z0-9])(?:(?!\1)[^\\]|\\[\s\S])*\1[msixpodualngc]*/,
  2841. greedy: true
  2842. },
  2843. // m(...)
  2844. {
  2845. pattern: /\b(?:m|qr)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngc]*/,
  2846. greedy: true
  2847. },
  2848. // m{...}
  2849. {
  2850. pattern: /\b(?:m|qr)\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngc]*/,
  2851. greedy: true
  2852. },
  2853. // m[...]
  2854. {
  2855. pattern: /\b(?:m|qr)\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngc]*/,
  2856. greedy: true
  2857. },
  2858. // m<...>
  2859. {
  2860. pattern: /\b(?:m|qr)\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngc]*/,
  2861. greedy: true
  2862. },
  2863. // The lookbehinds prevent -s from breaking
  2864. // FIXME We don't handle change of separator like s(...)[...]
  2865. // s/.../.../
  2866. {
  2867. pattern: /(^|[^-]\b)(?:s|tr|y)\s*([^a-zA-Z0-9\s{(\[<])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2[msixpodualngcer]*/,
  2868. lookbehind: true,
  2869. greedy: true
  2870. },
  2871. // s a...a...a
  2872. {
  2873. pattern: /(^|[^-]\b)(?:s|tr|y)\s+([a-zA-Z0-9])(?:(?!\2)[^\\]|\\[\s\S])*\2(?:(?!\2)[^\\]|\\[\s\S])*\2[msixpodualngcer]*/,
  2874. lookbehind: true,
  2875. greedy: true
  2876. },
  2877. // s(...)(...)
  2878. {
  2879. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\((?:[^()\\]|\\[\s\S])*\)\s*\((?:[^()\\]|\\[\s\S])*\)[msixpodualngcer]*/,
  2880. lookbehind: true,
  2881. greedy: true
  2882. },
  2883. // s{...}{...}
  2884. {
  2885. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\{(?:[^{}\\]|\\[\s\S])*\}\s*\{(?:[^{}\\]|\\[\s\S])*\}[msixpodualngcer]*/,
  2886. lookbehind: true,
  2887. greedy: true
  2888. },
  2889. // s[...][...]
  2890. {
  2891. pattern: /(^|[^-]\b)(?:s|tr|y)\s*\[(?:[^[\]\\]|\\[\s\S])*\]\s*\[(?:[^[\]\\]|\\[\s\S])*\][msixpodualngcer]*/,
  2892. lookbehind: true,
  2893. greedy: true
  2894. },
  2895. // s<...><...>
  2896. {
  2897. pattern: /(^|[^-]\b)(?:s|tr|y)\s*<(?:[^<>\\]|\\[\s\S])*>\s*<(?:[^<>\\]|\\[\s\S])*>[msixpodualngcer]*/,
  2898. lookbehind: true,
  2899. greedy: true
  2900. },
  2901. // /.../
  2902. // The look-ahead tries to prevent two divisions on
  2903. // the same line from being highlighted as regex.
  2904. // This does not support multi-line regex.
  2905. {
  2906. pattern: /\/(?:[^\/\\\r\n]|\\.)*\/[msixpodualngc]*(?=\s*(?:$|[\r\n,.;})&|\-+*~<>!?^]|(?:lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|x)\b))/,
  2907. greedy: true
  2908. }
  2909. ],
  2910. // FIXME Not sure about the handling of ::, ', and #
  2911. 'variable': [
  2912. // ${^POSTMATCH}
  2913. /[&*$@%]\{\^[A-Z]+\}/,
  2914. // $^V
  2915. /[&*$@%]\^[A-Z_]/,
  2916. // ${...}
  2917. /[&*$@%]#?(?=\{)/,
  2918. // $foo
  2919. /[&*$@%]#?(?:(?:::)*'?(?!\d)[\w$]+)+(?:::)*/i,
  2920. // $1
  2921. /[&*$@%]\d+/,
  2922. // $_, @_, %!
  2923. // The negative lookahead prevents from breaking the %= operator
  2924. /(?!%=)[$@%][!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/
  2925. ],
  2926. 'filehandle': {
  2927. // <>, <FOO>, _
  2928. pattern: /<(?![<=])\S*>|\b_\b/,
  2929. alias: 'symbol'
  2930. },
  2931. 'vstring': {
  2932. // v1.2, 1.2.3
  2933. pattern: /v\d+(?:\.\d+)*|\d+(?:\.\d+){2,}/,
  2934. alias: 'string'
  2935. },
  2936. 'function': {
  2937. pattern: /sub [a-z0-9_]+/i,
  2938. inside: {
  2939. keyword: /sub/
  2940. }
  2941. },
  2942. '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/,
  2943. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)\b/,
  2944. 'operator': /-[rwxoRWXOezsfdlpSbctugkTBMAC]\b|\+[+=]?|-[-=>]?|\*\*?=?|\/\/?=?|=[=~>]?|~[~=]?|\|\|?=?|&&?=?|<(?:=>?|<=?)?|>>?=?|![~=]?|[%^]=?|\.(?:=|\.\.?)?|[\\?]|\bx(?:=|\b)|\b(?:lt|gt|le|ge|eq|ne|cmp|not|and|or|xor)\b/,
  2945. 'punctuation': /[{}[\];(),:]/
  2946. };
  2947. /**
  2948. * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
  2949. * Modified by Miles Johnson: http://milesj.me
  2950. * Rewritten by Tom Pavelec
  2951. *
  2952. * Supports PHP 5.3 - 8.0
  2953. */
  2954. (function (Prism) {
  2955. var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
  2956. var constant = [
  2957. {
  2958. pattern: /\b(?:false|true)\b/i,
  2959. alias: 'boolean'
  2960. },
  2961. /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,
  2962. /\b(?:null)\b/i,
  2963. ];
  2964. 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;
  2965. var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
  2966. var punctuation = /[{}\[\](),:;]/;
  2967. Prism.languages.php = {
  2968. 'delimiter': {
  2969. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  2970. alias: 'important'
  2971. },
  2972. 'comment': comment,
  2973. 'variable': /\$+(?:\w+\b|(?={))/i,
  2974. 'package': {
  2975. pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  2976. lookbehind: true,
  2977. inside: {
  2978. 'punctuation': /\\/
  2979. }
  2980. },
  2981. 'class-name-definition': {
  2982. pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
  2983. lookbehind: true,
  2984. alias: 'class-name'
  2985. },
  2986. 'keyword': [
  2987. {
  2988. pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,
  2989. alias: 'type-casting',
  2990. greedy: true,
  2991. lookbehind: true
  2992. },
  2993. {
  2994. pattern: /([(,?]\s*)\b(?:bool|int|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b(?=\s*\$)/i,
  2995. alias: 'type-hint',
  2996. greedy: true,
  2997. lookbehind: true
  2998. },
  2999. {
  3000. pattern: /([(,?]\s*[a-z0-9_|]\|\s*)(?:null|false)\b(?=\s*\$)/i,
  3001. alias: 'type-hint',
  3002. greedy: true,
  3003. lookbehind: true
  3004. },
  3005. {
  3006. pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b/i,
  3007. alias: 'return-type',
  3008. greedy: true,
  3009. lookbehind: true
  3010. },
  3011. {
  3012. pattern: /(\)\s*:\s*(?:\?\s*)?[a-z0-9_|]\|\s*)(?:null|false)\b/i,
  3013. alias: 'return-type',
  3014. greedy: true,
  3015. lookbehind: true
  3016. },
  3017. {
  3018. pattern: /\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|iterable|(?:null|false)(?=\s*\|))\b/i,
  3019. alias: 'type-declaration',
  3020. greedy: true
  3021. },
  3022. {
  3023. pattern: /(\|\s*)(?:null|false)\b/i,
  3024. alias: 'type-declaration',
  3025. greedy: true,
  3026. lookbehind: true
  3027. },
  3028. {
  3029. pattern: /\b(?:parent|self|static)(?=\s*::)/i,
  3030. alias: 'static-context',
  3031. greedy: true
  3032. },
  3033. /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i
  3034. ],
  3035. 'argument-name': /\b[a-z_]\w*(?=\s*:(?!:))/i,
  3036. 'class-name': [
  3037. {
  3038. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
  3039. greedy: true,
  3040. lookbehind: true
  3041. },
  3042. {
  3043. pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
  3044. greedy: true,
  3045. lookbehind: true
  3046. },
  3047. {
  3048. pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
  3049. greedy: true
  3050. },
  3051. {
  3052. pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
  3053. alias: 'class-name-fully-qualified',
  3054. greedy: true,
  3055. lookbehind: true,
  3056. inside: {
  3057. 'punctuation': /\\/
  3058. }
  3059. },
  3060. {
  3061. pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
  3062. alias: 'class-name-fully-qualified',
  3063. greedy: true,
  3064. inside: {
  3065. 'punctuation': /\\/
  3066. }
  3067. },
  3068. {
  3069. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3070. alias: 'class-name-fully-qualified',
  3071. greedy: true,
  3072. lookbehind: true,
  3073. inside: {
  3074. 'punctuation': /\\/
  3075. }
  3076. },
  3077. {
  3078. pattern: /\b[a-z_]\w*(?=\s*\$)/i,
  3079. alias: 'type-declaration',
  3080. greedy: true
  3081. },
  3082. {
  3083. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  3084. alias: ['class-name-fully-qualified', 'type-declaration'],
  3085. greedy: true,
  3086. inside: {
  3087. 'punctuation': /\\/
  3088. }
  3089. },
  3090. {
  3091. pattern: /\b[a-z_]\w*(?=\s*::)/i,
  3092. alias: 'static-context',
  3093. greedy: true
  3094. },
  3095. {
  3096. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
  3097. alias: ['class-name-fully-qualified', 'static-context'],
  3098. greedy: true,
  3099. inside: {
  3100. 'punctuation': /\\/
  3101. }
  3102. },
  3103. {
  3104. pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
  3105. alias: 'type-hint',
  3106. greedy: true,
  3107. lookbehind: true
  3108. },
  3109. {
  3110. pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  3111. alias: ['class-name-fully-qualified', 'type-hint'],
  3112. greedy: true,
  3113. lookbehind: true,
  3114. inside: {
  3115. 'punctuation': /\\/
  3116. }
  3117. },
  3118. {
  3119. pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
  3120. alias: 'return-type',
  3121. greedy: true,
  3122. lookbehind: true
  3123. },
  3124. {
  3125. pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  3126. alias: ['class-name-fully-qualified', 'return-type'],
  3127. greedy: true,
  3128. lookbehind: true,
  3129. inside: {
  3130. 'punctuation': /\\/
  3131. }
  3132. }
  3133. ],
  3134. 'constant': constant,
  3135. 'function': /\w+\s*(?=\()/,
  3136. 'property': {
  3137. pattern: /(->)[\w]+/,
  3138. lookbehind: true
  3139. },
  3140. 'number': number,
  3141. 'operator': operator,
  3142. 'punctuation': punctuation
  3143. };
  3144. var string_interpolation = {
  3145. pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,
  3146. lookbehind: true,
  3147. inside: Prism.languages.php
  3148. };
  3149. var string = [
  3150. {
  3151. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  3152. alias: 'nowdoc-string',
  3153. greedy: true,
  3154. inside: {
  3155. 'delimiter': {
  3156. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  3157. alias: 'symbol',
  3158. inside: {
  3159. 'punctuation': /^<<<'?|[';]$/
  3160. }
  3161. }
  3162. }
  3163. },
  3164. {
  3165. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  3166. alias: 'heredoc-string',
  3167. greedy: true,
  3168. inside: {
  3169. 'delimiter': {
  3170. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  3171. alias: 'symbol',
  3172. inside: {
  3173. 'punctuation': /^<<<"?|[";]$/
  3174. }
  3175. },
  3176. 'interpolation': string_interpolation // See below
  3177. }
  3178. },
  3179. {
  3180. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  3181. alias: 'backtick-quoted-string',
  3182. greedy: true
  3183. },
  3184. {
  3185. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  3186. alias: 'single-quoted-string',
  3187. greedy: true
  3188. },
  3189. {
  3190. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  3191. alias: 'double-quoted-string',
  3192. greedy: true,
  3193. inside: {
  3194. 'interpolation': string_interpolation // See below
  3195. }
  3196. }
  3197. ];
  3198. Prism.languages.insertBefore('php', 'variable', {
  3199. 'string': string,
  3200. });
  3201. Prism.languages.insertBefore('php', 'variable', {
  3202. 'attribute': {
  3203. pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/mi,
  3204. greedy: true,
  3205. inside: {
  3206. 'attribute-content': {
  3207. pattern: /^(#\[)[\s\S]+(?=]$)/,
  3208. lookbehind: true,
  3209. // inside can appear subset of php
  3210. inside: {
  3211. 'comment': comment,
  3212. 'string': string,
  3213. 'attribute-class-name': [
  3214. {
  3215. pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
  3216. alias: 'class-name',
  3217. greedy: true,
  3218. lookbehind: true
  3219. },
  3220. {
  3221. pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
  3222. alias: [
  3223. 'class-name',
  3224. 'class-name-fully-qualified'
  3225. ],
  3226. greedy: true,
  3227. lookbehind: true,
  3228. inside: {
  3229. 'punctuation': /\\/
  3230. }
  3231. }
  3232. ],
  3233. 'constant': constant,
  3234. 'number': number,
  3235. 'operator': operator,
  3236. 'punctuation': punctuation
  3237. }
  3238. },
  3239. 'delimiter': {
  3240. pattern: /^#\[|]$/,
  3241. alias: 'punctuation'
  3242. }
  3243. }
  3244. },
  3245. });
  3246. Prism.hooks.add('before-tokenize', function(env) {
  3247. if (!/<\?/.test(env.code)) {
  3248. return;
  3249. }
  3250. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/ig;
  3251. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  3252. });
  3253. Prism.hooks.add('after-tokenize', function(env) {
  3254. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  3255. });
  3256. }(Prism));
  3257. Prism.languages.python = {
  3258. 'comment': {
  3259. pattern: /(^|[^\\])#.*/,
  3260. lookbehind: true
  3261. },
  3262. 'string-interpolation': {
  3263. pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  3264. greedy: true,
  3265. inside: {
  3266. 'interpolation': {
  3267. // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
  3268. pattern: /((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,
  3269. lookbehind: true,
  3270. inside: {
  3271. 'format-spec': {
  3272. pattern: /(:)[^:(){}]+(?=}$)/,
  3273. lookbehind: true
  3274. },
  3275. 'conversion-option': {
  3276. pattern: /![sra](?=[:}]$)/,
  3277. alias: 'punctuation'
  3278. },
  3279. rest: null
  3280. }
  3281. },
  3282. 'string': /[\s\S]+/
  3283. }
  3284. },
  3285. 'triple-quoted-string': {
  3286. pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,
  3287. greedy: true,
  3288. alias: 'string'
  3289. },
  3290. 'string': {
  3291. pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  3292. greedy: true
  3293. },
  3294. 'function': {
  3295. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  3296. lookbehind: true
  3297. },
  3298. 'class-name': {
  3299. pattern: /(\bclass\s+)\w+/i,
  3300. lookbehind: true
  3301. },
  3302. 'decorator': {
  3303. pattern: /(^\s*)@\w+(?:\.\w+)*/im,
  3304. lookbehind: true,
  3305. alias: ['annotation', 'punctuation'],
  3306. inside: {
  3307. 'punctuation': /\./
  3308. }
  3309. },
  3310. 'keyword': /\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
  3311. '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/,
  3312. 'boolean': /\b(?:True|False|None)\b/,
  3313. 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?j?\b/i,
  3314. 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  3315. 'punctuation': /[{}[\];(),.:]/
  3316. };
  3317. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  3318. Prism.languages.py = Prism.languages.python;
  3319. (function(Prism) {
  3320. var javascript = Prism.util.clone(Prism.languages.javascript);
  3321. var space = /(?:\s|\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))\*\/)/.source;
  3322. var braces = /(?:\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])*\})/.source;
  3323. var spread = /(?:\{<S>*\.{3}(?:[^{}]|<BRACES>)*\})/.source;
  3324. /**
  3325. * @param {string} source
  3326. * @param {string} [flags]
  3327. */
  3328. function re(source, flags) {
  3329. source = source
  3330. .replace(/<S>/g, function () { return space; })
  3331. .replace(/<BRACES>/g, function () { return braces; })
  3332. .replace(/<SPREAD>/g, function () { return spread; });
  3333. return RegExp(source, flags);
  3334. }
  3335. spread = re(spread).source;
  3336. Prism.languages.jsx = Prism.languages.extend('markup', javascript);
  3337. Prism.languages.jsx.tag.pattern = re(
  3338. /<\/?(?:[\w.:-]+(?:<S>+(?:[\w.:$-]+(?:=(?:"(?:\\[^]|[^\\"])*"|'(?:\\[^]|[^\\'])*'|[^\s{'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*\/?)?>/.source
  3339. );
  3340. Prism.languages.jsx.tag.inside['tag'].pattern = /^<\/?[^\s>\/]*/i;
  3341. Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:"(?:\\[^]|[^\\"])*"|'(?:\\[^]|[^\\'])*'|[^\s'">]+)/i;
  3342. Prism.languages.jsx.tag.inside['tag'].inside['class-name'] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
  3343. Prism.languages.jsx.tag.inside['comment'] = javascript['comment'];
  3344. Prism.languages.insertBefore('inside', 'attr-name', {
  3345. 'spread': {
  3346. pattern: re(/<SPREAD>/.source),
  3347. inside: Prism.languages.jsx
  3348. }
  3349. }, Prism.languages.jsx.tag);
  3350. Prism.languages.insertBefore('inside', 'attr-value',{
  3351. 'script': {
  3352. // Allow for two levels of nesting
  3353. pattern: re(/=<BRACES>/.source),
  3354. inside: {
  3355. 'script-punctuation': {
  3356. pattern: /^=(?={)/,
  3357. alias: 'punctuation'
  3358. },
  3359. rest: Prism.languages.jsx
  3360. },
  3361. 'alias': 'language-javascript'
  3362. }
  3363. }, Prism.languages.jsx.tag);
  3364. // The following will handle plain text inside tags
  3365. var stringifyToken = function (token) {
  3366. if (!token) {
  3367. return '';
  3368. }
  3369. if (typeof token === 'string') {
  3370. return token;
  3371. }
  3372. if (typeof token.content === 'string') {
  3373. return token.content;
  3374. }
  3375. return token.content.map(stringifyToken).join('');
  3376. };
  3377. var walkTokens = function (tokens) {
  3378. var openedTags = [];
  3379. for (var i = 0; i < tokens.length; i++) {
  3380. var token = tokens[i];
  3381. var notTagNorBrace = false;
  3382. if (typeof token !== 'string') {
  3383. if (token.type === 'tag' && token.content[0] && token.content[0].type === 'tag') {
  3384. // We found a tag, now find its kind
  3385. if (token.content[0].content[0].content === '</') {
  3386. // Closing tag
  3387. if (openedTags.length > 0 && openedTags[openedTags.length - 1].tagName === stringifyToken(token.content[0].content[1])) {
  3388. // Pop matching opening tag
  3389. openedTags.pop();
  3390. }
  3391. } else {
  3392. if (token.content[token.content.length - 1].content === '/>') {
  3393. // Autoclosed tag, ignore
  3394. } else {
  3395. // Opening tag
  3396. openedTags.push({
  3397. tagName: stringifyToken(token.content[0].content[1]),
  3398. openedBraces: 0
  3399. });
  3400. }
  3401. }
  3402. } else if (openedTags.length > 0 && token.type === 'punctuation' && token.content === '{') {
  3403. // Here we might have entered a JSX context inside a tag
  3404. openedTags[openedTags.length - 1].openedBraces++;
  3405. } else if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces > 0 && token.type === 'punctuation' && token.content === '}') {
  3406. // Here we might have left a JSX context inside a tag
  3407. openedTags[openedTags.length - 1].openedBraces--;
  3408. } else {
  3409. notTagNorBrace = true
  3410. }
  3411. }
  3412. if (notTagNorBrace || typeof token === 'string') {
  3413. if (openedTags.length > 0 && openedTags[openedTags.length - 1].openedBraces === 0) {
  3414. // Here we are inside a tag, and not inside a JSX context.
  3415. // That's plain text: drop any tokens matched.
  3416. var plainText = stringifyToken(token);
  3417. // And merge text with adjacent text
  3418. if (i < tokens.length - 1 && (typeof tokens[i + 1] === 'string' || tokens[i + 1].type === 'plain-text')) {
  3419. plainText += stringifyToken(tokens[i + 1]);
  3420. tokens.splice(i + 1, 1);
  3421. }
  3422. if (i > 0 && (typeof tokens[i - 1] === 'string' || tokens[i - 1].type === 'plain-text')) {
  3423. plainText = stringifyToken(tokens[i - 1]) + plainText;
  3424. tokens.splice(i - 1, 1);
  3425. i--;
  3426. }
  3427. tokens[i] = new Prism.Token('plain-text', plainText, null, plainText);
  3428. }
  3429. }
  3430. if (token.content && typeof token.content !== 'string') {
  3431. walkTokens(token.content);
  3432. }
  3433. }
  3434. };
  3435. Prism.hooks.add('after-tokenize', function (env) {
  3436. if (env.language !== 'jsx' && env.language !== 'tsx') {
  3437. return;
  3438. }
  3439. walkTokens(env.tokens);
  3440. });
  3441. }(Prism));
  3442. (function (Prism) {
  3443. var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
  3444. for (var i = 0; i < 2; i++) {
  3445. // support 4 levels of nested comments
  3446. multilineComment = multilineComment.replace(/<self>/g, function () { return multilineComment; });
  3447. }
  3448. multilineComment = multilineComment.replace(/<self>/g, function () { return /[^\s\S]/.source; });
  3449. Prism.languages.rust = {
  3450. 'comment': [
  3451. {
  3452. pattern: RegExp(/(^|[^\\])/.source + multilineComment),
  3453. lookbehind: true,
  3454. greedy: true
  3455. },
  3456. {
  3457. pattern: /(^|[^\\:])\/\/.*/,
  3458. lookbehind: true,
  3459. greedy: true
  3460. }
  3461. ],
  3462. 'string': {
  3463. pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
  3464. greedy: true
  3465. },
  3466. 'char': {
  3467. pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
  3468. greedy: true,
  3469. alias: 'string'
  3470. },
  3471. 'attribute': {
  3472. pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
  3473. greedy: true,
  3474. alias: 'attr-name',
  3475. inside: {
  3476. 'string': null // see below
  3477. }
  3478. },
  3479. // Closure params should not be confused with bitwise OR |
  3480. 'closure-params': {
  3481. pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
  3482. lookbehind: true,
  3483. greedy: true,
  3484. inside: {
  3485. 'closure-punctuation': {
  3486. pattern: /^\||\|$/,
  3487. alias: 'punctuation'
  3488. },
  3489. rest: null // see below
  3490. }
  3491. },
  3492. 'lifetime-annotation': {
  3493. pattern: /'\w+/,
  3494. alias: 'symbol'
  3495. },
  3496. 'fragment-specifier': {
  3497. pattern: /(\$\w+:)[a-z]+/,
  3498. lookbehind: true,
  3499. alias: 'punctuation'
  3500. },
  3501. 'variable': /\$\w+/,
  3502. 'function-definition': {
  3503. pattern: /(\bfn\s+)\w+/,
  3504. lookbehind: true,
  3505. alias: 'function'
  3506. },
  3507. 'type-definition': {
  3508. pattern: /(\b(?:enum|struct|union)\s+)\w+/,
  3509. lookbehind: true,
  3510. alias: 'class-name'
  3511. },
  3512. 'module-declaration': [
  3513. {
  3514. pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
  3515. lookbehind: true,
  3516. alias: 'namespace'
  3517. },
  3518. {
  3519. pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
  3520. lookbehind: true,
  3521. alias: 'namespace',
  3522. inside: {
  3523. 'punctuation': /::/
  3524. }
  3525. }
  3526. ],
  3527. 'keyword': [
  3528. // https://github.com/rust-lang/reference/blob/master/src/keywords.md
  3529. /\b(?: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|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,
  3530. // primitives and str
  3531. // https://doc.rust-lang.org/stable/rust-by-example/primitives.html
  3532. /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/
  3533. ],
  3534. // functions can technically start with an upper-case letter, but this will introduce a lot of false positives
  3535. // and Rust's naming conventions recommend snake_case anyway.
  3536. // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
  3537. 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
  3538. 'macro': {
  3539. pattern: /\w+!/,
  3540. alias: 'property'
  3541. },
  3542. 'constant': /\b[A-Z_][A-Z_\d]+\b/,
  3543. 'class-name': /\b[A-Z]\w*\b/,
  3544. 'namespace': {
  3545. pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
  3546. inside: {
  3547. 'punctuation': /::/
  3548. }
  3549. },
  3550. // Hex, oct, bin, dec numbers with visual separators and type suffix
  3551. 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/,
  3552. 'boolean': /\b(?:false|true)\b/,
  3553. 'punctuation': /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
  3554. 'operator': /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
  3555. };
  3556. Prism.languages.rust['closure-params'].inside.rest = Prism.languages.rust;
  3557. Prism.languages.rust['attribute'].inside['string'] = Prism.languages.rust['string'];
  3558. }(Prism));
  3559. Prism.languages.scss = Prism.languages.extend('css', {
  3560. 'comment': {
  3561. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  3562. lookbehind: true
  3563. },
  3564. 'atrule': {
  3565. pattern: /@[\w-](?:\([^()]+\)|[^()\s]|\s+(?!\s))*?(?=\s+[{;])/,
  3566. inside: {
  3567. 'rule': /@[\w-]+/
  3568. // See rest below
  3569. }
  3570. },
  3571. // url, compassified
  3572. 'url': /(?:[-a-z]+-)?url(?=\()/i,
  3573. // CSS selector regex is not appropriate for Sass
  3574. // since there can be lot more things (var, @ directive, nesting..)
  3575. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  3576. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  3577. // 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
  3578. // can "pass" as a selector- e.g: proper#{$erty})
  3579. // this one was hard to do, so please be careful if you edit this one :)
  3580. 'selector': {
  3581. // Initial look-ahead is used to prevent matching of blank selectors
  3582. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()\s]|\s+(?!\s)|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}][^:{}]*[:{][^}]+))/m,
  3583. inside: {
  3584. 'parent': {
  3585. pattern: /&/,
  3586. alias: 'important'
  3587. },
  3588. 'placeholder': /%[-\w]+/,
  3589. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  3590. }
  3591. },
  3592. 'property': {
  3593. pattern: /(?:[-\w]|\$[-\w]|#\{\$[-\w]+\})+(?=\s*:)/,
  3594. inside: {
  3595. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  3596. }
  3597. }
  3598. });
  3599. Prism.languages.insertBefore('scss', 'atrule', {
  3600. 'keyword': [
  3601. /@(?:if|else(?: if)?|forward|for|each|while|import|use|extend|debug|warn|mixin|include|function|return|content)\b/i,
  3602. {
  3603. pattern: /( +)(?:from|through)(?= )/,
  3604. lookbehind: true
  3605. }
  3606. ]
  3607. });
  3608. Prism.languages.insertBefore('scss', 'important', {
  3609. // var and interpolated vars
  3610. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  3611. });
  3612. Prism.languages.insertBefore('scss', 'function', {
  3613. 'module-modifier': {
  3614. pattern: /\b(?:as|with|show|hide)\b/i,
  3615. alias: 'keyword'
  3616. },
  3617. 'placeholder': {
  3618. pattern: /%[-\w]+/,
  3619. alias: 'selector'
  3620. },
  3621. 'statement': {
  3622. pattern: /\B!(?:default|optional)\b/i,
  3623. alias: 'keyword'
  3624. },
  3625. 'boolean': /\b(?:true|false)\b/,
  3626. 'null': {
  3627. pattern: /\bnull\b/,
  3628. alias: 'keyword'
  3629. },
  3630. 'operator': {
  3631. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|or|not)(?=\s)/,
  3632. lookbehind: true
  3633. }
  3634. });
  3635. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;
  3636. (function (Prism) {
  3637. // CAREFUL!
  3638. // The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
  3639. var strings = [
  3640. // normal string
  3641. // 1 capturing group
  3642. /(["'])(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|(?!\1)[^\\`$])*\1/.source,
  3643. // here doc
  3644. // 2 capturing groups
  3645. /<<-?\s*(["']?)(\w+)\2\s[\s\S]*?[\r\n]\3/.source
  3646. ].join('|');
  3647. Prism.languages['shell-session'] = {
  3648. 'command': {
  3649. pattern: RegExp(/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>:;|]+)?[$#](?:[^\\\r\n'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }), 'm'),
  3650. greedy: true,
  3651. inside: {
  3652. 'info': {
  3653. // foo@bar:~/files$ exit
  3654. // foo@bar$ exit
  3655. // ~/files$ exit
  3656. pattern: /^[^#$]+/,
  3657. alias: 'punctuation',
  3658. inside: {
  3659. 'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+/,
  3660. 'punctuation': /:/,
  3661. 'path': /[\s\S]+/
  3662. }
  3663. },
  3664. 'bash': {
  3665. pattern: /(^[$#]\s*)\S[\s\S]*/,
  3666. lookbehind: true,
  3667. alias: 'language-bash',
  3668. inside: Prism.languages.bash
  3669. },
  3670. 'shell-symbol': {
  3671. pattern: /^[$#]/,
  3672. alias: 'important'
  3673. }
  3674. }
  3675. },
  3676. 'output': /.(?:.*(?:[\r\n]|.$))*/
  3677. };
  3678. Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
  3679. }(Prism));
  3680. Prism.languages.sql = {
  3681. 'comment': {
  3682. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
  3683. lookbehind: true
  3684. },
  3685. 'variable': [
  3686. {
  3687. pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
  3688. greedy: true
  3689. },
  3690. /@[\w.$]+/
  3691. ],
  3692. 'string': {
  3693. pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
  3694. greedy: true,
  3695. lookbehind: true
  3696. },
  3697. '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?
  3698. '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(?:_INSERT|COL)?|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(?:S|ING)?|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,
  3699. 'boolean': /\b(?:TRUE|FALSE|NULL)\b/i,
  3700. 'number': /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
  3701. 'operator': /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|IN|ILIKE|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  3702. 'punctuation': /[;[\]()`,.]/
  3703. };
  3704. (function (Prism) {
  3705. Prism.languages.typescript = Prism.languages.extend('javascript', {
  3706. 'class-name': {
  3707. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
  3708. lookbehind: true,
  3709. greedy: true,
  3710. inside: null // see below
  3711. },
  3712. // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
  3713. 'keyword': /\b(?:abstract|as|asserts|async|await|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|null|of|package|private|protected|public|readonly|return|require|set|static|super|switch|this|throw|try|type|typeof|undefined|var|void|while|with|yield)\b/,
  3714. 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
  3715. });
  3716. // doesn't work with TS because TS is too complex
  3717. delete Prism.languages.typescript['parameter'];
  3718. // a version of typescript specifically for highlighting types
  3719. var typeInside = Prism.languages.extend('typescript', {});
  3720. delete typeInside['class-name'];
  3721. Prism.languages.typescript['class-name'].inside = typeInside;
  3722. Prism.languages.insertBefore('typescript', 'function', {
  3723. 'generic-function': {
  3724. // e.g. foo<T extends "bar" | "baz">( ...
  3725. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
  3726. greedy: true,
  3727. inside: {
  3728. 'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
  3729. 'generic': {
  3730. pattern: /<[\s\S]+/, // everything after the first <
  3731. alias: 'class-name',
  3732. inside: typeInside
  3733. }
  3734. }
  3735. }
  3736. });
  3737. Prism.languages.ts = Prism.languages.typescript;
  3738. }(Prism));
  3739. (function (Prism) {
  3740. // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
  3741. // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
  3742. var anchorOrAlias = /[*&][^\s[\]{},]+/;
  3743. // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
  3744. var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
  3745. // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
  3746. var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
  3747. + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
  3748. // https://yaml.org/spec/1.2/spec.html#ns-plain(n,c)
  3749. // This is a simplified version that doesn't support "#" and multiline keys
  3750. // All these long scarry character classes are simplified versions of YAML's characters
  3751. var plainKey = /(?:[^\s\x00-\x08\x0e-\x1f!"#%&'*,\-:>?@[\]`{|}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*/.source
  3752. .replace(/<PLAIN>/g, function () { return /[^\s\x00-\x08\x0e-\x1f,[\]{}\x7f-\x84\x86-\x9f\ud800-\udfff\ufffe\uffff]/.source; });
  3753. var string = /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/.source;
  3754. /**
  3755. *
  3756. * @param {string} value
  3757. * @param {string} [flags]
  3758. * @returns {RegExp}
  3759. */
  3760. function createValuePattern(value, flags) {
  3761. flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
  3762. var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|]|}|(?:[\r\n]\s*)?#))/.source
  3763. .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
  3764. return RegExp(pattern, flags)
  3765. }
  3766. Prism.languages.yaml = {
  3767. 'scalar': {
  3768. pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\S[^\r\n]*(?:\2[^\r\n]+)*)/.source
  3769. .replace(/<<prop>>/g, function () { return properties; })),
  3770. lookbehind: true,
  3771. alias: 'string'
  3772. },
  3773. 'comment': /#.*/,
  3774. 'key': {
  3775. pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\s*:\s)/.source
  3776. .replace(/<<prop>>/g, function () { return properties; })
  3777. .replace(/<<key>>/g, function () { return '(?:' + plainKey + '|' + string + ')'; })),
  3778. lookbehind: true,
  3779. greedy: true,
  3780. alias: 'atrule'
  3781. },
  3782. 'directive': {
  3783. pattern: /(^[ \t]*)%.+/m,
  3784. lookbehind: true,
  3785. alias: 'important'
  3786. },
  3787. 'datetime': {
  3788. 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),
  3789. lookbehind: true,
  3790. alias: 'number'
  3791. },
  3792. 'boolean': {
  3793. pattern: createValuePattern(/true|false/.source, 'i'),
  3794. lookbehind: true,
  3795. alias: 'important'
  3796. },
  3797. 'null': {
  3798. pattern: createValuePattern(/null|~/.source, 'i'),
  3799. lookbehind: true,
  3800. alias: 'important'
  3801. },
  3802. 'string': {
  3803. pattern: createValuePattern(string),
  3804. lookbehind: true,
  3805. greedy: true
  3806. },
  3807. 'number': {
  3808. pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+(?:\.\d*)?|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
  3809. lookbehind: true
  3810. },
  3811. 'tag': tag,
  3812. 'important': anchorOrAlias,
  3813. 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
  3814. };
  3815. Prism.languages.yml = Prism.languages.yaml;
  3816. }(Prism));