class MDTokenType{static Text=new MDTokenType("Text");static Whitespace=new MDTokenType("Whitespace");static Underscore=new MDTokenType("Underscore");static Asterisk=new MDTokenType("Asterisk");static Slash=new MDTokenType("Slash");static Tilde=new MDTokenType("Tilde");static Bang=new MDTokenType("Bang");static Backtick=new MDTokenType("Backtick");static Equal=new MDTokenType("Equal");static Caret=new MDTokenType("Caret");static Label=new MDTokenType("Label");static URL=new MDTokenType("URL");static Email=new MDTokenType("Email");static SimpleLink=new MDTokenType("SimpleLink");static SimpleEmail=new MDTokenType("SimpleEmail");static Footnote=new MDTokenType("Footnote");static Modifier=new MDTokenType("Modifier");static HTMLTag=new MDTokenType("HTMLTag");static META_AnyNonWhitespace=new MDTokenType("METAAnyNonWhitespace");static META_OptionalWhitespace=new MDTokenType("METAOptionalWhitespace");name;constructor(e){this.name=e}toString(){return`${this.constructor.name}.${this.name}`}equals(e){return e instanceof MDTokenType&&e.name==this.name}}class MDToken{original;type;content;extra;tag;modifier;constructor(e,t,n=null,s=null,r=null){this.original=e,this.type=t,n instanceof MDTagModifier?(this.content=null,this.modifier=n):(this.content=n,this.modifier=null),this.extra=s,this.tag=r}toString(){return`(${this.constructor.name} type=${this.type.toString()} content=${this.content})`}static findFirstTokens(e,t,n=0){for(var s=[],r=n;r=e.length)return null;let n=e[a],d=t[l];if(d==MDTokenType.META_OptionalWhitespace)n instanceof MDToken&&n.type==MDTokenType.Whitespace?s.push(n):o--;else if(d==MDTokenType.META_AnyNonWhitespace){if(n instanceof MDToken&&n.type==MDTokenType.Whitespace){i=!1;break}s.push(n)}else{if(!(n instanceof MDToken)||n.type!=d){i=!1;break}s.push(n)}}if(i)return{tokens:s,index:r}}return null}static findPairedTokens(e,t,n,s=null,r=0){for(var i=r;i0&&(null===s||s(d)))return{startTokens:o.tokens,contentTokens:d,endTokens:a.tokens,startIndex:o.index,contentIndex:o.index+o.tokens.length,endIndex:a.index,totalLength:a.index+a.tokens.length-o.index};l=a.index+1}i=o.index}return null}equals(e){return e instanceof MDToken&&(e.original===this.original&&(!!e.type.equals(this.type)&&(e.content===this.content&&(e.extra===this.extra&&(!!MDUtils.equal(e.tag,this.tag)&&!!MDUtils.equals(e.modifier,this.modifier))))))}}class MDUtils{static baseURLRegex=/(?:(?:(?:[a-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[a-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[a-z0-9\.\-]+)(?:(?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/i;static baseEmailRegex=/(?:(?:[^<>()\[\]\\.,;:\s@"]+(?:\.[^<>()\[\]\\.,;:\s@"]+)*)|(?:".+"))@(?:(?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(?:(?:[a-z\-0-9]+\.)+[a-z]{2,}))/i;static escapeHTML(e,t=!1){if("string"!=typeof e)return"";var n=e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""");return t&&(n=n.replace(/\n/g,"
\n")),n}static unescapeHTML(e,t=!1){t&&(e=e.replace(/\n?/g,"\n"));return(new DOMParser).parseFromString(e,"text/html").documentElement.textContent}static escapeObfuscated(e){if(e.startsWith("mailto:"))return"mailto:"+this.escapeObfuscated(e.substring(7));for(var t="",n=0;n"'=]+/,"")}static stripIndent(e,t=1){const n=new RegExp(`^(?: {1,4}|\t){${t}}`);return e instanceof Array?e.map((e=>e.replace(n,""))):e.replace(n,"")}static withoutTrailingBlankLines(e){for(var t=e.slice();t.length>0&&0==t[t.length-1].trim().length;)t.pop();return t}static containsBlankLine(e){for(const t of e)if(0==t.trim().length)return!0;return!1}static countIndents(e,t=!1){return e.replace(t?/(?: {4}|\t)/g:/(?: {1,4}|\t)/g,"\t").replace(/^(\t*)(.*?)$/,"$1").length}static tokenizeLabel(e){if(!e.startsWith("["))return null;for(var t=0,n=0,s=1;s0))return[e.substring(0,s+1),e.substring(1,s)];n--}}return null}static#e=/^\((\S+?)\s+"(.*?)"\)/i;static#t=/^\((\S+?)\)/i;static tokenizeURL(e){var t;return(t=this.#e.exec(e))?this.tokenizeEmail(e)?null:t:(t=this.#t.exec(e))?this.tokenizeEmail(e)?null:[...t,null]:null}static#n=new RegExp("^\\(\\s*("+MDUtils.baseEmailRegex.source+')\\s+"(.*?)"\\s*\\)',"i");static#s=new RegExp("^\\(\\s*("+MDUtils.baseEmailRegex.source+")\\s*\\)","i");static tokenizeEmail(e){var t;return(t=this.#n.exec(e))?t:(t=this.#s.exec(e))?[...t,null]:null}static typename(e){return null===e?"null":e instanceof Object?e.constructor.name:typeof e}static#r(e,t){if(e===t)return!0;if(!(e instanceof Array&&t instanceof Array))return!1;if(null==e||null==t)return!1;if(e.length!=t.length)return!1;for(var n=0;n=0?n+=`\\${s}`:",-=<>#&!%:;@~'`\"".indexOf(s)>=0?n+=t(s):n+="\f"==s?"\\f":"\n"==s?"\\n":"\r"==s?"\\r":"\t"==s?"\\t":"\v"==s?"\\v":s}return n}static replaceNodes(e,t,n){for(var s=0;s=this.lines.length)return null;const e=MDUtils.withoutTrailingBlankLines(this.lines.slice(this.p));return 0==e.length?null:(this.p=this.lines.length,this.inlineMarkdownToNode(e.join("\n")))}#T(){for(;this.hasLines(1)&&0==this.lines[this.p].trim().length;)this.p++;if(!this.hasLines(1))return null;for(const t of this.root.#a){var e=t[1];const n=this.p,s=e.readBlock(this);if(s){if(this.p==n)throw new Error(`${e.constructor.name} returned an ${s.constructor.name} without incrementing MDState.p. This could lead to an infinite loop.`);return s}}return this.#p()}#D(e){if(this.#o)return this.#o.#D(e);var t=[],n="",s=!1;const r=function(){if(0==n.length)return;const e=MDState.#M.exec(n);null!==e?(e[1].length>0&&t.push(new MDToken(e[1],MDTokenType.Whitespace,e[1])),void 0!==e[2]&&e[2].length>0&&t.push(new MDToken(e[2],MDTokenType.Text,e[2])),void 0!==e[3]&&e[3].length>0&&t.push(new MDToken(e[3],MDTokenType.Whitespace,e[3]))):t.push(new MDToken(n,MDTokenType.Text,n)),n=""};for(var i=0;i"))break;t.push(s)}if(t.length>0){let s=t.map((function(e){return e.substring(1).replace(/^ {0,3}\t?/,"")})),r=e.copy(s).readBlocks();return e.p=n,new MDBlockquoteNode(r)}return null}}class _MDListReader extends MDReader{#m(e,t){for(var n=e.p,s=[],r=!1;e.hasLines(1,n);){const o=n==e.p;var i=e.lines[n++];if(o&&(i=i.substring(t)),/^(?:\*|\+|\-|\d+\.)\s+/.exec(i)){0;break}const l=0==i.trim().length,a=null!==/^\s+\S/.exec(i);if(l)r=!0;else if(!a&&r)break;s.push(i)}return s=MDUtils.withoutTrailingBlankLines(s),MDUtils.stripIndent(s)}_readListItemContent(e,t){const n=this.#m(e,t);if(e.p+=Math.max(n.length,1),1==n.length)return e.inlineMarkdownToNode(n[0]);if(n.filter((e=>0==e.trim().length)).length>0){const t=e.copy(n).readBlocks();return 1==t.length?t[0]:new MDNode(t)}for(var s=1;s{if(!(e instanceof MDTextNode))return null;for(var t=!1,r=[e.text],i=0;i"string"==typeof e?new MDTextNode(e):e));return new MDNode(l)}))}}class MDParagraphReader extends MDReader{readBlock(e){for(var t=[],n=e.p;n=e.lines.length)return null;if(t.length>0){e.p=n;let s=t.join("\n");return new MDParagraphNode(e.inlineMarkdownToNodes(s))}return null}}class MDSimplePairInlineReader extends MDReader{attemptPair(e,t,n,s,r,i=1,o=!1){let l=Array(i).fill(r),a=this.substitutePriority instanceof Array?this.substitutePriority[0]:null,d=MDToken.findPairedTokens(n,l,l,(function(e){const n=e[0]instanceof MDToken?e[0].type:null,s=e[e.length-1]instanceof MDToken?e[e.length-1].type:null;if(n==MDTokenType.Whitespace)return!1;if(s==MDTokenType.Whitespace)return!1;if(t==a){var i=0;for(let t of e)t instanceof MDToken&&t.type==r&&i++;if(i%2!=0)return!1}return!0}));if(null===d)return!1;let c=o?d.contentTokens.map((e=>e.original)).join(""):e.tokensToNodes(d.contentTokens);return n.splice(d.startIndex,d.totalLength,new s(c)),!0}}class MDEmphasisReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("*")?new MDToken("*",MDTokenType.Asterisk):t.startsWith("_")?new MDToken("_",MDTokenType.Underscore):null}substituteTokens(e,t,n){return!!this.attemptPair(e,t,n,MDEmphasisNode,MDTokenType.Asterisk)||!!this.attemptPair(e,t,n,MDEmphasisNode,MDTokenType.Underscore)}}class MDStrongReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("*")?new MDToken("*",MDTokenType.Asterisk):t.startsWith("_")?new MDToken("_",MDTokenType.Underscore):null}substituteTokens(e,t,n){return!!this.attemptPair(e,t,n,MDStrongNode,MDTokenType.Asterisk,2)||!!this.attemptPair(e,t,n,MDStrongNode,MDTokenType.Underscore,2)}}class MDStrikethroughReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("~")?new MDToken("~",MDTokenType.Tilde):null}substituteTokens(e,t,n){return!!this.attemptPair(e,t,n,MDStrikethroughNode,MDTokenType.Tilde,2)||!!this.attemptPair(e,t,n,MDStrikethroughNode,MDTokenType.Tilde)}}class MDUnderlineReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("_")?new MDToken("_",MDTokenType.Underscore):null}substituteTokens(e,t,n){return this.attemptPair(e,t,n,MDUnderlineNode,MDTokenType.Underscore,2)}}class MDHighlightReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("=")?new MDToken("=",MDTokenType.Equal):null}substituteTokens(e,t,n){return this.attemptPair(e,t,n,MDHighlightNode,MDTokenType.Equal,2)}}class MDLinkReader extends MDReader{static#C=new RegExp("^<("+MDUtils.baseEmailRegex.source+")>","i");static#_=new RegExp("^<("+MDUtils.baseURLRegex.source+")>","i");constructor(e=0,t=0){super(e,t)}readToken(e,t){var n;return(n=MDUtils.tokenizeLabel(t))?new MDToken(n[0],MDTokenType.Label,n[1]):(n=MDUtils.tokenizeEmail(t))?new MDToken(n[0],MDTokenType.Email,n[1],n[2]):(n=MDUtils.tokenizeURL(t))?new MDToken(n[0],MDTokenType.URL,n[1],n[2]):(n=MDLinkReader.#C.exec(t))?new MDToken(n[0],MDTokenType.SimpleEmail,n[1]):(n=MDLinkReader.#_.exec(t))?new MDToken(n[0],MDTokenType.SimpleLink,n[1]):null}substituteTokens(e,t,n){var s;if(s=MDToken.findFirstTokens(n,[MDTokenType.Label,MDTokenType.META_OptionalWhitespace,MDTokenType.URL])){let t=s.tokens[0].content,r=s.tokens[s.tokens.length-1].content,i=s.tokens[s.tokens.length-1].extra;return n.splice(s.index,s.tokens.length,new MDLinkNode(r,e.inlineMarkdownToNode(t),i)),!0}if(s=MDToken.findFirstTokens(n,[MDTokenType.Label,MDTokenType.META_OptionalWhitespace,MDTokenType.Email])){let t=s.tokens[0].content,r=`mailto:${s.tokens[s.tokens.length-1].content}`,i=s.tokens[s.tokens.length-1].extra;return n.splice(s.index,s.tokens.length,new MDLinkNode(r,e.inlineMarkdownToNodes(t),i)),!0}if(s=MDToken.findFirstTokens(n,[MDTokenType.SimpleEmail])){const e=s.tokens[0],t=`mailto:${e.content}`,r=new MDLinkNode(t,new MDObfuscatedTextNode(e.content));return n.splice(s.index,1,r),!0}if(s=MDToken.findFirstTokens(n,[MDTokenType.SimpleLink])){const e=s.tokens[0].content,t=new MDLinkNode(e,new MDTextNode(e));return n.splice(s.index,1,t),!0}return!1}}class MDReferencedLinkReader extends MDLinkReader{readBlock(e){var t=e.p;let n=e.lines[t++];var s,r,i=null;let o=/^\s*\[(.+?)]:\s*(\S+)\s+"(.*?)"\s*$/.exec(n);if(o)s=o[1],r=o[2],i=o[3];else{if(o=/^\s*\[(.+?)]:\s*(\S+)\s*$/.exec(n),!o)return null;s=o[1],r=o[2]}return e.defineURL(s,r,i),e.p=t,new MDNode([])}substituteTokens(e,t,n){var s;if(s=MDToken.findFirstTokens(n,[MDTokenType.Label,MDTokenType.META_OptionalWhitespace,MDTokenType.Label])){let t=s.tokens[0].content,r=s.tokens[s.tokens.length-1].content;return n.splice(s.index,s.tokens.length,new MDReferencedLinkNode(r,e.inlineMarkdownToNodes(t))),!0}return!1}}class MDImageReader extends MDLinkReader{substituteTokens(e,t,n){}readToken(e,t){const n=super.readToken(e,t);return n||(t.startsWith("!")?new MDToken("!",MDTokenType.Bang):null)}substituteTokens(e,t,n){var s;if(s=MDToken.findFirstTokens(n,[MDTokenType.Bang,MDTokenType.Label,MDTokenType.META_OptionalWhitespace,MDTokenType.URL])){let e=s.tokens[1].content,t=s.tokens[s.tokens.length-1].content,r=s.tokens[s.tokens.length-1].extra;const i=new MDImageNode(t,e);return null!==r&&(i.attributes.title=r),n.splice(s.index,s.tokens.length,i),!0}if(s=MDToken.findFirstTokens(n,[MDTokenType.Bang,MDTokenType.Label,MDTokenType.META_OptionalWhitespace,MDTokenType.Label])){let e=s.tokens[1].content,t=s.tokens[s.tokens.length-1].content;return n.splice(s.index,s.tokens.length,new MDReferencedImageNode(t,e)),!0}return!1}}class MDReferencedImageReader extends MDReferencedLinkReader{readBlock(e){return null}}class MDCodeSpanReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("`")?new MDToken("`",MDTokenType.Backtick):null}substituteTokens(e,t,n){return!!this.attemptPair(e,t,n,MDCodeNode,MDTokenType.Backtick,2,!0)||(!!this.attemptPair(e,t,n,MDCodeNode,MDTokenType.Backtick,1,!0)||void 0)}}class MDSubscriptReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("~")?new MDToken("~",MDTokenType.Tilde):null}substituteTokens(e,t,n){return this.attemptPair(e,t,n,MDSubscriptNode,MDTokenType.Tilde)}}class MDSuperscriptReader extends MDSimplePairInlineReader{readToken(e,t){return t.startsWith("^")?new MDToken("^",MDTokenType.Caret):null}substituteTokens(e,t,n){return this.attemptPair(e,t,n,MDSuperscriptNode,MDTokenType.Caret)}}class MDHTMLTagReader extends MDReader{readToken(e,t){const n=MDHTMLTag.fromLineStart(t);return null===n?null:new MDToken(n.original,MDTokenType.HTMLTag,null,null,n)}substituteTokens(e,t,n){var s;if(s=MDToken.findFirstTokens(n,[MDTokenType.HTMLTag])){const e=s.tokens[0].tag;return n.splice(s.index,s.tokens.length,new MDHTMLTagNode(e)),!0}return!1}}class MDModifierReader extends MDReader{readToken(e,t){var n=MDTagModifier.fromStart(t);return n?new MDToken(n.original,MDTokenType.Modifier,n):null}substituteTokens(e,t,n){return!1}}class MDNode{cssClasses=[];cssId=null;cssStyles={};attributes={};children;constructor(e=[]){if(e instanceof Array){for(const t of e)if(!(t instanceof MDNode))throw new Error(`${this.constructor.name} expects children of type MDNode[] or MDNode, got array with ${MDUtils.typename(t)} element`);this.children=e}else{if(!(e instanceof MDNode))throw new Error(`${this.constructor.name} expects children of type MDNode[] or MDNode, got ${MDUtils.typename(e)}`);this.children=[e]}}toHTML(e){return MDNode.toHTML(this.children,e)}toPlaintext(e){return MDNode.toPlaintext(this.children,e)}_htmlAttributes(){var e="";this.cssClasses.length>0&&(e+=` class="${this.cssClasses.join(" ")}"`),null!==this.cssId&&this.cssId.length>0&&(e+=` id="${this.cssId}"`);var t=[];for(const e in this.cssStyles)t.push(`${e}: ${this.cssStyles[e]};`);t.length>0&&(e+=` style="${MDUtils.escapeHTML(t.join(" "))}"`);for(const t in this.attributes){if("class"==t||"id"==t||"style"==t)continue;const n=`${this.attributes[t]}`,s=MDUtils.scrubAttributeName(t);if(0==s.length)continue;e+=` ${s}="${MDUtils.escapeHTML(n)}"`}return e}_childHTML(e){return this.children.map((t=>t.toHTML(e))).join("")}_simplePairedTagHTML(e,t,n=!1){const s=this.children[0]instanceof MDBlockNode?"\n":"",r=this.children[this.children.length-1]instanceof MDBlockNode?"\n":"",i=this instanceof MDBlockNode?"\n":"";return`<${t}${this._htmlAttributes()}>${s}${this._childHTML(e)}${r}${i}`}visitChildren(e){if(void 0!==this.children&&Array.isArray(this.children))for(const t of this.children)e(t),t.visitChildren(e)}static toHTML(e,t){return e.map((e=>e.toHTML(t)+(e instanceof MDBlockNode?"\n":""))).join("")}static toPlaintext(e,t){return e.map((e=>e.toPlaintext(t))).join("")}}class MDBlockNode extends MDNode{}class MDParagraphNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"p")}}class MDHeaderNode extends MDBlockNode{level;constructor(e,t){if(super(t),"number"!=typeof e||e<1||e>6)throw new Error(`${this.constructor.name} requires header level 1 to 6`);this.level=e}toHTML(e){return this._simplePairedTagHTML(e,`h${this.level}`)}}class MDSubtextNode extends MDBlockNode{toHTML(e){return this.cssClasses.indexOf("subtext")<0&&this.cssClasses.push("subtext"),this._simplePairedTagHTML(e,"div")}}class MDHorizontalRuleNode extends MDBlockNode{toHTML(e){return``}}class MDBlockquoteNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"blockquote",!0)}}class MDUnorderedListNode extends MDBlockNode{constructor(e){super(e)}toHTML(e){return this._simplePairedTagHTML(e,"ul",!0)}}class MDOrderedListNode extends MDBlockNode{startOrdinal;constructor(e,t=null){super(e),this.startOrdinal=t}toHTML(e){return null!==this.startOrdinal&&1!=this.startOrdinal&&(this.attributes.start=this.startOrdinal),this._simplePairedTagHTML(e,"ol",!0)}}class MDListItemNode extends MDBlockNode{ordinal;constructor(e,t=null){super(e),this.ordinal=t}toHTML(e){return this._simplePairedTagHTML(e,"li")}}class MDCodeBlockNode extends MDBlockNode{text;constructor(e){super([]),this.text=e}toHTML(e){return`${MDUtils.escapeHTML(this.text)}\n`}}class MDTableNode extends MDBlockNode{get headerRow(){return this.#E}set headerRow(e){this.#E=e,this.#F()}#E;get bodyRows(){return this.#W}set bodyRows(e){this.#W=e,this.#F()}#W;columnAlignments=[];constructor(e,t){super([e,...t]),this.#E=e,this.#W=t}#F(){this.children=[this.#E,...this.#W]}#O(){this.children.forEach((e=>this.#z(e)))}#z(e){for(const[t,n]of e.children.entries()){const e=t\n`,t+="\n",t+=this.headerRow.toHTML(e)+"\n",t+="\n",t+="\n",t+=MDNode.toHTML(this.bodyRows,e)+"\n",t+="\n",t+="\n"}}class MDTableRowNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"tr",!0)}}class MDTableCellNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"td")}}class MDTableHeaderCellNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"th")}}class MDDefinitionListNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"dl",!0)}}class MDDefinitionListTermNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"dt")}}class MDDefinitionListDefinitionNode extends MDBlockNode{toHTML(e){return this._simplePairedTagHTML(e,"dd")}}class MDFootnoteListNode extends MDBlockNode{toHTML(e){const t=e.footnotes;var n=Object.keys(t);if(0==Object.keys(t).length)return"";const s=e.root.footnoteInstances;var r="";r+='

',r+="
    ";for(const i of n){let n=t[i];if(!n)continue;r+=`
  1. ${MDNode.toHTML(n,e)}`;const o=s[i];if(o)for(const e of o)r+=` ↩︎`;r+="
  2. \n"}return r+="
",r+="
"}toPlaintext(e){const t=e.footnotes;var n=Object.keys(t);if(0==Object.keys(t).length)return"";var s="";for(const r of n){let n=t[r];n&&(s+=`${r}. ${n.toPlaintext(e)}\n`)}return s.trim()}}class MDInlineNode extends MDNode{}class MDTextNode extends MDInlineNode{text;constructor(e){super([]),this.text=e}toHTML(e){return MDUtils.escapeHTML(this.text)}toPlaintext(e){return this.text}}class MDObfuscatedTextNode extends MDTextNode{toHTML(e){return MDUtils.escapeObfuscated(this.text)}}class MDEmphasisNode extends MDInlineNode{toHTML(e){return this._simplePairedTagHTML(e,"em")}}class MDStrongNode extends MDInlineNode{toHTML(e){return this._simplePairedTagHTML(e,"strong")}}class MDStrikethroughNode extends MDInlineNode{toHTML(e){return this._simplePairedTagHTML(e,"s")}}class MDUnderlineNode extends MDInlineNode{toHTML(e){return this._simplePairedTagHTML(e,"u")}}class MDHighlightNode extends MDInlineNode{toHTML(e){return this._simplePairedTagHTML(e,"mark")}}class MDSuperscriptNode extends MDInlineNode{toHTML(e){return this._simplePairedTagHTML(e,"sup")}}class MDSubscriptNode extends MDInlineNode{toHTML(e){return this._simplePairedTagHTML(e,"sub")}}class MDCodeNode extends MDInlineNode{text;constructor(e){super([]),this.text=e}toHTML(e){return`${MDUtils.escapeHTML(this.text)}`}}class MDFootnoteNode extends MDInlineNode{symbol;displaySymbol=null;footnoteId=null;occurrenceId=null;constructor(e,t=null){super([]),this.symbol=e,t&&(this.attributes.title=t)}toHTML(e){return null!==this.differentiator?`${MDUtils.escapeHTML(this.displaySymbol??this.symbol)}`:`\x3c!--FNREF:{${this.symbol}}--\x3e`}}class MDLinkNode extends MDInlineNode{href;constructor(e,t,n=null){super(t),this.href=e,null!==n&&(this.attributes.title=n)}toHTML(e){return`${this._childHTML(e)}`}}class MDReferencedLinkNode extends MDLinkNode{reference;constructor(e,t){super("",t),this.reference=e}toHTML(e){if(""===this.href){this.href=e.urlForReference(this.reference);const t=e.urlTitleForReference(this.reference);t&&(this.attributes.title=t)}return super.toHTML(e)}}class MDImageNode extends MDInlineNode{src;alt;constructor(e,t){super([]),this.src=e,this.alt=t}toHTML(e){var t=`${MDUtils.escapeHTML(this.alt)}`}}class MDReferencedImageNode extends MDImageNode{reference;constructor(e,t=""){super("",t,[]),this.reference=e}toHTML(e){return""===this.src&&(this.src=e.urlForReference(this.reference),this.attributes.title=e.urlTitleForReference(this.reference)),super.toHTML(e)}}class MDAbbreviationNode extends MDInlineNode{abbreviation;get definition(){return this.attributes.title??null}set definition(e){this.attributes.title=e}constructor(e,t){super([]),this.abbreviation=e,this.attributes.title=t}toHTML(e){return`${MDUtils.escapeHTML(this.abbreviation)}`}}class MDLineBreakNode extends MDInlineNode{toHTML(e){return"
"}toPlaintext(e){return"\n"}}class MDHTMLTagNode extends MDInlineNode{tag;constructor(e){super([]),this.tag=e}toHTML(e){return this.tag.toString()}}class MDHTMLTag{original;tagName;isCloser;attributes;constructor(e,t,n,s){this.original=e,this.tagName=t,this.isCloser=n,this.attributes=s}toString(){var e="<";this.isCloser&&(e+="/"),e+=this.tagName;for(const t in this.attributes){const n=MDUtils.scrubAttributeName(t),s=this.attributes[t];if(!0===s)e+=` ${n}`;else{e+=` ${n}="${MDUtils.escapeHTML(s)}"`}}return e+=">"}equals(e){return e instanceof MDHTMLTag&&(e.tagName==this.tagName&&(e.isCloser==this.isCloser&&MDUtils.equal(e.attributes,this.attributes)))}static#j=/[a-z]/i;static#Q=/[a-z0-9]/i;static#Z=/[a-z]/i;static#G=/[a-z0-9-]/i;static#J=/\s/;static fromLineStart(e){var t=!1,n="",s="",r="",i=null,o={},l=null;let a=function(e=!1){s.length>0&&(r.length>0||i?o[s]=e?MDUtils.unescapeHTML(r):r:o[s]=!0),s="",r="",i=null};for(var d=0,c=0;c"==o){l=e.substring(0,c+1);break}if(!this.#Z.exec(o))return null;s+=o}else if(u)d=4;else if("/"==o)a(),d=6;else{if(">"==o){a(),l=e.substring(0,c+1);break}if("="==o)d=5;else{if(!this.#G.exec(o))return null;s+=o}}break;case 4:if("="==o)d=5;else if(u);else if("/"==o)d=6;else{if(">"==o){l=e.substring(0,c+1);break}this.#Z.exec(o)&&(a(),d=3,c--)}break;case 5:if(0==r.length)if(null===i)u||('"'==o||"'"==o?i=o:(i="",c--));else if(o===i)a(""!=i),d=3;else{if(""===i&&("/"==o||">"==o))return null;r+=o}else o===i||""===i&&u?(a(),d=3):r+=o;break;case 6:if(u);else if(">"==o){l=e.substring(0,c+1);break}}}return null===l?null:(a(),new MDHTMLTag(l,n,t,o))}}class MDTagModifier{original;cssClasses=[];cssId=null;cssStyles={};attributes={};static#K=/\.([a-z_\-][a-z0-9_\-]*?)/i;static#V=/#([a-z_\-][a-z0-9_\-]*?)/i;static#X=/([a-z0-9]+?)=([^\s\}]+?)/i;static#Y=/\{([^}]+?)}/i;static#ee=new RegExp("^"+this.#Y.source,"i");static#te=new RegExp("^(.*?)\\s*"+this.#Y.source+"\\s*$","i");static#ne=new RegExp("^"+this.#K.source+"$","i");static#se=new RegExp("^"+this.#V.source+"$","i");static#re=new RegExp("^"+this.#X.source+"$","i");applyTo(e){if(e instanceof MDNode){e.cssClasses=e.cssClasses.concat(this.cssClasses),this.cssId&&(e.cssId=this.cssId);for(const t in this.attributes)e.attributes[t]=this.attributes[t];for(const t in this.cssStyles)e.cssStyles[t]=this.cssStyles[t]}}equals(e){return e instanceof MDTagModifier&&(!!MDUtils.equal(e.cssClasses,this.cssClasses)&&(e.cssId===this.cssId&&!!MDUtils.equal(e.attributes,this.attributes)))}toString(){return this.original}static#ie(e){const t=e.split(";");var n={};for(const e of t){const t=e.split(":");2==t.length&&(n[t[0]]=t[1])}return n}static#oe(e){let t=e.split(/\s+/),n=new MDTagModifier;var s;n.original=`{${e}}`;for(const e of t)if(""!=e.trim())if(s=this.#ne.exec(e))n.cssClasses.push(s[1]);else if(s=this.#se.exec(e))n.cssId=s[1];else{if(!(s=this.#re.exec(e)))return null;"style"==s[1]?n.cssStyles=this.#ie(s[2]):n.attributes[s[1]]=s[2]}return n}static fromLine(e){let t=this.#te.exec(e);return null===t?[e,null]:[t[1],this.#oe(t[2])]}static fromStart(e){let t=this.#ee.exec(e);return null===t?null:this.#oe(t[1])}static strip(e){let t=this.#te.exec(e);return null===t?e:t[1]}}class MDConfig{}class Markdown{static standardReaders=[new MDUnderlinedHeaderReader(0),new MDHashHeaderReader(1),new MDBlockQuoteReader(3),new MDHorizontalRuleReader(9),new MDUnorderedListReader(10),new MDOrderedListReader(11),new MDFencedCodeBlockReader(20),new MDIndentedCodeBlockReader(21),new MDParagraphReader(100),new MDStrongReader(101,10,[0,2]),new MDEmphasisReader(101,15,[5,55]),new MDCodeSpanReader(101,20,[10,60]),new MDImageReader(101,30,15),new MDLinkReader(101,35,20),new MDHTMLTagReader(101,80,30)];static allReaders=[...this.standardReaders,new MDSubtextReader(2),new MDTableReader(40),new MDDefinitionListReader(50),new MDFootnoteReader(60,5,40),new MDAbbreviationReader(70),new MDUnderlineReader(101,5,[9,11]),new MDStrikethroughReader(101,21,[12,50]),new MDHighlightReader(101,23,[13,51]),new MDSuperscriptReader(101,24,[14,54]),new MDReferencedImageReader(91,31,16),new MDReferencedLinkReader(90,36,21),new MDModifierReader(101,90,45)];static standardParser=new Markdown(this.standardReaders);static completeParser=new Markdown(this.allReaders);#le;#a;#d;#c;constructor(e=Markdown.allReaders){this.#le=e;const t=function(t){var n=[];for(const s of e){const e=t(s),r=e instanceof Array?e:[e];for(const e of r)n.push([e,s])}return n.sort(((e,t)=>e[0]-t[0])),n};this.#a=t((e=>e.blockPriority)),this.#d=t((e=>e.tokenizePriority)),this.#c=t((e=>e.substitutePriority))}toHTML(e){const t=e.split(/(?:\n|\r|\r\n)/),n=new MDState(t,this.#a,this.#d,this.#c);for(const e of this.#le)e.preProcess(n);const s=n.readBlocks();for(const e of this.#le)e.postProcess(n,s);return MDNode.toHTML(s,n)}}