discourse/public/javascripts/highlight.pack.js

1 line
35 KiB
JavaScript
Raw Normal View History

var hljs=new function(){function k(w){return w.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;")}function u(w){return w.nodeName.toLowerCase()}function i(x,y){var w=x&&x.exec(y);return w&&w.index==0}function s(x){var w=(x.className+" "+(x.parentNode?x.parentNode.className:"")).split(/\s+/);w=w.map(function(y){return y.replace(/^lang(uage)?-/,"")});return w.filter(function(y){return j(y)||/no(-?)highlight/.test(y)})[0]}function p(y,z){var w={};for(var x in y){w[x]=y[x]}if(z){for(var x in z){w[x]=z[x]}}return w}function v(y){var w=[];(function x(z,A){for(var B=z.firstChild;B;B=B.nextSibling){if(B.nodeType==3){A+=B.nodeValue.length}else{if(B.nodeType==1){w.push({event:"start",offset:A,node:B});A=x(B,A);if(!u(B).match(/br|hr|img|input/)){w.push({event:"stop",offset:A,node:B})}}}}return A})(y,0);return w}function r(x,z,D){var y=0;var G="";var A=[];function C(){if(!x.length||!z.length){return x.length?x:z}if(x[0].offset!=z[0].offset){return(x[0].offset<z[0].offset)?x:z}return z[0].event=="start"?x:z}function B(I){function H(J){return" "+J.nodeName+'="'+k(J.value)+'"'}G+="<"+u(I)+Array.prototype.map.call(I.attributes,H).join("")+">"}function F(H){G+="</"+u(H)+">"}function w(H){(H.event=="start"?B:F)(H.node)}while(x.length||z.length){var E=C();G+=k(D.substr(y,E[0].offset-y));y=E[0].offset;if(E==x){A.reverse().forEach(F);do{w(E.splice(0,1)[0]);E=C()}while(E==x&&E.length&&E[0].offset==y);A.reverse().forEach(B)}else{if(E[0].event=="start"){A.push(E[0].node)}else{A.pop()}w(E.splice(0,1)[0])}}return G+k(D.substr(y))}function n(z){function w(A){return(A&&A.source)||A}function x(B,A){return RegExp(w(B),"m"+(z.cI?"i":"")+(A?"g":""))}function y(E,D){if(E.compiled){return}E.compiled=true;E.k=E.k||E.bK;if(E.k){var A={};var F=function(H,G){if(z.cI){G=G.toLowerCase()}G.split(" ").forEach(function(I){var J=I.split("|");A[J[0]]=[H,J[1]?Number(J[1]):1]})};if(typeof E.k=="string"){F("keyword",E.k)}else{Object.keys(E.k).forEach(function(G){F(G,E.k[G])})}E.k=A}E.lR=x(E.l||/\b[A-Za-z0-9_]+\b/,true);if(D){if(E.bK){E.b="\\b("+E.bK.split(" ").join("|")+")\\b"}if(!E.b){E.b=/\B|\b/}E.bR=x(E.b);if(!E.e&&!E.eW){E.e=/\B|\b/}if(E.e){E.eR=x(E.e)}E.tE=w(E.e)||"";if(E.eW&&D.tE){E.tE+=(E.e?"|":"")+D.tE}}if(E.i){E.iR=x(E.i)}if(E.r===undefined){E.r=1}if(!E.c){E.c=[]}var C=[];E.c.forEach(function(G){if(G.v){G.v.forEach(function(H){C.push(p(G,H))})}else{C.push(G=="self"?E:G)}});E.c=C;E.c.forEach(function(G){y(G,E)});if(E.starts){y(E.starts,D)}var B=E.c.map(function(G){return G.bK?"\\.?("+G.b+")\\.?":G.b}).concat([E.tE,E.i]).map(w).filter(Boolean);E.t=B.length?x(B.join("|"),true):{exec:function(G){return null}}}y(z)}function c(U,N,L,T){function w(W,X){for(var V=0;V<X.c.length;V++){if(i(X.c[V].bR,W)){return X.c[V]}}}function A(W,V){if(i(W.eR,V)){return W}if(W.eW){return A(W.parent,V)}}function B(V,W){return !L&&i(W.iR,V)}function F(X,V){var W=O.cI?V[0].toLowerCase():V[0];return X.k.hasOwnProperty(W)&&X.k[W]}function x(ab,Z,Y,X){var V=X?"":b.classPrefix,W='<span class="'+V,aa=Y?"":"</span>";W+=ab+'">';return W+Z+aa}function P(){if(!K.k){return k(D)}var V="";var Y=0;K.lR.lastIndex=0;var W=K.lR.exec(D);while(W){V+=k(D.substr(Y,W.index-Y));var X=F(K,W);if(X){J+=X[1];V+=x(X[0],k(W[0]))}else{V+=k(W[0])}Y=K.lR.lastIndex;W=K.lR.exec(D)}return V+k(D.substr(Y))}function G(){if(K.sL&&!f[K.sL]){return k(D)}var V=K.sL?c(K.sL,D,true,I[K.sL]):g(D);if(K.r>0){J+=V.r}if(K.subLanguageMode=="continuous"){I[K.sL]=V.top}return x(V.language,V.value,false,true)}function S(){return K.sL!==undefined?G():P()}function R(X,W){var V=X.cN?x(X.cN,"",true):"";if(X.rB){E+=V;D=""}else{if(X.eB){E+=k(W)+V;D=""}else{E+=V;D=W}}K=Object.create(X,{parent:{value:K}})}function H(V,Z){D+=V;if(Z===undefined){E+=S();return 0}var X=w(Z,K);if(X){E+=S();R(X,Z);return X.rB?0:Z.length}var Y=A(K,Z);if(Y){var W=K;if(!(W.rE||W.eE)){D+=Z}E+=S();do{if(K.cN){E+="</span>"}J+=K.r;K=K.parent}while(K!=Y.parent);if(W.eE){E+=k(Z)}D="";if(Y.starts){R(Y.starts,"")}return W.rE?0:Z.length}if(B(Z,K)){throw new Error('Illegal lexeme "'+Z+'" for mode "'+(K.cN||"<unnamed>")+'"')}D+=Z;return Z.length||1}var O=j(U);if(!O