import{a as S}from"./chunk-EECWHBRF.js";import{h as g,m as M}from"./chunk-ZYLLMMM7.js";import{a as $}from"./chunk-62QEBAUP.js";function k(){return{enter:{mathFlow:t,mathFlowFenceMeta:o,mathText:s},exit:{mathFlow:e,mathFlowFence:r,mathFlowFenceMeta:l,mathFlowValue:x,mathText:m,mathTextData:x}};function t(i){let u={type:"element",tagName:"code",properties:{className:["language-math","math-display"]},children:[]};this.enter({type:"math",meta:null,value:"",data:{hName:"pre",hChildren:[u]}},i)}function o(){this.buffer()}function l(){let i=this.resume(),u=this.stack[this.stack.length-1];u.type,u.meta=i}function r(){this.data.mathFlowInside||(this.buffer(),this.data.mathFlowInside=!0)}function e(i){let u=this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),h=this.stack[this.stack.length-1];h.type,this.exit(i),h.value=u;let c=h.data.hChildren[0];c.type,c.tagName,c.children.push({type:"text",value:u}),this.data.mathFlowInside=void 0}function s(i){this.enter({type:"inlineMath",value:"",data:{hName:"code",hProperties:{className:["language-math","math-inline"]},hChildren:[]}},i),this.buffer()}function m(i){let u=this.resume(),h=this.stack[this.stack.length-1];h.type,this.exit(i),h.value=u,h.data.hChildren.push({type:"text",value:u})}function x(i){this.config.enter.data.call(this,i),this.config.exit.data.call(this,i)}}function y(t){let o=(t||{}).singleDollarTextMath;return o==null&&(o=!0),r.peek=e,{unsafe:[{character:"\r",inConstruct:"mathFlowMeta"},{character:`
`,inConstruct:"mathFlowMeta"},{character:"$",after:o?void 0:"\\$",inConstruct:"phrasing"},{character:"$",inConstruct:"mathFlowMeta"},{atBreak:!0,character:"$",after:"\\$"}],handlers:{math:l,inlineMath:r}};function l(s,m,x,i){let u=s.value||"",h=x.createTracker(i),c="$".repeat(Math.max(S(u,"$")+1,2)),f=x.enter("mathFlow"),p=h.move(c);if(s.meta){let w=x.enter("mathFlowMeta");p+=h.move(x.safe(s.meta,$({after:`
`,before:p,encode:["$"]},h.current()))),w()}return p+=h.move(`
`),u&&(p+=h.move(u+`
`)),p+=h.move(c),f(),p}function r(s,m,x){let i=s.value||"",u=1;for(o||u++;new RegExp("(^|[^$])"+"\\$".repeat(u)+"([^$]|$)").test(i);)u++;let h="$".repeat(u);/[^ \r\n]/.test(i)&&(/^[ \r\n]/.test(i)&&/[ \r\n]$/.test(i)||/^\$|\$$/.test(i))&&(i=" "+i+" ");let c=-1;for(;++c<x.unsafe.length;){let f=x.unsafe[c];if(!f.atBreak)continue;let p=x.compilePattern(f),w;for(;w=p.exec(i);){let d=w.index;i.codePointAt(d)===10&&i.codePointAt(d-1)===13&&d--,i=i.slice(0,d)+" "+i.slice(w.index+1)}}return h+i+h}function e(){return"$"}}var b={tokenize:O,concrete:!0,name:"mathFlow"},q={tokenize:_,partial:!0};function O(t,o,l){let r=this,e=r.events[r.events.length-1],s=e&&e[1].type==="linePrefix"?e[2].sliceSerialize(e[1],!0).length:0,m=0;return x;function x(n){return t.enter("mathFlow"),t.enter("mathFlowFence"),t.enter("mathFlowFenceSequence"),i(n)}function i(n){return n===36?(t.consume(n),m++,i):m<2?l(n):(t.exit("mathFlowFenceSequence"),M(t,u,"whitespace")(n))}function u(n){return n===null||g(n)?c(n):(t.enter("mathFlowFenceMeta"),t.enter("chunkString",{contentType:"string"}),h(n))}function h(n){return n===null||g(n)?(t.exit("chunkString"),t.exit("mathFlowFenceMeta"),c(n)):n===36?l(n):(t.consume(n),h)}function c(n){return t.exit("mathFlowFence"),r.interrupt?o(n):t.attempt(q,f,a)(n)}function f(n){return t.attempt({tokenize:v,partial:!0},a,p)(n)}function p(n){return(s?M(t,w,"linePrefix",s+1):w)(n)}function w(n){return n===null?a(n):g(n)?t.attempt(q,f,a)(n):(t.enter("mathFlowValue"),d(n))}function d(n){return n===null||g(n)?(t.exit("mathFlowValue"),w(n)):(t.consume(n),d)}function a(n){return t.exit("mathFlow"),o(n)}function v(n,N,E){let z=0;return M(n,I,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4);function I(F){return n.enter("mathFlowFence"),n.enter("mathFlowFenceSequence"),C(F)}function C(F){return F===36?(z++,n.consume(F),C):z<m?E(F):(n.exit("mathFlowFenceSequence"),M(n,L,"whitespace")(F))}function L(F){return F===null||g(F)?(n.exit("mathFlowFence"),N(F)):E(F)}}}function _(t,o,l){let r=this;return e;function e(m){return m===null?o(m):(t.enter("lineEnding"),t.consume(m),t.exit("lineEnding"),s)}function s(m){return r.parser.lazy[r.now().line]?l(m):o(m)}}function P(t){let l=(t||{}).singleDollarTextMath;return l==null&&(l=!0),{tokenize:r,resolve:A,previous:B,name:"mathText"};function r(e,s,m){let x=this,i=0,u,h;return c;function c(a){return e.enter("mathText"),e.enter("mathTextSequence"),f(a)}function f(a){return a===36?(e.consume(a),i++,f):i<2&&!l?m(a):(e.exit("mathTextSequence"),p(a))}function p(a){return a===null?m(a):a===36?(h=e.enter("mathTextSequence"),u=0,d(a)):a===32?(e.enter("space"),e.consume(a),e.exit("space"),p):g(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),p):(e.enter("mathTextData"),w(a))}function w(a){return a===null||a===32||a===36||g(a)?(e.exit("mathTextData"),p(a)):(e.consume(a),w)}function d(a){return a===36?(e.consume(a),u++,d):u===i?(e.exit("mathTextSequence"),e.exit("mathText"),s(a)):(h.type="mathTextData",w(a))}}}function A(t){let o=t.length-4,l=3,r,e;if((t[l][1].type==="lineEnding"||t[l][1].type==="space")&&(t[o][1].type==="lineEnding"||t[o][1].type==="space")){for(r=l;++r<o;)if(t[r][1].type==="mathTextData"){t[o][1].type="mathTextPadding",t[l][1].type="mathTextPadding",l+=2,o-=2;break}}for(r=l-1,o++;++r<=o;)e===void 0?r!==o&&t[r][1].type!=="lineEnding"&&(e=r):(r===o||t[r][1].type==="lineEnding")&&(t[e][1].type="mathTextData",r!==e+2&&(t[e][1].end=t[r-1][1].end,t.splice(e+2,r-e-2),o-=r-e-2,r=e+2),e=void 0);return t}function B(t){return t!==36||this.events[this.events.length-1][1].type==="characterEscape"}function T(t){return{flow:{36:b},text:{36:P(t)}}}var V={};function D(t){let o=this,l=t||V,r=o.data(),e=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),m=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);e.push(T(l)),s.push(k()),m.push(y(l))}export{D as default};
