/* esm.sh - micromark-extension-gfm-footnote@2.1.0 */
import{blankLine as L}from"../../micromark-core-commonmark@^2.0.0?target=es2022";import{factorySpace as k}from"../../micromark-factory-space@^2.0.0?target=es2022";import{markdownLineEndingOrSpace as F}from"../../micromark-util-character@^2.0.0?target=es2022";import{normalizeIdentifier as d}from"../../micromark-util-normalize-identifier@^2.0.0?target=es2022";var y={tokenize:N,partial:!0};function z(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:E,continuation:{tokenize:w},exit:j}},text:{91:{name:"gfmFootnoteCall",tokenize:O},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:I,resolveTo:M}}}}function I(t,i,o){let f=this,m=f.events.length,s=f.parser.gfmFootnotes||(f.parser.gfmFootnotes=[]),a;for(;m--;){let r=f.events[m][1];if(r.type==="labelImage"){a=r;break}if(r.type==="gfmFootnoteCall"||r.type==="labelLink"||r.type==="label"||r.type==="image"||r.type==="link")break}return l;function l(r){if(!a||!a._balanced)return o(r);let u=d(f.sliceSerialize({start:a.end,end:f.now()}));return u.codePointAt(0)!==94||!s.includes(u.slice(1))?o(r):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(r),t.exit("gfmFootnoteCallLabelMarker"),i(r))}}function M(t,i){let o=t.length,f;for(;o--;)if(t[o][1].type==="labelImage"&&t[o][0]==="enter"){f=t[o][1];break}t[o+1][1].type="data",t[o+3][1].type="gfmFootnoteCallLabelMarker";let m={type:"gfmFootnoteCall",start:Object.assign({},t[o+3][1].start),end:Object.assign({},t[t.length-1][1].end)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},t[o+3][1].end),end:Object.assign({},t[o+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;let a={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},t[t.length-1][1].start)},l={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},r=[t[o+1],t[o+2],["enter",m,i],t[o+3],t[o+4],["enter",s,i],["exit",s,i],["enter",a,i],["enter",l,i],["exit",l,i],["exit",a,i],t[t.length-2],t[t.length-1],["exit",m,i]];return t.splice(o,t.length-o+1,...r),t}function O(t,i,o){let f=this,m=f.parser.gfmFootnotes||(f.parser.gfmFootnotes=[]),s=0,a;return l;function l(n){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(n),t.exit("gfmFootnoteCallLabelMarker"),r}function r(n){return n!==94?o(n):(t.enter("gfmFootnoteCallMarker"),t.consume(n),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",u)}function u(n){if(s>999||n===93&&!a||n===null||n===91||F(n))return o(n);if(n===93){t.exit("chunkString");let c=t.exit("gfmFootnoteCallString");return m.includes(d(f.sliceSerialize(c)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(n),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),i):o(n)}return F(n)||(a=!0),s++,t.consume(n),n===92?g:u}function g(n){return n===91||n===92||n===93?(t.consume(n),s++,u):u(n)}}function E(t,i,o){let f=this,m=f.parser.gfmFootnotes||(f.parser.gfmFootnotes=[]),s,a=0,l;return r;function r(e){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(e),t.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(e){return e===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(e),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",g):o(e)}function g(e){if(a>999||e===93&&!l||e===null||e===91||F(e))return o(e);if(e===93){t.exit("chunkString");let b=t.exit("gfmFootnoteDefinitionLabelString");return s=d(f.sliceSerialize(b)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(e),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),c}return F(e)||(l=!0),a++,t.consume(e),e===92?n:g}function n(e){return e===91||e===92||e===93?(t.consume(e),a++,g):g(e)}function c(e){return e===58?(t.enter("definitionMarker"),t.consume(e),t.exit("definitionMarker"),m.includes(s)||m.push(s),k(t,h,"gfmFootnoteDefinitionWhitespace")):o(e)}function h(e){return i(e)}}function w(t,i,o){return t.check(L,i,t.attempt(y,i,o))}function j(t){t.exit("gfmFootnoteDefinition")}function N(t,i,o){let f=this;return k(t,m,"gfmFootnoteDefinitionIndent",5);function m(s){let a=f.events[f.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?i(s):o(s)}}import{normalizeIdentifier as D}from"../../micromark-util-normalize-identifier@^2.0.0?target=es2022";import{sanitizeUri as C}from"../../micromark-util-sanitize-uri@^2.0.0?target=es2022";var P={}.hasOwnProperty,A={};function S(t,i){return"Back to reference "+(t+1)+(i>1?"-"+i:"")}function T(t){let i=t||A,o=i.label||"Footnotes",f=i.labelTagName||"h2",m=i.labelAttributes===null||i.labelAttributes===void 0?'class="sr-only"':i.labelAttributes,s=i.backLabel||S,a=i.clobberPrefix===null||i.clobberPrefix===void 0?"user-content-":i.clobberPrefix;return{enter:{gfmFootnoteDefinition(){this.getData("tightStack").push(!1)},gfmFootnoteDefinitionLabelString(){this.buffer()},gfmFootnoteCallString(){this.buffer()}},exit:{gfmFootnoteDefinition(){let l=this.getData("gfmFootnoteDefinitions"),r=this.getData("gfmFootnoteDefinitionStack"),u=this.getData("tightStack"),g=r.pop(),n=this.resume();l||this.setData("gfmFootnoteDefinitions",l={}),P.call(l,g)||(l[g]=n),u.pop(),this.setData("slurpOneLineEnding",!0),this.setData("lastWasTag")},gfmFootnoteDefinitionLabelString(l){let r=this.getData("gfmFootnoteDefinitionStack");r||this.setData("gfmFootnoteDefinitionStack",r=[]),r.push(D(this.sliceSerialize(l))),this.resume(),this.buffer()},gfmFootnoteCallString(l){let r=this.getData("gfmFootnoteCallOrder"),u=this.getData("gfmFootnoteCallCounts"),g=D(this.sliceSerialize(l)),n;this.resume(),r||this.setData("gfmFootnoteCallOrder",r=[]),u||this.setData("gfmFootnoteCallCounts",u={});let c=r.indexOf(g),h=C(g.toLowerCase());c===-1?(r.push(g),u[g]=1,n=r.length):(u[g]++,n=c+1);let e=u[g];this.tag('<sup><a href="#'+a+"fn-"+h+'" id="'+a+"fnref-"+h+(e>1?"-"+e:"")+'" data-footnote-ref="" aria-describedby="footnote-label">'+String(n)+"</a></sup>")},null(){let l=this.getData("gfmFootnoteCallOrder")||[],r=this.getData("gfmFootnoteCallCounts")||{},u=this.getData("gfmFootnoteDefinitions")||{},g=-1;for(l.length>0&&(this.lineEndingIfNeeded(),this.tag('<section data-footnotes="" class="footnotes"><'+f+' id="footnote-label"'+(m?" "+m:"")+">"),this.raw(this.encode(o)),this.tag("</"+f+">"),this.lineEndingIfNeeded(),this.tag("<ol>"));++g<l.length;){let n=l[g],c=C(n.toLowerCase()),h=0,e=[];for(;++h<=r[n];)e.push('<a href="#'+a+"fnref-"+c+(h>1?"-"+h:"")+'" data-footnote-backref="" aria-label="'+this.encode(typeof s=="string"?s:s(g,h))+'" class="data-footnote-backref">\u21A9'+(h>1?"<sup>"+h+"</sup>":"")+"</a>");let b=e.join(" "),p=!1;this.lineEndingIfNeeded(),this.tag('<li id="'+a+"fn-"+c+'">'),this.lineEndingIfNeeded(),this.tag(u[n].replace(/<\/p>(?:\r?\n|\r)?$/,function(x){return p=!0," "+b+x})),p||(this.lineEndingIfNeeded(),this.tag(b)),this.lineEndingIfNeeded(),this.tag("</li>")}l.length>0&&(this.lineEndingIfNeeded(),this.tag("</ol>"),this.lineEndingIfNeeded(),this.tag("</section>"))}}}}export{S as defaultBackLabel,z as gfmFootnote,T as gfmFootnoteHtml};
//# sourceMappingURL=micromark-extension-gfm-footnote.mjs.map