openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.66 kB
JavaScript
import{u as scanFenceSpans}from"./code-regions-iiBEGTOw.mjs";
//!packages/markdown-core/src/code-spans.ts
function createInlineCodeState(){return{open:false,ticks:0}}function buildCodeSpanIndex(e,t,n){const r=n?.pendingLine;const i=r?r.text+e:e;const a=r?.text.length??0;const{spans:o,state:s}=scanFenceSpans(i,r?{atLineStart:true,open:r.open}:n);const c=(r?t?.beforePendingFence??t:t)??createInlineCodeState();const l=s.pendingLine?i.length-s.pendingLine.text.length:-1;let u;const d=[];const f=!r&&i.startsWith("`")?t?.pendingRun:void 0;const p=f??c;let m=p.open;let h=p.ticks;let g=i.length===0?t?.pendingRun:void 0;let _=m?0:-1;let v=!m&&c.escaped===true;let y=0;let b=0;while(y<i.length){if(l>=0&&y>=l&&!u)u={open:m,ticks:h,escaped:v};const e=o[b];if(e&&y>=e.start){y=e.end;b+=1;v=false;continue}if(v){v=false;if(i[y]==="`"||i[y]===`\\`){y+=1;continue}}if(i[y]===`\\`&&!m){v=true;y+=1;continue}if(i[y]!=="`"){y+=1;continue}const t=y;let n=t===0?f?.length??0:0;while(y<i.length&&i[y]==="`"){n+=1;y+=1}if(y===i.length)g={length:n,open:m,ticks:h};if(!m){m=true;h=n;_=t;continue}if(n===h){d.push({start:_,end:y});m=false;h=0;_=-1}}if(m)d.push({start:_,end:i.length});return{inlineState:{open:m,ticks:h,...v?{escaped:v}:{},...g?{pendingRun:g}:{},...l>=0?{beforePendingFence:u??{open:m,ticks:h,escaped:v}}:{}},fenceState:s,isInside:t=>t>=0&&t<e.length&&(isInsideSpan(a+t,o)||isInsideSpan(a+t,d))}}function isInsideSpan(e,t){let n=0;let r=t.length;while(n<r){const i=Math.floor((n+r)/2);const a=t[i];if(!a)return false;if(e>=a.end)n=i+1;else r=i}const i=t[n];return i!==void 0&&e>=i.start&&e<i.end}export{createInlineCodeState as n,buildCodeSpanIndex as t};