MCPcopy Create free account
hub / github.com/danvk/webdiff / T

Function T

webdiff/static/js/highlight.min.js:187–250  ·  view source on GitHub ↗
(e,t,r,i)

Source from the content-addressed store, hash-verified

185r=e,n=t),void 0===a&&(a=!0);const i={code:n,language:r};I("before:highlight",i)
186;const s=i.result?i.result:T(i.language,i.code,a)
187;return s.code=i.code,I("after:highlight",s),s}function T(e,t,r,i){
188const l=Object.create(null);function _(){if(!h.keywords)return void A.addText(v)
189;let e=0;h.keywordPatternRe.lastIndex=0;let t=h.keywordPatternRe.exec(v),a=""
190;for(;t;){a+=v.substring(e,t.index)
191;const r=R.case_insensitive?t[0].toLowerCase():t[0],i=(n=r,h.keywords[n]);if(i){
192const[e,n]=i
193;if(A.addText(a),a="",l[r]=(l[r]||0)+1,l[r]<=7&&(y+=n),e.startsWith("_"))a+=t[0];else{
194const a=R.classNameAliases[e]||e;A.addKeyword(t[0],a)}}else a+=t[0]
195;e=h.keywordPatternRe.lastIndex,t=h.keywordPatternRe.exec(v)}var n
196;a+=v.substring(e),A.addText(a)}function d(){null!=h.subLanguage?(()=>{
197if(""===v)return;let e=null;if("string"==typeof h.subLanguage){
198if(!n[h.subLanguage])return void A.addText(v)
199;e=T(h.subLanguage,v,!0,I[h.subLanguage]),I[h.subLanguage]=e._top
200}else e=b(v,h.subLanguage.length?h.subLanguage:null)
201;h.relevance>0&&(y+=e.relevance),A.addSublanguage(e._emitter,e.language)
202})():_(),v=""}function m(e,t){let a=1;const n=t.length-1;for(;a<=n;){
203if(!e._emit[a]){a++;continue}const n=R.classNameAliases[e[a]]||e[a],r=t[a]
204;n?A.addKeyword(r,n):(v=r,_(),v=""),a++}}function p(e,t){
205return e.scope&&"string"==typeof e.scope&&A.openNode(R.classNameAliases[e.scope]||e.scope),
206e.beginScope&&(e.beginScope._wrap?(A.addKeyword(v,R.classNameAliases[e.beginScope._wrap]||e.beginScope._wrap),
207v=""):e.beginScope._multi&&(m(e.beginScope,t),v="")),h=Object.create(e,{parent:{
208value:h}}),h}function u(e,t,n){let r=((e,t)=>{const a=e&&e.exec(t)
209;return a&&0===a.index})(e.endRe,n);if(r){if(e["on:end"]){const n=new a(e)
210;e["on:end"](t,n),n.isMatchIgnored&&(r=!1)}if(r){
211for(;e.endsParent&&e.parent;)e=e.parent;return e}}
212if(e.endsWithParent)return u(e.parent,t,n)}function E(e){
213return 0===h.matcher.regexIndex?(v+=e[0],1):(L=!0,0)}function g(e){
214const a=e[0],n=t.substring(e.index),r=u(h,e,n);if(!r)return te;const i=h
215;h.endScope&&h.endScope._wrap?(d(),
216A.addKeyword(a,h.endScope._wrap)):h.endScope&&h.endScope._multi?(d(),
217m(h.endScope,e)):i.skip?v+=a:(i.returnEnd||i.excludeEnd||(v+=a),
218d(),i.excludeEnd&&(v=a));do{
219h.scope&&A.closeNode(),h.skip||h.subLanguage||(y+=h.relevance),h=h.parent
220}while(h!==r.parent);return r.starts&&p(r.starts,e),i.returnEnd?0:a.length}
221let S={};function C(n,i){const o=i&&i[0];if(v+=n,null==o)return d(),0
222;if("begin"===S.type&&"end"===i.type&&S.index===i.index&&""===o){
223if(v+=t.slice(i.index,i.index+1),!s){const t=Error(`0 width match regex (${e})`)
224;throw t.languageName=e,t.badRule=S.rule,t}return 1}
225if(S=i,"begin"===i.type)return(e=>{
226const t=e[0],n=e.rule,r=new a(n),i=[n.__beforeBegin,n["on:begin"]]
227;for(const a of i)if(a&&(a(e,r),r.isMatchIgnored))return E(t)
228;return n.skip?v+=t:(n.excludeBegin&&(v+=t),
229d(),n.returnBegin||n.excludeBegin||(v=t)),p(n,e),n.returnBegin?0:t.length})(i)
230;if("illegal"===i.type&&!r){
231const e=Error('Illegal lexeme "'+o+'" for mode "'+(h.scope||"<unnamed>")+'"')
232;throw e.mode=h,e}if("end"===i.type){const e=g(i);if(e!==te)return e}
233if("illegal"===i.type&&""===o)return 1
234;if(M>1e5&&M>3*i.index)throw Error("potential infinite loop, way more iterations than matches")
235;return v+=o,o.length}const R=O(e)
236;if(!R)throw q(o.replace("{}",e)),Error('Unknown language: "'+e+'"')
237;const N=j(R);let f="",h=i||N;const I={},A=new c.__emitter(c);(()=>{const e=[]
238;for(let t=h;t!==R;t=t.parent)t.scope&&e.unshift(t.scope)
239;e.forEach((e=>A.openNode(e)))})();let v="",y=0,D=0,M=0,L=!1;try{
240for(h.matcher.considerAll();;){
241M++,L?L=!1:h.matcher.considerAll(),h.matcher.lastIndex=D
242;const e=h.matcher.exec(t);if(!e)break;const a=C(t.substring(D,e.index),e)
243;D=e.index+a}
244return C(t.substring(D)),A.closeAllNodes(),A.finalize(),f=A.toHTML(),{

Callers 5

SFunction · 0.70
dFunction · 0.70
bFunction · 0.70
RFunction · 0.70
NFunction · 0.70

Calls 11

qFunction · 0.85
jFunction · 0.85
considerAllMethod · 0.80
closeAllNodesMethod · 0.80
finalizeMethod · 0.80
toHTMLMethod · 0.80
OFunction · 0.70
CFunction · 0.70
EFunction · 0.70
openNodeMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected