/* esm.sh - micromark@4.0.3/lib/compile */
import{decodeNamedCharacterReference as _e}from"../../../decode-named-character-reference@^1.0.0?target=es2022";import{push as F}from"../../../micromark-util-chunked@^2.0.0?target=es2022";import{combineHtmlExtensions as Ue}from"../../../micromark-util-combine-extensions@^2.0.0?target=es2022";import{decodeNumericCharacterReference as Ve}from"../../../micromark-util-decode-numeric-character-reference@^2.0.0?target=es2022";import{encode as je}from"../../../micromark-util-encode@^2.0.0?target=es2022";import{normalizeIdentifier as W}from"../../../micromark-util-normalize-identifier@^2.0.0?target=es2022";import{sanitizeUri as I}from"../../../micromark-util-sanitize-uri@^2.0.0?target=es2022";var _={}.hasOwnProperty,U=/^(https?|ircs?|mailto|xmpp)$/i,Qe=/^https?$/i;function en(V){let k=V||{},E=!0,T={},p=[[]],o=[],d=[],S=Ue([{enter:{blockQuote:Z,codeFenced:te,codeFencedFenceInfo:a,codeFencedFenceMeta:a,codeIndented:re,codeText:He,content:Ee,definition:pe,definitionDestinationString:me,definitionLabelString:a,definitionTitleString:a,emphasis:Ce,htmlFlow:De,htmlText:q,image:le,label:a,link:ce,listItemMarker:K,listItemValue:J,listOrdered:$,listUnordered:G,paragraph:ee,reference:a,resource:ue,resourceDestinationString:fe,resourceTitleString:a,setextHeading:we,strong:Ae},exit:{atxHeading:Ie,atxHeadingSequence:Te,autolinkEmail:We,autolinkProtocol:Ne,blockQuote:v,characterEscapeValue:b,characterReferenceMarkerHexadecimal:P,characterReferenceMarkerNumeric:P,characterReferenceValue:Be,codeFenced:C,codeFencedFence:oe,codeFencedFenceInfo:ie,codeFencedFenceMeta:y,codeFlowValue:ye,codeIndented:C,codeText:Oe,codeTextData:b,data:b,definition:be,definitionDestinationString:ke,definitionLabelString:xe,definitionTitleString:Se,emphasis:qe,hardBreakEscape:H,hardBreakTrailing:H,htmlFlow:O,htmlFlowData:b,htmlText:O,htmlTextData:b,image:A,label:se,labelText:ae,lineEnding:ze,link:A,listOrdered:X,listUnordered:Y,paragraph:ne,reference:y,referenceString:de,resource:y,resourceDestinationString:ge,resourceTitleString:he,setextHeading:Re,setextHeadingLineSequence:Le,setextHeadingText:Fe,strong:Pe,thematicBreak:Me}},...k.htmlExtensions||[]]),L={definitions:T,tightStack:d},R={buffer:a,encode:m,getData:r,lineEndingIfNeeded:l,options:k,raw:s,resume:u,setData:i,tag:t},z=k.defaultLineEnding;return j;function j(e){let n=-1,c=0,f=[],g=[],x=[];for(;++n<e.length;)!z&&(e[n][1].type==="lineEnding"||e[n][1].type==="lineEndingBlank")&&(z=e[n][2].sliceSerialize(e[n][1])),(e[n][1].type==="listOrdered"||e[n][1].type==="listUnordered")&&(e[n][0]==="enter"?f.push(n):Q(e.slice(f.pop(),n))),e[n][1].type==="definition"&&(e[n][0]==="enter"?(x=F(x,e.slice(c,n)),c=n):(g=F(g,e.slice(c,n+1)),c=n+1));g=F(g,x),g=F(g,e.slice(c)),n=-1;let h=g;for(S.enter.null&&S.enter.null.call(R);++n<e.length;){let M=S[h[n][0]],B=h[n][1].type,N=M[B];_.call(M,B)&&N&&N.call({sliceSerialize:h[n][2].sliceSerialize,...R},h[n][1])}return S.exit.null&&S.exit.null.call(R),p[0].join("")}function Q(e){let n=e.length,c=0,f=0,g=!1,x;for(;++c<n;){let h=e[c];if(h[1]._container)x=void 0,h[0]==="enter"?f++:f--;else switch(h[1].type){case"listItemPrefix":{h[0]==="exit"&&(x=!0);break}case"linePrefix":break;case"lineEndingBlank":{h[0]==="enter"&&!f&&(x?x=void 0:g=!0);break}default:x=void 0}}e[0][1]._loose=g}function i(e,n){L[e]=n}function r(e){return L[e]}function a(){p.push([])}function u(){return p.pop().join("")}function t(e){E&&(i("lastWasTag",!0),p[p.length-1].push(e))}function s(e){i("lastWasTag"),p[p.length-1].push(e)}function w(){s(z||`
`)}function l(){let e=p[p.length-1],n=e[e.length-1],c=n?n.charCodeAt(n.length-1):null;c===10||c===13||c===null||w()}function m(e){return r("ignoreEncode")?e:je(e)}function y(){u()}function $(e){d.push(!e._loose),l(),t("<ol"),i("expectFirstItem",!0)}function G(e){d.push(!e._loose),l(),t("<ul"),i("expectFirstItem",!0)}function J(e){if(r("expectFirstItem")){let n=Number.parseInt(this.sliceSerialize(e),10);n!==1&&t(' start="'+m(String(n))+'"')}}function K(){r("expectFirstItem")?t(">"):D(),l(),t("<li>"),i("expectFirstItem"),i("lastWasTag")}function X(){D(),d.pop(),w(),t("</ol>")}function Y(){D(),d.pop(),w(),t("</ul>")}function D(){r("lastWasTag")&&!r("slurpAllLineEndings")&&l(),t("</li>"),i("slurpAllLineEndings")}function Z(){d.push(!1),l(),t("<blockquote>")}function v(){d.pop(),l(),t("</blockquote>"),i("slurpAllLineEndings")}function ee(){d[d.length-1]||(l(),t("<p>")),i("slurpAllLineEndings")}function ne(){d[d.length-1]?i("slurpAllLineEndings",!0):t("</p>")}function te(){l(),t("<pre><code"),i("fencesCount",0)}function ie(){let e=u();t(' class="language-'+e+'"')}function oe(){let e=r("fencesCount")||0;e||(t(">"),i("slurpOneLineEnding",!0)),i("fencesCount",e+1)}function re(){l(),t("<pre><code>")}function C(){let e=r("fencesCount");e!==void 0&&e<2&&L.tightStack.length>0&&!r("lastWasTag")&&w(),r("flowCodeSeenData")&&l(),t("</code></pre>"),e!==void 0&&e<2&&l(),i("flowCodeSeenData"),i("fencesCount"),i("slurpOneLineEnding")}function le(){o.push({image:!0}),E=void 0}function ce(){o.push({})}function ae(e){o[o.length-1].labelId=this.sliceSerialize(e)}function se(){o[o.length-1].label=u()}function de(e){o[o.length-1].referenceId=this.sliceSerialize(e)}function ue(){a(),o[o.length-1].destination=""}function fe(){a(),i("ignoreEncode",!0)}function ge(){o[o.length-1].destination=u(),i("ignoreEncode")}function he(){o[o.length-1].title=u()}function A(){let e=o.length-1,n=o[e],c=n.referenceId||n.labelId,f=n.destination===void 0?T[W(c)]:n;for(E=!0;e--;)if(o[e].image){E=void 0;break}n.image?(t('<img src="'+I(f.destination,k.allowDangerousProtocol?void 0:Qe)+'" alt="'),s(n.label),t('"')):t('<a href="'+I(f.destination,k.allowDangerousProtocol?void 0:U)+'"'),t(f.title?' title="'+f.title+'"':""),n.image?t(" />"):(t(">"),s(n.label),t("</a>")),o.pop()}function pe(){a(),o.push({})}function xe(e){u(),o[o.length-1].labelId=this.sliceSerialize(e)}function me(){a(),i("ignoreEncode",!0)}function ke(){o[o.length-1].destination=u(),i("ignoreEncode")}function Se(){o[o.length-1].title=u()}function be(){let e=o[o.length-1],n=W(e.labelId);u(),_.call(T,n)||(T[n]=o[o.length-1]),o.pop()}function Ee(){i("slurpAllLineEndings",!0)}function Te(e){r("headingRank")||(i("headingRank",this.sliceSerialize(e).length),l(),t("<h"+r("headingRank")+">"))}function we(){a(),i("slurpAllLineEndings")}function Fe(){i("slurpAllLineEndings",!0)}function Ie(){t("</h"+r("headingRank")+">"),i("headingRank")}function Le(e){i("headingRank",this.sliceSerialize(e).charCodeAt(0)===61?1:2)}function Re(){let e=u();l(),t("<h"+r("headingRank")+">"),s(e),t("</h"+r("headingRank")+">"),i("slurpAllLineEndings"),i("headingRank")}function b(e){s(m(this.sliceSerialize(e)))}function ze(e){if(!r("slurpAllLineEndings")){if(r("slurpOneLineEnding")){i("slurpOneLineEnding");return}if(r("inCodeText")){s(" ");return}s(m(this.sliceSerialize(e)))}}function ye(e){s(m(this.sliceSerialize(e))),i("flowCodeSeenData",!0)}function H(){t("<br />")}function De(){l(),q()}function O(){i("ignoreEncode")}function q(){k.allowDangerousHtml&&i("ignoreEncode",!0)}function Ce(){t("<em>")}function Ae(){t("<strong>")}function He(){i("inCodeText",!0),t("<code>")}function Oe(){i("inCodeText"),t("</code>")}function qe(){t("</em>")}function Pe(){t("</strong>")}function Me(){l(),t("<hr />")}function P(e){i("characterReferenceType",e.type)}function Be(e){let n=this.sliceSerialize(e),c=r("characterReferenceType")?Ve(n,r("characterReferenceType")==="characterReferenceMarkerNumeric"?10:16):_e(n);s(m(c)),i("characterReferenceType")}function Ne(e){let n=this.sliceSerialize(e);t('<a href="'+I(n,k.allowDangerousProtocol?void 0:U)+'">'),s(m(n)),t("</a>")}function We(e){let n=this.sliceSerialize(e);t('<a href="'+I("mailto:"+n)+'">'),s(m(n)),t("</a>")}}export{en as compile};
//# sourceMappingURL=compile.mjs.map