import u,{useMemo as h}from"react";import{parse as p,transform as m,renderers as b,Tag as g,nodes as d}from"@markdoc/markdoc";import{CodeBlock as k}from"@redocly/theme/components/CodeBlock/CodeBlock";const y=t=>/\{%\s*(?:\/?\w+(?:-\w+)*|\/)(?:\s+[^%]+)?\s*(?:\/%|%\})/.test(t),C=(t,e)=>{try{const r=m(t,e);return Array.isArray(r)?r:[r]}catch(r){console.error("Error transforming node:",r)}return[]},l=(t,e,r,n)=>new g("CodeBlock",{...t,header:{title:n,controls:{copy:{}}},source:e,lang:r},[]),N=(t,e)=>{const r=t.transformAttributes(e),n=r["data-language"]||"markdoc",c=r["data-title"],o=t.attributes.content||"",a=l(r,o,n,c),s=[];if(!t.children||t.children.length<=1)return{codeNode:a,contentNodes:s};for(const i of t.children){if(!i)continue;const f=C(i,e);s.push(...f)}return{codeNode:a,contentNodes:s}},w=(t,e)=>{const r=t.transformAttributes(e),n=r["data-language"],c=r["data-title"],o=t.attributes.content||"";if(!y(o)||!t.children||t.children.length===0)return l(r,o,n,c);const a=t.children[0];if(!a||a.type!=="tag")return l(r,o,n,c);const{codeNode:s,contentNodes:i}=N(t,e);return new g("Fragment",{},[s,...i])},B=t=>h(()=>{if(!t)return null;const r=p(t),n=m(r,{nodes:{document:{...d.document,render:"div"},fence:{...d.fence,attributes:{...d.fence.attributes,label:{type:String,render:"data-label"},title:{type:String,render:"data-title"},highlight:{type:String,render:"data-highlight"}},transform:w}}});return b.react(n,u,{components:{CodeBlock:k,Fragment:u.Fragment}})},[t]);export{y as containsMarkdocTags,B as useMarkdownText};
