// @bun
var{defineProperty:Z,getOwnPropertyNames:S,getOwnPropertyDescriptor:U}=Object,I=Object.prototype.hasOwnProperty;function B(z){return this[z]}var x=(z)=>{var D=(_??=new WeakMap).get(z),F;if(D)return D;if(D=Z({},"__esModule",{value:!0}),z&&typeof z==="object"||typeof z==="function"){for(var G of S(z))if(!I.call(D,G))Z(D,G,{get:B.bind(z,G),enumerable:!(F=U(z,G))||F.enumerable})}return _.set(z,D),D},_;var P=(z)=>z;function R(z,D){this[z]=P.bind(null,D)}var b=(z,D)=>{for(var F in D)Z(z,F,{get:D[F],enumerable:!0,configurable:!0,set:R.bind(D,F)})};var f=(z,D)=>()=>(z&&(D=z(z=0)),D);var H=import.meta.require;function O(z){return z.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function $(z){let D=z.trim().toLowerCase();return!D.startsWith("javascript:")&&!D.startsWith("vbscript:")&&!D.startsWith("data:text/html")}function L(z){let D=/^---\r?\n([\s\S]*?)\r?\n---\r?\n/,F=z.match(D);if(!F)return{data:{},content:z.trim()};let G=F[1],j=z.slice(F[0].length),Q={};for(let W of G.split(`
`)){let J=W.trim();if(!J||J.startsWith("#"))continue;let M=J.indexOf(":");if(M===-1)continue;let N=J.slice(0,M).trim(),q=J.slice(M+1).trim();if(typeof q==="string"){if(q.startsWith('"')&&q.endsWith('"')||q.startsWith("'")&&q.endsWith("'"))q=q.slice(1,-1);else if(q.startsWith("[")&&q.endsWith("]"))try{q=JSON.parse(q)}catch{}else if(q==="true")q=!0;else if(q==="false")q=!1;else if(/^-?\d+(?:\.\d+)?$/.test(q))q=Number(q)}Q[N]=q}return{data:Q,content:j.trim()}}function k(z,D={}){let{gfm:F=!0,breaks:G=!1}=D,j=z,Q=[];if(j=j.replace(/```(\w*)\n([\s\S]*?)```/g,(q,E,K)=>{let V=Q.length,X=E?` class="language-${O(E)}"`:"";return Q.push(`<pre><code${X}>${O(K.trim())}</code></pre>`),`\x00CODEBLOCK${V}\x00`}),j=j.replace(/`([^`]*)`/g,(q,E)=>`<code>${O(E)}</code>`),j=j.replace(/^######\s+(.*)$/gm,"<h6>$1</h6>"),j=j.replace(/^#####\s+(.*)$/gm,"<h5>$1</h5>"),j=j.replace(/^####\s+(.*)$/gm,"<h4>$1</h4>"),j=j.replace(/^###\s+(.*)$/gm,"<h3>$1</h3>"),j=j.replace(/^##\s+(.*)$/gm,"<h2>$1</h2>"),j=j.replace(/^#\s+(.*)$/gm,"<h1>$1</h1>"),j=j.replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>"),j=j.replace(/___(.+?)___/g,"<strong><em>$1</em></strong>"),j=j.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),j=j.replace(/__(.+?)__/g,"<strong>$1</strong>"),j=j.replace(/\*(.+?)\*/g,"<em>$1</em>"),j=j.replace(/(?<![a-zA-Z0-9])_(.+?)_(?![a-zA-Z0-9])/g,"<em>$1</em>"),F)j=j.replace(/~~(.+?)~~/g,"<del>$1</del>");if(j=j.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(q,E,K)=>{return`<img src="${$(K)?O(K):""}" alt="${O(E)}" />`}),j=j.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(q,E,K)=>{return`<a href="${$(K)?O(K):""}">${E}</a>`}),j=j.replace(/^(?:---|\*\*\*|___)\s*$/gm,"<hr />"),j=j.replace(/^>\s+(.*)$/gm,"<blockquote>$1</blockquote>"),j=j.replace(/<\/blockquote>\n<blockquote>/g,`
`),j=j.replace(/^[*\-+]\s+(.*)$/gm,"<li data-ul>$1</li>"),j=j.replace(/(<li data-ul>.*<\/li>\n?)+/g,"<ul>$&</ul>"),j=j.replace(/<\/ul>\n<ul>/g,""),j=j.replace(/^\d+\.\s+(.*)$/gm,"<li data-ol>$1</li>"),j=j.replace(/(<li data-ol>.*<\/li>\n?)+/g,"<ol>$&</ol>"),j=j.replace(/<\/ol>\n<ol>/g,""),j=j.replace(/<li data-ul>/g,"<li>"),j=j.replace(/<li data-ol>/g,"<li>"),F)j=j.replace(/^\|(.+)\|\s*\n\|[-:\s|]+\|\s*\n((?:\|.+\|\s*\n)*)/gm,(q,E,K)=>{let X=`<tr>${E.split("|").map((T)=>T.trim()).filter(Boolean).map((T)=>`<th>${O(T)}</th>`).join("")}</tr>`,A=K.trim().split(`
`).map((T)=>{return`<tr>${T.split("|").map((Y)=>Y.trim()).filter(Boolean).map((Y)=>`<td>${O(Y)}</td>`).join("")}</tr>`}).join(`
`);return`<table>
<thead>
${X}
</thead>
<tbody>
${A}
</tbody>
</table>`});if(F)j=j.replace(/<li>\s*\[\s*\]\s*/g,'<li><input type="checkbox" disabled /> '),j=j.replace(/<li>\s*\[x\]\s*/gi,'<li><input type="checkbox" checked disabled /> ');let W=j.split(`
`),J=[],M=!1,N=[];for(let q of W){let E=q.trim();if(/^<(?:h[1-6]|ul|ol|li|blockquote|pre|table|thead|tbody|tr|th|td|hr|div|p)/.test(E)||/^\0CODEBLOCK\d+\0$/.test(E)||E===""){if(M&&N.length>0)J.push(`<p>${N.join(G?`<br />
`:`
`)}</p>`),N=[],M=!1;J.push(q)}else M=!0,N.push(E)}if(M&&N.length>0)J.push(`<p>${N.join(G?`<br />
`:`
`)}</p>`);if(j=J.join(`
`),G)j=j.replace(/\n/g,`<br />
`);for(let q=0;q<Q.length;q++)j=j.replace(`\x00CODEBLOCK${q}\x00`,Q[q]);return j=j.replace(/<p>\s*<\/p>/g,""),j.trim()}export{k as parseMarkdown,L as parseFrontmatter};
