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