123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937 |
- /* PrismJS 1.20.0
- https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+bash+csharp+gcode+json+less+lua+markdown+markup-templating+php+processing+python+regex+ruby+sass+swift+typescript+unrealscript+xml-doc+yaml */
- var _self = (typeof window !== 'undefined')
- ? window // if in browser
- : (
- (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
- ? self // if in worker
- : {} // if in node js
- );
- /**
- * Prism: Lightweight, robust, elegant syntax highlighting
- * MIT license http://www.opensource.org/licenses/mit-license.php/
- * @author Lea Verou http://lea.verou.me
- */
- var Prism = (function (_self){
- // Private helper vars
- var lang = /\blang(?:uage)?-([\w-]+)\b/i;
- var uniqueId = 0;
- var _ = {
- manual: _self.Prism && _self.Prism.manual,
- disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
- util: {
- encode: function encode(tokens) {
- if (tokens instanceof Token) {
- return new Token(tokens.type, encode(tokens.content), tokens.alias);
- } else if (Array.isArray(tokens)) {
- return tokens.map(encode);
- } else {
- return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
- }
- },
- type: function (o) {
- return Object.prototype.toString.call(o).slice(8, -1);
- },
- objId: function (obj) {
- if (!obj['__id']) {
- Object.defineProperty(obj, '__id', { value: ++uniqueId });
- }
- return obj['__id'];
- },
- // Deep clone a language definition (e.g. to extend it)
- clone: function deepClone(o, visited) {
- var clone, id, type = _.util.type(o);
- visited = visited || {};
- switch (type) {
- case 'Object':
- id = _.util.objId(o);
- if (visited[id]) {
- return visited[id];
- }
- clone = {};
- visited[id] = clone;
- for (var key in o) {
- if (o.hasOwnProperty(key)) {
- clone[key] = deepClone(o[key], visited);
- }
- }
- return clone;
- case 'Array':
- id = _.util.objId(o);
- if (visited[id]) {
- return visited[id];
- }
- clone = [];
- visited[id] = clone;
- o.forEach(function (v, i) {
- clone[i] = deepClone(v, visited);
- });
- return clone;
- default:
- return o;
- }
- },
- /**
- * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
- *
- * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
- *
- * @param {Element} element
- * @returns {string}
- */
- getLanguage: function (element) {
- while (element && !lang.test(element.className)) {
- element = element.parentElement;
- }
- if (element) {
- return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
- }
- return 'none';
- },
- /**
- * Returns the script element that is currently executing.
- *
- * This does __not__ work for line script element.
- *
- * @returns {HTMLScriptElement | null}
- */
- currentScript: function () {
- if (typeof document === 'undefined') {
- return null;
- }
- if ('currentScript' in document) {
- return document.currentScript;
- }
- // IE11 workaround
- // we'll get the src of the current script by parsing IE11's error stack trace
- // this will not work for inline scripts
- try {
- throw new Error();
- } catch (err) {
- // Get file src url from stack. Specifically works with the format of stack traces in IE.
- // A stack will look like this:
- //
- // Error
- // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
- // at Global code (http://localhost/components/prism-core.js:606:1)
- var src = (/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(err.stack) || [])[1];
- if (src) {
- var scripts = document.getElementsByTagName('script');
- for (var i in scripts) {
- if (scripts[i].src == src) {
- return scripts[i];
- }
- }
- }
- return null;
- }
- }
- },
- languages: {
- extend: function (id, redef) {
- var lang = _.util.clone(_.languages[id]);
- for (var key in redef) {
- lang[key] = redef[key];
- }
- return lang;
- },
- /**
- * Insert a token before another token in a language literal
- * As this needs to recreate the object (we cannot actually insert before keys in object literals),
- * we cannot just provide an object, we need an object and a key.
- * @param inside The key (or language id) of the parent
- * @param before The key to insert before.
- * @param insert Object with the key/value pairs to insert
- * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
- */
- insertBefore: function (inside, before, insert, root) {
- root = root || _.languages;
- var grammar = root[inside];
- var ret = {};
- for (var token in grammar) {
- if (grammar.hasOwnProperty(token)) {
- if (token == before) {
- for (var newToken in insert) {
- if (insert.hasOwnProperty(newToken)) {
- ret[newToken] = insert[newToken];
- }
- }
- }
- // Do not insert token which also occur in insert. See #1525
- if (!insert.hasOwnProperty(token)) {
- ret[token] = grammar[token];
- }
- }
- }
- var old = root[inside];
- root[inside] = ret;
- // Update references in other language definitions
- _.languages.DFS(_.languages, function(key, value) {
- if (value === old && key != inside) {
- this[key] = ret;
- }
- });
- return ret;
- },
- // Traverse a language definition with Depth First Search
- DFS: function DFS(o, callback, type, visited) {
- visited = visited || {};
- var objId = _.util.objId;
- for (var i in o) {
- if (o.hasOwnProperty(i)) {
- callback.call(o, i, o[i], type || i);
- var property = o[i],
- propertyType = _.util.type(property);
- if (propertyType === 'Object' && !visited[objId(property)]) {
- visited[objId(property)] = true;
- DFS(property, callback, null, visited);
- }
- else if (propertyType === 'Array' && !visited[objId(property)]) {
- visited[objId(property)] = true;
- DFS(property, callback, i, visited);
- }
- }
- }
- }
- },
- plugins: {},
- highlightAll: function(async, callback) {
- _.highlightAllUnder(document, async, callback);
- },
- highlightAllUnder: function(container, async, callback) {
- var env = {
- callback: callback,
- container: container,
- selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
- };
- _.hooks.run('before-highlightall', env);
- env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
- _.hooks.run('before-all-elements-highlight', env);
- for (var i = 0, element; element = env.elements[i++];) {
- _.highlightElement(element, async === true, env.callback);
- }
- },
- highlightElement: function(element, async, callback) {
- // Find language
- var language = _.util.getLanguage(element);
- var grammar = _.languages[language];
- // Set language on the element, if not present
- element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
- // Set language on the parent, for styling
- var parent = element.parentNode;
- if (parent && parent.nodeName.toLowerCase() === 'pre') {
- parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
- }
- var code = element.textContent;
- var env = {
- element: element,
- language: language,
- grammar: grammar,
- code: code
- };
- function insertHighlightedCode(highlightedCode) {
- env.highlightedCode = highlightedCode;
- _.hooks.run('before-insert', env);
- env.element.innerHTML = env.highlightedCode;
- _.hooks.run('after-highlight', env);
- _.hooks.run('complete', env);
- callback && callback.call(env.element);
- }
- _.hooks.run('before-sanity-check', env);
- if (!env.code) {
- _.hooks.run('complete', env);
- callback && callback.call(env.element);
- return;
- }
- _.hooks.run('before-highlight', env);
- if (!env.grammar) {
- insertHighlightedCode(_.util.encode(env.code));
- return;
- }
- if (async && _self.Worker) {
- var worker = new Worker(_.filename);
- worker.onmessage = function(evt) {
- insertHighlightedCode(evt.data);
- };
- worker.postMessage(JSON.stringify({
- language: env.language,
- code: env.code,
- immediateClose: true
- }));
- }
- else {
- insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
- }
- },
- highlight: function (text, grammar, language) {
- var env = {
- code: text,
- grammar: grammar,
- language: language
- };
- _.hooks.run('before-tokenize', env);
- env.tokens = _.tokenize(env.code, env.grammar);
- _.hooks.run('after-tokenize', env);
- return Token.stringify(_.util.encode(env.tokens), env.language);
- },
- tokenize: function(text, grammar) {
- var rest = grammar.rest;
- if (rest) {
- for (var token in rest) {
- grammar[token] = rest[token];
- }
- delete grammar.rest;
- }
- var tokenList = new LinkedList();
- addAfter(tokenList, tokenList.head, text);
- matchGrammar(text, tokenList, grammar, tokenList.head, 0);
- return toArray(tokenList);
- },
- hooks: {
- all: {},
- add: function (name, callback) {
- var hooks = _.hooks.all;
- hooks[name] = hooks[name] || [];
- hooks[name].push(callback);
- },
- run: function (name, env) {
- var callbacks = _.hooks.all[name];
- if (!callbacks || !callbacks.length) {
- return;
- }
- for (var i=0, callback; callback = callbacks[i++];) {
- callback(env);
- }
- }
- },
- Token: Token
- };
- _self.Prism = _;
- function Token(type, content, alias, matchedStr, greedy) {
- this.type = type;
- this.content = content;
- this.alias = alias;
- // Copy of the full string this token was created from
- this.length = (matchedStr || '').length|0;
- this.greedy = !!greedy;
- }
- Token.stringify = function stringify(o, language) {
- if (typeof o == 'string') {
- return o;
- }
- if (Array.isArray(o)) {
- var s = '';
- o.forEach(function (e) {
- s += stringify(e, language);
- });
- return s;
- }
- var env = {
- type: o.type,
- content: stringify(o.content, language),
- tag: 'span',
- classes: ['token', o.type],
- attributes: {},
- language: language
- };
- var aliases = o.alias;
- if (aliases) {
- if (Array.isArray(aliases)) {
- Array.prototype.push.apply(env.classes, aliases);
- } else {
- env.classes.push(aliases);
- }
- }
- _.hooks.run('wrap', env);
- var attributes = '';
- for (var name in env.attributes) {
- attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
- }
- return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
- };
- /**
- * @param {string} text
- * @param {LinkedList<string | Token>} tokenList
- * @param {any} grammar
- * @param {LinkedListNode<string | Token>} startNode
- * @param {number} startPos
- * @param {boolean} [oneshot=false]
- * @param {string} [target]
- */
- function matchGrammar(text, tokenList, grammar, startNode, startPos, oneshot, target) {
- for (var token in grammar) {
- if (!grammar.hasOwnProperty(token) || !grammar[token]) {
- continue;
- }
- var patterns = grammar[token];
- patterns = Array.isArray(patterns) ? patterns : [patterns];
- for (var j = 0; j < patterns.length; ++j) {
- if (target && target == token + ',' + j) {
- return;
- }
- var pattern = patterns[j],
- inside = pattern.inside,
- lookbehind = !!pattern.lookbehind,
- greedy = !!pattern.greedy,
- lookbehindLength = 0,
- alias = pattern.alias;
- if (greedy && !pattern.pattern.global) {
- // Without the global flag, lastIndex won't work
- var flags = pattern.pattern.toString().match(/[imsuy]*$/)[0];
- pattern.pattern = RegExp(pattern.pattern.source, flags + 'g');
- }
- pattern = pattern.pattern || pattern;
- for ( // iterate the token list and keep track of the current token/string position
- var currentNode = startNode.next, pos = startPos;
- currentNode !== tokenList.tail;
- pos += currentNode.value.length, currentNode = currentNode.next
- ) {
- var str = currentNode.value;
- if (tokenList.length > text.length) {
- // Something went terribly wrong, ABORT, ABORT!
- return;
- }
- if (str instanceof Token) {
- continue;
- }
- var removeCount = 1; // this is the to parameter of removeBetween
- if (greedy && currentNode != tokenList.tail.prev) {
- pattern.lastIndex = pos;
- var match = pattern.exec(text);
- if (!match) {
- break;
- }
- var from = match.index + (lookbehind && match[1] ? match[1].length : 0);
- var to = match.index + match[0].length;
- var p = pos;
- // find the node that contains the match
- p += currentNode.value.length;
- while (from >= p) {
- currentNode = currentNode.next;
- p += currentNode.value.length;
- }
- // adjust pos (and p)
- p -= currentNode.value.length;
- pos = p;
- // the current node is a Token, then the match starts inside another Token, which is invalid
- if (currentNode.value instanceof Token) {
- continue;
- }
- // find the last node which is affected by this match
- for (
- var k = currentNode;
- k !== tokenList.tail && (p < to || (typeof k.value === 'string' && !k.prev.value.greedy));
- k = k.next
- ) {
- removeCount++;
- p += k.value.length;
- }
- removeCount--;
- // replace with the new match
- str = text.slice(pos, p);
- match.index -= pos;
- } else {
- pattern.lastIndex = 0;
- var match = pattern.exec(str);
- }
- if (!match) {
- if (oneshot) {
- break;
- }
- continue;
- }
- if (lookbehind) {
- lookbehindLength = match[1] ? match[1].length : 0;
- }
- var from = match.index + lookbehindLength,
- match = match[0].slice(lookbehindLength),
- to = from + match.length,
- before = str.slice(0, from),
- after = str.slice(to);
- var removeFrom = currentNode.prev;
- if (before) {
- removeFrom = addAfter(tokenList, removeFrom, before);
- pos += before.length;
- }
- removeRange(tokenList, removeFrom, removeCount);
- var wrapped = new Token(token, inside ? _.tokenize(match, inside) : match, alias, match, greedy);
- currentNode = addAfter(tokenList, removeFrom, wrapped);
- if (after) {
- addAfter(tokenList, currentNode, after);
- }
- if (removeCount > 1)
- matchGrammar(text, tokenList, grammar, currentNode.prev, pos, true, token + ',' + j);
- if (oneshot)
- break;
- }
- }
- }
- }
- /**
- * @typedef LinkedListNode
- * @property {T} value
- * @property {LinkedListNode<T> | null} prev The previous node.
- * @property {LinkedListNode<T> | null} next The next node.
- * @template T
- */
- /**
- * @template T
- */
- function LinkedList() {
- /** @type {LinkedListNode<T>} */
- var head = { value: null, prev: null, next: null };
- /** @type {LinkedListNode<T>} */
- var tail = { value: null, prev: head, next: null };
- head.next = tail;
- /** @type {LinkedListNode<T>} */
- this.head = head;
- /** @type {LinkedListNode<T>} */
- this.tail = tail;
- this.length = 0;
- }
- /**
- * Adds a new node with the given value to the list.
- * @param {LinkedList<T>} list
- * @param {LinkedListNode<T>} node
- * @param {T} value
- * @returns {LinkedListNode<T>} The added node.
- * @template T
- */
- function addAfter(list, node, value) {
- // assumes that node != list.tail && values.length >= 0
- var next = node.next;
- var newNode = { value: value, prev: node, next: next };
- node.next = newNode;
- next.prev = newNode;
- list.length++;
- return newNode;
- }
- /**
- * Removes `count` nodes after the given node. The given node will not be removed.
- * @param {LinkedList<T>} list
- * @param {LinkedListNode<T>} node
- * @param {number} count
- * @template T
- */
- function removeRange(list, node, count) {
- var next = node.next;
- for (var i = 0; i < count && next !== list.tail; i++) {
- next = next.next;
- }
- node.next = next;
- next.prev = node;
- list.length -= i;
- }
- /**
- * @param {LinkedList<T>} list
- * @returns {T[]}
- * @template T
- */
- function toArray(list) {
- var array = [];
- var node = list.head.next;
- while (node !== list.tail) {
- array.push(node.value);
- node = node.next;
- }
- return array;
- }
- if (!_self.document) {
- if (!_self.addEventListener) {
- // in Node.js
- return _;
- }
- if (!_.disableWorkerMessageHandler) {
- // In worker
- _self.addEventListener('message', function (evt) {
- var message = JSON.parse(evt.data),
- lang = message.language,
- code = message.code,
- immediateClose = message.immediateClose;
- _self.postMessage(_.highlight(code, _.languages[lang], lang));
- if (immediateClose) {
- _self.close();
- }
- }, false);
- }
- return _;
- }
- //Get current script and highlight
- var script = _.util.currentScript();
- if (script) {
- _.filename = script.src;
- if (script.hasAttribute('data-manual')) {
- _.manual = true;
- }
- }
- function highlightAutomaticallyCallback() {
- if (!_.manual) {
- _.highlightAll();
- }
- }
- if (!_.manual) {
- // If the document state is "loading", then we'll use DOMContentLoaded.
- // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
- // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
- // might take longer one animation frame to execute which can create a race condition where only some plugins have
- // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
- // See https://github.com/PrismJS/prism/issues/2102
- var readyState = document.readyState;
- if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
- document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
- } else {
- if (window.requestAnimationFrame) {
- window.requestAnimationFrame(highlightAutomaticallyCallback);
- } else {
- window.setTimeout(highlightAutomaticallyCallback, 16);
- }
- }
- }
- return _;
- })(_self);
- if (typeof module !== 'undefined' && module.exports) {
- module.exports = Prism;
- }
- // hack for components to work correctly in node.js
- if (typeof global !== 'undefined') {
- global.Prism = Prism;
- }
- ;
- Prism.languages.markup = {
- 'comment': /<!--[\s\S]*?-->/,
- 'prolog': /<\?[\s\S]+?\?>/,
- 'doctype': {
- // https://www.w3.org/TR/xml/#NT-doctypedecl
- pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
- greedy: true,
- inside: {
- 'internal-subset': {
- pattern: /(\[)[\s\S]+(?=\]>$)/,
- lookbehind: true,
- greedy: true,
- inside: null // see below
- },
- 'string': {
- pattern: /"[^"]*"|'[^']*'/,
- greedy: true
- },
- 'punctuation': /^<!|>$|[[\]]/,
- 'doctype-tag': /^DOCTYPE/,
- 'name': /[^\s<>'"]+/
- }
- },
- 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
- 'tag': {
- pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
- greedy: true,
- inside: {
- 'tag': {
- pattern: /^<\/?[^\s>\/]+/,
- inside: {
- 'punctuation': /^<\/?/,
- 'namespace': /^[^\s>\/:]+:/
- }
- },
- 'attr-value': {
- pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
- inside: {
- 'punctuation': [
- {
- pattern: /^=/,
- alias: 'attr-equals'
- },
- /"|'/
- ]
- }
- },
- 'punctuation': /\/?>/,
- 'attr-name': {
- pattern: /[^\s>\/]+/,
- inside: {
- 'namespace': /^[^\s>\/:]+:/
- }
- }
- }
- },
- 'entity': [
- {
- pattern: /&[\da-z]{1,8};/i,
- alias: 'named-entity'
- },
- /&#x?[\da-f]{1,8};/i
- ]
- };
- Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
- Prism.languages.markup['entity'];
- Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
- // Plugin to make entity title show the real entity, idea by Roman Komarov
- Prism.hooks.add('wrap', function (env) {
- if (env.type === 'entity') {
- env.attributes['title'] = env.content.replace(/&/, '&');
- }
- });
- Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
- /**
- * Adds an inlined language to markup.
- *
- * An example of an inlined language is CSS with `<style>` tags.
- *
- * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
- * case insensitive.
- * @param {string} lang The language key.
- * @example
- * addInlined('style', 'css');
- */
- value: function addInlined(tagName, lang) {
- var includedCdataInside = {};
- includedCdataInside['language-' + lang] = {
- pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
- lookbehind: true,
- inside: Prism.languages[lang]
- };
- includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
- var inside = {
- 'included-cdata': {
- pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
- inside: includedCdataInside
- }
- };
- inside['language-' + lang] = {
- pattern: /[\s\S]+/,
- inside: Prism.languages[lang]
- };
- var def = {};
- def[tagName] = {
- pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
- lookbehind: true,
- greedy: true,
- inside: inside
- };
- Prism.languages.insertBefore('markup', 'cdata', def);
- }
- });
- Prism.languages.html = Prism.languages.markup;
- Prism.languages.mathml = Prism.languages.markup;
- Prism.languages.svg = Prism.languages.markup;
- Prism.languages.xml = Prism.languages.extend('markup', {});
- Prism.languages.ssml = Prism.languages.xml;
- Prism.languages.atom = Prism.languages.xml;
- Prism.languages.rss = Prism.languages.xml;
- (function (Prism) {
- var string = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
- Prism.languages.css = {
- 'comment': /\/\*[\s\S]*?\*\//,
- 'atrule': {
- pattern: /@[\w-]+[\s\S]*?(?:;|(?=\s*\{))/,
- inside: {
- 'rule': /^@[\w-]+/,
- 'selector-function-argument': {
- pattern: /(\bselector\s*\((?!\s*\))\s*)(?:[^()]|\((?:[^()]|\([^()]*\))*\))+?(?=\s*\))/,
- lookbehind: true,
- alias: 'selector'
- }
- // See rest below
- }
- },
- 'url': {
- pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
- greedy: true,
- inside: {
- 'function': /^url/i,
- 'punctuation': /^\(|\)$/
- }
- },
- 'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
- 'string': {
- pattern: string,
- greedy: true
- },
- 'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,
- 'important': /!important\b/i,
- 'function': /[-a-z0-9]+(?=\()/i,
- 'punctuation': /[(){};:,]/
- };
- Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
- var markup = Prism.languages.markup;
- if (markup) {
- markup.tag.addInlined('style', 'css');
- Prism.languages.insertBefore('inside', 'attr-value', {
- 'style-attr': {
- pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,
- inside: {
- 'attr-name': {
- pattern: /^\s*style/i,
- inside: markup.tag.inside
- },
- 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
- 'attr-value': {
- pattern: /.+/i,
- inside: Prism.languages.css
- }
- },
- alias: 'language-css'
- }
- }, markup.tag);
- }
- }(Prism));
- Prism.languages.clike = {
- 'comment': [
- {
- pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
- lookbehind: true
- },
- {
- pattern: /(^|[^\\:])\/\/.*/,
- lookbehind: true,
- greedy: true
- }
- ],
- 'string': {
- pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
- greedy: true
- },
- 'class-name': {
- pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,
- lookbehind: true,
- inside: {
- 'punctuation': /[.\\]/
- }
- },
- 'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
- 'boolean': /\b(?:true|false)\b/,
- 'function': /\w+(?=\()/,
- 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
- 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
- 'punctuation': /[{}[\];(),.:]/
- };
- Prism.languages.javascript = Prism.languages.extend('clike', {
- 'class-name': [
- Prism.languages.clike['class-name'],
- {
- pattern: /(^|[^$\w\xA0-\uFFFF])[_$A-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\.(?:prototype|constructor))/,
- lookbehind: true
- }
- ],
- 'keyword': [
- {
- pattern: /((?:^|})\s*)(?:catch|finally)\b/,
- lookbehind: true
- },
- {
- 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|for|from|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/,
- lookbehind: true
- },
- ],
- '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)?)+)?/,
- // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
- 'function': /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
- 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
- });
- Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;
- Prism.languages.insertBefore('javascript', 'keyword', {
- 'regex': {
- pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,
- lookbehind: true,
- greedy: true
- },
- // This must be declared before keyword because we use "function" inside the look-forward
- 'function-variable': {
- pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/,
- alias: 'function'
- },
- 'parameter': [
- {
- pattern: /(function(?:\s+[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)?\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\))/,
- lookbehind: true,
- inside: Prism.languages.javascript
- },
- {
- pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=>)/i,
- inside: Prism.languages.javascript
- },
- {
- pattern: /(\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*=>)/,
- lookbehind: true,
- inside: Prism.languages.javascript
- },
- {
- 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]))(?:[_$A-Za-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()]|\([^()]*\))+?(?=\s*\)\s*\{)/,
- lookbehind: true,
- inside: Prism.languages.javascript
- }
- ],
- 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
- });
- Prism.languages.insertBefore('javascript', 'string', {
- 'template-string': {
- pattern: /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,
- greedy: true,
- inside: {
- 'template-punctuation': {
- pattern: /^`|`$/,
- alias: 'string'
- },
- 'interpolation': {
- pattern: /((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,
- lookbehind: true,
- inside: {
- 'interpolation-punctuation': {
- pattern: /^\${|}$/,
- alias: 'punctuation'
- },
- rest: Prism.languages.javascript
- }
- },
- 'string': /[\s\S]+/
- }
- }
- });
- if (Prism.languages.markup) {
- Prism.languages.markup.tag.addInlined('script', 'javascript');
- }
- Prism.languages.js = Prism.languages.javascript;
- (function(Prism) {
- // $ set | grep '^[A-Z][^[:space:]]*=' | cut -d= -f1 | tr '\n' '|'
- // + LC_ALL, RANDOM, REPLY, SECONDS.
- // + make sure PS1..4 are here as they are not always set,
- // - some useless things.
- 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';
- var insideString = {
- 'environment': {
- pattern: RegExp("\\$" + envVars),
- alias: 'constant'
- },
- 'variable': [
- // [0]: Arithmetic Environment
- {
- pattern: /\$?\(\([\s\S]+?\)\)/,
- greedy: true,
- inside: {
- // If there is a $ sign at the beginning highlight $(( and )) as variable
- 'variable': [
- {
- pattern: /(^\$\(\([\s\S]+)\)\)/,
- lookbehind: true
- },
- /^\$\(\(/
- ],
- 'number': /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee]-?\d+)?/,
- // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
- 'operator': /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
- // If there is no $ sign at the beginning highlight (( and )) as punctuation
- 'punctuation': /\(\(?|\)\)?|,|;/
- }
- },
- // [1]: Command Substitution
- {
- pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
- greedy: true,
- inside: {
- 'variable': /^\$\(|^`|\)$|`$/
- }
- },
- // [2]: Brace expansion
- {
- pattern: /\$\{[^}]+\}/,
- greedy: true,
- inside: {
- 'operator': /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
- 'punctuation': /[\[\]]/,
- 'environment': {
- pattern: RegExp("(\\{)" + envVars),
- lookbehind: true,
- alias: 'constant'
- }
- }
- },
- /\$(?:\w+|[#?*!@$])/
- ],
- // Escape sequences from echo and printf's manuals, and escaped quotes.
- '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})/
- };
- Prism.languages.bash = {
- 'shebang': {
- pattern: /^#!\s*\/.*/,
- alias: 'important'
- },
- 'comment': {
- pattern: /(^|[^"{\\$])#.*/,
- lookbehind: true
- },
- 'function-name': [
- // a) function foo {
- // b) foo() {
- // c) function foo() {
- // but not “foo {”
- {
- // a) and c)
- pattern: /(\bfunction\s+)\w+(?=(?:\s*\(?:\s*\))?\s*\{)/,
- lookbehind: true,
- alias: 'function'
- },
- {
- // b)
- pattern: /\b\w+(?=\s*\(\s*\)\s*\{)/,
- alias: 'function'
- }
- ],
- // Highlight variable names as variables in for and select beginnings.
- 'for-or-select': {
- pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
- alias: 'variable',
- lookbehind: true
- },
- // Highlight variable names as variables in the left-hand part
- // of assignments (“=” and “+=”).
- 'assign-left': {
- pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
- inside: {
- 'environment': {
- pattern: RegExp("(^|[\\s;|&]|[<>]\\()" + envVars),
- lookbehind: true,
- alias: 'constant'
- }
- },
- alias: 'variable',
- lookbehind: true
- },
- 'string': [
- // Support for Here-documents https://en.wikipedia.org/wiki/Here_document
- {
- pattern: /((?:^|[^<])<<-?\s*)(\w+?)\s*(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\2/,
- lookbehind: true,
- greedy: true,
- inside: insideString
- },
- // Here-document with quotes around the tag
- // → No expansion (so no “inside”).
- {
- pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s*(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\3/,
- lookbehind: true,
- greedy: true
- },
- // “Normal” string
- {
- pattern: /(^|[^\\](?:\\\\)*)(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\2)[^\\])*\2/,
- lookbehind: true,
- greedy: true,
- inside: insideString
- }
- ],
- 'environment': {
- pattern: RegExp("\\$?" + envVars),
- alias: 'constant'
- },
- 'variable': insideString.variable,
- 'function': {
- 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;|&])/,
- lookbehind: true
- },
- 'keyword': {
- pattern: /(^|[\s;|&]|[<>]\()(?:if|then|else|elif|fi|for|while|in|case|esac|function|select|do|done|until)(?=$|[)\s;|&])/,
- lookbehind: true
- },
- // https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
- 'builtin': {
- 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;|&])/,
- lookbehind: true,
- // Alias added to make those easier to distinguish from strings.
- alias: 'class-name'
- },
- 'boolean': {
- pattern: /(^|[\s;|&]|[<>]\()(?:true|false)(?=$|[)\s;|&])/,
- lookbehind: true
- },
- 'file-descriptor': {
- pattern: /\B&\d\b/,
- alias: 'important'
- },
- 'operator': {
- // Lots of redirections here, but not just that.
- pattern: /\d?<>|>\||\+=|==?|!=?|=~|<<[<-]?|[&\d]?>>|\d?[<>]&?|&[>&]?|\|[&|]?|<=?|>=?/,
- inside: {
- 'file-descriptor': {
- pattern: /^\d/,
- alias: 'important'
- }
- }
- },
- 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
- 'number': {
- pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
- lookbehind: true
- }
- };
- /* Patterns in command substitution. */
- var toBeCopied = [
- 'comment',
- 'function-name',
- 'for-or-select',
- 'assign-left',
- 'string',
- 'environment',
- 'function',
- 'keyword',
- 'builtin',
- 'boolean',
- 'file-descriptor',
- 'operator',
- 'punctuation',
- 'number'
- ];
- var inside = insideString.variable[1].inside;
- for(var i = 0; i < toBeCopied.length; i++) {
- inside[toBeCopied[i]] = Prism.languages.bash[toBeCopied[i]];
- }
- Prism.languages.shell = Prism.languages.bash;
- })(Prism);
- (function (Prism) {
- /**
- * Replaces all placeholders "<<n>>" of given pattern with the n-th replacement (zero based).
- *
- * Note: This is a simple text based replacement. Be careful when using backreferences!
- *
- * @param {string} pattern the given pattern.
- * @param {string[]} replacements a list of replacement which can be inserted into the given pattern.
- * @returns {string} the pattern with all placeholders replaced with their corresponding replacements.
- * @example replace(/a<<0>>a/.source, [/b+/.source]) === /a(?:b+)a/.source
- */
- function replace(pattern, replacements) {
- return pattern.replace(/<<(\d+)>>/g, function (m, index) {
- return '(?:' + replacements[+index] + ')';
- });
- }
- /**
- * @param {string} pattern
- * @param {string[]} replacements
- * @param {string} [flags]
- * @returns {RegExp}
- */
- function re(pattern, replacements, flags) {
- return RegExp(replace(pattern, replacements), flags || '');
- }
- /**
- * Creates a nested pattern where all occurrences of the string `<<self>>` are replaced with the pattern itself.
- *
- * @param {string} pattern
- * @param {number} depthLog2
- * @returns {string}
- */
- function nested(pattern, depthLog2) {
- for (var i = 0; i < depthLog2; i++) {
- pattern = pattern.replace(/<<self>>/g, function () { return '(?:' + pattern + ')'; });
- }
- return pattern.replace(/<<self>>/g, '[^\\s\\S]');
- }
- // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
- var keywordKinds = {
- // keywords which represent a return or variable type
- type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void',
- // keywords which are used to declare a type
- typeDeclaration: 'class enum interface struct',
- // contextual keywords
- // ("var" and "dynamic" are missing because they are used like types)
- contextual: 'add alias and ascending async await by descending from get global group into join let nameof not notnull on or orderby partial remove select set unmanaged value when where where',
- // all other keywords
- other: 'abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield'
- };
- // keywords
- function keywordsToPattern(words) {
- return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b';
- }
- var typeDeclarationKeywords = keywordsToPattern(keywordKinds.typeDeclaration);
- var keywords = RegExp(keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other));
- var nonTypeKeywords = keywordsToPattern(keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other);
- var nonContextualKeywords = keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.other);
- // types
- var generic = nested(/<(?:[^<>;=+\-*/%&|^]|<<self>>)*>/.source, 2); // the idea behind the other forbidden characters is to prevent false positives. Same for tupleElement.
- var nestedRound = nested(/\((?:[^()]|<<self>>)*\)/.source, 2);
- var name = /@?\b[A-Za-z_]\w*\b/.source;
- var genericName = replace(/<<0>>(?:\s*<<1>>)?/.source, [name, generic]);
- var identifier = replace(/(?!<<0>>)<<1>>(?:\s*\.\s*<<1>>)*/.source, [nonTypeKeywords, genericName]);
- var array = /\[\s*(?:,\s*)*\]/.source;
- var typeExpressionWithoutTuple = replace(/<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, [identifier, array]);
- var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [generic, nestedRound, array])
- var tuple = replace(/\(<<0>>+(?:,<<0>>+)+\)/.source, [tupleElement]);
- var typeExpression = replace(/(?:<<0>>|<<1>>)(?:\s*(?:\?\s*)?<<2>>)*(?:\s*\?)?/.source, [tuple, identifier, array]);
- var typeInside = {
- 'keyword': keywords,
- 'punctuation': /[<>()?,.:[\]]/
- };
- // strings & characters
- // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#character-literals
- // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#string-literals
- var character = /'(?:[^\r\n'\\]|\\.|\\[Uux][\da-fA-F]{1,8})'/.source; // simplified pattern
- var regularString = /"(?:\\.|[^\\"\r\n])*"/.source;
- var verbatimString = /@"(?:""|\\[\s\S]|[^\\"])*"(?!")/.source;
- Prism.languages.csharp = Prism.languages.extend('clike', {
- 'string': [
- {
- pattern: re(/(^|[^$\\])<<0>>/.source, [verbatimString]),
- lookbehind: true,
- greedy: true
- },
- {
- pattern: re(/(^|[^@$\\])<<0>>/.source, [regularString]),
- lookbehind: true,
- greedy: true
- },
- {
- pattern: RegExp(character),
- greedy: true,
- alias: 'character'
- }
- ],
- 'class-name': [
- {
- // Using static
- // using static System.Math;
- pattern: re(/(\busing\s+static\s+)<<0>>(?=\s*;)/.source, [identifier]),
- lookbehind: true,
- inside: typeInside
- },
- {
- // Using alias (type)
- // using Project = PC.MyCompany.Project;
- pattern: re(/(\busing\s+<<0>>\s*=\s*)<<1>>(?=\s*;)/.source, [name, typeExpression]),
- lookbehind: true,
- inside: typeInside
- },
- {
- // Using alias (alias)
- // using Project = PC.MyCompany.Project;
- pattern: re(/(\busing\s+)<<0>>(?=\s*=)/.source, [name]),
- lookbehind: true
- },
- {
- // Type declarations
- // class Foo<A, B>
- // interface Foo<out A, B>
- pattern: re(/(\b<<0>>\s+)<<1>>/.source, [typeDeclarationKeywords, genericName]),
- lookbehind: true,
- inside: typeInside
- },
- {
- // Single catch exception declaration
- // catch(Foo)
- // (things like catch(Foo e) is covered by variable declaration)
- pattern: re(/(\bcatch\s*\(\s*)<<0>>/.source, [identifier]),
- lookbehind: true,
- inside: typeInside
- },
- {
- // Name of the type parameter of generic constraints
- // where Foo : class
- pattern: re(/(\bwhere\s+)<<0>>/.source, [name]),
- lookbehind: true
- },
- {
- // Casts and checks via as and is.
- // as Foo<A>, is Bar<B>
- // (things like if(a is Foo b) is covered by variable declaration)
- pattern: re(/(\b(?:is(?:\s+not)?|as)\s+)<<0>>/.source, [typeExpressionWithoutTuple]),
- lookbehind: true,
- inside: typeInside
- },
- {
- // Variable, field and parameter declaration
- // (Foo bar, Bar baz, Foo[,,] bay, Foo<Bar, FooBar<Bar>> bax)
- pattern: re(/\b<<0>>(?=\s+(?!<<1>>)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [typeExpression, nonContextualKeywords, name]),
- inside: typeInside
- }
- ],
- 'keyword': keywords,
- // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#literals
- 'number': /(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:ul|lu|[dflmu])?\b/i,
- 'operator': />>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,
- 'punctuation': /\?\.?|::|[{}[\];(),.:]/
- });
- Prism.languages.insertBefore('csharp', 'number', {
- 'range': {
- pattern: /\.\./,
- alias: 'operator'
- }
- });
- Prism.languages.insertBefore('csharp', 'punctuation', {
- 'named-parameter': {
- pattern: re(/([(,]\s*)<<0>>(?=\s*:)/.source, [name]),
- lookbehind: true,
- alias: 'punctuation'
- }
- });
- Prism.languages.insertBefore('csharp', 'class-name', {
- 'namespace': {
- // namespace Foo.Bar {}
- // using Foo.Bar;
- pattern: re(/(\b(?:namespace|using)\s+)<<0>>(?:\s*\.\s*<<0>>)*(?=\s*[;{])/.source, [name]),
- lookbehind: true,
- inside: {
- 'punctuation': /\./
- }
- },
- 'type-expression': {
- // default(Foo), typeof(Foo<Bar>), sizeof(int)
- pattern: re(/(\b(?:default|typeof|sizeof)\s*\(\s*)(?:[^()\s]|\s(?!\s*\))|<<0>>)*(?=\s*\))/.source, [nestedRound]),
- lookbehind: true,
- alias: 'class-name',
- inside: typeInside
- },
- 'return-type': {
- // Foo<Bar> ForBar(); Foo IFoo.Bar() => 0
- // int this[int index] => 0; T IReadOnlyList<T>.this[int index] => this[index];
- // int Foo => 0; int Foo { get; set } = 0;
- pattern: re(/<<0>>(?=\s+(?:<<1>>\s*(?:=>|[({]|\.\s*this\s*\[)|this\s*\[))/.source, [typeExpression, identifier]),
- inside: typeInside,
- alias: 'class-name'
- },
- 'constructor-invocation': {
- // new List<Foo<Bar[]>> { }
- pattern: re(/(\bnew\s+)<<0>>(?=\s*[[({])/.source, [typeExpression]),
- lookbehind: true,
- inside: typeInside,
- alias: 'class-name'
- },
- /*'explicit-implementation': {
- // int IFoo<Foo>.Bar => 0; void IFoo<Foo<Foo>>.Foo<T>();
- pattern: replace(/\b<<0>>(?=\.<<1>>)/, className, methodOrPropertyDeclaration),
- inside: classNameInside,
- alias: 'class-name'
- },*/
- 'generic-method': {
- // foo<Bar>()
- pattern: re(/<<0>>\s*<<1>>(?=\s*\()/.source, [name, generic]),
- inside: {
- 'function': re(/^<<0>>/.source, [name]),
- 'generic': {
- pattern: RegExp(generic),
- alias: 'class-name',
- inside: typeInside
- }
- }
- },
- 'type-list': {
- // The list of types inherited or of generic constraints
- // class Foo<F> : Bar, IList<FooBar>
- // where F : Bar, IList<int>
- pattern: re(
- /\b((?:<<0>>\s+<<1>>|where\s+<<2>>)\s*:\s*)(?:<<3>>|<<4>>)(?:\s*,\s*(?:<<3>>|<<4>>))*(?=\s*(?:where|[{;]|=>|$))/.source,
- [typeDeclarationKeywords, genericName, name, typeExpression, keywords.source]
- ),
- lookbehind: true,
- inside: {
- 'keyword': keywords,
- 'class-name': {
- pattern: RegExp(typeExpression),
- greedy: true,
- inside: typeInside
- },
- 'punctuation': /,/
- }
- },
- 'preprocessor': {
- pattern: /(^\s*)#.*/m,
- lookbehind: true,
- alias: 'property',
- inside: {
- // highlight preprocessor directives as keywords
- 'directive': {
- pattern: /(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
- lookbehind: true,
- alias: 'keyword'
- }
- }
- }
- });
- // attributes
- var regularStringOrCharacter = regularString + '|' + character;
- var regularStringCharacterOrComment = replace(/\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>/.source, [regularStringOrCharacter]);
- var roundExpression = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
- // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/#attribute-targets
- var attrTarget = /\b(?:assembly|event|field|method|module|param|property|return|type)\b/.source;
- var attr = replace(/<<0>>(?:\s*\(<<1>>*\))?/.source, [identifier, roundExpression]);
- Prism.languages.insertBefore('csharp', 'class-name', {
- 'attribute': {
- // Attributes
- // [Foo], [Foo(1), Bar(2, Prop = "foo")], [return: Foo(1), Bar(2)], [assembly: Foo(Bar)]
- pattern: re(/((?:^|[^\s\w>)?])\s*\[\s*)(?:<<0>>\s*:\s*)?<<1>>(?:\s*,\s*<<1>>)*(?=\s*\])/.source, [attrTarget, attr]),
- lookbehind: true,
- greedy: true,
- inside: {
- 'target': {
- pattern: re(/^<<0>>(?=\s*:)/.source, [attrTarget]),
- alias: 'keyword'
- },
- 'attribute-arguments': {
- pattern: re(/\(<<0>>*\)/.source, [roundExpression]),
- inside: Prism.languages.csharp
- },
- 'class-name': {
- pattern: RegExp(identifier),
- inside: {
- 'punctuation': /\./
- }
- },
- 'punctuation': /[:,]/
- }
- }
- });
- // string interpolation
- var formatString = /:[^}\r\n]+/.source;
- // multi line
- var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2)
- var mInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [mInterpolationRound, formatString]);
- // single line
- var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<<self>>*\)/.source, [regularStringOrCharacter]), 2)
- var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [sInterpolationRound, formatString]);
- function createInterpolationInside(interpolation, interpolationRound) {
- return {
- 'interpolation': {
- pattern: re(/((?:^|[^{])(?:\{\{)*)<<0>>/.source, [interpolation]),
- lookbehind: true,
- inside: {
- 'format-string': {
- pattern: re(/(^\{(?:(?![}:])<<0>>)*)<<1>>(?=\}$)/.source, [interpolationRound, formatString]),
- lookbehind: true,
- inside: {
- 'punctuation': /^:/
- }
- },
- 'punctuation': /^\{|\}$/,
- 'expression': {
- pattern: /[\s\S]+/,
- alias: 'language-csharp',
- inside: Prism.languages.csharp
- }
- }
- },
- 'string': /[\s\S]+/
- };
- }
- Prism.languages.insertBefore('csharp', 'string', {
- 'interpolation-string': [
- {
- pattern: re(/(^|[^\\])(?:\$@|@\$)"(?:""|\\[\s\S]|\{\{|<<0>>|[^\\{"])*"/.source, [mInterpolation]),
- lookbehind: true,
- greedy: true,
- inside: createInterpolationInside(mInterpolation, mInterpolationRound),
- },
- {
- pattern: re(/(^|[^@\\])\$"(?:\\.|\{\{|<<0>>|[^\\"{])*"/.source, [sInterpolation]),
- lookbehind: true,
- greedy: true,
- inside: createInterpolationInside(sInterpolation, sInterpolationRound),
- }
- ]
- });
- }(Prism));
- Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp;
- Prism.languages.gcode = {
- 'comment': /;.*|\B\(.*?\)\B/,
- 'string': {
- pattern: /"(?:""|[^"])*"/,
- greedy: true
- },
- 'keyword': /\b[GM]\d+(?:\.\d+)?\b/,
- 'property': /\b[A-Z]/,
- 'checksum': {
- pattern: /\*\d+/,
- alias: 'punctuation'
- },
- // T0:0:0
- 'punctuation': /:/
- };
- // https://www.json.org/json-en.html
- Prism.languages.json = {
- 'property': {
- pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
- greedy: true
- },
- 'string': {
- pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
- greedy: true
- },
- 'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
- 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
- 'punctuation': /[{}[\],]/,
- 'operator': /:/,
- 'boolean': /\b(?:true|false)\b/,
- 'null': {
- pattern: /\bnull\b/,
- alias: 'keyword'
- }
- };
- Prism.languages.webmanifest = Prism.languages.json;
- /* FIXME :
- :extend() is not handled specifically : its highlighting is buggy.
- Mixin usage must be inside a ruleset to be highlighted.
- At-rules (e.g. import) containing interpolations are buggy.
- Detached rulesets are highlighted as at-rules.
- A comment before a mixin usage prevents the latter to be properly highlighted.
- */
- Prism.languages.less = Prism.languages.extend('css', {
- 'comment': [
- /\/\*[\s\S]*?\*\//,
- {
- pattern: /(^|[^\\])\/\/.*/,
- lookbehind: true
- }
- ],
- 'atrule': {
- pattern: /@[\w-]+?(?:\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};])*?(?=\s*\{)/,
- inside: {
- 'punctuation': /[:()]/
- }
- },
- // selectors and mixins are considered the same
- 'selector': {
- pattern: /(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};@])*?(?=\s*\{)/,
- inside: {
- // mixin parameters
- 'variable': /@+[\w-]+/
- }
- },
- 'property': /(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/i,
- 'operator': /[+\-*\/]/
- });
- Prism.languages.insertBefore('less', 'property', {
- 'variable': [
- // Variable declaration (the colon must be consumed!)
- {
- pattern: /@[\w-]+\s*:/,
- inside: {
- "punctuation": /:/
- }
- },
- // Variable usage
- /@@?[\w-]+/
- ],
- 'mixin-usage': {
- pattern: /([{;]\s*)[.#](?!\d)[\w-]+.*?(?=[(;])/,
- lookbehind: true,
- alias: 'function'
- }
- });
- Prism.languages.lua = {
- 'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
- // \z may be used to skip the following space
- 'string': {
- pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[\s\S]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
- greedy: true
- },
- 'number': /\b0x[a-f\d]+\.?[a-f\d]*(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|\.?\d*(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
- '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/,
- 'function': /(?!\d)\w+(?=\s*(?:[({]))/,
- 'operator': [
- /[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
- {
- // Match ".." but don't break "..."
- pattern: /(^|[^.])\.\.(?!\.)/,
- lookbehind: true
- }
- ],
- 'punctuation': /[\[\](){},;]|\.+|:+/
- };
- (function (Prism) {
- // Allow only one line break
- var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?!\n|\r\n?))/.source;
- /**
- * This function is intended for the creation of the bold or italic pattern.
- *
- * This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
- *
- * _Note:_ Keep in mind that this adds a capturing group.
- *
- * @param {string} pattern
- * @returns {RegExp}
- */
- function createInline(pattern) {
- pattern = pattern.replace(/<inner>/g, function () { return inner; });
- return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')');
- }
- var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
- var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|$)/.source.replace(/__/g, function () { return tableCell; });
- var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
- Prism.languages.markdown = Prism.languages.extend('markup', {});
- Prism.languages.insertBefore('markdown', 'prolog', {
- 'blockquote': {
- // > ...
- pattern: /^>(?:[\t ]*>)*/m,
- alias: 'punctuation'
- },
- 'table': {
- pattern: RegExp('^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm'),
- inside: {
- 'table-data-rows': {
- pattern: RegExp('^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$'),
- lookbehind: true,
- inside: {
- 'table-data': {
- pattern: RegExp(tableCell),
- inside: Prism.languages.markdown
- },
- 'punctuation': /\|/
- }
- },
- 'table-line': {
- pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'),
- lookbehind: true,
- inside: {
- 'punctuation': /\||:?-{3,}:?/
- }
- },
- 'table-header-row': {
- pattern: RegExp('^' + tableRow + '$'),
- inside: {
- 'table-header': {
- pattern: RegExp(tableCell),
- alias: 'important',
- inside: Prism.languages.markdown
- },
- 'punctuation': /\|/
- }
- }
- }
- },
- 'code': [
- {
- // Prefixed by 4 spaces or 1 tab and preceded by an empty line
- pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
- lookbehind: true,
- alias: 'keyword'
- },
- {
- // `code`
- // ``code``
- pattern: /``.+?``|`[^`\r\n]+`/,
- alias: 'keyword'
- },
- {
- // ```optional language
- // code block
- // ```
- pattern: /^```[\s\S]*?^```$/m,
- greedy: true,
- inside: {
- 'code-block': {
- pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
- lookbehind: true
- },
- 'code-language': {
- pattern: /^(```).+/,
- lookbehind: true
- },
- 'punctuation': /```/
- }
- }
- ],
- 'title': [
- {
- // title 1
- // =======
- // title 2
- // -------
- pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
- alias: 'important',
- inside: {
- punctuation: /==+$|--+$/
- }
- },
- {
- // # title 1
- // ###### title 6
- pattern: /(^\s*)#+.+/m,
- lookbehind: true,
- alias: 'important',
- inside: {
- punctuation: /^#+|#+$/
- }
- }
- ],
- 'hr': {
- // ***
- // ---
- // * * *
- // -----------
- pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
- lookbehind: true,
- alias: 'punctuation'
- },
- 'list': {
- // * item
- // + item
- // - item
- // 1. item
- pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
- lookbehind: true,
- alias: 'punctuation'
- },
- 'url-reference': {
- // [id]: http://example.com "Optional title"
- // [id]: http://example.com 'Optional title'
- // [id]: http://example.com (Optional title)
- // [id]: <http://example.com> "Optional title"
- pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
- inside: {
- 'variable': {
- pattern: /^(!?\[)[^\]]+/,
- lookbehind: true
- },
- 'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
- 'punctuation': /^[\[\]!:]|[<>]/
- },
- alias: 'url'
- },
- 'bold': {
- // **strong**
- // __strong__
- // allow one nested instance of italic text using the same delimiter
- pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
- lookbehind: true,
- greedy: true,
- inside: {
- 'content': {
- pattern: /(^..)[\s\S]+(?=..$)/,
- lookbehind: true,
- inside: {} // see below
- },
- 'punctuation': /\*\*|__/
- }
- },
- 'italic': {
- // *em*
- // _em_
- // allow one nested instance of bold text using the same delimiter
- pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
- lookbehind: true,
- greedy: true,
- inside: {
- 'content': {
- pattern: /(^.)[\s\S]+(?=.$)/,
- lookbehind: true,
- inside: {} // see below
- },
- 'punctuation': /[*_]/
- }
- },
- 'strike': {
- // ~~strike through~~
- // ~strike~
- pattern: createInline(/(~~?)(?:(?!~)<inner>)+?\2/.source),
- lookbehind: true,
- greedy: true,
- inside: {
- 'content': {
- pattern: /(^~~?)[\s\S]+(?=\1$)/,
- lookbehind: true,
- inside: {} // see below
- },
- 'punctuation': /~~?/
- }
- },
- 'url': {
- // [example](http://example.com "Optional title")
- // [example][id]
- // [example] [id]
- pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)| ?\[(?:(?!\])<inner>)+\])/.source),
- lookbehind: true,
- greedy: true,
- inside: {
- 'variable': {
- pattern: /(\[)[^\]]+(?=\]$)/,
- lookbehind: true
- },
- 'content': {
- pattern: /(^!?\[)[^\]]+(?=\])/,
- lookbehind: true,
- inside: {} // see below
- },
- 'string': {
- pattern: /"(?:\\.|[^"\\])*"(?=\)$)/
- }
- }
- }
- });
- ['url', 'bold', 'italic', 'strike'].forEach(function (token) {
- ['url', 'bold', 'italic', 'strike'].forEach(function (inside) {
- if (token !== inside) {
- Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
- }
- });
- });
- Prism.hooks.add('after-tokenize', function (env) {
- if (env.language !== 'markdown' && env.language !== 'md') {
- return;
- }
- function walkTokens(tokens) {
- if (!tokens || typeof tokens === 'string') {
- return;
- }
- for (var i = 0, l = tokens.length; i < l; i++) {
- var token = tokens[i];
- if (token.type !== 'code') {
- walkTokens(token.content);
- continue;
- }
- /*
- * Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
- * is optional. But the grammar is defined so that there is only one case we have to handle:
- *
- * token.content = [
- * <span class="punctuation">```</span>,
- * <span class="code-language">xxxx</span>,
- * '\n', // exactly one new lines (\r or \n or \r\n)
- * <span class="code-block">...</span>,
- * '\n', // exactly one new lines again
- * <span class="punctuation">```</span>
- * ];
- */
- var codeLang = token.content[1];
- var codeBlock = token.content[3];
- if (codeLang && codeBlock &&
- codeLang.type === 'code-language' && codeBlock.type === 'code-block' &&
- typeof codeLang.content === 'string') {
- // this might be a language that Prism does not support
- // do some replacements to support C++, C#, and F#
- var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp')
- // only use the first word
- lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase();
- var alias = 'language-' + lang;
- // add alias
- if (!codeBlock.alias) {
- codeBlock.alias = [alias];
- } else if (typeof codeBlock.alias === 'string') {
- codeBlock.alias = [codeBlock.alias, alias];
- } else {
- codeBlock.alias.push(alias);
- }
- }
- }
- }
- walkTokens(env.tokens);
- });
- Prism.hooks.add('wrap', function (env) {
- if (env.type !== 'code-block') {
- return;
- }
- var codeLang = '';
- for (var i = 0, l = env.classes.length; i < l; i++) {
- var cls = env.classes[i];
- var match = /language-(.+)/.exec(cls);
- if (match) {
- codeLang = match[1];
- break;
- }
- }
- var grammar = Prism.languages[codeLang];
- if (!grammar) {
- if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) {
- var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16);
- env.attributes['id'] = id;
- Prism.plugins.autoloader.loadLanguages(codeLang, function () {
- var ele = document.getElementById(id);
- if (ele) {
- ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
- }
- });
- }
- } else {
- // reverse Prism.util.encode
- var code = env.content.replace(/</g, '<').replace(/&/g, '&');
- env.content = Prism.highlight(code, grammar, codeLang);
- }
- });
- Prism.languages.md = Prism.languages.markdown;
- }(Prism));
- (function (Prism) {
- /**
- * Returns the placeholder for the given language id and index.
- *
- * @param {string} language
- * @param {string|number} index
- * @returns {string}
- */
- function getPlaceholder(language, index) {
- return '___' + language.toUpperCase() + index + '___';
- }
- Object.defineProperties(Prism.languages['markup-templating'] = {}, {
- buildPlaceholders: {
- /**
- * Tokenize all inline templating expressions matching `placeholderPattern`.
- *
- * If `replaceFilter` is provided, only matches of `placeholderPattern` for which `replaceFilter` returns
- * `true` will be replaced.
- *
- * @param {object} env The environment of the `before-tokenize` hook.
- * @param {string} language The language id.
- * @param {RegExp} placeholderPattern The matches of this pattern will be replaced by placeholders.
- * @param {(match: string) => boolean} [replaceFilter]
- */
- value: function (env, language, placeholderPattern, replaceFilter) {
- if (env.language !== language) {
- return;
- }
- var tokenStack = env.tokenStack = [];
- env.code = env.code.replace(placeholderPattern, function (match) {
- if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
- return match;
- }
- var i = tokenStack.length;
- var placeholder;
- // Check for existing strings
- while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1)
- ++i;
- // Create a sparse array
- tokenStack[i] = match;
- return placeholder;
- });
- // Switch the grammar to markup
- env.grammar = Prism.languages.markup;
- }
- },
- tokenizePlaceholders: {
- /**
- * Replace placeholders with proper tokens after tokenizing.
- *
- * @param {object} env The environment of the `after-tokenize` hook.
- * @param {string} language The language id.
- */
- value: function (env, language) {
- if (env.language !== language || !env.tokenStack) {
- return;
- }
- // Switch the grammar back
- env.grammar = Prism.languages[language];
- var j = 0;
- var keys = Object.keys(env.tokenStack);
- function walkTokens(tokens) {
- for (var i = 0; i < tokens.length; i++) {
- // all placeholders are replaced already
- if (j >= keys.length) {
- break;
- }
- var token = tokens[i];
- if (typeof token === 'string' || (token.content && typeof token.content === 'string')) {
- var k = keys[j];
- var t = env.tokenStack[k];
- var s = typeof token === 'string' ? token : token.content;
- var placeholder = getPlaceholder(language, k);
- var index = s.indexOf(placeholder);
- if (index > -1) {
- ++j;
- var before = s.substring(0, index);
- var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
- var after = s.substring(index + placeholder.length);
- var replacement = [];
- if (before) {
- replacement.push.apply(replacement, walkTokens([before]));
- }
- replacement.push(middle);
- if (after) {
- replacement.push.apply(replacement, walkTokens([after]));
- }
- if (typeof token === 'string') {
- tokens.splice.apply(tokens, [i, 1].concat(replacement));
- } else {
- token.content = replacement;
- }
- }
- } else if (token.content /* && typeof token.content !== 'string' */) {
- walkTokens(token.content);
- }
- }
- return tokens;
- }
- walkTokens(env.tokens);
- }
- }
- });
- }(Prism));
- /**
- * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
- * Modified by Miles Johnson: http://milesj.me
- *
- * Supports the following:
- * - Extends clike syntax
- * - Support for PHP 5.3+ (namespaces, traits, generators, etc)
- * - Smarter constant and function matching
- *
- * Adds the following new token classes:
- * constant, delimiter, variable, function, package
- */
- (function (Prism) {
- Prism.languages.php = Prism.languages.extend('clike', {
- 'keyword': /\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|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,
- 'boolean': {
- pattern: /\b(?:false|true)\b/i,
- alias: 'constant'
- },
- 'constant': [
- /\b[A-Z_][A-Z0-9_]*\b/,
- /\b(?:null)\b/i,
- ],
- 'comment': {
- pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
- lookbehind: true
- }
- });
- Prism.languages.insertBefore('php', 'string', {
- 'shell-comment': {
- pattern: /(^|[^\\])#.*/,
- lookbehind: true,
- alias: 'comment'
- }
- });
- Prism.languages.insertBefore('php', 'comment', {
- 'delimiter': {
- pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
- alias: 'important'
- }
- });
- Prism.languages.insertBefore('php', 'keyword', {
- 'variable': /\$+(?:\w+\b|(?={))/i,
- 'package': {
- pattern: /(\\|namespace\s+|use\s+)[\w\\]+/,
- lookbehind: true,
- inside: {
- punctuation: /\\/
- }
- }
- });
- // Must be defined after the function pattern
- Prism.languages.insertBefore('php', 'operator', {
- 'property': {
- pattern: /(->)[\w]+/,
- lookbehind: true
- }
- });
- var string_interpolation = {
- pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,
- lookbehind: true,
- inside: Prism.languages.php
- };
- Prism.languages.insertBefore('php', 'string', {
- 'nowdoc-string': {
- pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
- greedy: true,
- alias: 'string',
- inside: {
- 'delimiter': {
- pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
- alias: 'symbol',
- inside: {
- 'punctuation': /^<<<'?|[';]$/
- }
- }
- }
- },
- 'heredoc-string': {
- pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
- greedy: true,
- alias: 'string',
- inside: {
- 'delimiter': {
- pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
- alias: 'symbol',
- inside: {
- 'punctuation': /^<<<"?|[";]$/
- }
- },
- 'interpolation': string_interpolation // See below
- }
- },
- 'single-quoted-string': {
- pattern: /'(?:\\[\s\S]|[^\\'])*'/,
- greedy: true,
- alias: 'string'
- },
- 'double-quoted-string': {
- pattern: /"(?:\\[\s\S]|[^\\"])*"/,
- greedy: true,
- alias: 'string',
- inside: {
- 'interpolation': string_interpolation // See below
- }
- }
- });
- // The different types of PHP strings "replace" the C-like standard string
- delete Prism.languages.php['string'];
- Prism.hooks.add('before-tokenize', function(env) {
- if (!/<\?/.test(env.code)) {
- return;
- }
- var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig;
- Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
- });
- Prism.hooks.add('after-tokenize', function(env) {
- Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
- });
- }(Prism));
- Prism.languages.processing = Prism.languages.extend('clike', {
- 'keyword': /\b(?:break|catch|case|class|continue|default|else|extends|final|for|if|implements|import|new|null|private|public|return|static|super|switch|this|try|void|while)\b/,
- 'operator': /<[<=]?|>[>=]?|&&?|\|\|?|[%?]|[!=+\-*\/]=?/
- });
- Prism.languages.insertBefore('processing', 'number', {
- // Special case: XML is a type
- 'constant': /\b(?!XML\b)[A-Z][A-Z\d_]+\b/,
- 'type': {
- pattern: /\b(?:boolean|byte|char|color|double|float|int|XML|[A-Z]\w*)\b/,
- alias: 'variable'
- }
- });
- // Spaces are allowed between function name and parenthesis
- Prism.languages.processing['function'].pattern = /\w+(?=\s*\()/;
- // Class-names is not styled by default
- Prism.languages.processing['class-name'].alias = 'variable';
- Prism.languages.python = {
- 'comment': {
- pattern: /(^|[^\\])#.*/,
- lookbehind: true
- },
- 'string-interpolation': {
- pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
- greedy: true,
- inside: {
- 'interpolation': {
- // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
- pattern: /((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,
- lookbehind: true,
- inside: {
- 'format-spec': {
- pattern: /(:)[^:(){}]+(?=}$)/,
- lookbehind: true
- },
- 'conversion-option': {
- pattern: /![sra](?=[:}]$)/,
- alias: 'punctuation'
- },
- rest: null
- }
- },
- 'string': /[\s\S]+/
- }
- },
- 'triple-quoted-string': {
- pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,
- greedy: true,
- alias: 'string'
- },
- 'string': {
- pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
- greedy: true
- },
- 'function': {
- pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
- lookbehind: true
- },
- 'class-name': {
- pattern: /(\bclass\s+)\w+/i,
- lookbehind: true
- },
- 'decorator': {
- pattern: /(^\s*)@\w+(?:\.\w+)*/im,
- lookbehind: true,
- alias: ['annotation', 'punctuation'],
- inside: {
- 'punctuation': /\./
- }
- },
- '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/,
- '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/,
- 'boolean': /\b(?:True|False|None)\b/,
- 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
- 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
- 'punctuation': /[{}[\];(),.:]/
- };
- Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
- Prism.languages.py = Prism.languages.python;
- (function (Prism) {
- Prism.languages.typescript = Prism.languages.extend('javascript', {
- 'class-name': {
- pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
- lookbehind: true,
- greedy: true,
- inside: null // see below
- },
- // From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
- '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/,
- 'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
- });
- // doesn't work with TS because TS is too complex
- delete Prism.languages.typescript['parameter'];
- // a version of typescript specifically for highlighting types
- var typeInside = Prism.languages.extend('typescript', {});
- delete typeInside['class-name'];
- Prism.languages.typescript['class-name'].inside = typeInside;
- Prism.languages.insertBefore('typescript', 'function', {
- 'generic-function': {
- // e.g. foo<T extends "bar" | "baz">( ...
- pattern: /#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
- greedy: true,
- inside: {
- 'function': /^#?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*/,
- 'generic': {
- pattern: /<[\s\S]+/, // everything after the first <
- alias: 'class-name',
- inside: typeInside
- }
- }
- }
- });
- Prism.languages.ts = Prism.languages.typescript;
- }(Prism));
- (function (Prism) {
- var specialEscape = {
- pattern: /\\[\\(){}[\]^$+*?|.]/,
- alias: 'escape'
- };
- var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|c[a-zA-Z]|0[0-7]{0,2}|[123][0-7]{2}|.)/;
- var charClass = {
- pattern: /\.|\\[wsd]|\\p{[^{}]+}/i,
- alias: 'class-name'
- };
- var charClassWithoutDot = {
- pattern: /\\[wsd]|\\p{[^{}]+}/i,
- alias: 'class-name'
- };
- var rangeChar = '(?:[^\\\\-]|' + escape.source + ')';
- var range = RegExp(rangeChar + '-' + rangeChar);
- // the name of a capturing group
- var groupName = {
- pattern: /(<|')[^<>']+(?=[>']$)/,
- lookbehind: true,
- alias: 'variable'
- };
- Prism.languages.regex = {
- 'charset': {
- pattern: /((?:^|[^\\])(?:\\\\)*)\[(?:[^\\\]]|\\[\s\S])*\]/,
- lookbehind: true,
- inside: {
- 'charset-negation': {
- pattern: /(^\[)\^/,
- lookbehind: true,
- alias: 'operator'
- },
- 'charset-punctuation': {
- pattern: /^\[|\]$/,
- alias: 'punctuation'
- },
- 'range': {
- pattern: range,
- inside: {
- 'escape': escape,
- 'range-punctuation': {
- pattern: /-/,
- alias: 'operator'
- }
- }
- },
- 'special-escape': specialEscape,
- 'charclass': charClassWithoutDot,
- 'escape': escape
- }
- },
- 'special-escape': specialEscape,
- 'charclass': charClass,
- 'backreference': [
- {
- // a backreference which is not an octal escape
- pattern: /\\(?![123][0-7]{2})[1-9]/,
- alias: 'keyword'
- },
- {
- pattern: /\\k<[^<>']+>/,
- alias: 'keyword',
- inside: {
- 'group-name': groupName
- }
- }
- ],
- 'anchor': {
- pattern: /[$^]|\\[ABbGZz]/,
- alias: 'function'
- },
- 'escape': escape,
- 'group': [
- {
- // https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html
- // https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference?view=netframework-4.7.2#grouping-constructs
- // (), (?<name>), (?'name'), (?>), (?:), (?=), (?!), (?<=), (?<!), (?is-m), (?i-m:)
- pattern: /\((?:\?(?:<[^<>']+>|'[^<>']+'|[>:]|<?[=!]|[idmnsuxU]+(?:-[idmnsuxU]+)?:?))?/,
- alias: 'punctuation',
- inside: {
- 'group-name': groupName
- }
- },
- {
- pattern: /\)/,
- alias: 'punctuation'
- }
- ],
- 'quantifier': {
- pattern: /(?:[+*?]|\{(?:\d+,?\d*)\})[?+]?/,
- alias: 'number'
- },
- 'alternation': {
- pattern: /\|/,
- alias: 'keyword'
- }
- };
- [
- 'actionscript',
- 'coffescript',
- 'flow',
- 'javascript',
- 'typescript',
- 'vala'
- ].forEach(function (lang) {
- var grammar = Prism.languages[lang];
- if (grammar) {
- grammar['regex'].inside = {
- 'language-regex': {
- pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/i,
- lookbehind: true,
- inside: Prism.languages.regex
- },
- 'regex-flags': /[a-z]+$/i,
- 'regex-delimiter': /^\/|\/$/,
- };
- }
- });
- }(Prism))
- ;
- /**
- * Original by Samuel Flores
- *
- * Adds the following new token classes:
- * constant, builtin, variable, symbol, regex
- */
- (function (Prism) {
- Prism.languages.ruby = Prism.languages.extend('clike', {
- 'comment': [
- /#.*/,
- {
- pattern: /^=begin\s[\s\S]*?^=end/m,
- greedy: true
- }
- ],
- 'class-name': {
- pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
- lookbehind: true,
- inside: {
- 'punctuation': /[.\\]/
- }
- },
- '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/
- });
- var interpolation = {
- pattern: /#\{[^}]+\}/,
- inside: {
- 'delimiter': {
- pattern: /^#\{|\}$/,
- alias: 'tag'
- },
- rest: Prism.languages.ruby
- }
- };
- delete Prism.languages.ruby.function;
- Prism.languages.insertBefore('ruby', 'keyword', {
- 'regex': [
- {
- pattern: RegExp(/%r/.source + '(?:' + [
- /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1[gim]{0,3}/.source,
- /\((?:[^()\\]|\\[\s\S])*\)[gim]{0,3}/.source,
- // Here we need to specifically allow interpolation
- /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}[gim]{0,3}/.source,
- /\[(?:[^\[\]\\]|\\[\s\S])*\][gim]{0,3}/.source,
- /<(?:[^<>\\]|\\[\s\S])*>[gim]{0,3}/.source
- ].join('|') + ')'),
- greedy: true,
- inside: {
- 'interpolation': interpolation
- }
- },
- {
- pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[gim]{0,3}(?=\s*(?:$|[\r\n,.;})]))/,
- lookbehind: true,
- greedy: true
- }
- ],
- 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
- 'symbol': {
- pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
- lookbehind: true
- },
- 'method-definition': {
- pattern: /(\bdef\s+)[\w.]+/,
- lookbehind: true,
- inside: {
- 'function': /\w+$/,
- rest: Prism.languages.ruby
- }
- }
- });
- Prism.languages.insertBefore('ruby', 'number', {
- '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/,
- 'constant': /\b[A-Z]\w*(?:[?!]|\b)/
- });
- Prism.languages.ruby.string = [
- {
- pattern: RegExp(/%[qQiIwWxs]?/.source + '(?:' + [
- /([^a-zA-Z0-9\s{(\[<])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
- /\((?:[^()\\]|\\[\s\S])*\)/.source,
- // Here we need to specifically allow interpolation
- /\{(?:[^#{}\\]|#(?:\{[^}]+\})?|\\[\s\S])*\}/.source,
- /\[(?:[^\[\]\\]|\\[\s\S])*\]/.source,
- /<(?:[^<>\\]|\\[\s\S])*>/.source
- ].join('|') + ')'),
- greedy: true,
- inside: {
- 'interpolation': interpolation
- }
- },
- {
- pattern: /("|')(?:#\{[^}]+\}|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
- greedy: true,
- inside: {
- 'interpolation': interpolation
- }
- }
- ];
- Prism.languages.rb = Prism.languages.ruby;
- }(Prism));
- (function(Prism) {
- Prism.languages.sass = Prism.languages.extend('css', {
- // Sass comments don't need to be closed, only indented
- 'comment': {
- pattern: /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t]+.+)*/m,
- lookbehind: true
- }
- });
- Prism.languages.insertBefore('sass', 'atrule', {
- // We want to consume the whole line
- 'atrule-line': {
- // Includes support for = and + shortcuts
- pattern: /^(?:[ \t]*)[@+=].+/m,
- inside: {
- 'atrule': /(?:@[\w-]+|[+=])/m
- }
- }
- });
- delete Prism.languages.sass.atrule;
- var variable = /\$[-\w]+|#\{\$[-\w]+\}/;
- var operator = [
- /[+*\/%]|[=!]=|<=?|>=?|\b(?:and|or|not)\b/,
- {
- pattern: /(\s+)-(?=\s)/,
- lookbehind: true
- }
- ];
- Prism.languages.insertBefore('sass', 'property', {
- // We want to consume the whole line
- 'variable-line': {
- pattern: /^[ \t]*\$.+/m,
- inside: {
- 'punctuation': /:/,
- 'variable': variable,
- 'operator': operator
- }
- },
- // We want to consume the whole line
- 'property-line': {
- pattern: /^[ \t]*(?:[^:\s]+ *:.*|:[^:\s]+.*)/m,
- inside: {
- 'property': [
- /[^:\s]+(?=\s*:)/,
- {
- pattern: /(:)[^:\s]+/,
- lookbehind: true
- }
- ],
- 'punctuation': /:/,
- 'variable': variable,
- 'operator': operator,
- 'important': Prism.languages.sass.important
- }
- }
- });
- delete Prism.languages.sass.property;
- delete Prism.languages.sass.important;
- // Now that whole lines for other patterns are consumed,
- // what's left should be selectors
- Prism.languages.insertBefore('sass', 'punctuation', {
- 'selector': {
- pattern: /([ \t]*)\S(?:,?[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,?[^,\r\n]+)*)*/,
- lookbehind: true
- }
- });
- }(Prism));
- // issues: nested multiline comments
- Prism.languages.swift = Prism.languages.extend('clike', {
- 'string': {
- pattern: /("|')(?:\\(?:\((?:[^()]|\([^)]+\))+\)|\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
- greedy: true,
- inside: {
- 'interpolation': {
- pattern: /\\\((?:[^()]|\([^)]+\))+\)/,
- inside: {
- delimiter: {
- pattern: /^\\\(|\)$/,
- alias: 'variable'
- }
- // See rest below
- }
- }
- }
- },
- 'keyword': /\b(?:as|associativity|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic(?:Type)?|else|enum|extension|fallthrough|final|for|func|get|guard|if|import|in|infix|init|inout|internal|is|lazy|left|let|mutating|new|none|nonmutating|operator|optional|override|postfix|precedence|prefix|private|protocol|public|repeat|required|rethrows|return|right|safe|self|Self|set|static|struct|subscript|super|switch|throws?|try|Type|typealias|unowned|unsafe|var|weak|where|while|willSet|__(?:COLUMN__|FILE__|FUNCTION__|LINE__))\b/,
- 'number': /\b(?:[\d_]+(?:\.[\de_]+)?|0x[a-f0-9_]+(?:\.[a-f0-9p_]+)?|0b[01_]+|0o[0-7_]+)\b/i,
- 'constant': /\b(?:nil|[A-Z_]{2,}|k[A-Z][A-Za-z_]+)\b/,
- 'atrule': /@\b(?:IB(?:Outlet|Designable|Action|Inspectable)|class_protocol|exported|noreturn|NS(?:Copying|Managed)|objc|UIApplicationMain|auto_closure)\b/,
- 'builtin': /\b(?:[A-Z]\S+|abs|advance|alignof(?:Value)?|assert|contains|count(?:Elements)?|debugPrint(?:ln)?|distance|drop(?:First|Last)|dump|enumerate|equal|filter|find|first|getVaList|indices|isEmpty|join|last|lexicographicalCompare|map|max(?:Element)?|min(?:Element)?|numericCast|overlaps|partition|print(?:ln)?|reduce|reflect|reverse|sizeof(?:Value)?|sort(?:ed)?|split|startsWith|stride(?:of(?:Value)?)?|suffix|swap|toDebugString|toString|transcode|underestimateCount|unsafeBitCast|with(?:ExtendedLifetime|Unsafe(?:MutablePointers?|Pointers?)|VaList))\b/
- });
- Prism.languages.swift['string'].inside['interpolation'].inside.rest = Prism.languages.swift;
- Prism.languages.unrealscript = {
- 'comment': /\/\/.*|\/\*[\s\S]*?\*\//,
- 'string': {
- pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
- greedy: true
- },
- 'category': {
- pattern: /(\b(?:(?:autoexpand|hide|show)categories|var)\s*\()[^()]+(?=\))/,
- lookbehind: true,
- greedy: true,
- alias: 'property'
- },
- 'metadata': {
- pattern: /(\w\s*)<\s*\w+\s*=[^<>|=\r\n]+(?:\|\s*\w+\s*=[^<>|=\r\n]+)*>/,
- lookbehind: true,
- greedy: true,
- inside: {
- 'property': /\w+(?=\s*=)/,
- 'operator': /=/,
- 'punctuation': /[<>|]/
- }
- },
- 'macro': {
- pattern: /`\w+/,
- alias: 'property'
- },
- 'class-name': {
- pattern: /(\b(?:class|enum|extends|interface|state(?:\(\))?|struct|within)\s+)\w+/,
- lookbehind: true
- },
- 'keyword': /\b(?:abstract|actor|array|auto|autoexpandcategories|bool|break|byte|case|class|classgroup|client|coerce|collapsecategories|config|const|continue|default|defaultproperties|delegate|dependson|deprecated|do|dontcollapsecategories|editconst|editinlinenew|else|enum|event|exec|export|extends|final|float|for|forcescriptorder|foreach|function|goto|guid|hidecategories|hidedropdown|if|ignores|implements|inherits|input|int|interface|iterator|latent|local|material|name|native|nativereplication|noexport|nontransient|noteditinlinenew|notplaceable|operator|optional|out|pawn|perobjectconfig|perobjectlocalized|placeable|postoperator|preoperator|private|protected|reliable|replication|return|server|showcategories|simulated|singular|state|static|string|struct|structdefault|structdefaultproperties|switch|texture|transient|travel|unreliable|until|var|vector|while|within)\b/,
- 'function': /[a-z_]\w*(?=\s*\()/i,
- 'boolean': /\b(?:false|true)\b/,
- 'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
- // https://docs.unrealengine.com/udk/Three/UnrealScriptExpressions.html
- 'operator': />>|<<|--|\+\+|\*\*|[-+*/~!=<>$@]=?|&&?|\|\|?|\^\^?|[?:%]|\b(?:Cross|Dot|ClockwiseFrom)\b/,
- 'punctuation': /[()[\]{};,.]/
- };
- Prism.languages.uc = Prism.languages.uscript = Prism.languages.unrealscript;
- (function (Prism) {
- /**
- * If the given language is present, it will insert the given doc comment grammar token into it.
- *
- * @param {string} lang
- * @param {any} docComment
- */
- function insertDocComment(lang, docComment) {
- if (Prism.languages[lang]) {
- Prism.languages.insertBefore(lang, 'comment', {
- 'doc-comment': docComment
- });
- }
- }
- var tag = Prism.languages.markup.tag;
- var slashDocComment = {
- pattern: /\/\/\/.*/,
- greedy: true,
- alias: 'comment',
- inside: {
- 'tag': tag
- }
- };
- var tickDocComment = {
- pattern: /'''.*/,
- greedy: true,
- alias: 'comment',
- inside: {
- 'tag': tag
- }
- };
- insertDocComment('csharp', slashDocComment);
- insertDocComment('fsharp', slashDocComment);
- insertDocComment('vbnet', tickDocComment);
- }(Prism));
- (function (Prism) {
- // https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
- // https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
- var anchorOrAlias = /[*&][^\s[\]{},]+/;
- // https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
- var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
- // https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
- var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
- + anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
- /**
- *
- * @param {string} value
- * @param {string} [flags]
- * @returns {RegExp}
- */
- function createValuePattern(value, flags) {
- flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
- var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|]|}|\s*#))/.source
- .replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
- return RegExp(pattern, flags)
- }
- Prism.languages.yaml = {
- 'scalar': {
- pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)[^\r\n]+(?:\2[^\r\n]+)*)/.source
- .replace(/<<prop>>/g, function () { return properties; })),
- lookbehind: true,
- alias: 'string'
- },
- 'comment': /#.*/,
- 'key': {
- pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)[^\r\n{[\]},#\s]+?(?=\s*:\s)/.source
- .replace(/<<prop>>/g, function () { return properties; })),
- lookbehind: true,
- alias: 'atrule'
- },
- 'directive': {
- pattern: /(^[ \t]*)%.+/m,
- lookbehind: true,
- alias: 'important'
- },
- 'datetime': {
- 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),
- lookbehind: true,
- alias: 'number'
- },
- 'boolean': {
- pattern: createValuePattern(/true|false/.source, 'i'),
- lookbehind: true,
- alias: 'important'
- },
- 'null': {
- pattern: createValuePattern(/null|~/.source, 'i'),
- lookbehind: true,
- alias: 'important'
- },
- 'string': {
- // \2 because of the lookbehind group
- pattern: createValuePattern(/("|')(?:(?!\2)[^\\\r\n]|\\.)*\2/.source),
- lookbehind: true,
- greedy: true
- },
- 'number': {
- pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+\.?\d*|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
- lookbehind: true
- },
- 'tag': tag,
- 'important': anchorOrAlias,
- 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
- };
- Prism.languages.yml = Prism.languages.yaml;
- }(Prism));
|