function v(e){let n="";for(;N.test(e);){let r=e.indexOf("!["),t=e.slice(0,r);n+=t,e=e.slice(r+2);let l=e.indexOf("]("),s=e.slice(0,l);e=e.slice(l+2);let i=e.indexOf(")"),u=e.slice(0,i);e=e.slice(i+1),n+=`<p><img alt=${s} src=${u} /></p>`}return n+e}function S(e){let n="";for(;C.test(e);){let r=e.indexOf("["),t=e.slice(0,r);n+=t,e=e.slice(r+1);let l=e.indexOf("]("),s=e.slice(0,l);e=e.slice(l+2);let i=e.indexOf(")"),u=e.slice(0,i);e=e.slice(i+1),n+=`<a href=${u}>${s}</a>`}return n+e}function d(e,n=!1){let r=x(e);return r=k(r),r=w(r),r=T(r),r=v(r),r=S(r),r=y(r),n?r:`<p>${r}</p>`}function x(e){let n="",r=-1;for(;(r=e.indexOf("**"))!=-1;){n+=e.slice(0,r),e=e.slice(r+2);let t=e.indexOf("**");if(t==-1){e="**"+e;break}n+=`<strong>${e.slice(0,t)}</strong>`,e=e.slice(t+2)}return e&&(n+=e),n}function k(e){let n="",r=-1;for(;(r=e.indexOf("*"))!=-1;){n+=e.slice(0,r),e=e.slice(r+1);let t=e.indexOf("*");if(t==-1){e="*"+e;break}n+=`<i>${e.slice(0,t)}</i>`,e=e.slice(t+1)}return e&&(n+=e),n}function T(e){let n="",r=-1;for(;(r=e.indexOf("~~"))!=-1;){n+=e.slice(0,r),e=e.slice(r+2);let t=e.indexOf("~~");if(t==-1){e="~~"+e;break}n+=`<del>${e.slice(0,t)}</del>`,e=e.slice(t+2)}return e&&(n+=e),n}function w(e){let n="",r=-1;for(;(r=e.indexOf("`"))!=-1;){n+=e.slice(0,r),e=e.slice(r+1);let t=e.indexOf("`");if(t==-1){e="`"+e;break}n+=`<code class=single-code>${e.slice(0,t)}</code>`,e=e.slice(t+1)}return e&&(n+=e),n}function y(e){return e.replace(/icon:(\w+)(\s|\b)/g,(n,r)=>`<i class='iconfont icon-${r}'></i>`)}const E=/(#+)\s(.*)/g,H=/^\s*(\d+)\.\s(.+)/,C=/\[(.*)\]\((.*)\)/,N=/!\[(.*)\]\((.*)\)/;function O(e){/^\s+/.test(e[0])&&(e[0]=e[0].replace(/^(\s+)/g,n=>`
`)),e[0].startsWith(`
`)||(e[0]=`
`+e[0])}function h(e,n){let r="";for(let t of e){let l=t.children.length?h(t.children,n):"";r+=`<li>${d(t.value+l,!0)}</li>`}return`<${n?"ol":"ul"}>${r}</${n?"ol":"ul"}>`}function g(e){return H.test(e)}function M(e){let n=e.indexOf("- ");return n==0||n!=-1&&!e.slice(0,n).trim()}function q(e){return e.indexOf("#")!=-1}function B(e){return e.startsWith("```")}function W(e){return/^>/.test(e.trim())}function j(e){return e.trim()==="---"}function z(e){return e.trim()[0]==="|"}function R(e){return e.replace(/</g,"&lt;")}function $(e){return e.trim()==="::: start"}function D(e){return e.trim()==="::: end"}function F(e){return e.trim()===":::"}function m(e){return e.trim()==="::: headStart"}function P(e){return e.trim()==="::: headEnd"}function V(e){return e.trim()==="::: mainStart"}function A(e){return e.trim()==="::: mainEnd"}function G(e){return`<blockquote>${e.slice(1)}</blockquote>`}function J(e,n,r,t){let l="",s=e[n].slice(3).trim().toLowerCase();for(++n;n<r&&!e[n].startsWith("```");)l+=e[n]+`
`,n++;e[n]="";const i=t.highlight?`language-${s}`:"",u=t.lineNumber?"line-numbers":"",c=[i,u].join(" ");return l=`<pre><code ${c&&`class='${c}'`}>${l}</code></pre>`,{startIdx:n,result:l}}function K(e,n,r){let t="";for(;n<r;n++)if(!!e[n].trim())if(e[n].trim()[0]==="-"&&e[n].indexOf("-")!=-1)t+=e[n]+`
`;else break;return t=Q(t),{startIdx:n,result:t}}function Q(e){const n=e.match(/(\s?)*-\s(.+)/g);if(!n)return e;O(n);const r=U(n);return h(r,!1)}function U(e){const n=[],r=[],t=e.length;for(let l=0;l<t;l++){const s=e[l].indexOf("- "),i={children:[],value:e[l].slice(s+2),level:s,parent:null};if(!r.length){n.push(i),r.push(i);continue}const u=r[r.length-1].level,c=e[l].indexOf("-");let o;if(u===c)o=r[r.length-1].parent;else if(u>c){for(;r[r.length-1].level>c;)r.pop();o=r[r.length-1].parent}else o=r[r.length-1];i.parent=o,o?o.children.push(i):n.push(i),r.push(i)}return n}function X(e,n,r){let t="";for(;n<r;n++)if(!!e[n].trim())if(g(e[n]))t+=e[n]+`
`;else break;return t=Y(t),{startIdx:n,result:t}}function Y(e){const n=e.match(/\s*\d+\.\s(.+)/g);if(!n)return e;O(n);const r=Z(n);return h(r,!0)}function Z(e){const n=[],r=[],t=e.length;for(let l=0;l<t;l++){let s=0;g(e[l])&&(s=e[l].indexOf(String(RegExp.$1+".")));const i={children:[],value:RegExp.$2,level:s,parent:null};if(!r.length){n.push(i),r.push(i);continue}const u=r[r.length-1].level,c=s;let o;if(u===c)o=r[r.length-1].parent;else if(u>c){for(;r[r.length-1].level>c;)r.pop();o=r[r.length-1].parent}else o=r[r.length-1];i.parent=o,o?o.children.push(i):n.push(i),r.push(i)}return n}function _(e){return e.length!==3?e:e==="---"?"<hr/>":e}function p(e){return e.length>6?6:e.length}function ee(e){return e.trim().replace(E,(n,r,t)=>`<h${p(r)}>${d(t,!0)}</h${p(r)}>`)}function ne(e,n,r){let t="<table>";for(t+=re(e[n]),t+="<tbody >",++n;n<r&&e[n].trim()[0]==="|";n++)t+=te(e[n]);return t+="</tbody></table>",{startIdx:n-1,result:t}}function re(e){let n=-1,r="<thead><tr>";for(let t=0,l=e.length;t<l;t++)e[t]=="|"&&f(e,t-1)&&f(e,t+1)&&(n!=-1&&(r+=`<th>${e.slice(n+1,t)}</th>`),n=t);return r+"</tr></thead>"}function te(e){let n=-1,r="<tr>";for(let t=0,l=e.length;t<l;t++)if(e[t]=="|"&&f(e,t-1)&&f(e,t+1)){if(n!=-1){let s=e.slice(n+1,t);if(s.trim()[0]==="-")continue;r+=`<td>${s}</td>`}n=t}return r+"</tr>"}function f(e,n){return e[n]===" "||e[n]==null}function L(e,n,r,t){let l="<div class=head-layout>",s="";for(++n;n<r&&!P(e[n]);)e[n].trim()&&(s+=e[n]+`
`),n++;return l+=a(s,{...t,xss:!1})+"</div>",{result:l,startIdx:n}}function b(e,n,r,t){let l="<div class=flex-layout>",s="";for(++n;n<r&&!D(e[n]);){if($(e[n])){const{result:i,startIdx:u}=b(e,n,r,t);s+=i,n=u}else if(m(e[n])){const{result:i,startIdx:u}=L(e,n,r,t);s+=i,n=u}else F(e[n])?(l+=`<div class=flex-layout-item>${a(s,{...t,xss:!1})}</div>`,s=""):s+=e[n].trim()?`
`+e[n]+`
`:"";n++}return l+=`<div class=flex-layout-item>${a(s,{...t,xss:!1})}</div>`,l+="</div>",{result:l,startIdx:n}}function le(e,n,r,t){let l="<div class=main-layout>",s="";for(++n;n<r&&!A(e[n]);)e[n].trim()&&(s+=e[n]+`
`),n++;return l+=a(s,{...t,xss:!1})+"</div>",{result:l,startIdx:n}}const I={lineNumber:!1,highlight:!1,xss:!0};function a(e,n){let r=n||I,t="";r=Object.assign({...I},r);let l=r.xss?R(e).split(`
`):e.split(`
`),s=(l==null?void 0:l.length)||0;for(let i=0;i<s;){if(q(l[i]))t+=ee(l[i]);else if(m(l[i])){const{result:u,startIdx:c}=L(l,i,s,r);i=c,t+=u}else if(V(l[i])){const{result:u,startIdx:c}=le(l,i,s,r);i=c,t+=u}else if($(l[i])){const{result:u,startIdx:c}=b(l,i,s,r);i=c,t+=u}else if(j(l[i]))t+=_(l[i]),++i;else if(z(l[i])){const{result:u,startIdx:c}=ne(l,i,s);i=c,t+=u}else if(M(l[i])){const{result:u,startIdx:c}=K(l,i,s);i=c-1,t+=u}else if(g(l[i])){const{result:u,startIdx:c}=X(l,i,s);i=c-1,t+=u}else if(B(l[i])){const{result:u,startIdx:c}=J(l,i,s,r);i=c,t+=u}else W(l[i].trim())?t+=G(l[i].trim()):(l[i]=l[i].trim())&&(t+=d(l[i]));i++}return t}export{a as m};
