import{f as p}from"./vendor-micromark-factory-space-BM4zcA-B.js";import{j as F}from"./vendor-micromark-util-character-Cn8n62xE.js";import{n as b}from"./vendor-micromark-util-normalize-identifier-C9ANKk3v.js";import{b as D}from"./vendor-micromark-core-commonmark-BEN53qso.js";const x={tokenize:d,partial:!0};function P(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:L,continuation:{tokenize:z},exit:c}},text:{91:{name:"gfmFootnoteCall",tokenize:y},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:M,resolveTo:S}}}}function M(t,r,n){const o=this;let u=o.events.length;const l=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let a;for(;u--;){const g=o.events[u][1];if(g.type==="labelImage"){a=g;break}if(g.type==="gfmFootnoteCall"||g.type==="labelLink"||g.type==="label"||g.type==="image"||g.type==="link")break}return f;function f(g){if(!a||!a._balanced)return n(g);const m=b(o.sliceSerialize({start:a.end,end:o.now()}));return m.codePointAt(0)!==94||!l.includes(m.slice(1))?n(g):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(g),t.exit("gfmFootnoteCallLabelMarker"),r(g))}}function S(t,r){let n=t.length;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";const o={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},u={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};u.end.column++,u.end.offset++,u.end._bufferIndex++;const l={type:"gfmFootnoteCallString",start:Object.assign({},u.end),end:Object.assign({},t[t.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},l.start),end:Object.assign({},l.end)},f=[t[n+1],t[n+2],["enter",o,r],t[n+3],t[n+4],["enter",u,r],["exit",u,r],["enter",l,r],["enter",a,r],["exit",a,r],["exit",l,r],t[t.length-2],t[t.length-1],["exit",o,r]];return t.splice(n,t.length-n+1,...f),t}function y(t,r,n){const o=this,u=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let l=0,a;return f;function f(i){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(i),t.exit("gfmFootnoteCallLabelMarker"),g}function g(i){return i!==94?n(i):(t.enter("gfmFootnoteCallMarker"),t.consume(i),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",m)}function m(i){if(l>999||i===93&&!a||i===null||i===91||F(i))return n(i);if(i===93){t.exit("chunkString");const k=t.exit("gfmFootnoteCallString");return u.includes(b(o.sliceSerialize(k)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(i),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),r):n(i)}return F(i)||(a=!0),l++,t.consume(i),i===92?s:m}function s(i){return i===91||i===92||i===93?(t.consume(i),l++,m):m(i)}}function L(t,r,n){const o=this,u=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let l,a=0,f;return g;function g(e){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(e),t.exit("gfmFootnoteDefinitionLabelMarker"),m}function m(e){return e===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(e),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",s):n(e)}function s(e){if(a>999||e===93&&!f||e===null||e===91||F(e))return n(e);if(e===93){t.exit("chunkString");const C=t.exit("gfmFootnoteDefinitionLabelString");return l=b(o.sliceSerialize(C)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(e),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),k}return F(e)||(f=!0),a++,t.consume(e),e===92?i:s}function i(e){return e===91||e===92||e===93?(t.consume(e),a++,s):s(e)}function k(e){return e===58?(t.enter("definitionMarker"),t.consume(e),t.exit("definitionMarker"),u.includes(l)||u.push(l),p(t,h,"gfmFootnoteDefinitionWhitespace")):n(e)}function h(e){return r(e)}}function z(t,r,n){return t.check(D,r,t.attempt(x,r,n))}function c(t){t.exit("gfmFootnoteDefinition")}function d(t,r,n){const o=this;return p(t,u,"gfmFootnoteDefinitionIndent",5);function u(l){const a=o.events[o.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?r(l):n(l)}}export{P as g};
