import f from"@markdoc/markdoc";import{isTag as g}from"../../../shared/utils.js";import{slugger as u}from"../../utils/index.js";import{getMarkdocOptions as b}from"./markdoc/markdoc-options.js";import{visit as l,getHeadingData as h}from"./markdoc/plugins/utils.js";import{renderMermaid as k}from"./markdoc/plugins/render-mermaid.js";import{deepStringify as v}from"./markdoc/utils/deep-stringify.js";import{stringifyTagChildrenObjects as M}from"./utils/stringify-tag-children-objects.js";async function j(n,e,d){const p=await b(d),t=[],a=[],i=v(e.variables?.pageProps),{headers:w,...c}=e.variables||{};u.reset();const s=f.transform(n,{...p,...e,variables:{...c,pageProps:i}});l(s,r=>{if(g(r)){switch(r.name){case"Heading":const m=h(r);m&&t.push(m);break;case"Mermaid":a.push({tag:r,source:r.attributes.diagramSource});break}M(r)}});const o=await k(a.map(r=>r.source));for(let r=0;r<o.length;r++)a[r].tag.attributes.diagramHtml=o[r];return{headings:t,renderableAst:s,pageProps:i}}export{j as transformMdAst};
