Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nlux/markdown

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nlux/markdown - npm Package Compare versions

Comparing version 2.3.7 to 2.3.8

2

cjs/markdown.js

@@ -1,1 +0,1 @@

"use strict";const e=e=>/^[ \t]{2}\n$/m.test(e),t=e=>/^[ \t\n]{1}$/.test(e),n=["Root","Paragraph","LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Blockquote","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","OrderedList","UnorderedList","Code","CodeBlock","HorizontalRule","Link","Image"],s=["^\\[$","^\\[[^\\]]+$","^\\[[^\\]]+\\]$","^\\[[^\\]]+\\]\\($","^\\[[^\\]]+\\]\\([^\\)]*$"],r={shouldOpen:/\[([^\]]+)\]\(([^\)]*)\)/,canOpen:e=>s.some((t=>new RegExp(t).test(e))),shouldClose:()=>!0,canClose:()=>!1},i=(e,t)=>n=>{const s=o.get(e);if(!s)throw new Error(`No sequence parsers found for markdown element ${e}`);const r=s[t];return r instanceof RegExp?r.test(n):r(n)},o=new Map;o.set("Code",{shouldOpen:/^`[^`]$/,canOpen:/^`$/,shouldClose:/^`[\s\S]+$/,canClose:/^`$/}),o.set("CodeBlock",{shouldOpen:/^```.*\n$/,canOpen:/^`{1,3}.*$/,shouldClose:/^\n?```[\s\S]+$/,canClose:/^\n$|^\n?`{1,3}$/}),o.set("Heading1",{shouldOpen:/^\n*#{1} $/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading2",{shouldOpen:/^\n*#{2} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading3",{shouldOpen:/^\n*#{3} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading4",{shouldOpen:/^\n*#{4} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading5",{shouldOpen:/^\n*#{5} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading6",{shouldOpen:/^\n*#{6} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("BoldAsterisk",{canOpen:/^\*{1,2}$/,shouldOpen:/^\*{2}[^(\s\n)]$/,canClose:/^\*{1,2}$/,shouldClose:/^\*{2}[\s\S]$/}),o.set("BoldUnderscore",{canOpen:/^_{1,2}$/,shouldOpen:/^_{2}[^(\s\n)]$/,canClose:/^_{1,2}$/,shouldClose:/^_{2}[\s\S]$/}),o.set("ItalicAsterisk",{canOpen:/^\*$/,shouldOpen:/^\*[^(\*\s\n)]$/,canClose:/^\*$/,shouldClose:/^\*[\s\S]$/}),o.set("ItalicUnderscore",{canOpen:/^_$/,shouldOpen:/^_[^(_\s\n)]$/,canClose:/^_$/,shouldClose:/^_[\s\S]$/}),o.set("Link",r),o.set("LineBreak",{shouldOpen:()=>!1,canOpen:()=>!1,shouldClose:()=>!1,canClose:()=>!1}),o.set("Root",{canOpen:()=>!1,shouldOpen:()=>!1,canClose:()=>!1,shouldClose:()=>!1}),o.set("Paragraph",{canOpen:/^\n+$/,shouldOpen:/^\n{2,}$/,canClose:/^\n$/,shouldClose:/^\n{2,}$/}),o.set("Blockquote",{shouldOpen:/^$/,canOpen:/^>$/,shouldClose:/^$/,canClose:/^$/}),o.set("OrderedList",{shouldOpen:/^$/,canOpen:/^\d+\. $/,shouldClose:/^\n$/,canClose:/^\n$/}),o.set("UnorderedList",{shouldOpen:/^$/,canOpen:/^\* $/,shouldClose:/^\n$/,canClose:/^\n$/}),o.set("HorizontalRule",{shouldOpen:/^$/,canOpen:/^---$/,shouldClose:/^$/,canClose:/^$/}),o.set("Image",{shouldOpen:/^$/,canOpen:/^!\[.*\]\(.*\)$/,shouldClose:/^$/,canClose:/^$/});var a=Object.defineProperty,l=(e,t,n)=>((e,t,n)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class d{constructor(e,t="none",s="none"){l(this,"__canLeadToClosingMarkdown",!1),l(this,"__latestSequenceProcessed",!1),l(this,"__markdownElement"),l(this,"__markdownThatShouldBeNested"),l(this,"__markdownThatShouldBeRenderedAtParentLevel"),l(this,"__possibleNestedMarkdownElements"),l(this,"__possibleYieldingMarkdownElements"),l(this,"__potentialNestedMarkdownElements",[]),l(this,"__potentialYieldingMarkdownElements",[]),l(this,"__sequence",""),l(this,"__shouldCloseCurrentMarkdown",!1),this.__markdownElement=e,this.__possibleNestedMarkdownElements="all"===t?n:"none"===t?[]:t,this.__possibleYieldingMarkdownElements="none"===s?[]:s}get canLeadToClosingOrNewMarkdown(){return this.__latestSequenceProcessed||this.processSequence(),this.__canLeadToClosingMarkdown||this.__potentialYieldingMarkdownElements.length>0||this.__potentialNestedMarkdownElements.length>0}get elementToCreateAtParentLevel(){return this.__latestSequenceProcessed||this.processSequence(),this.__markdownThatShouldBeRenderedAtParentLevel}get nestedElementToCreate(){return this.__latestSequenceProcessed||this.processSequence(),this.__markdownThatShouldBeNested}get sequence(){return this.__sequence}get shouldCloseCurrentMarkdown(){return this.__latestSequenceProcessed||this.processSequence(),this.__shouldCloseCurrentMarkdown}appendCharacter(e){this.__sequence+=e,this.__latestSequenceProcessed=!1}reset(){this.__sequence="",this.__latestSequenceProcessed=!1,this.__canLeadToClosingMarkdown=!1,this.__potentialYieldingMarkdownElements=[],this.__potentialNestedMarkdownElements=[],this.__shouldCloseCurrentMarkdown=!1,this.__markdownThatShouldBeRenderedAtParentLevel=void 0,this.__markdownThatShouldBeNested=void 0}processSequence(){if(this.__latestSequenceProcessed)return;const e=this.__sequence;this.__canLeadToClosingMarkdown=i(this.__markdownElement,"canClose")(e),this.__potentialYieldingMarkdownElements=this.__possibleYieldingMarkdownElements.filter((t=>i(t,"canOpen")(e))),this.__potentialNestedMarkdownElements=this.__possibleNestedMarkdownElements.filter((t=>i(t,"canOpen")(e))),this.__shouldCloseCurrentMarkdown=i(this.__markdownElement,"shouldClose")(e),this.__markdownThatShouldBeRenderedAtParentLevel=this.__possibleYieldingMarkdownElements.find((t=>i(t,"shouldOpen")(e))),this.__markdownThatShouldBeNested=this.__possibleNestedMarkdownElements.find((t=>i(t,"shouldOpen")(e)))}}var c=Object.defineProperty,h=(e,t,n)=>((e,t,n)=>t in e?c(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class u{constructor(e,t,n,s,r){h(this,"__parent"),h(this,"__element"),h(this,"__initialContent"),h(this,"__initialized",!1),h(this,"__last3Characters",""),h(this,"__markdownElementName"),h(this,"__openingSequence"),h(this,"__options",{}),h(this,"__parsingChild"),h(this,"__sequenceParser"),h(this,"__yielded",!1),this.__markdownElementName=t,this.__parent=e??void 0,this.__options=r||{},this.__openingSequence=n??void 0,this.__initialContent="Root"!==t?s??void 0:void 0}get domElement(){return this.__element}get markdownElementName(){return this.__markdownElementName}get parsingChild(){return this.__parsingChild}get removeWhenEmpty(){return!1}get sequenceParser(){if(this.yielded)throw new Error("Cannot access sequence parser of a yielded processor");return this.__sequenceParser||(this.__sequenceParser=new d(this.__markdownElementName,this.nestedMarkdownElements,this.yieldingMarkdownElements)),this.__sequenceParser}get yielded(){return this.__yielded}get initialContent(){return this.__initialContent}get last3Characters(){return this.__last3Characters}get markdownProcessorOptions(){return this.__options}get syntaxHighlighter(){return this.__options.syntaxHighlighter}get htmlSanitizer(){return this.__options.htmlSanitizer??(e=>e)}init(){if(!this.__initialized&&(this.__initialized=!0,"Root"!==this.__markdownElementName?this.__element=this.createElement(this.__openingSequence):this.__element=void 0,this.__initialContent))for(let e=0;e<this.__initialContent.length;e++){const t=this.__initialContent[e];this.processCharacter(t)}}parsingChildYielded(e,t,n,s){this.__parsingChild===e&&(this.__parsingChild=void 0),t&&this.createAndAppendMarkdown(t,n),s&&this.processCharacter(s)}preProcessCharacter(e){this.__last3Characters.length<3?this.__last3Characters+=e:this.__last3Characters=this.__last3Characters.slice(1)+e}purgeSequence(){this.__parsingChild&&this.__parsingChild.purgeSequence(),this.__sequenceParser?.sequence&&(this.__element?.append(this.__sequenceParser.sequence),this.__sequenceParser.reset())}resetSequenceParser(){this.__sequenceParser?.reset(),this.__sequenceParser=new d(this.__markdownElementName,this.nestedMarkdownElements,this.yieldingMarkdownElements)}setParsingChild(e){if(this.__parsingChild&&"Root"!==this.__markdownElementName)throw new Error("Cannot set spawn child while parsing child");this.__parsingChild=e,e.domElement&&this.domElement?.append(e.domElement),e.__parent=this}yield(e,t){if(this.yielded)return;const n=this.__sequenceParser&&!this.__sequenceParser?.shouldCloseCurrentMarkdown?this.__sequenceParser?.sequence:void 0;if(this.__yielded=!0,this.__sequenceParser=void 0,this.__parsingChild&&(this.__parsingChild.yield(),this.__parsingChild=void 0),this.__element){const e=this.htmlSanitizer,t=this.__element.innerHTML.trim();this.__element.innerHTML=e?e(t):t,this.removeWhenEmpty&&""===this.__element.innerHTML&&this.__element.remove(),this.__element=void 0}this.__parent&&(this.__parent.parsingChildYielded(this,e,n,t),this.__parent=void 0)}}class p extends u{constructor(e,t,n,s,r){super(e,t,n,s,r)}createAndAppendMarkdown(e,t){B(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}processCharacter(t){if(this.preProcessCharacter(t),this.parsingChild)return void this.parsingChild.processCharacter(t);const{sequenceDiscarded:n,discardedSequence:s,yielded:r}=this.processSequence(t);if(!r)if(e(this.last3Characters)&&(this.nestedMarkdownElements.includes("LineBreak")||"all"===this.nestedMarkdownElements)){if(this.domElement?.innerHTML){const e=this.markdownProcessorOptions?.htmlSanitizer,t=this.domElement.innerHTML.trim();this.domElement.innerHTML=e?e(t):t}this.createAndAppendMarkdown("LineBreak"),this.sequenceParser.reset()}else if(n){this.resetSequenceParser();this.processSequence(t).sequenceDiscarded?(this.sequenceParser.reset(),s&&this.domElement?.append(s)):s&&s.length>1&&this.domElement?.append(s.slice(0,-1))}}processSequence(e){if(this.sequenceParser.appendCharacter(e),this.sequenceParser.shouldCloseCurrentMarkdown)return this.yield(void 0,e),{sequenceDiscarded:!1,yielded:!0};if(this.sequenceParser.elementToCreateAtParentLevel)return this.yield(this.sequenceParser.elementToCreateAtParentLevel,e),{sequenceDiscarded:!1,yielded:!0};const t=this.sequenceParser.nestedElementToCreate;if(t)return B(t,this,this.sequenceParser.sequence,e,this.markdownProcessorOptions),this.sequenceParser.reset(),{sequenceDiscarded:!1};if(this.sequenceParser.canLeadToClosingOrNewMarkdown)return{sequenceDiscarded:!1};const n=this.sequenceParser.sequence;return this.sequenceParser.reset(),{sequenceDiscarded:!0,discardedSequence:n}}}class m extends p{constructor(e,t,n,s){super(e,"BoldAsterisk",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("strong")}}class _ extends p{constructor(e,t,n,s){super(e,"BoldUnderscore",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("strong")}}class g extends p{constructor(e,t,n,s){super(e,"Code",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("code")}}var C=Object.defineProperty,k=(e,t,n)=>((e,t,n)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class w extends p{constructor(e,n,s,r={}){super(e,"CodeBlock",n??null,!s||t(s)?null:s,r),k(this,"codeContainer",null),k(this,"currentLineContainer",null),k(this,"language"),this.language=this.extractLanguageFromOpeningSequence(n)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return"none"}get yieldingMarkdownElements(){return"none"}createElement(){const e=document.createElement("div");return e.classList.add("code-block"),this.codeContainer=document.createElement("pre"),e.append(this.codeContainer),this.language&&(this.codeContainer.dataset.language=this.language),e}processCharacter(e){this.preProcessCharacter(e);const{sequenceDiscarded:t,discardedSequence:n,yielded:s}=this.processSequence(e);if(s)return;if(!t)return;if(n&&n.length>1&&this.codeContainer)for(let e=0;e<n.length-1;e++)this.appendCharacterToCodeBlock(n[e]);this.resetSequenceParser();this.processSequence(e).sequenceDiscarded&&(this.sequenceParser.reset(),this.appendCharacterToCodeBlock(e))}yield(e,t){if(this.highlightCurrentLine(),!1!==this.markdownProcessorOptions.showCodeBlockCopyButton){const e=this.__parent?.domElement;e&&(e.querySelectorAll(".code-block").forEach((e=>{if(!e.querySelector("pre"))return;if(e.previousElementSibling?.classList.contains("nlux-comp-copyButton"))return;const t="Copy code block to clipboard",n=document.createElement("button");n.classList.add("nlux-comp-copyButton"),n.setAttribute("aria-label",t),n.setAttribute("title",t);const s=document.createElement("span");s.classList.add("icon-copy"),n.appendChild(s),e.insertAdjacentElement("beforebegin",n)})),(e=>{e.querySelectorAll(".nlux-comp-copyButton").forEach((e=>{if(!(e instanceof HTMLButtonElement))return;if("true"===e.dataset.clickListenerSet)return;let t=!1;const n=e.nextElementSibling;e.addEventListener("click",(()=>{if(t||!n)return;const s=n.innerText;navigator.clipboard.writeText(s??""),t=!0,e.classList.add("clicked"),setTimeout((()=>{t=!1,e.classList.remove("clicked")}),1e3)})),e.dataset.clickListenerSet="true"}))})(e))}super.yield(e,t),this.codeContainer=null,this.currentLineContainer=null}appendCharacterToCodeBlock(e){if(this.codeContainer)if("\n"!==e)this.currentLineContainer||(this.currentLineContainer=document.createElement("div"),this.codeContainer.append(this.currentLineContainer)),this.currentLineContainer.append(e);else if(this.currentLineContainer)this.currentLineContainer.innerHTML?this.highlightCurrentLine():this.currentLineContainer.replaceChildren(" "),this.currentLineContainer=null;else if(this.codeContainer.innerHTML){const e=document.createElement("div");e.replaceChildren(" "),this.codeContainer.append(e)}}extractLanguageFromOpeningSequence(e){if(!e)return;const t=e.match(/```(\w+)/);return Array.isArray(t)&&t.length>1?t[1]:void 0}highlightCurrentLine(){if(!this.domElement||!this.currentLineContainer)return;const e=this.currentLineContainer.innerText??this.currentLineContainer.innerHTML;if(this.syntaxHighlighter&&this.codeContainer&&e){const t=this.codeContainer.dataset.language;if(t){const n=this.syntaxHighlighter.createHighlighter({language:t,colorMode:"dark"}),s=this.syntaxHighlighter.highlightingClass(t);this.codeContainer.classList.contains(s)||this.codeContainer.classList.add(s);const r=n(e,t);this.currentLineContainer.innerHTML=this.htmlSanitizer?this.htmlSanitizer(r):r}}}}var E=Object.defineProperty,q=(e,t,n)=>((e,t,n)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class P extends p{constructor(e,t,n,s,r){super(t,L(e),n??null,s??null,r??null),q(this,"__headingLevel"),this.__headingLevel=e}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("h"+this.__headingLevel)}processCharacter(e){if(this.preProcessCharacter(e),this.parsingChild)return void this.parsingChild.processCharacter(e);const{sequenceDiscarded:t,discardedSequence:n,yielded:s}=this.processSequence(e);s||t&&n&&(/^\s+$/.test(n)||this.domElement?.append(n))}}const L=e=>{switch(e){case 1:return"Heading1";case 2:return"Heading2";case 3:return"Heading3";case 4:return"Heading4";case 5:return"Heading5";case 6:return"Heading6"}};class f extends p{constructor(e,t,n,s){super(e,"ItalicAsterisk",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("em")}}class v extends p{constructor(e,t,n,s){super(e,"ItalicUnderscore",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("em")}}class M extends u{constructor(e,t,n){super(e,"LineBreak",t??null,n??null,null)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return"none"}get yieldingMarkdownElements(){return"none"}createAndAppendMarkdown(e,t){B(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}createElement(){return document.createElement("br")}init(){super.init()}processCharacter(e){this.yield(void 0,e)}}var S=Object.defineProperty,y=(e,t,n)=>((e,t,n)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class $ extends p{constructor(e,t,n,s={}){super(e,"Link",t??null,n??null,s),y(this,"linkContentProcessed","")}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code"]}get yieldingMarkdownElements(){return["Paragraph","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code"]}createElement(e){const t=/\[(.*[^\]])\]\((.*[^\)])\)/.exec(e),n=document.createElement("a");return n.textContent="",t&&t.length>=3&&t[2]&&(n.href=t[2]),"self"!==this.markdownProcessorOptions.markdownLinkTarget&&(n.target="_blank"),n}processCharacter(e){super.processCharacter(e),this.yielded||(this.linkContentProcessed+=e)}processSequence(e){if(!this.initialContent||this.initialContent===this.linkContentProcessed)return this.yield(void 0,e),{yielded:!0,sequenceDiscarded:!0,discardedSequence:e};this.sequenceParser.appendCharacter(e);const t=this.sequenceParser.nestedElementToCreate;if(t)return B(t,this,this.sequenceParser.sequence,e,this.markdownProcessorOptions),this.sequenceParser.reset(),{sequenceDiscarded:!1};if(this.sequenceParser.canLeadToClosingOrNewMarkdown)return{sequenceDiscarded:!1};const n=this.sequenceParser.sequence;return this.sequenceParser.reset(),{sequenceDiscarded:!0,discardedSequence:n}}}class O extends p{constructor(e,t,n,s){super(e,"Paragraph",t??null,n??null,s??null)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return["LineBreak","Blockquote","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get removeWhenEmpty(){return!0}get yieldingMarkdownElements(){return["Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","CodeBlock","UnorderedList","OrderedList","HorizontalRule","Image"]}createElement(){return document.createElement("p")}}const B=(e,t,n,s,r)=>{if("Paragraph"===e){const e=new O(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("LineBreak"===e){const e=new M(t,n,s);return e.init(),void t.setParsingChild(e)}if("Link"===e){const e=/\[([^\]]+)\]\(([^\)]*)\)/.exec(n),s=e&&e.length>=3?e[1]:"",i=new $(t,n,s,r);return i.init(),void t.setParsingChild(i)}if("Heading1"===e||"Heading2"===e||"Heading3"===e||"Heading4"===e||"Heading5"===e||"Heading6"===e){const i=parseInt(e[e.length-1]);if(Number.isNaN(i)||!Number.isFinite(i)||i<1||i>6)throw new Error("Invalid heading level");const o=new P(i,t,n,s,r);return o.init(),void t.setParsingChild(o)}if("Code"===e){const e=new g(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("CodeBlock"===e){const e=new w(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("BoldAsterisk"===e){const e=new m(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("BoldUnderscore"===e){const e=new _(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("ItalicAsterisk"===e){const e=new f(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("ItalicUnderscore"===e){const e=new v(t,n,s,r);return e.init(),void t.setParsingChild(e)}throw new Error("Unable to create child processor for markdown element "+e)};var A=Object.defineProperty,H=(e,t,n)=>((e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class b extends u{constructor(e,t,n){super(null,"Root",t??null,null,n??null),H(this,"__rootDomElement"),this.__rootDomElement=e}get canExistAtRootLevel(){return!1}get domElement(){return this.__rootDomElement}get nestedMarkdownElements(){return"all"}get yieldingMarkdownElements(){return"none"}complete(){var e;this.parsingChild&&this.parsingChild.purgeSequence(),this.purgeSequence(),e=this.domElement?.lastChild,e instanceof HTMLElement&&"BR"===e.tagName&&this.domElement?.lastChild?.remove()}createAndAppendMarkdown(e,t){B(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}createElement(){throw new Error("Root cannot create an element")}processCharacter(e){this.preProcessCharacter(e),this.parsingChild?this.parsingChild.processCharacter(e):(this.sequenceParser.appendCharacter(e),this.processSequence(e))}yield(){super.yield(),this.__rootDomElement=void 0}processSequence(n){if(this.sequenceParser.shouldCloseCurrentMarkdown)return;const s=this.sequenceParser.nestedElementToCreate;if(s){B(s,this,this.sequenceParser.sequence,n,this.markdownProcessorOptions);const e=this.parsingChild;return e&&!e.canExistAtRootLevel&&(B("Paragraph",this,void 0,void 0,this.markdownProcessorOptions),this.parsingChild?.setParsingChild(e)),void this.sequenceParser.reset()}this.sequenceParser.canLeadToClosingOrNewMarkdown||(e(this.last3Characters)?this.createAndAppendMarkdown("LineBreak"):n&&!t(n)&&(B("Paragraph",this,void 0,this.sequenceParser.sequence,this.markdownProcessorOptions),this.sequenceParser.reset()))}}const x=10;exports.createMarkdownStreamParser=(e,t)=>{const n=((e,t)=>{const{syntaxHighlighter:n,htmlSanitizer:s,streamingAnimationSpeed:r=x,markdownLinkTarget:i,showCodeBlockCopyButton:o,skipStreamingAnimation:a=!1,onComplete:l}=t||{},d=new b(e,void 0,{syntaxHighlighter:n,htmlSanitizer:s,markdownLinkTarget:i,showCodeBlockCopyButton:o}),c=[];let h=0,u=!1,p="idle";const m=a?0:Math.max(r,0),_=r>0?r:20,g=Math.ceil(2e3/_),C=()=>{if("closed"===p)return;if("idle"===p&&(p="processing"),0===c.length)return void(!1===u&&h<g?(p="waitingForMoreCharacters",h+=1,setTimeout(C,_)):(d.processCharacter("\n"),d.complete(),d.yield(),t?.htmlSanitizer&&(e.innerHTML=t.htmlSanitizer(e.innerHTML)),p="closed",l?.()));p="processing",h=0;const n=c.shift();n&&d.processCharacter(n),setTimeout(C,m)};return{next:e=>{if(e){for(let t=0;t<e.length;t++)c.push(e[t]);"idle"===p&&C()}},complete:()=>{u=!0},error:()=>{}}})(e,{syntaxHighlighter:t?.syntaxHighlighter,htmlSanitizer:t?.htmlSanitizer,markdownLinkTarget:t?.markdownLinkTarget,showCodeBlockCopyButton:t?.showCodeBlockCopyButton,skipStreamingAnimation:t?.skipStreamingAnimation,streamingAnimationSpeed:t?.streamingAnimationSpeed,onComplete:t?.onComplete});return{next(e){n.next(e)},complete(){n.complete()}}};
"use strict";const e=e=>{"string"!=typeof e?e&&"function"==typeof e.toString?console.warn(`[nlux] ${e.toString()}`):console.warn("[nlux]"):console.warn(`[nlux] ${e}`)};function t(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let n={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function s(e){n=e}var r=Object.defineProperty,i=(e,t,n)=>((e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class l{constructor(e){i(this,"options"),this.options=e||n}postprocess(e){return e}preprocess(e){return e}processAllTokens(e){return e}}i(l,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));const o=/[&<>"']/,a=new RegExp(o.source,"g"),c=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,h=new RegExp(c.source,"g"),p={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},u=e=>p[e];function g(e,t){if(t){if(o.test(e))return e.replace(a,u)}else if(c.test(e))return e.replace(h,u);return e}const k=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function f(e){return e.replace(k,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const d=/(^|[^\[])\^/g;function x(e,t){let n="string"==typeof e?e:e.source;t=t||"";const s={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(d,"$1"),n=n.replace(e,r),s},getRegex:()=>new RegExp(n,t)};return s}function m(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const b={exec:()=>null};function w(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function y(e,t,n){const s=e.length;if(0===s)return"";let r=0;for(;r<s;){const i=e.charAt(s-r-1);if(i!==t||n){if(i===t||!n)break;r++}else r++}return e.slice(0,s-r)}const $=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,z=/(?:[*+-]|\d{1,9}[.)])/,T=x(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,z).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),S=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,A=/(?!\s*\])(?:\\.|[^\[\]\\])+/,R=x(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",A).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),_=x(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,z).getRegex(),v="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",E=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,L=x("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",E).replace("tag",v).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),I=x(S).replace("hr",$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",v).getRegex(),C={blockquote:x(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",I).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:R,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:$,html:L,lheading:T,list:_,newline:/^(?: *(?:\n|$))+/,paragraph:I,table:b,text:/^[^\n]+/},q=x("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",v).getRegex(),B={...C,table:q,paragraph:x(S).replace("hr",$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",q).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",v).getRegex()},P={...C,html:x("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",E).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:b,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:x(S).replace("hr",$).replace("heading"," *#{1,6} *[^\n]").replace("lheading",T).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Z=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,M=/^( {2,}|\\)\n(?!\s*$)/,H="\\p{P}\\p{S}",O=x(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,H).getRegex(),Q=x(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,H).getRegex(),j=x("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,H).getRegex(),D=x("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,H).getRegex(),W=x(/\\([punct])/,"gu").replace(/punct/g,H).getRegex(),F=x(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),N=x(E).replace("(?:--\x3e|$)","--\x3e").getRegex(),U=x("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",N).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),X=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,G=x(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",X).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),J=x(/^!?\[(label)\]\[(ref)\]/).replace("label",X).replace("ref",A).getRegex(),K=x(/^!?\[(ref)\](?:\[\])?/).replace("ref",A).getRegex(),V={_backpedal:b,anyPunctuation:W,autolink:F,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:M,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:b,emStrongLDelim:Q,emStrongRDelimAst:j,emStrongRDelimUnd:D,escape:Z,link:G,nolink:K,punctuation:O,reflink:J,reflinkSearch:x("reflink|nolink(?!\\()","g").replace("reflink",J).replace("nolink",K).getRegex(),tag:U,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:b},Y={...V,link:x(/^!?\[(label)\]\((.*?)\)/).replace("label",X).getRegex(),reflink:x(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",X).getRegex()},ee={...V,escape:x(Z).replace("])","~|])").getRegex(),url:x(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},te={...ee,br:x(M).replace("{2,}","*").getRegex(),text:x(ee.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ne={normal:C,gfm:B,pedantic:P},se={normal:V,gfm:ee,breaks:te,pedantic:Y};var re=Object.defineProperty,ie=(e,t,n)=>((e,t,n)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);function le(e,t,n,s){const r=t.href,i=t.title?g(t.title):null,l=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:n,href:r,title:i,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,e}return{type:"image",raw:n,href:r,title:i,text:g(l)}}class oe{constructor(e){ie(this,"lexer"),ie(this,"options"),ie(this,"rules"),this.options=e||n}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=g(t[1]),n="mailto:"+e):(e=g(t[1]),n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=t[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1");e=y(e.replace(/^ *>[ \t]?/gm,""),"\n");const n=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(e);return this.lexer.state.top=n,{type:"blockquote",raw:t[0],tokens:s,text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:y(e,"\n")}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const n=/[^ ]/.test(e),s=/^ /.test(e)&&/ $/.test(e);return n&&s&&(e=e.substring(1,e.length-1)),e=g(e,!0),{type:"codespan",raw:t[0],text:e}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:s}}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s)return;if(s[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const n=[...s[0]].length-1;let r,i,l=n,o=0;const a="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,t=t.slice(-1*e.length+n);null!=(s=a.exec(t));){if(r=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!r)continue;if(i=[...r].length,s[3]||s[4]){l+=i;continue}if((s[5]||s[6])&&n%3&&!((n+i)%3)){o+=i;continue}if(l-=i,l>0)continue;i=Math.min(i,i+l+o);const t=[...s[0]][0].length,a=e.slice(0,n+s.index+t+i);if(Math.min(n,i)%2){const e=a.slice(1,-1);return{type:"em",raw:a,text:e,tokens:this.lexer.inlineTokens(e)}}const c=a.slice(2,-2);return{type:"strong",raw:a,text:c,tokens:this.lexer.inlineTokens(c)}}}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:g(t[1])}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const s=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=y(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:g(t[0]),{type:"text",raw:t[0],text:e}}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}link(e){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=y(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return-1}(t[2],"()");if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],s="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);e&&(n=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),/^</.test(n)&&(n=this.options.pedantic&&!/>$/.test(e)?n.slice(1):n.slice(1,-1)),le(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:s?s.replace(this.rules.inline.anyPunctuation,"$1"):s},t[0],this.lexer)}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");const i=new RegExp(`^( {0,3}${n})((?:[\t ][^\\n]*)?(?:\\n|$))`);let l="",o="",a=!1;for(;e;){let n=!1;if(!(t=i.exec(e)))break;if(this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let s=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),c=e.split("\n",1)[0],h=0;this.options.pedantic?(h=2,o=s.trimStart()):(h=t[2].search(/[^ ]/),h=h>4?1:h,o=s.slice(h),h+=t[1].length);let p=!1;if(!s&&/^ *$/.test(c)&&(l+=c+"\n",e=e.substring(c.length+1),n=!0),!n){const t=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),n=new RegExp(`^ {0,${Math.min(3,h-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),r=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:\`\`\`|~~~)`),i=new RegExp(`^ {0,${Math.min(3,h-1)}}#`);for(;e;){const a=e.split("\n",1)[0];if(c=a,this.options.pedantic&&(c=c.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),r.test(c))break;if(i.test(c))break;if(t.test(c))break;if(n.test(e))break;if(c.search(/[^ ]/)>=h||!c.trim())o+="\n"+c.slice(h);else{if(p)break;if(s.search(/[^ ]/)>=4)break;if(r.test(s))break;if(i.test(s))break;if(n.test(s))break;o+="\n"+c}p||c.trim()||(p=!0),l+=a+"\n",e=e.substring(a.length+1),s=c.slice(h)}}r.loose||(a?r.loose=!0:/\n *\n *$/.test(l)&&(a=!0));let u,g=null;this.options.gfm&&(g=/^\[[ xX]\] /.exec(o),g&&(u="[ ] "!==g[0],o=o.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:l,task:!!g,checked:u,loose:!1,text:o,tokens:[]}),r.raw+=l}r.items[r.items.length-1].raw=l.trimEnd(),r.items[r.items.length-1].text=o.trimEnd(),r.raw=r.raw.trimEnd();for(let e=0;e<r.items.length;e++)if(this.lexer.state.top=!1,r.items[e].tokens=this.lexer.blockTokens(r.items[e].text,[]),!r.loose){const t=r.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));r.loose=n}if(r.loose)for(let e=0;e<r.items.length;e++)r.items[e].loose=!0;return r}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){const e=t[(n[2]||n[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return le(n,e,n[0],this.lexer)}}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const n=w(t[1]),s=t[2].replace(/^\||\| *$/g,"").split("|"),r=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],i={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(const e of s)/^ *-+: *$/.test(e)?i.align.push("right"):/^ *:-+: *$/.test(e)?i.align.push("center"):/^ *:-+ *$/.test(e)?i.align.push("left"):i.align.push(null);for(const e of n)i.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of r)i.rows.push(w(e,i.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return i}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=g(t[0]),n="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=g(t[0]),n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}}var ae=Object.defineProperty,ce=(e,t,n)=>((e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class he{constructor(e){ce(this,"options"),ce(this,"state"),ce(this,"tokens"),ce(this,"inlineQueue"),ce(this,"tokenizer"),this.tokens=[],this.tokens.links=Object.create(null),this.options=e||n,this.options.tokenizer=this.options.tokenizer||new oe,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={block:ne.normal,inline:se.normal};this.options.pedantic?(t.block=ne.pedantic,t.inline=se.pedantic):this.options.gfm&&(t.block=ne.gfm,this.options.breaks?t.inline=se.breaks:t.inline=se.gfm),this.tokenizer.rules=t}static get rules(){return{block:ne,inline:se}}static lex(e,t){return new he(t).lex(e)}static lexInline(e,t){return new he(t).inlineTokens(e)}blockTokens(e,t=[]){let n,s,r,i;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,n)=>t+" ".repeat(n.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.space(e))e=e.substring(n.raw.length),1===n.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(n);else if(n=this.tokenizer.code(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?t.push(n):(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.fences(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.heading(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.hr(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.blockquote(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.list(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.html(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.def(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title}):(s.raw+="\n"+n.raw,s.text+="\n"+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.table(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.lheading(e))e=e.substring(n.raw.length),t.push(n);else{if(r=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startBlock.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(this.state.top&&(n=this.tokenizer.paragraph(r)))s=t[t.length-1],i&&"paragraph"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n),i=r.length!==e.length,e=e.substring(n.raw.length);else if(n=this.tokenizer.text(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,s,r,i,l,o,a=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(i=this.tokenizer.rules.inline.reflinkSearch.exec(a));)e.includes(i[0].slice(i[0].lastIndexOf("[")+1,-1))&&(a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(i=this.tokenizer.rules.inline.blockSkip.exec(a));)a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(i=this.tokenizer.rules.inline.anyPunctuation.exec(a));)a=a.slice(0,i.index)+"++"+a.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(l||(o=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.escape(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.tag(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.link(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.emStrong(e,a,o))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.codespan(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.br(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.del(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.autolink(e))e=e.substring(n.raw.length),t.push(n);else if(this.state.inLink||!(n=this.tokenizer.url(e))){if(r=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startInline.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(r))e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(o=n.raw.slice(-1)),l=!0,s=t[t.length-1],s&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(n.raw.length),t.push(n);return t}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}}var pe=Object.defineProperty,ue=(e,t,n)=>((e,t,n)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class ge{constructor(e){ue(this,"options"),this.options=e||n}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}br(){return"<br>"}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}code(e,t,n){const s=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",s?'<pre><code class="language-'+g(s)+'">'+(n?e:g(e,!0))+"</code></pre>\n":"<pre><code>"+(n?e:g(e,!0))+"</code></pre>\n"}codespan(e){return`<code>${e}</code>`}del(e){return`<del>${e}</del>`}em(e){return`<em>${e}</em>`}heading(e,t,n){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}html(e,t){return e}image(e,t,n){const s=m(e);if(null===s)return n;let r=`<img src="${e=s}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">",r}link(e,t,n){const s=m(e);if(null===s)return n;let r='<a href="'+(e=s)+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>",r}list(e,t,n){const s=t?"ol":"ul";return"<"+s+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"</"+s+">\n"}listitem(e,t,n){return`<li>${e}</li>\n`}paragraph(e){return`<p>${e}</p>\n`}strong(e){return`<strong>${e}</strong>`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>\n`}tablerow(e){return`<tr>\n${e}</tr>\n`}text(e){return e}}class ke{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}var fe=Object.defineProperty,de=(e,t,n)=>((e,t,n)=>t in e?fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class xe{constructor(e){de(this,"options"),de(this,"renderer"),de(this,"textRenderer"),this.options=e||n,this.options.renderer=this.options.renderer||new ge,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ke}static parse(e,t){return new xe(t).parse(e)}static parseInline(e,t){return new xe(t).parseInline(e)}parse(e,t=!0){let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=r,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}switch(r.type){case"space":continue;case"hr":n+=this.renderer.hr();continue;case"heading":{const e=r;n+=this.renderer.heading(this.parseInline(e.tokens),e.depth,f(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=r;n+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=r;let t="",s="";for(let t=0;t<e.header.length;t++)s+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(s);let i="";for(let t=0;t<e.rows.length;t++){const n=e.rows[t];s="";for(let t=0;t<n.length;t++)s+=this.renderer.tablecell(this.parseInline(n[t].tokens),{header:!1,align:e.align[t]});i+=this.renderer.tablerow(s)}n+=this.renderer.table(t,i);continue}case"blockquote":{const e=r,t=this.parse(e.tokens);n+=this.renderer.blockquote(t);continue}case"list":{const e=r,t=e.ordered,s=e.start,i=e.loose;let l="";for(let t=0;t<e.items.length;t++){const n=e.items[t],s=n.checked,r=n.task;let o="";if(n.task){const e=this.renderer.checkbox(!!s);i?n.tokens.length>0&&"paragraph"===n.tokens[0].type?(n.tokens[0].text=e+" "+n.tokens[0].text,n.tokens[0].tokens&&n.tokens[0].tokens.length>0&&"text"===n.tokens[0].tokens[0].type&&(n.tokens[0].tokens[0].text=e+" "+n.tokens[0].tokens[0].text)):n.tokens.unshift({type:"text",text:e+" "}):o+=e+" "}o+=this.parse(n.tokens,i),l+=this.renderer.listitem(o,r,!!s)}n+=this.renderer.list(l,t,s);continue}case"html":{const e=r;n+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=r;n+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let i=r,l=i.tokens?this.parseInline(i.tokens):i.text;for(;s+1<e.length&&"text"===e[s+1].type;)i=e[++s],l+="\n"+(i.tokens?this.parseInline(i.tokens):i.text);n+=t?this.renderer.paragraph(l):l;continue}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=this.options.extensions.renderers[r.type].call({parser:this},r);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=e||"";continue}}switch(r.type){case"escape":{const e=r;n+=t.text(e.text);break}case"html":{const e=r;n+=t.html(e.text);break}case"link":{const e=r;n+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=r;n+=t.image(e.href,e.title,e.text);break}case"strong":{const e=r;n+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=r;n+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=r;n+=t.codespan(e.text);break}case"br":n+=t.br();break;case"del":{const e=r;n+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=r;n+=t.text(e.text);break}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}var me,be,we,ye=Object.defineProperty,$e=e=>{throw TypeError(e)},ze=(e,t,n)=>((e,t,n)=>t in e?ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),Te=(e,t,n)=>(((e,t,n)=>{t.has(e)||$e("Cannot "+n)})(e,t,"access private method"),n);me=new WeakSet,be=function(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+g(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}},we=function(e,t){return(n,s)=>{const r={...s},i={...this.defaults,...r};!0===this.defaults.async&&!1===r.async&&(i.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),i.async=!0);const l=Te(this,me,be).call(this,!!i.silent,!!i.async);if(null==n)return l(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof n)return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(i.hooks&&(i.hooks.options=i),i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(n):n).then((t=>e(t,i))).then((e=>i.hooks?i.hooks.processAllTokens(e):e)).then((e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then((()=>e)):e)).then((e=>t(e,i))).then((e=>i.hooks?i.hooks.postprocess(e):e)).catch(l);try{i.hooks&&(n=i.hooks.preprocess(n));let s=e(n,i);i.hooks&&(s=i.hooks.processAllTokens(s)),i.walkTokens&&this.walkTokens(s,i.walkTokens);let r=t(s,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return l(e)}}};const Se=new class{constructor(...e){var t,n,s;t=this,(n=me).has(t)?$e("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,s),ze(this,"Hooks",l),ze(this,"Lexer",he),ze(this,"Parser",xe),ze(this,"Renderer",ge),ze(this,"TextRenderer",ke),ze(this,"Tokenizer",oe),ze(this,"defaults",{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}),ze(this,"options",this.setOptions),ze(this,"parse",Te(this,me,we).call(this,he.lex,xe.parse)),ze(this,"parseInline",Te(this,me,we).call(this,he.lexInline,xe.parseInline)),this.use(...e)}lexer(e,t){return he.lex(e,t??this.defaults)}parser(e,t){return xe.parse(e,t??this.defaults)}setOptions(e){return this.defaults={...this.defaults,...e},this}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=n.apply(this,t)),s}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new ge(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.renderer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new oe(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const s=n,r=e.tokenizer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new l;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.hooks[s],i=t[s];l.passThroughHooks.has(n)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(r.call(t,e)).then((e=>i.call(t,e)));const n=r.call(t,e);return i.call(t,n)}:t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,s=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(s.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}walkTokens(e,t){let n=[];for(const s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{const e=s;for(const s of e.header)n=n.concat(this.walkTokens(s.tokens,t));for(const s of e.rows)for(const e of s)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=s;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((s=>{const r=e[s].flat(1/0);n=n.concat(this.walkTokens(r,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}};function Ae(e,t){return Se.parse(e,t)}Ae.options=Ae.setOptions=function(e){return Se.setOptions(e),Ae.defaults=Se.defaults,s(Ae.defaults),Ae},Ae.getDefaults=t,Ae.defaults=n,Ae.use=function(...e){return Se.use(...e),Ae.defaults=Se.defaults,s(Ae.defaults),Ae},Ae.walkTokens=function(e,t){return Se.walkTokens(e,t)},Ae.parseInline=Se.parseInline,Ae.Parser=xe,Ae.parser=xe.parse,Ae.Renderer=ge,Ae.TextRenderer=ke,Ae.Lexer=he,Ae.lexer=he.lex,Ae.Tokenizer=oe,Ae.Hooks=l,Ae.parse=Ae;const Re=(e,t)=>{const{showCodeBlockCopyButton:n,markdownLinkTarget:s,syntaxHighlighter:r,htmlSanitizer:i}=t||{},l=Ae(e,{async:!1,breaks:!0});if("string"!=typeof l)throw new Error("Markdown parsing failed");const o=document.createElement("div");return o.innerHTML=i?i(l):l,o.querySelectorAll("pre").forEach((e=>{const n=document.createElement("div");n.className="code-block";const s=e.querySelector("code");if(!s){const t=e.innerHTML;return n.innerHTML=i?i(t):t,void e.replaceWith(n)}let l;for(let e=0;e<s.classList.length;e++){const t=s.classList[e];if(t.startsWith("language-")){l=t.slice(9);break}}const o=document.createElement("pre"),a="<div>"+s.innerHTML+"</div>";if(o.innerHTML=t?.htmlSanitizer?t.htmlSanitizer(a):a,l&&(o.setAttribute("data-language",l),r)){const e="<div>"+r.createHighlighter()(s.textContent||"",l)+"</div>";o.innerHTML=i?i(e):e,o.className="highlighter-dark"}(e=>{e.replaceChildren()})(n),n.appendChild(o),e.replaceWith(n)})),!1!==n&&o.querySelectorAll(".code-block").forEach((e=>{if(!e.querySelector("pre"))return;if(e.previousElementSibling?.classList.contains("nlux-comp-copyButton"))return;const t="Copy code block to clipboard",n=document.createElement("button");n.classList.add("nlux-comp-copyButton"),n.setAttribute("aria-label",t),n.setAttribute("title",t);const s=document.createElement("span");s.classList.add("icon-copy"),n.appendChild(s),e.insertAdjacentElement("beforebegin",n)})),"self"!==s&&o.querySelectorAll("a").forEach((e=>{e.setAttribute("target","_blank")})),o.innerHTML},_e=e=>{if(!(e instanceof HTMLButtonElement))return;if("true"===e.dataset.clickListenerSet)return;let t=!1;const n=e.nextElementSibling;e.addEventListener("click",(()=>{if(t||!n)return;const s=n.innerText;navigator.clipboard.writeText(s??""),t=!0,e.classList.add("clicked"),setTimeout((()=>{t=!1,e.classList.remove("clicked")}),1e3)})),e.dataset.clickListenerSet="true"},ve=e=>{const t="nlux-comp-copyButton";e instanceof HTMLButtonElement&&e.classList.contains(t)?_e(e):e.querySelectorAll(`.${t}`).forEach(_e)},Ee=(t,n)=>{let s=!1;const{onComplete:r}=n||{},i=[],l="timeout"===(n?.skipStreamingAnimation?"timeout":"animationFrame")?e=>setTimeout(e,0):e=>requestAnimationFrame(e);const o=document.createElement("div");o.classList.add("md-in-progress"),t.append(o);const a=()=>{for(;o.firstChild;){const e=o.firstChild;e instanceof HTMLElement&&ve(e),o.before(e)}},c=!n?.skipStreamingAnimation&&n?.streamingAnimationSpeed&&n.streamingAnimationSpeed>=0?n.streamingAnimationSpeed:2;let h,p,u="",g=setInterval((()=>{const t=(new Date).getTime();if(0===i.length)return void((s||h&&t-h>2e3)&&(s=!0,g&&(clearInterval(g),g=void 0),a(),o.remove(),r?.()));h=t;const c=i.shift();c&&l((()=>{const t=u+c,s=Re(t,n).trim();if("string"!=typeof s)return u=u.slice(0,-c.length),void e("Markdown parsing failed");if(p&&s.length>p.length&&s.startsWith(p)){a();const e=s.slice(p.length).trim();o.innerHTML=n?.htmlSanitizer?n.htmlSanitizer(e):e,u=c,p=void 0}else o.innerHTML=n?.htmlSanitizer?n.htmlSanitizer(s):s,u=t,p=s}))}),c);return{next:t=>{if(s)e("Stream is already complete. No more chunks can be added");else for(const e of t)i.push(e)},complete:()=>{s=!0},error:()=>{s=!0}}};exports.createMarkdownStreamParser=(e,t)=>{const n=Ee(e,{syntaxHighlighter:t?.syntaxHighlighter,htmlSanitizer:t?.htmlSanitizer,markdownLinkTarget:t?.markdownLinkTarget,showCodeBlockCopyButton:t?.showCodeBlockCopyButton,skipStreamingAnimation:t?.skipStreamingAnimation,streamingAnimationSpeed:t?.streamingAnimationSpeed,onComplete:t?.onComplete});return{next(e){n.next(e)},complete(){n.complete()}}};

@@ -1,1 +0,1 @@

const e=e=>/^[ \t]{2}\n$/m.test(e),t=e=>/^[ \t\n]{1}$/.test(e),n=["Root","Paragraph","LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Blockquote","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","OrderedList","UnorderedList","Code","CodeBlock","HorizontalRule","Link","Image"],s=["^\\[$","^\\[[^\\]]+$","^\\[[^\\]]+\\]$","^\\[[^\\]]+\\]\\($","^\\[[^\\]]+\\]\\([^\\)]*$"],r={shouldOpen:/\[([^\]]+)\]\(([^\)]*)\)/,canOpen:e=>s.some((t=>new RegExp(t).test(e))),shouldClose:()=>!0,canClose:()=>!1},i=(e,t)=>n=>{const s=o.get(e);if(!s)throw new Error(`No sequence parsers found for markdown element ${e}`);const r=s[t];return r instanceof RegExp?r.test(n):r(n)},o=new Map;o.set("Code",{shouldOpen:/^`[^`]$/,canOpen:/^`$/,shouldClose:/^`[\s\S]+$/,canClose:/^`$/}),o.set("CodeBlock",{shouldOpen:/^```.*\n$/,canOpen:/^`{1,3}.*$/,shouldClose:/^\n?```[\s\S]+$/,canClose:/^\n$|^\n?`{1,3}$/}),o.set("Heading1",{shouldOpen:/^\n*#{1} $/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading2",{shouldOpen:/^\n*#{2} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading3",{shouldOpen:/^\n*#{3} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading4",{shouldOpen:/^\n*#{4} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading5",{shouldOpen:/^\n*#{5} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("Heading6",{shouldOpen:/^\n*#{6} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),o.set("BoldAsterisk",{canOpen:/^\*{1,2}$/,shouldOpen:/^\*{2}[^(\s\n)]$/,canClose:/^\*{1,2}$/,shouldClose:/^\*{2}[\s\S]$/}),o.set("BoldUnderscore",{canOpen:/^_{1,2}$/,shouldOpen:/^_{2}[^(\s\n)]$/,canClose:/^_{1,2}$/,shouldClose:/^_{2}[\s\S]$/}),o.set("ItalicAsterisk",{canOpen:/^\*$/,shouldOpen:/^\*[^(\*\s\n)]$/,canClose:/^\*$/,shouldClose:/^\*[\s\S]$/}),o.set("ItalicUnderscore",{canOpen:/^_$/,shouldOpen:/^_[^(_\s\n)]$/,canClose:/^_$/,shouldClose:/^_[\s\S]$/}),o.set("Link",r),o.set("LineBreak",{shouldOpen:()=>!1,canOpen:()=>!1,shouldClose:()=>!1,canClose:()=>!1}),o.set("Root",{canOpen:()=>!1,shouldOpen:()=>!1,canClose:()=>!1,shouldClose:()=>!1}),o.set("Paragraph",{canOpen:/^\n+$/,shouldOpen:/^\n{2,}$/,canClose:/^\n$/,shouldClose:/^\n{2,}$/}),o.set("Blockquote",{shouldOpen:/^$/,canOpen:/^>$/,shouldClose:/^$/,canClose:/^$/}),o.set("OrderedList",{shouldOpen:/^$/,canOpen:/^\d+\. $/,shouldClose:/^\n$/,canClose:/^\n$/}),o.set("UnorderedList",{shouldOpen:/^$/,canOpen:/^\* $/,shouldClose:/^\n$/,canClose:/^\n$/}),o.set("HorizontalRule",{shouldOpen:/^$/,canOpen:/^---$/,shouldClose:/^$/,canClose:/^$/}),o.set("Image",{shouldOpen:/^$/,canOpen:/^!\[.*\]\(.*\)$/,shouldClose:/^$/,canClose:/^$/});var a=Object.defineProperty,l=(e,t,n)=>((e,t,n)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class d{constructor(e,t="none",s="none"){l(this,"__canLeadToClosingMarkdown",!1),l(this,"__latestSequenceProcessed",!1),l(this,"__markdownElement"),l(this,"__markdownThatShouldBeNested"),l(this,"__markdownThatShouldBeRenderedAtParentLevel"),l(this,"__possibleNestedMarkdownElements"),l(this,"__possibleYieldingMarkdownElements"),l(this,"__potentialNestedMarkdownElements",[]),l(this,"__potentialYieldingMarkdownElements",[]),l(this,"__sequence",""),l(this,"__shouldCloseCurrentMarkdown",!1),this.__markdownElement=e,this.__possibleNestedMarkdownElements="all"===t?n:"none"===t?[]:t,this.__possibleYieldingMarkdownElements="none"===s?[]:s}get canLeadToClosingOrNewMarkdown(){return this.__latestSequenceProcessed||this.processSequence(),this.__canLeadToClosingMarkdown||this.__potentialYieldingMarkdownElements.length>0||this.__potentialNestedMarkdownElements.length>0}get elementToCreateAtParentLevel(){return this.__latestSequenceProcessed||this.processSequence(),this.__markdownThatShouldBeRenderedAtParentLevel}get nestedElementToCreate(){return this.__latestSequenceProcessed||this.processSequence(),this.__markdownThatShouldBeNested}get sequence(){return this.__sequence}get shouldCloseCurrentMarkdown(){return this.__latestSequenceProcessed||this.processSequence(),this.__shouldCloseCurrentMarkdown}appendCharacter(e){this.__sequence+=e,this.__latestSequenceProcessed=!1}reset(){this.__sequence="",this.__latestSequenceProcessed=!1,this.__canLeadToClosingMarkdown=!1,this.__potentialYieldingMarkdownElements=[],this.__potentialNestedMarkdownElements=[],this.__shouldCloseCurrentMarkdown=!1,this.__markdownThatShouldBeRenderedAtParentLevel=void 0,this.__markdownThatShouldBeNested=void 0}processSequence(){if(this.__latestSequenceProcessed)return;const e=this.__sequence;this.__canLeadToClosingMarkdown=i(this.__markdownElement,"canClose")(e),this.__potentialYieldingMarkdownElements=this.__possibleYieldingMarkdownElements.filter((t=>i(t,"canOpen")(e))),this.__potentialNestedMarkdownElements=this.__possibleNestedMarkdownElements.filter((t=>i(t,"canOpen")(e))),this.__shouldCloseCurrentMarkdown=i(this.__markdownElement,"shouldClose")(e),this.__markdownThatShouldBeRenderedAtParentLevel=this.__possibleYieldingMarkdownElements.find((t=>i(t,"shouldOpen")(e))),this.__markdownThatShouldBeNested=this.__possibleNestedMarkdownElements.find((t=>i(t,"shouldOpen")(e)))}}var c=Object.defineProperty,h=(e,t,n)=>((e,t,n)=>t in e?c(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class u{constructor(e,t,n,s,r){h(this,"__parent"),h(this,"__element"),h(this,"__initialContent"),h(this,"__initialized",!1),h(this,"__last3Characters",""),h(this,"__markdownElementName"),h(this,"__openingSequence"),h(this,"__options",{}),h(this,"__parsingChild"),h(this,"__sequenceParser"),h(this,"__yielded",!1),this.__markdownElementName=t,this.__parent=e??void 0,this.__options=r||{},this.__openingSequence=n??void 0,this.__initialContent="Root"!==t?s??void 0:void 0}get domElement(){return this.__element}get markdownElementName(){return this.__markdownElementName}get parsingChild(){return this.__parsingChild}get removeWhenEmpty(){return!1}get sequenceParser(){if(this.yielded)throw new Error("Cannot access sequence parser of a yielded processor");return this.__sequenceParser||(this.__sequenceParser=new d(this.__markdownElementName,this.nestedMarkdownElements,this.yieldingMarkdownElements)),this.__sequenceParser}get yielded(){return this.__yielded}get initialContent(){return this.__initialContent}get last3Characters(){return this.__last3Characters}get markdownProcessorOptions(){return this.__options}get syntaxHighlighter(){return this.__options.syntaxHighlighter}get htmlSanitizer(){return this.__options.htmlSanitizer??(e=>e)}init(){if(!this.__initialized&&(this.__initialized=!0,"Root"!==this.__markdownElementName?this.__element=this.createElement(this.__openingSequence):this.__element=void 0,this.__initialContent))for(let e=0;e<this.__initialContent.length;e++){const t=this.__initialContent[e];this.processCharacter(t)}}parsingChildYielded(e,t,n,s){this.__parsingChild===e&&(this.__parsingChild=void 0),t&&this.createAndAppendMarkdown(t,n),s&&this.processCharacter(s)}preProcessCharacter(e){this.__last3Characters.length<3?this.__last3Characters+=e:this.__last3Characters=this.__last3Characters.slice(1)+e}purgeSequence(){this.__parsingChild&&this.__parsingChild.purgeSequence(),this.__sequenceParser?.sequence&&(this.__element?.append(this.__sequenceParser.sequence),this.__sequenceParser.reset())}resetSequenceParser(){this.__sequenceParser?.reset(),this.__sequenceParser=new d(this.__markdownElementName,this.nestedMarkdownElements,this.yieldingMarkdownElements)}setParsingChild(e){if(this.__parsingChild&&"Root"!==this.__markdownElementName)throw new Error("Cannot set spawn child while parsing child");this.__parsingChild=e,e.domElement&&this.domElement?.append(e.domElement),e.__parent=this}yield(e,t){if(this.yielded)return;const n=this.__sequenceParser&&!this.__sequenceParser?.shouldCloseCurrentMarkdown?this.__sequenceParser?.sequence:void 0;if(this.__yielded=!0,this.__sequenceParser=void 0,this.__parsingChild&&(this.__parsingChild.yield(),this.__parsingChild=void 0),this.__element){const e=this.htmlSanitizer,t=this.__element.innerHTML.trim();this.__element.innerHTML=e?e(t):t,this.removeWhenEmpty&&""===this.__element.innerHTML&&this.__element.remove(),this.__element=void 0}this.__parent&&(this.__parent.parsingChildYielded(this,e,n,t),this.__parent=void 0)}}class p extends u{constructor(e,t,n,s,r){super(e,t,n,s,r)}createAndAppendMarkdown(e,t){B(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}processCharacter(t){if(this.preProcessCharacter(t),this.parsingChild)return void this.parsingChild.processCharacter(t);const{sequenceDiscarded:n,discardedSequence:s,yielded:r}=this.processSequence(t);if(!r)if(e(this.last3Characters)&&(this.nestedMarkdownElements.includes("LineBreak")||"all"===this.nestedMarkdownElements)){if(this.domElement?.innerHTML){const e=this.markdownProcessorOptions?.htmlSanitizer,t=this.domElement.innerHTML.trim();this.domElement.innerHTML=e?e(t):t}this.createAndAppendMarkdown("LineBreak"),this.sequenceParser.reset()}else if(n){this.resetSequenceParser();this.processSequence(t).sequenceDiscarded?(this.sequenceParser.reset(),s&&this.domElement?.append(s)):s&&s.length>1&&this.domElement?.append(s.slice(0,-1))}}processSequence(e){if(this.sequenceParser.appendCharacter(e),this.sequenceParser.shouldCloseCurrentMarkdown)return this.yield(void 0,e),{sequenceDiscarded:!1,yielded:!0};if(this.sequenceParser.elementToCreateAtParentLevel)return this.yield(this.sequenceParser.elementToCreateAtParentLevel,e),{sequenceDiscarded:!1,yielded:!0};const t=this.sequenceParser.nestedElementToCreate;if(t)return B(t,this,this.sequenceParser.sequence,e,this.markdownProcessorOptions),this.sequenceParser.reset(),{sequenceDiscarded:!1};if(this.sequenceParser.canLeadToClosingOrNewMarkdown)return{sequenceDiscarded:!1};const n=this.sequenceParser.sequence;return this.sequenceParser.reset(),{sequenceDiscarded:!0,discardedSequence:n}}}class m extends p{constructor(e,t,n,s){super(e,"BoldAsterisk",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("strong")}}class _ extends p{constructor(e,t,n,s){super(e,"BoldUnderscore",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("strong")}}class g extends p{constructor(e,t,n,s){super(e,"Code",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("code")}}var C=Object.defineProperty,k=(e,t,n)=>((e,t,n)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class w extends p{constructor(e,n,s,r={}){super(e,"CodeBlock",n??null,!s||t(s)?null:s,r),k(this,"codeContainer",null),k(this,"currentLineContainer",null),k(this,"language"),this.language=this.extractLanguageFromOpeningSequence(n)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return"none"}get yieldingMarkdownElements(){return"none"}createElement(){const e=document.createElement("div");return e.classList.add("code-block"),this.codeContainer=document.createElement("pre"),e.append(this.codeContainer),this.language&&(this.codeContainer.dataset.language=this.language),e}processCharacter(e){this.preProcessCharacter(e);const{sequenceDiscarded:t,discardedSequence:n,yielded:s}=this.processSequence(e);if(s)return;if(!t)return;if(n&&n.length>1&&this.codeContainer)for(let e=0;e<n.length-1;e++)this.appendCharacterToCodeBlock(n[e]);this.resetSequenceParser();this.processSequence(e).sequenceDiscarded&&(this.sequenceParser.reset(),this.appendCharacterToCodeBlock(e))}yield(e,t){if(this.highlightCurrentLine(),!1!==this.markdownProcessorOptions.showCodeBlockCopyButton){const e=this.__parent?.domElement;e&&(e.querySelectorAll(".code-block").forEach((e=>{if(!e.querySelector("pre"))return;if(e.previousElementSibling?.classList.contains("nlux-comp-copyButton"))return;const t="Copy code block to clipboard",n=document.createElement("button");n.classList.add("nlux-comp-copyButton"),n.setAttribute("aria-label",t),n.setAttribute("title",t);const s=document.createElement("span");s.classList.add("icon-copy"),n.appendChild(s),e.insertAdjacentElement("beforebegin",n)})),(e=>{e.querySelectorAll(".nlux-comp-copyButton").forEach((e=>{if(!(e instanceof HTMLButtonElement))return;if("true"===e.dataset.clickListenerSet)return;let t=!1;const n=e.nextElementSibling;e.addEventListener("click",(()=>{if(t||!n)return;const s=n.innerText;navigator.clipboard.writeText(s??""),t=!0,e.classList.add("clicked"),setTimeout((()=>{t=!1,e.classList.remove("clicked")}),1e3)})),e.dataset.clickListenerSet="true"}))})(e))}super.yield(e,t),this.codeContainer=null,this.currentLineContainer=null}appendCharacterToCodeBlock(e){if(this.codeContainer)if("\n"!==e)this.currentLineContainer||(this.currentLineContainer=document.createElement("div"),this.codeContainer.append(this.currentLineContainer)),this.currentLineContainer.append(e);else if(this.currentLineContainer)this.currentLineContainer.innerHTML?this.highlightCurrentLine():this.currentLineContainer.replaceChildren(" "),this.currentLineContainer=null;else if(this.codeContainer.innerHTML){const e=document.createElement("div");e.replaceChildren(" "),this.codeContainer.append(e)}}extractLanguageFromOpeningSequence(e){if(!e)return;const t=e.match(/```(\w+)/);return Array.isArray(t)&&t.length>1?t[1]:void 0}highlightCurrentLine(){if(!this.domElement||!this.currentLineContainer)return;const e=this.currentLineContainer.innerText??this.currentLineContainer.innerHTML;if(this.syntaxHighlighter&&this.codeContainer&&e){const t=this.codeContainer.dataset.language;if(t){const n=this.syntaxHighlighter.createHighlighter({language:t,colorMode:"dark"}),s=this.syntaxHighlighter.highlightingClass(t);this.codeContainer.classList.contains(s)||this.codeContainer.classList.add(s);const r=n(e,t);this.currentLineContainer.innerHTML=this.htmlSanitizer?this.htmlSanitizer(r):r}}}}var E=Object.defineProperty,q=(e,t,n)=>((e,t,n)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class P extends p{constructor(e,t,n,s,r){super(t,L(e),n??null,s??null,r??null),q(this,"__headingLevel"),this.__headingLevel=e}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("h"+this.__headingLevel)}processCharacter(e){if(this.preProcessCharacter(e),this.parsingChild)return void this.parsingChild.processCharacter(e);const{sequenceDiscarded:t,discardedSequence:n,yielded:s}=this.processSequence(e);s||t&&n&&(/^\s+$/.test(n)||this.domElement?.append(n))}}const L=e=>{switch(e){case 1:return"Heading1";case 2:return"Heading2";case 3:return"Heading3";case 4:return"Heading4";case 5:return"Heading5";case 6:return"Heading6"}};class f extends p{constructor(e,t,n,s){super(e,"ItalicAsterisk",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("em")}}class v extends p{constructor(e,t,n,s){super(e,"ItalicUnderscore",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("em")}}class M extends u{constructor(e,t,n){super(e,"LineBreak",t??null,n??null,null)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return"none"}get yieldingMarkdownElements(){return"none"}createAndAppendMarkdown(e,t){B(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}createElement(){return document.createElement("br")}init(){super.init()}processCharacter(e){this.yield(void 0,e)}}var S=Object.defineProperty,y=(e,t,n)=>((e,t,n)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class $ extends p{constructor(e,t,n,s={}){super(e,"Link",t??null,n??null,s),y(this,"linkContentProcessed","")}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code"]}get yieldingMarkdownElements(){return["Paragraph","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code"]}createElement(e){const t=/\[(.*[^\]])\]\((.*[^\)])\)/.exec(e),n=document.createElement("a");return n.textContent="",t&&t.length>=3&&t[2]&&(n.href=t[2]),"self"!==this.markdownProcessorOptions.markdownLinkTarget&&(n.target="_blank"),n}processCharacter(e){super.processCharacter(e),this.yielded||(this.linkContentProcessed+=e)}processSequence(e){if(!this.initialContent||this.initialContent===this.linkContentProcessed)return this.yield(void 0,e),{yielded:!0,sequenceDiscarded:!0,discardedSequence:e};this.sequenceParser.appendCharacter(e);const t=this.sequenceParser.nestedElementToCreate;if(t)return B(t,this,this.sequenceParser.sequence,e,this.markdownProcessorOptions),this.sequenceParser.reset(),{sequenceDiscarded:!1};if(this.sequenceParser.canLeadToClosingOrNewMarkdown)return{sequenceDiscarded:!1};const n=this.sequenceParser.sequence;return this.sequenceParser.reset(),{sequenceDiscarded:!0,discardedSequence:n}}}class O extends p{constructor(e,t,n,s){super(e,"Paragraph",t??null,n??null,s??null)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return["LineBreak","Blockquote","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get removeWhenEmpty(){return!0}get yieldingMarkdownElements(){return["Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","CodeBlock","UnorderedList","OrderedList","HorizontalRule","Image"]}createElement(){return document.createElement("p")}}const B=(e,t,n,s,r)=>{if("Paragraph"===e){const e=new O(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("LineBreak"===e){const e=new M(t,n,s);return e.init(),void t.setParsingChild(e)}if("Link"===e){const e=/\[([^\]]+)\]\(([^\)]*)\)/.exec(n),s=e&&e.length>=3?e[1]:"",i=new $(t,n,s,r);return i.init(),void t.setParsingChild(i)}if("Heading1"===e||"Heading2"===e||"Heading3"===e||"Heading4"===e||"Heading5"===e||"Heading6"===e){const i=parseInt(e[e.length-1]);if(Number.isNaN(i)||!Number.isFinite(i)||i<1||i>6)throw new Error("Invalid heading level");const o=new P(i,t,n,s,r);return o.init(),void t.setParsingChild(o)}if("Code"===e){const e=new g(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("CodeBlock"===e){const e=new w(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("BoldAsterisk"===e){const e=new m(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("BoldUnderscore"===e){const e=new _(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("ItalicAsterisk"===e){const e=new f(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("ItalicUnderscore"===e){const e=new v(t,n,s,r);return e.init(),void t.setParsingChild(e)}throw new Error("Unable to create child processor for markdown element "+e)};var A=Object.defineProperty,H=(e,t,n)=>((e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class b extends u{constructor(e,t,n){super(null,"Root",t??null,null,n??null),H(this,"__rootDomElement"),this.__rootDomElement=e}get canExistAtRootLevel(){return!1}get domElement(){return this.__rootDomElement}get nestedMarkdownElements(){return"all"}get yieldingMarkdownElements(){return"none"}complete(){var e;this.parsingChild&&this.parsingChild.purgeSequence(),this.purgeSequence(),e=this.domElement?.lastChild,e instanceof HTMLElement&&"BR"===e.tagName&&this.domElement?.lastChild?.remove()}createAndAppendMarkdown(e,t){B(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}createElement(){throw new Error("Root cannot create an element")}processCharacter(e){this.preProcessCharacter(e),this.parsingChild?this.parsingChild.processCharacter(e):(this.sequenceParser.appendCharacter(e),this.processSequence(e))}yield(){super.yield(),this.__rootDomElement=void 0}processSequence(n){if(this.sequenceParser.shouldCloseCurrentMarkdown)return;const s=this.sequenceParser.nestedElementToCreate;if(s){B(s,this,this.sequenceParser.sequence,n,this.markdownProcessorOptions);const e=this.parsingChild;return e&&!e.canExistAtRootLevel&&(B("Paragraph",this,void 0,void 0,this.markdownProcessorOptions),this.parsingChild?.setParsingChild(e)),void this.sequenceParser.reset()}this.sequenceParser.canLeadToClosingOrNewMarkdown||(e(this.last3Characters)?this.createAndAppendMarkdown("LineBreak"):n&&!t(n)&&(B("Paragraph",this,void 0,this.sequenceParser.sequence,this.markdownProcessorOptions),this.sequenceParser.reset()))}}const x=10,T=(e,t)=>{const n=((e,t)=>{const{syntaxHighlighter:n,htmlSanitizer:s,streamingAnimationSpeed:r=x,markdownLinkTarget:i,showCodeBlockCopyButton:o,skipStreamingAnimation:a=!1,onComplete:l}=t||{},d=new b(e,void 0,{syntaxHighlighter:n,htmlSanitizer:s,markdownLinkTarget:i,showCodeBlockCopyButton:o}),c=[];let h=0,u=!1,p="idle";const m=a?0:Math.max(r,0),_=r>0?r:20,g=Math.ceil(2e3/_),C=()=>{if("closed"===p)return;if("idle"===p&&(p="processing"),0===c.length)return void(!1===u&&h<g?(p="waitingForMoreCharacters",h+=1,setTimeout(C,_)):(d.processCharacter("\n"),d.complete(),d.yield(),t?.htmlSanitizer&&(e.innerHTML=t.htmlSanitizer(e.innerHTML)),p="closed",l?.()));p="processing",h=0;const n=c.shift();n&&d.processCharacter(n),setTimeout(C,m)};return{next:e=>{if(e){for(let t=0;t<e.length;t++)c.push(e[t]);"idle"===p&&C()}},complete:()=>{u=!0},error:()=>{}}})(e,{syntaxHighlighter:t?.syntaxHighlighter,htmlSanitizer:t?.htmlSanitizer,markdownLinkTarget:t?.markdownLinkTarget,showCodeBlockCopyButton:t?.showCodeBlockCopyButton,skipStreamingAnimation:t?.skipStreamingAnimation,streamingAnimationSpeed:t?.streamingAnimationSpeed,onComplete:t?.onComplete});return{next(e){n.next(e)},complete(){n.complete()}}};export{T as createMarkdownStreamParser};
const e=e=>{"string"!=typeof e?e&&"function"==typeof e.toString?console.warn(`[nlux] ${e.toString()}`):console.warn("[nlux]"):console.warn(`[nlux] ${e}`)};function t(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let n={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function s(e){n=e}var r=Object.defineProperty,i=(e,t,n)=>((e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class l{constructor(e){i(this,"options"),this.options=e||n}postprocess(e){return e}preprocess(e){return e}processAllTokens(e){return e}}i(l,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));const o=/[&<>"']/,a=new RegExp(o.source,"g"),c=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,h=new RegExp(c.source,"g"),p={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},u=e=>p[e];function g(e,t){if(t){if(o.test(e))return e.replace(a,u)}else if(c.test(e))return e.replace(h,u);return e}const k=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function f(e){return e.replace(k,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const d=/(^|[^\[])\^/g;function x(e,t){let n="string"==typeof e?e:e.source;t=t||"";const s={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(d,"$1"),n=n.replace(e,r),s},getRegex:()=>new RegExp(n,t)};return s}function m(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const b={exec:()=>null};function w(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function y(e,t,n){const s=e.length;if(0===s)return"";let r=0;for(;r<s;){const i=e.charAt(s-r-1);if(i!==t||n){if(i===t||!n)break;r++}else r++}return e.slice(0,s-r)}const $=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,z=/(?:[*+-]|\d{1,9}[.)])/,T=x(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,z).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),S=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,A=/(?!\s*\])(?:\\.|[^\[\]\\])+/,R=x(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",A).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),_=x(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,z).getRegex(),v="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",E=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,L=x("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",E).replace("tag",v).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),I=x(S).replace("hr",$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",v).getRegex(),C={blockquote:x(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",I).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:R,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:$,html:L,lheading:T,list:_,newline:/^(?: *(?:\n|$))+/,paragraph:I,table:b,text:/^[^\n]+/},q=x("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",v).getRegex(),B={...C,table:q,paragraph:x(S).replace("hr",$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",q).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",v).getRegex()},Z={...C,html:x("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",E).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:b,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:x(S).replace("hr",$).replace("heading"," *#{1,6} *[^\n]").replace("lheading",T).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},P=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,M=/^( {2,}|\\)\n(?!\s*$)/,H="\\p{P}\\p{S}",O=x(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,H).getRegex(),Q=x(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,H).getRegex(),j=x("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,H).getRegex(),D=x("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,H).getRegex(),W=x(/\\([punct])/,"gu").replace(/punct/g,H).getRegex(),F=x(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),N=x(E).replace("(?:--\x3e|$)","--\x3e").getRegex(),U=x("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",N).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),X=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,G=x(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",X).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),J=x(/^!?\[(label)\]\[(ref)\]/).replace("label",X).replace("ref",A).getRegex(),K=x(/^!?\[(ref)\](?:\[\])?/).replace("ref",A).getRegex(),V={_backpedal:b,anyPunctuation:W,autolink:F,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:M,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:b,emStrongLDelim:Q,emStrongRDelimAst:j,emStrongRDelimUnd:D,escape:P,link:G,nolink:K,punctuation:O,reflink:J,reflinkSearch:x("reflink|nolink(?!\\()","g").replace("reflink",J).replace("nolink",K).getRegex(),tag:U,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:b},Y={...V,link:x(/^!?\[(label)\]\((.*?)\)/).replace("label",X).getRegex(),reflink:x(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",X).getRegex()},ee={...V,escape:x(P).replace("])","~|])").getRegex(),url:x(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},te={...ee,br:x(M).replace("{2,}","*").getRegex(),text:x(ee.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ne={normal:C,gfm:B,pedantic:Z},se={normal:V,gfm:ee,breaks:te,pedantic:Y};var re=Object.defineProperty,ie=(e,t,n)=>((e,t,n)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);function le(e,t,n,s){const r=t.href,i=t.title?g(t.title):null,l=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:n,href:r,title:i,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,e}return{type:"image",raw:n,href:r,title:i,text:g(l)}}class oe{constructor(e){ie(this,"lexer"),ie(this,"options"),ie(this,"rules"),this.options=e||n}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=g(t[1]),n="mailto:"+e):(e=g(t[1]),n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=t[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1");e=y(e.replace(/^ *>[ \t]?/gm,""),"\n");const n=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(e);return this.lexer.state.top=n,{type:"blockquote",raw:t[0],tokens:s,text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:y(e,"\n")}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const n=/[^ ]/.test(e),s=/^ /.test(e)&&/ $/.test(e);return n&&s&&(e=e.substring(1,e.length-1)),e=g(e,!0),{type:"codespan",raw:t[0],text:e}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:s}}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s)return;if(s[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const n=[...s[0]].length-1;let r,i,l=n,o=0;const a="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,t=t.slice(-1*e.length+n);null!=(s=a.exec(t));){if(r=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!r)continue;if(i=[...r].length,s[3]||s[4]){l+=i;continue}if((s[5]||s[6])&&n%3&&!((n+i)%3)){o+=i;continue}if(l-=i,l>0)continue;i=Math.min(i,i+l+o);const t=[...s[0]][0].length,a=e.slice(0,n+s.index+t+i);if(Math.min(n,i)%2){const e=a.slice(1,-1);return{type:"em",raw:a,text:e,tokens:this.lexer.inlineTokens(e)}}const c=a.slice(2,-2);return{type:"strong",raw:a,text:c,tokens:this.lexer.inlineTokens(c)}}}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:g(t[1])}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const s=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=y(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:g(t[0]),{type:"text",raw:t[0],text:e}}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}link(e){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=y(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return-1}(t[2],"()");if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],s="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);e&&(n=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),/^</.test(n)&&(n=this.options.pedantic&&!/>$/.test(e)?n.slice(1):n.slice(1,-1)),le(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:s?s.replace(this.rules.inline.anyPunctuation,"$1"):s},t[0],this.lexer)}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");const i=new RegExp(`^( {0,3}${n})((?:[\t ][^\\n]*)?(?:\\n|$))`);let l="",o="",a=!1;for(;e;){let n=!1;if(!(t=i.exec(e)))break;if(this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let s=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),c=e.split("\n",1)[0],h=0;this.options.pedantic?(h=2,o=s.trimStart()):(h=t[2].search(/[^ ]/),h=h>4?1:h,o=s.slice(h),h+=t[1].length);let p=!1;if(!s&&/^ *$/.test(c)&&(l+=c+"\n",e=e.substring(c.length+1),n=!0),!n){const t=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),n=new RegExp(`^ {0,${Math.min(3,h-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),r=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:\`\`\`|~~~)`),i=new RegExp(`^ {0,${Math.min(3,h-1)}}#`);for(;e;){const a=e.split("\n",1)[0];if(c=a,this.options.pedantic&&(c=c.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),r.test(c))break;if(i.test(c))break;if(t.test(c))break;if(n.test(e))break;if(c.search(/[^ ]/)>=h||!c.trim())o+="\n"+c.slice(h);else{if(p)break;if(s.search(/[^ ]/)>=4)break;if(r.test(s))break;if(i.test(s))break;if(n.test(s))break;o+="\n"+c}p||c.trim()||(p=!0),l+=a+"\n",e=e.substring(a.length+1),s=c.slice(h)}}r.loose||(a?r.loose=!0:/\n *\n *$/.test(l)&&(a=!0));let u,g=null;this.options.gfm&&(g=/^\[[ xX]\] /.exec(o),g&&(u="[ ] "!==g[0],o=o.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:l,task:!!g,checked:u,loose:!1,text:o,tokens:[]}),r.raw+=l}r.items[r.items.length-1].raw=l.trimEnd(),r.items[r.items.length-1].text=o.trimEnd(),r.raw=r.raw.trimEnd();for(let e=0;e<r.items.length;e++)if(this.lexer.state.top=!1,r.items[e].tokens=this.lexer.blockTokens(r.items[e].text,[]),!r.loose){const t=r.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));r.loose=n}if(r.loose)for(let e=0;e<r.items.length;e++)r.items[e].loose=!0;return r}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){const e=t[(n[2]||n[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return le(n,e,n[0],this.lexer)}}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const n=w(t[1]),s=t[2].replace(/^\||\| *$/g,"").split("|"),r=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],i={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(const e of s)/^ *-+: *$/.test(e)?i.align.push("right"):/^ *:-+: *$/.test(e)?i.align.push("center"):/^ *:-+ *$/.test(e)?i.align.push("left"):i.align.push(null);for(const e of n)i.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of r)i.rows.push(w(e,i.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return i}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=g(t[0]),n="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=g(t[0]),n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}}var ae=Object.defineProperty,ce=(e,t,n)=>((e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class he{constructor(e){ce(this,"options"),ce(this,"state"),ce(this,"tokens"),ce(this,"inlineQueue"),ce(this,"tokenizer"),this.tokens=[],this.tokens.links=Object.create(null),this.options=e||n,this.options.tokenizer=this.options.tokenizer||new oe,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={block:ne.normal,inline:se.normal};this.options.pedantic?(t.block=ne.pedantic,t.inline=se.pedantic):this.options.gfm&&(t.block=ne.gfm,this.options.breaks?t.inline=se.breaks:t.inline=se.gfm),this.tokenizer.rules=t}static get rules(){return{block:ne,inline:se}}static lex(e,t){return new he(t).lex(e)}static lexInline(e,t){return new he(t).inlineTokens(e)}blockTokens(e,t=[]){let n,s,r,i;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,n)=>t+" ".repeat(n.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.space(e))e=e.substring(n.raw.length),1===n.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(n);else if(n=this.tokenizer.code(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?t.push(n):(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.fences(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.heading(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.hr(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.blockquote(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.list(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.html(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.def(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title}):(s.raw+="\n"+n.raw,s.text+="\n"+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.table(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.lheading(e))e=e.substring(n.raw.length),t.push(n);else{if(r=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startBlock.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(this.state.top&&(n=this.tokenizer.paragraph(r)))s=t[t.length-1],i&&"paragraph"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n),i=r.length!==e.length,e=e.substring(n.raw.length);else if(n=this.tokenizer.text(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,s,r,i,l,o,a=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(i=this.tokenizer.rules.inline.reflinkSearch.exec(a));)e.includes(i[0].slice(i[0].lastIndexOf("[")+1,-1))&&(a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(i=this.tokenizer.rules.inline.blockSkip.exec(a));)a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(i=this.tokenizer.rules.inline.anyPunctuation.exec(a));)a=a.slice(0,i.index)+"++"+a.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(l||(o=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.escape(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.tag(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.link(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.emStrong(e,a,o))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.codespan(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.br(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.del(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.autolink(e))e=e.substring(n.raw.length),t.push(n);else if(this.state.inLink||!(n=this.tokenizer.url(e))){if(r=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startInline.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(r))e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(o=n.raw.slice(-1)),l=!0,s=t[t.length-1],s&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(n.raw.length),t.push(n);return t}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}}var pe=Object.defineProperty,ue=(e,t,n)=>((e,t,n)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class ge{constructor(e){ue(this,"options"),this.options=e||n}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}br(){return"<br>"}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}code(e,t,n){const s=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",s?'<pre><code class="language-'+g(s)+'">'+(n?e:g(e,!0))+"</code></pre>\n":"<pre><code>"+(n?e:g(e,!0))+"</code></pre>\n"}codespan(e){return`<code>${e}</code>`}del(e){return`<del>${e}</del>`}em(e){return`<em>${e}</em>`}heading(e,t,n){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}html(e,t){return e}image(e,t,n){const s=m(e);if(null===s)return n;let r=`<img src="${e=s}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">",r}link(e,t,n){const s=m(e);if(null===s)return n;let r='<a href="'+(e=s)+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>",r}list(e,t,n){const s=t?"ol":"ul";return"<"+s+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"</"+s+">\n"}listitem(e,t,n){return`<li>${e}</li>\n`}paragraph(e){return`<p>${e}</p>\n`}strong(e){return`<strong>${e}</strong>`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>\n`}tablerow(e){return`<tr>\n${e}</tr>\n`}text(e){return e}}class ke{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}var fe=Object.defineProperty,de=(e,t,n)=>((e,t,n)=>t in e?fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class xe{constructor(e){de(this,"options"),de(this,"renderer"),de(this,"textRenderer"),this.options=e||n,this.options.renderer=this.options.renderer||new ge,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ke}static parse(e,t){return new xe(t).parse(e)}static parseInline(e,t){return new xe(t).parseInline(e)}parse(e,t=!0){let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=r,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}switch(r.type){case"space":continue;case"hr":n+=this.renderer.hr();continue;case"heading":{const e=r;n+=this.renderer.heading(this.parseInline(e.tokens),e.depth,f(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=r;n+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=r;let t="",s="";for(let t=0;t<e.header.length;t++)s+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(s);let i="";for(let t=0;t<e.rows.length;t++){const n=e.rows[t];s="";for(let t=0;t<n.length;t++)s+=this.renderer.tablecell(this.parseInline(n[t].tokens),{header:!1,align:e.align[t]});i+=this.renderer.tablerow(s)}n+=this.renderer.table(t,i);continue}case"blockquote":{const e=r,t=this.parse(e.tokens);n+=this.renderer.blockquote(t);continue}case"list":{const e=r,t=e.ordered,s=e.start,i=e.loose;let l="";for(let t=0;t<e.items.length;t++){const n=e.items[t],s=n.checked,r=n.task;let o="";if(n.task){const e=this.renderer.checkbox(!!s);i?n.tokens.length>0&&"paragraph"===n.tokens[0].type?(n.tokens[0].text=e+" "+n.tokens[0].text,n.tokens[0].tokens&&n.tokens[0].tokens.length>0&&"text"===n.tokens[0].tokens[0].type&&(n.tokens[0].tokens[0].text=e+" "+n.tokens[0].tokens[0].text)):n.tokens.unshift({type:"text",text:e+" "}):o+=e+" "}o+=this.parse(n.tokens,i),l+=this.renderer.listitem(o,r,!!s)}n+=this.renderer.list(l,t,s);continue}case"html":{const e=r;n+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=r;n+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let i=r,l=i.tokens?this.parseInline(i.tokens):i.text;for(;s+1<e.length&&"text"===e[s+1].type;)i=e[++s],l+="\n"+(i.tokens?this.parseInline(i.tokens):i.text);n+=t?this.renderer.paragraph(l):l;continue}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=this.options.extensions.renderers[r.type].call({parser:this},r);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=e||"";continue}}switch(r.type){case"escape":{const e=r;n+=t.text(e.text);break}case"html":{const e=r;n+=t.html(e.text);break}case"link":{const e=r;n+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=r;n+=t.image(e.href,e.title,e.text);break}case"strong":{const e=r;n+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=r;n+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=r;n+=t.codespan(e.text);break}case"br":n+=t.br();break;case"del":{const e=r;n+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=r;n+=t.text(e.text);break}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}var me,be,we,ye=Object.defineProperty,$e=e=>{throw TypeError(e)},ze=(e,t,n)=>((e,t,n)=>t in e?ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),Te=(e,t,n)=>(((e,t,n)=>{t.has(e)||$e("Cannot "+n)})(e,t,"access private method"),n);me=new WeakSet,be=function(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+g(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}},we=function(e,t){return(n,s)=>{const r={...s},i={...this.defaults,...r};!0===this.defaults.async&&!1===r.async&&(i.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),i.async=!0);const l=Te(this,me,be).call(this,!!i.silent,!!i.async);if(null==n)return l(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof n)return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(i.hooks&&(i.hooks.options=i),i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(n):n).then((t=>e(t,i))).then((e=>i.hooks?i.hooks.processAllTokens(e):e)).then((e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then((()=>e)):e)).then((e=>t(e,i))).then((e=>i.hooks?i.hooks.postprocess(e):e)).catch(l);try{i.hooks&&(n=i.hooks.preprocess(n));let s=e(n,i);i.hooks&&(s=i.hooks.processAllTokens(s)),i.walkTokens&&this.walkTokens(s,i.walkTokens);let r=t(s,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return l(e)}}};const Se=new class{constructor(...e){var t,n,s;t=this,(n=me).has(t)?$e("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,s),ze(this,"Hooks",l),ze(this,"Lexer",he),ze(this,"Parser",xe),ze(this,"Renderer",ge),ze(this,"TextRenderer",ke),ze(this,"Tokenizer",oe),ze(this,"defaults",{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}),ze(this,"options",this.setOptions),ze(this,"parse",Te(this,me,we).call(this,he.lex,xe.parse)),ze(this,"parseInline",Te(this,me,we).call(this,he.lexInline,xe.parseInline)),this.use(...e)}lexer(e,t){return he.lex(e,t??this.defaults)}parser(e,t){return xe.parse(e,t??this.defaults)}setOptions(e){return this.defaults={...this.defaults,...e},this}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=n.apply(this,t)),s}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new ge(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.renderer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new oe(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const s=n,r=e.tokenizer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new l;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.hooks[s],i=t[s];l.passThroughHooks.has(n)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(r.call(t,e)).then((e=>i.call(t,e)));const n=r.call(t,e);return i.call(t,n)}:t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,s=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(s.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}walkTokens(e,t){let n=[];for(const s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{const e=s;for(const s of e.header)n=n.concat(this.walkTokens(s.tokens,t));for(const s of e.rows)for(const e of s)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=s;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((s=>{const r=e[s].flat(1/0);n=n.concat(this.walkTokens(r,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}};function Ae(e,t){return Se.parse(e,t)}Ae.options=Ae.setOptions=function(e){return Se.setOptions(e),Ae.defaults=Se.defaults,s(Ae.defaults),Ae},Ae.getDefaults=t,Ae.defaults=n,Ae.use=function(...e){return Se.use(...e),Ae.defaults=Se.defaults,s(Ae.defaults),Ae},Ae.walkTokens=function(e,t){return Se.walkTokens(e,t)},Ae.parseInline=Se.parseInline,Ae.Parser=xe,Ae.parser=xe.parse,Ae.Renderer=ge,Ae.TextRenderer=ke,Ae.Lexer=he,Ae.lexer=he.lex,Ae.Tokenizer=oe,Ae.Hooks=l,Ae.parse=Ae;const Re=(e,t)=>{const{showCodeBlockCopyButton:n,markdownLinkTarget:s,syntaxHighlighter:r,htmlSanitizer:i}=t||{},l=Ae(e,{async:!1,breaks:!0});if("string"!=typeof l)throw new Error("Markdown parsing failed");const o=document.createElement("div");return o.innerHTML=i?i(l):l,o.querySelectorAll("pre").forEach((e=>{const n=document.createElement("div");n.className="code-block";const s=e.querySelector("code");if(!s){const t=e.innerHTML;return n.innerHTML=i?i(t):t,void e.replaceWith(n)}let l;for(let e=0;e<s.classList.length;e++){const t=s.classList[e];if(t.startsWith("language-")){l=t.slice(9);break}}const o=document.createElement("pre"),a="<div>"+s.innerHTML+"</div>";if(o.innerHTML=t?.htmlSanitizer?t.htmlSanitizer(a):a,l&&(o.setAttribute("data-language",l),r)){const e="<div>"+r.createHighlighter()(s.textContent||"",l)+"</div>";o.innerHTML=i?i(e):e,o.className="highlighter-dark"}(e=>{e.replaceChildren()})(n),n.appendChild(o),e.replaceWith(n)})),!1!==n&&o.querySelectorAll(".code-block").forEach((e=>{if(!e.querySelector("pre"))return;if(e.previousElementSibling?.classList.contains("nlux-comp-copyButton"))return;const t="Copy code block to clipboard",n=document.createElement("button");n.classList.add("nlux-comp-copyButton"),n.setAttribute("aria-label",t),n.setAttribute("title",t);const s=document.createElement("span");s.classList.add("icon-copy"),n.appendChild(s),e.insertAdjacentElement("beforebegin",n)})),"self"!==s&&o.querySelectorAll("a").forEach((e=>{e.setAttribute("target","_blank")})),o.innerHTML},_e=e=>{if(!(e instanceof HTMLButtonElement))return;if("true"===e.dataset.clickListenerSet)return;let t=!1;const n=e.nextElementSibling;e.addEventListener("click",(()=>{if(t||!n)return;const s=n.innerText;navigator.clipboard.writeText(s??""),t=!0,e.classList.add("clicked"),setTimeout((()=>{t=!1,e.classList.remove("clicked")}),1e3)})),e.dataset.clickListenerSet="true"},ve=e=>{const t="nlux-comp-copyButton";e instanceof HTMLButtonElement&&e.classList.contains(t)?_e(e):e.querySelectorAll(`.${t}`).forEach(_e)},Ee=(t,n)=>{let s=!1;const{onComplete:r}=n||{},i=[],l="timeout"===(n?.skipStreamingAnimation?"timeout":"animationFrame")?e=>setTimeout(e,0):e=>requestAnimationFrame(e);const o=document.createElement("div");o.classList.add("md-in-progress"),t.append(o);const a=()=>{for(;o.firstChild;){const e=o.firstChild;e instanceof HTMLElement&&ve(e),o.before(e)}},c=!n?.skipStreamingAnimation&&n?.streamingAnimationSpeed&&n.streamingAnimationSpeed>=0?n.streamingAnimationSpeed:2;let h,p,u="",g=setInterval((()=>{const t=(new Date).getTime();if(0===i.length)return void((s||h&&t-h>2e3)&&(s=!0,g&&(clearInterval(g),g=void 0),a(),o.remove(),r?.()));h=t;const c=i.shift();c&&l((()=>{const t=u+c,s=Re(t,n).trim();if("string"!=typeof s)return u=u.slice(0,-c.length),void e("Markdown parsing failed");if(p&&s.length>p.length&&s.startsWith(p)){a();const e=s.slice(p.length).trim();o.innerHTML=n?.htmlSanitizer?n.htmlSanitizer(e):e,u=c,p=void 0}else o.innerHTML=n?.htmlSanitizer?n.htmlSanitizer(s):s,u=t,p=s}))}),c);return{next:t=>{if(s)e("Stream is already complete. No more chunks can be added");else for(const e of t)i.push(e)},complete:()=>{s=!0},error:()=>{s=!0}}},Le=(e,t)=>{const n=Ee(e,{syntaxHighlighter:t?.syntaxHighlighter,htmlSanitizer:t?.htmlSanitizer,markdownLinkTarget:t?.markdownLinkTarget,showCodeBlockCopyButton:t?.showCodeBlockCopyButton,skipStreamingAnimation:t?.skipStreamingAnimation,streamingAnimationSpeed:t?.streamingAnimationSpeed,onComplete:t?.onComplete});return{next(e){n.next(e)},complete(){n.complete()}}};export{Le as createMarkdownStreamParser};
{
"name": "@nlux/markdown",
"version": "2.3.7",
"version": "2.3.8",
"description": "A lightweight and fast markdown parser used by nlux that can be used to parse markdown text streams into DOM.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@nlux/markdown"]={})}(this,(function(e){"use strict";const t=e=>/^[ \t]{2}\n$/m.test(e),n=e=>/^[ \t\n]{1}$/.test(e),s=["Root","Paragraph","LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Blockquote","Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","OrderedList","UnorderedList","Code","CodeBlock","HorizontalRule","Link","Image"],r=["^\\[$","^\\[[^\\]]+$","^\\[[^\\]]+\\]$","^\\[[^\\]]+\\]\\($","^\\[[^\\]]+\\]\\([^\\)]*$"],i={shouldOpen:/\[([^\]]+)\]\(([^\)]*)\)/,canOpen:e=>r.some((t=>new RegExp(t).test(e))),shouldClose:()=>!0,canClose:()=>!1},o=(e,t)=>n=>{const s=a.get(e);if(!s)throw new Error(`No sequence parsers found for markdown element ${e}`);const r=s[t];return r instanceof RegExp?r.test(n):r(n)},a=new Map;a.set("Code",{shouldOpen:/^`[^`]$/,canOpen:/^`$/,shouldClose:/^`[\s\S]+$/,canClose:/^`$/}),a.set("CodeBlock",{shouldOpen:/^```.*\n$/,canOpen:/^`{1,3}.*$/,shouldClose:/^\n?```[\s\S]+$/,canClose:/^\n$|^\n?`{1,3}$/}),a.set("Heading1",{shouldOpen:/^\n*#{1} $/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),a.set("Heading2",{shouldOpen:/^\n*#{2} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),a.set("Heading3",{shouldOpen:/^\n*#{3} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),a.set("Heading4",{shouldOpen:/^\n*#{4} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),a.set("Heading5",{shouldOpen:/^\n*#{5} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),a.set("Heading6",{shouldOpen:/^\n*#{6} +$/,canOpen:/^\n*#*$/,shouldClose:/^\n$/,canClose:()=>!1}),a.set("BoldAsterisk",{canOpen:/^\*{1,2}$/,shouldOpen:/^\*{2}[^(\s\n)]$/,canClose:/^\*{1,2}$/,shouldClose:/^\*{2}[\s\S]$/}),a.set("BoldUnderscore",{canOpen:/^_{1,2}$/,shouldOpen:/^_{2}[^(\s\n)]$/,canClose:/^_{1,2}$/,shouldClose:/^_{2}[\s\S]$/}),a.set("ItalicAsterisk",{canOpen:/^\*$/,shouldOpen:/^\*[^(\*\s\n)]$/,canClose:/^\*$/,shouldClose:/^\*[\s\S]$/}),a.set("ItalicUnderscore",{canOpen:/^_$/,shouldOpen:/^_[^(_\s\n)]$/,canClose:/^_$/,shouldClose:/^_[\s\S]$/}),a.set("Link",i),a.set("LineBreak",{shouldOpen:()=>!1,canOpen:()=>!1,shouldClose:()=>!1,canClose:()=>!1}),a.set("Root",{canOpen:()=>!1,shouldOpen:()=>!1,canClose:()=>!1,shouldClose:()=>!1}),a.set("Paragraph",{canOpen:/^\n+$/,shouldOpen:/^\n{2,}$/,canClose:/^\n$/,shouldClose:/^\n{2,}$/}),a.set("Blockquote",{shouldOpen:/^$/,canOpen:/^>$/,shouldClose:/^$/,canClose:/^$/}),a.set("OrderedList",{shouldOpen:/^$/,canOpen:/^\d+\. $/,shouldClose:/^\n$/,canClose:/^\n$/}),a.set("UnorderedList",{shouldOpen:/^$/,canOpen:/^\* $/,shouldClose:/^\n$/,canClose:/^\n$/}),a.set("HorizontalRule",{shouldOpen:/^$/,canOpen:/^---$/,shouldClose:/^$/,canClose:/^$/}),a.set("Image",{shouldOpen:/^$/,canOpen:/^!\[.*\]\(.*\)$/,shouldClose:/^$/,canClose:/^$/});var l=Object.defineProperty,d=(e,t,n)=>((e,t,n)=>t in e?l(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class c{constructor(e,t="none",n="none"){d(this,"__canLeadToClosingMarkdown",!1),d(this,"__latestSequenceProcessed",!1),d(this,"__markdownElement"),d(this,"__markdownThatShouldBeNested"),d(this,"__markdownThatShouldBeRenderedAtParentLevel"),d(this,"__possibleNestedMarkdownElements"),d(this,"__possibleYieldingMarkdownElements"),d(this,"__potentialNestedMarkdownElements",[]),d(this,"__potentialYieldingMarkdownElements",[]),d(this,"__sequence",""),d(this,"__shouldCloseCurrentMarkdown",!1),this.__markdownElement=e,this.__possibleNestedMarkdownElements="all"===t?s:"none"===t?[]:t,this.__possibleYieldingMarkdownElements="none"===n?[]:n}get canLeadToClosingOrNewMarkdown(){return this.__latestSequenceProcessed||this.processSequence(),this.__canLeadToClosingMarkdown||this.__potentialYieldingMarkdownElements.length>0||this.__potentialNestedMarkdownElements.length>0}get elementToCreateAtParentLevel(){return this.__latestSequenceProcessed||this.processSequence(),this.__markdownThatShouldBeRenderedAtParentLevel}get nestedElementToCreate(){return this.__latestSequenceProcessed||this.processSequence(),this.__markdownThatShouldBeNested}get sequence(){return this.__sequence}get shouldCloseCurrentMarkdown(){return this.__latestSequenceProcessed||this.processSequence(),this.__shouldCloseCurrentMarkdown}appendCharacter(e){this.__sequence+=e,this.__latestSequenceProcessed=!1}reset(){this.__sequence="",this.__latestSequenceProcessed=!1,this.__canLeadToClosingMarkdown=!1,this.__potentialYieldingMarkdownElements=[],this.__potentialNestedMarkdownElements=[],this.__shouldCloseCurrentMarkdown=!1,this.__markdownThatShouldBeRenderedAtParentLevel=void 0,this.__markdownThatShouldBeNested=void 0}processSequence(){if(this.__latestSequenceProcessed)return;const e=this.__sequence;this.__canLeadToClosingMarkdown=o(this.__markdownElement,"canClose")(e),this.__potentialYieldingMarkdownElements=this.__possibleYieldingMarkdownElements.filter((t=>o(t,"canOpen")(e))),this.__potentialNestedMarkdownElements=this.__possibleNestedMarkdownElements.filter((t=>o(t,"canOpen")(e))),this.__shouldCloseCurrentMarkdown=o(this.__markdownElement,"shouldClose")(e),this.__markdownThatShouldBeRenderedAtParentLevel=this.__possibleYieldingMarkdownElements.find((t=>o(t,"shouldOpen")(e))),this.__markdownThatShouldBeNested=this.__possibleNestedMarkdownElements.find((t=>o(t,"shouldOpen")(e)))}}var h=Object.defineProperty,u=(e,t,n)=>((e,t,n)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class p{constructor(e,t,n,s,r){u(this,"__parent"),u(this,"__element"),u(this,"__initialContent"),u(this,"__initialized",!1),u(this,"__last3Characters",""),u(this,"__markdownElementName"),u(this,"__openingSequence"),u(this,"__options",{}),u(this,"__parsingChild"),u(this,"__sequenceParser"),u(this,"__yielded",!1),this.__markdownElementName=t,this.__parent=e??void 0,this.__options=r||{},this.__openingSequence=n??void 0,this.__initialContent="Root"!==t?s??void 0:void 0}get domElement(){return this.__element}get markdownElementName(){return this.__markdownElementName}get parsingChild(){return this.__parsingChild}get removeWhenEmpty(){return!1}get sequenceParser(){if(this.yielded)throw new Error("Cannot access sequence parser of a yielded processor");return this.__sequenceParser||(this.__sequenceParser=new c(this.__markdownElementName,this.nestedMarkdownElements,this.yieldingMarkdownElements)),this.__sequenceParser}get yielded(){return this.__yielded}get initialContent(){return this.__initialContent}get last3Characters(){return this.__last3Characters}get markdownProcessorOptions(){return this.__options}get syntaxHighlighter(){return this.__options.syntaxHighlighter}get htmlSanitizer(){return this.__options.htmlSanitizer??(e=>e)}init(){if(!this.__initialized&&(this.__initialized=!0,"Root"!==this.__markdownElementName?this.__element=this.createElement(this.__openingSequence):this.__element=void 0,this.__initialContent))for(let e=0;e<this.__initialContent.length;e++){const t=this.__initialContent[e];this.processCharacter(t)}}parsingChildYielded(e,t,n,s){this.__parsingChild===e&&(this.__parsingChild=void 0),t&&this.createAndAppendMarkdown(t,n),s&&this.processCharacter(s)}preProcessCharacter(e){this.__last3Characters.length<3?this.__last3Characters+=e:this.__last3Characters=this.__last3Characters.slice(1)+e}purgeSequence(){this.__parsingChild&&this.__parsingChild.purgeSequence(),this.__sequenceParser?.sequence&&(this.__element?.append(this.__sequenceParser.sequence),this.__sequenceParser.reset())}resetSequenceParser(){this.__sequenceParser?.reset(),this.__sequenceParser=new c(this.__markdownElementName,this.nestedMarkdownElements,this.yieldingMarkdownElements)}setParsingChild(e){if(this.__parsingChild&&"Root"!==this.__markdownElementName)throw new Error("Cannot set spawn child while parsing child");this.__parsingChild=e,e.domElement&&this.domElement?.append(e.domElement),e.__parent=this}yield(e,t){if(this.yielded)return;const n=this.__sequenceParser&&!this.__sequenceParser?.shouldCloseCurrentMarkdown?this.__sequenceParser?.sequence:void 0;if(this.__yielded=!0,this.__sequenceParser=void 0,this.__parsingChild&&(this.__parsingChild.yield(),this.__parsingChild=void 0),this.__element){const e=this.htmlSanitizer,t=this.__element.innerHTML.trim();this.__element.innerHTML=e?e(t):t,this.removeWhenEmpty&&""===this.__element.innerHTML&&this.__element.remove(),this.__element=void 0}this.__parent&&(this.__parent.parsingChildYielded(this,e,n,t),this.__parent=void 0)}}class m extends p{constructor(e,t,n,s,r){super(e,t,n,s,r)}createAndAppendMarkdown(e,t){A(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}processCharacter(e){if(this.preProcessCharacter(e),this.parsingChild)return void this.parsingChild.processCharacter(e);const{sequenceDiscarded:n,discardedSequence:s,yielded:r}=this.processSequence(e);if(!r)if(t(this.last3Characters)&&(this.nestedMarkdownElements.includes("LineBreak")||"all"===this.nestedMarkdownElements)){if(this.domElement?.innerHTML){const e=this.markdownProcessorOptions?.htmlSanitizer,t=this.domElement.innerHTML.trim();this.domElement.innerHTML=e?e(t):t}this.createAndAppendMarkdown("LineBreak"),this.sequenceParser.reset()}else if(n){this.resetSequenceParser();this.processSequence(e).sequenceDiscarded?(this.sequenceParser.reset(),s&&this.domElement?.append(s)):s&&s.length>1&&this.domElement?.append(s.slice(0,-1))}}processSequence(e){if(this.sequenceParser.appendCharacter(e),this.sequenceParser.shouldCloseCurrentMarkdown)return this.yield(void 0,e),{sequenceDiscarded:!1,yielded:!0};if(this.sequenceParser.elementToCreateAtParentLevel)return this.yield(this.sequenceParser.elementToCreateAtParentLevel,e),{sequenceDiscarded:!1,yielded:!0};const t=this.sequenceParser.nestedElementToCreate;if(t)return A(t,this,this.sequenceParser.sequence,e,this.markdownProcessorOptions),this.sequenceParser.reset(),{sequenceDiscarded:!1};if(this.sequenceParser.canLeadToClosingOrNewMarkdown)return{sequenceDiscarded:!1};const n=this.sequenceParser.sequence;return this.sequenceParser.reset(),{sequenceDiscarded:!0,discardedSequence:n}}}class _ extends m{constructor(e,t,n,s){super(e,"BoldAsterisk",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("strong")}}class g extends m{constructor(e,t,n,s){super(e,"BoldUnderscore",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("strong")}}class C extends m{constructor(e,t,n,s){super(e,"Code",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("code")}}var k=Object.defineProperty,w=(e,t,n)=>((e,t,n)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class E extends m{constructor(e,t,s,r={}){super(e,"CodeBlock",t??null,!s||n(s)?null:s,r),w(this,"codeContainer",null),w(this,"currentLineContainer",null),w(this,"language"),this.language=this.extractLanguageFromOpeningSequence(t)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return"none"}get yieldingMarkdownElements(){return"none"}createElement(){const e=document.createElement("div");return e.classList.add("code-block"),this.codeContainer=document.createElement("pre"),e.append(this.codeContainer),this.language&&(this.codeContainer.dataset.language=this.language),e}processCharacter(e){this.preProcessCharacter(e);const{sequenceDiscarded:t,discardedSequence:n,yielded:s}=this.processSequence(e);if(s)return;if(!t)return;if(n&&n.length>1&&this.codeContainer)for(let e=0;e<n.length-1;e++)this.appendCharacterToCodeBlock(n[e]);this.resetSequenceParser();this.processSequence(e).sequenceDiscarded&&(this.sequenceParser.reset(),this.appendCharacterToCodeBlock(e))}yield(e,t){if(this.highlightCurrentLine(),!1!==this.markdownProcessorOptions.showCodeBlockCopyButton){const e=this.__parent?.domElement;e&&(e.querySelectorAll(".code-block").forEach((e=>{if(!e.querySelector("pre"))return;if(e.previousElementSibling?.classList.contains("nlux-comp-copyButton"))return;const t="Copy code block to clipboard",n=document.createElement("button");n.classList.add("nlux-comp-copyButton"),n.setAttribute("aria-label",t),n.setAttribute("title",t);const s=document.createElement("span");s.classList.add("icon-copy"),n.appendChild(s),e.insertAdjacentElement("beforebegin",n)})),(e=>{e.querySelectorAll(".nlux-comp-copyButton").forEach((e=>{if(!(e instanceof HTMLButtonElement))return;if("true"===e.dataset.clickListenerSet)return;let t=!1;const n=e.nextElementSibling;e.addEventListener("click",(()=>{if(t||!n)return;const s=n.innerText;navigator.clipboard.writeText(s??""),t=!0,e.classList.add("clicked"),setTimeout((()=>{t=!1,e.classList.remove("clicked")}),1e3)})),e.dataset.clickListenerSet="true"}))})(e))}super.yield(e,t),this.codeContainer=null,this.currentLineContainer=null}appendCharacterToCodeBlock(e){if(this.codeContainer)if("\n"!==e)this.currentLineContainer||(this.currentLineContainer=document.createElement("div"),this.codeContainer.append(this.currentLineContainer)),this.currentLineContainer.append(e);else if(this.currentLineContainer)this.currentLineContainer.innerHTML?this.highlightCurrentLine():this.currentLineContainer.replaceChildren(" "),this.currentLineContainer=null;else if(this.codeContainer.innerHTML){const e=document.createElement("div");e.replaceChildren(" "),this.codeContainer.append(e)}}extractLanguageFromOpeningSequence(e){if(!e)return;const t=e.match(/```(\w+)/);return Array.isArray(t)&&t.length>1?t[1]:void 0}highlightCurrentLine(){if(!this.domElement||!this.currentLineContainer)return;const e=this.currentLineContainer.innerText??this.currentLineContainer.innerHTML;if(this.syntaxHighlighter&&this.codeContainer&&e){const t=this.codeContainer.dataset.language;if(t){const n=this.syntaxHighlighter.createHighlighter({language:t,colorMode:"dark"}),s=this.syntaxHighlighter.highlightingClass(t);this.codeContainer.classList.contains(s)||this.codeContainer.classList.add(s);const r=n(e,t);this.currentLineContainer.innerHTML=this.htmlSanitizer?this.htmlSanitizer(r):r}}}}var q=Object.defineProperty,P=(e,t,n)=>((e,t,n)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class L extends m{constructor(e,t,n,s,r){super(t,f(e),n??null,s??null,r??null),P(this,"__headingLevel"),this.__headingLevel=e}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("h"+this.__headingLevel)}processCharacter(e){if(this.preProcessCharacter(e),this.parsingChild)return void this.parsingChild.processCharacter(e);const{sequenceDiscarded:t,discardedSequence:n,yielded:s}=this.processSequence(e);s||t&&n&&(/^\s+$/.test(n)||this.domElement?.append(n))}}const f=e=>{switch(e){case 1:return"Heading1";case 2:return"Heading2";case 3:return"Heading3";case 4:return"Heading4";case 5:return"Heading5";case 6:return"Heading6"}};class v extends m{constructor(e,t,n,s){super(e,"ItalicAsterisk",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("em")}}class M extends m{constructor(e,t,n,s){super(e,"ItalicUnderscore",t??null,n??null,s??null)}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["LineBreak","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get yieldingMarkdownElements(){return"none"}createElement(){return document.createElement("em")}}class y extends p{constructor(e,t,n){super(e,"LineBreak",t??null,n??null,null)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return"none"}get yieldingMarkdownElements(){return"none"}createAndAppendMarkdown(e,t){A(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}createElement(){return document.createElement("br")}init(){super.init()}processCharacter(e){this.yield(void 0,e)}}var S=Object.defineProperty,$=(e,t,n)=>((e,t,n)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class O extends m{constructor(e,t,n,s={}){super(e,"Link",t??null,n??null,s),$(this,"linkContentProcessed","")}get canExistAtRootLevel(){return!1}get nestedMarkdownElements(){return["BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code"]}get yieldingMarkdownElements(){return["Paragraph","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code"]}createElement(e){const t=/\[(.*[^\]])\]\((.*[^\)])\)/.exec(e),n=document.createElement("a");return n.textContent="",t&&t.length>=3&&t[2]&&(n.href=t[2]),"self"!==this.markdownProcessorOptions.markdownLinkTarget&&(n.target="_blank"),n}processCharacter(e){super.processCharacter(e),this.yielded||(this.linkContentProcessed+=e)}processSequence(e){if(!this.initialContent||this.initialContent===this.linkContentProcessed)return this.yield(void 0,e),{yielded:!0,sequenceDiscarded:!0,discardedSequence:e};this.sequenceParser.appendCharacter(e);const t=this.sequenceParser.nestedElementToCreate;if(t)return A(t,this,this.sequenceParser.sequence,e,this.markdownProcessorOptions),this.sequenceParser.reset(),{sequenceDiscarded:!1};if(this.sequenceParser.canLeadToClosingOrNewMarkdown)return{sequenceDiscarded:!1};const n=this.sequenceParser.sequence;return this.sequenceParser.reset(),{sequenceDiscarded:!0,discardedSequence:n}}}class B extends m{constructor(e,t,n,s){super(e,"Paragraph",t??null,n??null,s??null)}get canExistAtRootLevel(){return!0}get nestedMarkdownElements(){return["LineBreak","Blockquote","BoldAsterisk","ItalicAsterisk","BoldUnderscore","ItalicUnderscore","Code","Link"]}get removeWhenEmpty(){return!0}get yieldingMarkdownElements(){return["Heading1","Heading2","Heading3","Heading4","Heading5","Heading6","CodeBlock","UnorderedList","OrderedList","HorizontalRule","Image"]}createElement(){return document.createElement("p")}}const A=(e,t,n,s,r)=>{if("Paragraph"===e){const e=new B(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("LineBreak"===e){const e=new y(t,n,s);return e.init(),void t.setParsingChild(e)}if("Link"===e){const e=/\[([^\]]+)\]\(([^\)]*)\)/.exec(n),s=e&&e.length>=3?e[1]:"",i=new O(t,n,s,r);return i.init(),void t.setParsingChild(i)}if("Heading1"===e||"Heading2"===e||"Heading3"===e||"Heading4"===e||"Heading5"===e||"Heading6"===e){const i=parseInt(e[e.length-1]);if(Number.isNaN(i)||!Number.isFinite(i)||i<1||i>6)throw new Error("Invalid heading level");const o=new L(i,t,n,s,r);return o.init(),void t.setParsingChild(o)}if("Code"===e){const e=new C(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("CodeBlock"===e){const e=new E(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("BoldAsterisk"===e){const e=new _(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("BoldUnderscore"===e){const e=new g(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("ItalicAsterisk"===e){const e=new v(t,n,s,r);return e.init(),void t.setParsingChild(e)}if("ItalicUnderscore"===e){const e=new M(t,n,s,r);return e.init(),void t.setParsingChild(e)}throw new Error("Unable to create child processor for markdown element "+e)};var H=Object.defineProperty,b=(e,t,n)=>((e,t,n)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class x extends p{constructor(e,t,n){super(null,"Root",t??null,null,n??null),b(this,"__rootDomElement"),this.__rootDomElement=e}get canExistAtRootLevel(){return!1}get domElement(){return this.__rootDomElement}get nestedMarkdownElements(){return"all"}get yieldingMarkdownElements(){return"none"}complete(){var e;this.parsingChild&&this.parsingChild.purgeSequence(),this.purgeSequence(),e=this.domElement?.lastChild,e instanceof HTMLElement&&"BR"===e.tagName&&this.domElement?.lastChild?.remove()}createAndAppendMarkdown(e,t){A(e,this,t,void 0,this.markdownProcessorOptions),this.sequenceParser.reset()}createElement(){throw new Error("Root cannot create an element")}processCharacter(e){this.preProcessCharacter(e),this.parsingChild?this.parsingChild.processCharacter(e):(this.sequenceParser.appendCharacter(e),this.processSequence(e))}yield(){super.yield(),this.__rootDomElement=void 0}processSequence(e){if(this.sequenceParser.shouldCloseCurrentMarkdown)return;const s=this.sequenceParser.nestedElementToCreate;if(s){A(s,this,this.sequenceParser.sequence,e,this.markdownProcessorOptions);const t=this.parsingChild;return t&&!t.canExistAtRootLevel&&(A("Paragraph",this,void 0,void 0,this.markdownProcessorOptions),this.parsingChild?.setParsingChild(t)),void this.sequenceParser.reset()}this.sequenceParser.canLeadToClosingOrNewMarkdown||(t(this.last3Characters)?this.createAndAppendMarkdown("LineBreak"):e&&!n(e)&&(A("Paragraph",this,void 0,this.sequenceParser.sequence,this.markdownProcessorOptions),this.sequenceParser.reset()))}}const T=10;e.createMarkdownStreamParser=(e,t)=>{const n=((e,t)=>{const{syntaxHighlighter:n,htmlSanitizer:s,streamingAnimationSpeed:r=T,markdownLinkTarget:i,showCodeBlockCopyButton:o,skipStreamingAnimation:a=!1,onComplete:l}=t||{},d=new x(e,void 0,{syntaxHighlighter:n,htmlSanitizer:s,markdownLinkTarget:i,showCodeBlockCopyButton:o}),c=[];let h=0,u=!1,p="idle";const m=a?0:Math.max(r,0),_=r>0?r:20,g=Math.ceil(2e3/_),C=()=>{if("closed"===p)return;if("idle"===p&&(p="processing"),0===c.length)return void(!1===u&&h<g?(p="waitingForMoreCharacters",h+=1,setTimeout(C,_)):(d.processCharacter("\n"),d.complete(),d.yield(),t?.htmlSanitizer&&(e.innerHTML=t.htmlSanitizer(e.innerHTML)),p="closed",l?.()));p="processing",h=0;const n=c.shift();n&&d.processCharacter(n),setTimeout(C,m)};return{next:e=>{if(e){for(let t=0;t<e.length;t++)c.push(e[t]);"idle"===p&&C()}},complete:()=>{u=!0},error:()=>{}}})(e,{syntaxHighlighter:t?.syntaxHighlighter,htmlSanitizer:t?.htmlSanitizer,markdownLinkTarget:t?.markdownLinkTarget,showCodeBlockCopyButton:t?.showCodeBlockCopyButton,skipStreamingAnimation:t?.skipStreamingAnimation,streamingAnimationSpeed:t?.streamingAnimationSpeed,onComplete:t?.onComplete});return{next(e){n.next(e)},complete(){n.complete()}}}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@nlux/markdown"]={})}(this,(function(e){"use strict";const t=e=>{"string"!=typeof e?e&&"function"==typeof e.toString?console.warn(`[nlux] ${e.toString()}`):console.warn("[nlux]"):console.warn(`[nlux] ${e}`)};function n(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let s={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function r(e){s=e}var i=Object.defineProperty,l=(e,t,n)=>((e,t,n)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class o{constructor(e){l(this,"options"),this.options=e||s}postprocess(e){return e}preprocess(e){return e}processAllTokens(e){return e}}l(o,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));const a=/[&<>"']/,c=new RegExp(a.source,"g"),h=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,p=new RegExp(h.source,"g"),u={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},g=e=>u[e];function k(e,t){if(t){if(a.test(e))return e.replace(c,g)}else if(h.test(e))return e.replace(p,g);return e}const f=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function d(e){return e.replace(f,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const x=/(^|[^\[])\^/g;function m(e,t){let n="string"==typeof e?e:e.source;t=t||"";const s={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(x,"$1"),n=n.replace(e,r),s},getRegex:()=>new RegExp(n,t)};return s}function b(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const w={exec:()=>null};function y(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function $(e,t,n){const s=e.length;if(0===s)return"";let r=0;for(;r<s;){const i=e.charAt(s-r-1);if(i!==t||n){if(i===t||!n)break;r++}else r++}return e.slice(0,s-r)}const z=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,T=/(?:[*+-]|\d{1,9}[.)])/,S=m(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,T).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),A=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,R=/(?!\s*\])(?:\\.|[^\[\]\\])+/,_=m(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",R).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),v=m(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,T).getRegex(),E="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",L=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,I=m("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",L).replace("tag",E).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),C=m(A).replace("hr",z).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",E).getRegex(),q={blockquote:m(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",C).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:_,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:z,html:I,lheading:S,list:v,newline:/^(?: *(?:\n|$))+/,paragraph:C,table:w,text:/^[^\n]+/},B=m("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",z).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",E).getRegex(),P={...q,table:B,paragraph:m(A).replace("hr",z).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",B).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",E).getRegex()},Z={...q,html:m("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",L).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:w,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:m(A).replace("hr",z).replace("heading"," *#{1,6} *[^\n]").replace("lheading",S).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},M=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,H=/^( {2,}|\\)\n(?!\s*$)/,O="\\p{P}\\p{S}",Q=m(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,O).getRegex(),j=m(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,O).getRegex(),D=m("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,O).getRegex(),W=m("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,O).getRegex(),F=m(/\\([punct])/,"gu").replace(/punct/g,O).getRegex(),N=m(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),U=m(L).replace("(?:--\x3e|$)","--\x3e").getRegex(),X=m("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",U).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),G=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,J=m(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",G).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),K=m(/^!?\[(label)\]\[(ref)\]/).replace("label",G).replace("ref",R).getRegex(),V=m(/^!?\[(ref)\](?:\[\])?/).replace("ref",R).getRegex(),Y={_backpedal:w,anyPunctuation:F,autolink:N,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:H,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:w,emStrongLDelim:j,emStrongRDelimAst:D,emStrongRDelimUnd:W,escape:M,link:J,nolink:V,punctuation:Q,reflink:K,reflinkSearch:m("reflink|nolink(?!\\()","g").replace("reflink",K).replace("nolink",V).getRegex(),tag:X,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:w},ee={...Y,link:m(/^!?\[(label)\]\((.*?)\)/).replace("label",G).getRegex(),reflink:m(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",G).getRegex()},te={...Y,escape:m(M).replace("])","~|])").getRegex(),url:m(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},ne={...te,br:m(H).replace("{2,}","*").getRegex(),text:m(te.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},se={normal:q,gfm:P,pedantic:Z},re={normal:Y,gfm:te,breaks:ne,pedantic:ee};var ie=Object.defineProperty,le=(e,t,n)=>((e,t,n)=>t in e?ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);function oe(e,t,n,s){const r=t.href,i=t.title?k(t.title):null,l=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:n,href:r,title:i,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,e}return{type:"image",raw:n,href:r,title:i,text:k(l)}}class ae{constructor(e){le(this,"lexer"),le(this,"options"),le(this,"rules"),this.options=e||s}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=k(t[1]),n="mailto:"+e):(e=k(t[1]),n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=t[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1");e=$(e.replace(/^ *>[ \t]?/gm,""),"\n");const n=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(e);return this.lexer.state.top=n,{type:"blockquote",raw:t[0],tokens:s,text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:$(e,"\n")}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const n=/[^ ]/.test(e),s=/^ /.test(e)&&/ $/.test(e);return n&&s&&(e=e.substring(1,e.length-1)),e=k(e,!0),{type:"codespan",raw:t[0],text:e}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:s}}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s)return;if(s[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const n=[...s[0]].length-1;let r,i,l=n,o=0;const a="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,t=t.slice(-1*e.length+n);null!=(s=a.exec(t));){if(r=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!r)continue;if(i=[...r].length,s[3]||s[4]){l+=i;continue}if((s[5]||s[6])&&n%3&&!((n+i)%3)){o+=i;continue}if(l-=i,l>0)continue;i=Math.min(i,i+l+o);const t=[...s[0]][0].length,a=e.slice(0,n+s.index+t+i);if(Math.min(n,i)%2){const e=a.slice(1,-1);return{type:"em",raw:a,text:e,tokens:this.lexer.inlineTokens(e)}}const c=a.slice(2,-2);return{type:"strong",raw:a,text:c,tokens:this.lexer.inlineTokens(c)}}}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:k(t[1])}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const s=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=$(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:k(t[0]),{type:"text",raw:t[0],text:e}}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}link(e){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=$(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return-1}(t[2],"()");if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],s="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);e&&(n=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),/^</.test(n)&&(n=this.options.pedantic&&!/>$/.test(e)?n.slice(1):n.slice(1,-1)),oe(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:s?s.replace(this.rules.inline.anyPunctuation,"$1"):s},t[0],this.lexer)}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");const i=new RegExp(`^( {0,3}${n})((?:[\t ][^\\n]*)?(?:\\n|$))`);let l="",o="",a=!1;for(;e;){let n=!1;if(!(t=i.exec(e)))break;if(this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let s=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),c=e.split("\n",1)[0],h=0;this.options.pedantic?(h=2,o=s.trimStart()):(h=t[2].search(/[^ ]/),h=h>4?1:h,o=s.slice(h),h+=t[1].length);let p=!1;if(!s&&/^ *$/.test(c)&&(l+=c+"\n",e=e.substring(c.length+1),n=!0),!n){const t=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),n=new RegExp(`^ {0,${Math.min(3,h-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),r=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:\`\`\`|~~~)`),i=new RegExp(`^ {0,${Math.min(3,h-1)}}#`);for(;e;){const a=e.split("\n",1)[0];if(c=a,this.options.pedantic&&(c=c.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),r.test(c))break;if(i.test(c))break;if(t.test(c))break;if(n.test(e))break;if(c.search(/[^ ]/)>=h||!c.trim())o+="\n"+c.slice(h);else{if(p)break;if(s.search(/[^ ]/)>=4)break;if(r.test(s))break;if(i.test(s))break;if(n.test(s))break;o+="\n"+c}p||c.trim()||(p=!0),l+=a+"\n",e=e.substring(a.length+1),s=c.slice(h)}}r.loose||(a?r.loose=!0:/\n *\n *$/.test(l)&&(a=!0));let u,g=null;this.options.gfm&&(g=/^\[[ xX]\] /.exec(o),g&&(u="[ ] "!==g[0],o=o.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:l,task:!!g,checked:u,loose:!1,text:o,tokens:[]}),r.raw+=l}r.items[r.items.length-1].raw=l.trimEnd(),r.items[r.items.length-1].text=o.trimEnd(),r.raw=r.raw.trimEnd();for(let e=0;e<r.items.length;e++)if(this.lexer.state.top=!1,r.items[e].tokens=this.lexer.blockTokens(r.items[e].text,[]),!r.loose){const t=r.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));r.loose=n}if(r.loose)for(let e=0;e<r.items.length;e++)r.items[e].loose=!0;return r}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){const e=t[(n[2]||n[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return oe(n,e,n[0],this.lexer)}}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const n=y(t[1]),s=t[2].replace(/^\||\| *$/g,"").split("|"),r=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],i={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(const e of s)/^ *-+: *$/.test(e)?i.align.push("right"):/^ *:-+: *$/.test(e)?i.align.push("center"):/^ *:-+ *$/.test(e)?i.align.push("left"):i.align.push(null);for(const e of n)i.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of r)i.rows.push(y(e,i.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return i}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=k(t[0]),n="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=k(t[0]),n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}}var ce=Object.defineProperty,he=(e,t,n)=>((e,t,n)=>t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class pe{constructor(e){he(this,"options"),he(this,"state"),he(this,"tokens"),he(this,"inlineQueue"),he(this,"tokenizer"),this.tokens=[],this.tokens.links=Object.create(null),this.options=e||s,this.options.tokenizer=this.options.tokenizer||new ae,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={block:se.normal,inline:re.normal};this.options.pedantic?(t.block=se.pedantic,t.inline=re.pedantic):this.options.gfm&&(t.block=se.gfm,this.options.breaks?t.inline=re.breaks:t.inline=re.gfm),this.tokenizer.rules=t}static get rules(){return{block:se,inline:re}}static lex(e,t){return new pe(t).lex(e)}static lexInline(e,t){return new pe(t).inlineTokens(e)}blockTokens(e,t=[]){let n,s,r,i;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,n)=>t+" ".repeat(n.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.space(e))e=e.substring(n.raw.length),1===n.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(n);else if(n=this.tokenizer.code(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?t.push(n):(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.fences(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.heading(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.hr(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.blockquote(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.list(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.html(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.def(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title}):(s.raw+="\n"+n.raw,s.text+="\n"+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.table(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.lheading(e))e=e.substring(n.raw.length),t.push(n);else{if(r=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startBlock.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(this.state.top&&(n=this.tokenizer.paragraph(r)))s=t[t.length-1],i&&"paragraph"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n),i=r.length!==e.length,e=e.substring(n.raw.length);else if(n=this.tokenizer.text(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,s,r,i,l,o,a=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(i=this.tokenizer.rules.inline.reflinkSearch.exec(a));)e.includes(i[0].slice(i[0].lastIndexOf("[")+1,-1))&&(a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(i=this.tokenizer.rules.inline.blockSkip.exec(a));)a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(i=this.tokenizer.rules.inline.anyPunctuation.exec(a));)a=a.slice(0,i.index)+"++"+a.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(l||(o=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.escape(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.tag(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.link(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.emStrong(e,a,o))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.codespan(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.br(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.del(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.autolink(e))e=e.substring(n.raw.length),t.push(n);else if(this.state.inLink||!(n=this.tokenizer.url(e))){if(r=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startInline.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(r))e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(o=n.raw.slice(-1)),l=!0,s=t[t.length-1],s&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(n.raw.length),t.push(n);return t}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}}var ue=Object.defineProperty,ge=(e,t,n)=>((e,t,n)=>t in e?ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,t+"",n);class ke{constructor(e){ge(this,"options"),this.options=e||s}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}br(){return"<br>"}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}code(e,t,n){const s=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",s?'<pre><code class="language-'+k(s)+'">'+(n?e:k(e,!0))+"</code></pre>\n":"<pre><code>"+(n?e:k(e,!0))+"</code></pre>\n"}codespan(e){return`<code>${e}</code>`}del(e){return`<del>${e}</del>`}em(e){return`<em>${e}</em>`}heading(e,t,n){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}html(e,t){return e}image(e,t,n){const s=b(e);if(null===s)return n;let r=`<img src="${e=s}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">",r}link(e,t,n){const s=b(e);if(null===s)return n;let r='<a href="'+(e=s)+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>",r}list(e,t,n){const s=t?"ol":"ul";return"<"+s+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"</"+s+">\n"}listitem(e,t,n){return`<li>${e}</li>\n`}paragraph(e){return`<p>${e}</p>\n`}strong(e){return`<strong>${e}</strong>`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>\n`}tablerow(e){return`<tr>\n${e}</tr>\n`}text(e){return e}}class fe{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}var de=Object.defineProperty,xe=(e,t,n)=>((e,t,n)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);class me{constructor(e){xe(this,"options"),xe(this,"renderer"),xe(this,"textRenderer"),this.options=e||s,this.options.renderer=this.options.renderer||new ke,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new fe}static parse(e,t){return new me(t).parse(e)}static parseInline(e,t){return new me(t).parseInline(e)}parse(e,t=!0){let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=r,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}switch(r.type){case"space":continue;case"hr":n+=this.renderer.hr();continue;case"heading":{const e=r;n+=this.renderer.heading(this.parseInline(e.tokens),e.depth,d(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=r;n+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=r;let t="",s="";for(let t=0;t<e.header.length;t++)s+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(s);let i="";for(let t=0;t<e.rows.length;t++){const n=e.rows[t];s="";for(let t=0;t<n.length;t++)s+=this.renderer.tablecell(this.parseInline(n[t].tokens),{header:!1,align:e.align[t]});i+=this.renderer.tablerow(s)}n+=this.renderer.table(t,i);continue}case"blockquote":{const e=r,t=this.parse(e.tokens);n+=this.renderer.blockquote(t);continue}case"list":{const e=r,t=e.ordered,s=e.start,i=e.loose;let l="";for(let t=0;t<e.items.length;t++){const n=e.items[t],s=n.checked,r=n.task;let o="";if(n.task){const e=this.renderer.checkbox(!!s);i?n.tokens.length>0&&"paragraph"===n.tokens[0].type?(n.tokens[0].text=e+" "+n.tokens[0].text,n.tokens[0].tokens&&n.tokens[0].tokens.length>0&&"text"===n.tokens[0].tokens[0].type&&(n.tokens[0].tokens[0].text=e+" "+n.tokens[0].tokens[0].text)):n.tokens.unshift({type:"text",text:e+" "}):o+=e+" "}o+=this.parse(n.tokens,i),l+=this.renderer.listitem(o,r,!!s)}n+=this.renderer.list(l,t,s);continue}case"html":{const e=r;n+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=r;n+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let i=r,l=i.tokens?this.parseInline(i.tokens):i.text;for(;s+1<e.length&&"text"===e[s+1].type;)i=e[++s],l+="\n"+(i.tokens?this.parseInline(i.tokens):i.text);n+=t?this.renderer.paragraph(l):l;continue}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=this.options.extensions.renderers[r.type].call({parser:this},r);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=e||"";continue}}switch(r.type){case"escape":{const e=r;n+=t.text(e.text);break}case"html":{const e=r;n+=t.html(e.text);break}case"link":{const e=r;n+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=r;n+=t.image(e.href,e.title,e.text);break}case"strong":{const e=r;n+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=r;n+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=r;n+=t.codespan(e.text);break}case"br":n+=t.br();break;case"del":{const e=r;n+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=r;n+=t.text(e.text);break}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}var be,we,ye,$e=Object.defineProperty,ze=e=>{throw TypeError(e)},Te=(e,t,n)=>((e,t,n)=>t in e?$e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),Se=(e,t,n)=>(((e,t,n)=>{t.has(e)||ze("Cannot "+n)})(e,t,"access private method"),n);be=new WeakSet,we=function(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+k(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}},ye=function(e,t){return(n,s)=>{const r={...s},i={...this.defaults,...r};!0===this.defaults.async&&!1===r.async&&(i.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),i.async=!0);const l=Se(this,be,we).call(this,!!i.silent,!!i.async);if(null==n)return l(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof n)return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(i.hooks&&(i.hooks.options=i),i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(n):n).then((t=>e(t,i))).then((e=>i.hooks?i.hooks.processAllTokens(e):e)).then((e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then((()=>e)):e)).then((e=>t(e,i))).then((e=>i.hooks?i.hooks.postprocess(e):e)).catch(l);try{i.hooks&&(n=i.hooks.preprocess(n));let s=e(n,i);i.hooks&&(s=i.hooks.processAllTokens(s)),i.walkTokens&&this.walkTokens(s,i.walkTokens);let r=t(s,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return l(e)}}};const Ae=new class{constructor(...e){var t,n,s;t=this,(n=be).has(t)?ze("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(t):n.set(t,s),Te(this,"Hooks",o),Te(this,"Lexer",pe),Te(this,"Parser",me),Te(this,"Renderer",ke),Te(this,"TextRenderer",fe),Te(this,"Tokenizer",ae),Te(this,"defaults",{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}),Te(this,"options",this.setOptions),Te(this,"parse",Se(this,be,ye).call(this,pe.lex,me.parse)),Te(this,"parseInline",Se(this,be,ye).call(this,pe.lexInline,me.parseInline)),this.use(...e)}lexer(e,t){return pe.lex(e,t??this.defaults)}parser(e,t){return me.parse(e,t??this.defaults)}setOptions(e){return this.defaults={...this.defaults,...e},this}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=n.apply(this,t)),s}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new ke(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.renderer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new ae(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const s=n,r=e.tokenizer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new o;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.hooks[s],i=t[s];o.passThroughHooks.has(n)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(r.call(t,e)).then((e=>i.call(t,e)));const n=r.call(t,e);return i.call(t,n)}:t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,s=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(s.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}walkTokens(e,t){let n=[];for(const s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{const e=s;for(const s of e.header)n=n.concat(this.walkTokens(s.tokens,t));for(const s of e.rows)for(const e of s)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=s;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((s=>{const r=e[s].flat(1/0);n=n.concat(this.walkTokens(r,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}};function Re(e,t){return Ae.parse(e,t)}Re.options=Re.setOptions=function(e){return Ae.setOptions(e),Re.defaults=Ae.defaults,r(Re.defaults),Re},Re.getDefaults=n,Re.defaults=s,Re.use=function(...e){return Ae.use(...e),Re.defaults=Ae.defaults,r(Re.defaults),Re},Re.walkTokens=function(e,t){return Ae.walkTokens(e,t)},Re.parseInline=Ae.parseInline,Re.Parser=me,Re.parser=me.parse,Re.Renderer=ke,Re.TextRenderer=fe,Re.Lexer=pe,Re.lexer=pe.lex,Re.Tokenizer=ae,Re.Hooks=o,Re.parse=Re;const _e=(e,t)=>{const{showCodeBlockCopyButton:n,markdownLinkTarget:s,syntaxHighlighter:r,htmlSanitizer:i}=t||{},l=Re(e,{async:!1,breaks:!0});if("string"!=typeof l)throw new Error("Markdown parsing failed");const o=document.createElement("div");return o.innerHTML=i?i(l):l,o.querySelectorAll("pre").forEach((e=>{const n=document.createElement("div");n.className="code-block";const s=e.querySelector("code");if(!s){const t=e.innerHTML;return n.innerHTML=i?i(t):t,void e.replaceWith(n)}let l;for(let e=0;e<s.classList.length;e++){const t=s.classList[e];if(t.startsWith("language-")){l=t.slice(9);break}}const o=document.createElement("pre"),a="<div>"+s.innerHTML+"</div>";if(o.innerHTML=t?.htmlSanitizer?t.htmlSanitizer(a):a,l&&(o.setAttribute("data-language",l),r)){const e="<div>"+r.createHighlighter()(s.textContent||"",l)+"</div>";o.innerHTML=i?i(e):e,o.className="highlighter-dark"}(e=>{e.replaceChildren()})(n),n.appendChild(o),e.replaceWith(n)})),!1!==n&&o.querySelectorAll(".code-block").forEach((e=>{if(!e.querySelector("pre"))return;if(e.previousElementSibling?.classList.contains("nlux-comp-copyButton"))return;const t="Copy code block to clipboard",n=document.createElement("button");n.classList.add("nlux-comp-copyButton"),n.setAttribute("aria-label",t),n.setAttribute("title",t);const s=document.createElement("span");s.classList.add("icon-copy"),n.appendChild(s),e.insertAdjacentElement("beforebegin",n)})),"self"!==s&&o.querySelectorAll("a").forEach((e=>{e.setAttribute("target","_blank")})),o.innerHTML},ve=e=>{if(!(e instanceof HTMLButtonElement))return;if("true"===e.dataset.clickListenerSet)return;let t=!1;const n=e.nextElementSibling;e.addEventListener("click",(()=>{if(t||!n)return;const s=n.innerText;navigator.clipboard.writeText(s??""),t=!0,e.classList.add("clicked"),setTimeout((()=>{t=!1,e.classList.remove("clicked")}),1e3)})),e.dataset.clickListenerSet="true"},Ee=e=>{const t="nlux-comp-copyButton";e instanceof HTMLButtonElement&&e.classList.contains(t)?ve(e):e.querySelectorAll(`.${t}`).forEach(ve)},Le=(e,n)=>{let s=!1;const{onComplete:r}=n||{},i=[],l="timeout"===(n?.skipStreamingAnimation?"timeout":"animationFrame")?e=>setTimeout(e,0):e=>requestAnimationFrame(e);const o=document.createElement("div");o.classList.add("md-in-progress"),e.append(o);const a=()=>{for(;o.firstChild;){const e=o.firstChild;e instanceof HTMLElement&&Ee(e),o.before(e)}},c=!n?.skipStreamingAnimation&&n?.streamingAnimationSpeed&&n.streamingAnimationSpeed>=0?n.streamingAnimationSpeed:2;let h,p,u="",g=setInterval((()=>{const e=(new Date).getTime();if(0===i.length)return void((s||h&&e-h>2e3)&&(s=!0,g&&(clearInterval(g),g=void 0),a(),o.remove(),r?.()));h=e;const c=i.shift();c&&l((()=>{const e=u+c,s=_e(e,n).trim();if("string"!=typeof s)return u=u.slice(0,-c.length),void t("Markdown parsing failed");if(p&&s.length>p.length&&s.startsWith(p)){a();const e=s.slice(p.length).trim();o.innerHTML=n?.htmlSanitizer?n.htmlSanitizer(e):e,u=c,p=void 0}else o.innerHTML=n?.htmlSanitizer?n.htmlSanitizer(s):s,u=e,p=s}))}),c);return{next:e=>{if(s)t("Stream is already complete. No more chunks can be added");else for(const t of e)i.push(t)},complete:()=>{s=!0},error:()=>{s=!0}}};e.createMarkdownStreamParser=(e,t)=>{const n=Le(e,{syntaxHighlighter:t?.syntaxHighlighter,htmlSanitizer:t?.htmlSanitizer,markdownLinkTarget:t?.markdownLinkTarget,showCodeBlockCopyButton:t?.showCodeBlockCopyButton,skipStreamingAnimation:t?.skipStreamingAnimation,streamingAnimationSpeed:t?.streamingAnimationSpeed,onComplete:t?.onComplete});return{next(e){n.next(e)},complete(){n.complete()}}}}));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc