import{Remarkable}from"remarkable";import*as defs from"./FormDefinition.js";const htmlContent=document.createElement("div"),textContent=document.createElement("div"),textNode=document.createTextNode("");htmlContent.appendChild(textNode);const phrasingContentElement=document.createElement("span"),markdownCharsRegExp=/[\\`*_{}[\]()#+\-.!>~]/g,markdownCodeBlockSpacesRegExp=/^[ ]{4}/gm,markdownCodeBlockTabRegExp=/^[ ]{0,3}[	]{1}/gm,markdownLineBreakSuffixRegExp=/[ ]{2}$/gm,remarkable=new Remarkable("commonmark",{html:!1,linkTarget:"_blank"});function escapeTextForMarkdown(e){let t=e.replace(markdownCharsRegExp,"\\$&");return t=t.replace(markdownCodeBlockSpacesRegExp," "),t=t.replace(markdownCodeBlockTabRegExp," "),t=t.replace(markdownLineBreakSuffixRegExp," "),t}function isMarkdown(e){return null!=e&&"string"==typeof e.markdown}function isStatus(e){return null!=e&&"string"==typeof e.status}function textToHtml(e){return textNode.data=e,htmlContent.innerHTML}const phrasingContentTags=["abbr","audio","b","bdo","br","button","canvas","cite","code","command","data","datalist","dfn","em","embed","i","iframe","img","input","kbd","keygen","label","mark","math","meter","noscript","object","output","progress","q","ruby","samp","script","select","small","span","strong","sub","sup","svg","textarea","time","const","video","wbr"];function isPhrasingContent(e){let t=!1;var n;return e instanceof Text?(n=e.textContent.trim(),t=""!==n):e instanceof HTMLElement&&(e=e.tagName.toLowerCase(),t=-1!==phrasingContentTags.indexOf(e)),t}function nodeToPhrasingContent(t){let n="",e="";if(isPhrasingContent(t))if(t instanceof Text)n+=textToHtml(t.textContent);else if(t instanceof HTMLElement){const a=t.outerHTML;var o=a.substring(0,a.indexOf(">")+1);n+=o;var r=a.lastIndexOf("<");e=r<o.length?"":a.substring(r)}for(let e=0;e<t.childNodes.length;e++)n+=nodeToPhrasingContent(t.childNodes[e]);return n+=e,n}function htmlToPhrasingContent(e){phrasingContentElement.innerHTML=e;let t="";for(let e=0;e<phrasingContentElement.childNodes.length;e++)t+=nodeToPhrasingContent(phrasingContentElement.childNodes[e]);return t}function markdownToHtml(e,t=defs.HTMLContentCategory.Flow){let n=remarkable.render(e);return t===defs.HTMLContentCategory.Phrasing&&(n=htmlToPhrasingContent(n)),n}function markdownToText(e){return textContent.innerHTML=markdownToHtml(e,defs.HTMLContentCategory.Flow),textContent.innerText}export{escapeTextForMarkdown,isMarkdown,isStatus,textToHtml,markdownToHtml,markdownToText};