// @bun
var h=/^##\s+Metadata[\s\S]*?(?=^##\s|^#\s|Z)/m;function g(i){return i.replace(/^#\s+.*\n+/m,"").replace(h,"")}function l(i){return/^#{1,4}\s+/.test(i)||/^```/.test(i)||/^\s*[-*]\s+/.test(i)||/^\s*\d+\.\s+/.test(i)||/^>\s+/.test(i)}function u(i){let e=g(i).split(/\r?\n/),r=[],t=0;while(t<e.length){let c=e[t]??"";if(c.startsWith("<!-- @generated")){t+=1;continue}let n=c.trim();if(!n){t+=1;continue}if(n.startsWith("```")){let s=n.slice(3).trim(),o=[];t+=1;while(t<e.length&&!(e[t]??"").trim().startsWith("```"))o.push(e[t]??""),t+=1;t+=1,r.push({type:"code",language:s||"text",code:o.join(`
`)});continue}if(/^#{1,4}\s+/.test(n)){let s=n.match(/^#{1,4}/)?.[0].length??2;r.push({type:"heading",level:s,text:n.replace(/^#{1,4}\s+/,"")}),t+=1;continue}if(/^>\s+/.test(n)){let s=[];while(t<e.length&&/^>\s+/.test((e[t]??"").trim()))s.push((e[t]??"").trim().replace(/^>\s+/,"")),t+=1;r.push({type:"quote",text:s.join(" ")});continue}if(/^[-*]\s+/.test(n)||/^\d+\.\s+/.test(n)){let s=/^\d+\.\s+/.test(n),o=[];while(t<e.length&&l((e[t]??"").trim())){let a=(e[t]??"").trim();if(s&&/^\d+\.\s+/.test(a))o.push(a.replace(/^\d+\.\s+/,""));else if(!s&&/^[-*]\s+/.test(a))o.push(a.replace(/^[-*]\s+/,""));else break;t+=1}r.push({type:"list",ordered:s,items:o});continue}let p=[];while(t<e.length&&!l((e[t]??"").trim())){let s=(e[t]??"").trim();if(!s)break;p.push(s),t+=1}r.push({type:"paragraph",text:p.join(" ")})}return r}export{u as parseDocsMarkdown};
