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