"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../../../../micromark-factory-space@2.0.1/node_modules/micromark-factory-space/index.cjs.js"),F=require("../../../../micromark-util-character@2.1.1/node_modules/micromark-util-character/index.cjs.js"),b=require("../../../../micromark-util-normalize-identifier@2.0.1/node_modules/micromark-util-normalize-identifier/index.cjs.js"),c=require("../../../../micromark-core-commonmark@2.0.3/node_modules/micromark-core-commonmark/lib/blank-line.cjs.js"),d={tokenize:O,partial:!0};function C(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:D,continuation:{tokenize:M},exit:z}},text:{91:{name:"gfmFootnoteCall",tokenize:y},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:L,resolveTo:x}}}}function L(n,o,t){const r=this;let u=r.events.length;const l=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a;for(;u--;){const g=r.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 t(g);const m=b.normalizeIdentifier(r.sliceSerialize({start:a.end,end:r.now()}));return m.codePointAt(0)!==94||!l.includes(m.slice(1))?t(g):(n.enter("gfmFootnoteCallLabelMarker"),n.consume(g),n.exit("gfmFootnoteCallLabelMarker"),o(g))}}function x(n,o){let t=n.length;for(;t--;)if(n[t][1].type==="labelImage"&&n[t][0]==="enter"){n[t][1];break}n[t+1][1].type="data",n[t+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},n[t+3][1].start),end:Object.assign({},n[n.length-1][1].end)},u={type:"gfmFootnoteCallMarker",start:Object.assign({},n[t+3][1].end),end:Object.assign({},n[t+3][1].end)};u.end.column++,u.end.offset++,u.end._bufferIndex++;const l={type:"gfmFootnoteCallString",start:Object.assign({},u.end),end:Object.assign({},n[n.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},l.start),end:Object.assign({},l.end)},f=[n[t+1],n[t+2],["enter",r,o],n[t+3],n[t+4],["enter",u,o],["exit",u,o],["enter",l,o],["enter",a,o],["exit",a,o],["exit",l,o],n[n.length-2],n[n.length-1],["exit",r,o]];return n.splice(t,n.length-t+1,...f),n}function y(n,o,t){const r=this,u=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l=0,a;return f;function f(i){return n.enter("gfmFootnoteCall"),n.enter("gfmFootnoteCallLabelMarker"),n.consume(i),n.exit("gfmFootnoteCallLabelMarker"),g}function g(i){return i!==94?t(i):(n.enter("gfmFootnoteCallMarker"),n.consume(i),n.exit("gfmFootnoteCallMarker"),n.enter("gfmFootnoteCallString"),n.enter("chunkString").contentType="string",m)}function m(i){if(l>999||i===93&&!a||i===null||i===91||F.markdownLineEndingOrSpace(i))return t(i);if(i===93){n.exit("chunkString");const k=n.exit("gfmFootnoteCallString");return u.includes(b.normalizeIdentifier(r.sliceSerialize(k)))?(n.enter("gfmFootnoteCallLabelMarker"),n.consume(i),n.exit("gfmFootnoteCallLabelMarker"),n.exit("gfmFootnoteCall"),o):t(i)}return F.markdownLineEndingOrSpace(i)||(a=!0),l++,n.consume(i),i===92?s:m}function s(i){return i===91||i===92||i===93?(n.consume(i),l++,m):m(i)}}function D(n,o,t){const r=this,u=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l,a=0,f;return g;function g(e){return n.enter("gfmFootnoteDefinition")._container=!0,n.enter("gfmFootnoteDefinitionLabel"),n.enter("gfmFootnoteDefinitionLabelMarker"),n.consume(e),n.exit("gfmFootnoteDefinitionLabelMarker"),m}function m(e){return e===94?(n.enter("gfmFootnoteDefinitionMarker"),n.consume(e),n.exit("gfmFootnoteDefinitionMarker"),n.enter("gfmFootnoteDefinitionLabelString"),n.enter("chunkString").contentType="string",s):t(e)}function s(e){if(a>999||e===93&&!f||e===null||e===91||F.markdownLineEndingOrSpace(e))return t(e);if(e===93){n.exit("chunkString");const S=n.exit("gfmFootnoteDefinitionLabelString");return l=b.normalizeIdentifier(r.sliceSerialize(S)),n.enter("gfmFootnoteDefinitionLabelMarker"),n.consume(e),n.exit("gfmFootnoteDefinitionLabelMarker"),n.exit("gfmFootnoteDefinitionLabel"),k}return F.markdownLineEndingOrSpace(e)||(f=!0),a++,n.consume(e),e===92?i:s}function i(e){return e===91||e===92||e===93?(n.consume(e),a++,s):s(e)}function k(e){return e===58?(n.enter("definitionMarker"),n.consume(e),n.exit("definitionMarker"),u.includes(l)||u.push(l),p.factorySpace(n,h,"gfmFootnoteDefinitionWhitespace")):t(e)}function h(e){return o(e)}}function M(n,o,t){return n.check(c.blankLine,o,n.attempt(d,o,t))}function z(n){n.exit("gfmFootnoteDefinition")}function O(n,o,t){const r=this;return p.factorySpace(n,u,"gfmFootnoteDefinitionIndent",5);function u(l){const a=r.events[r.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?o(l):t(l)}}exports.gfmFootnote=C;
//# sourceMappingURL=syntax.cjs.js.map
