import{jsx as l,Fragment as A}from"react/jsx-runtime";import g,{Fragment as h}from"react";import e from"@markdoc/markdoc";import{useAtomValue as b}from"jotai";import y from"dompurify";import{isString as _}from"@redocly/theme/core/openapi";import{Markdown as z}from"@redocly/theme/components/Markdown/Markdown";import{globalOptionsAtom as R}from"../../jotai/store.js";const S=["OpenApiResponse","OpenApiRequestBody"],W=({source:n,ast:m,htmlWrap:f,markdocOptions:c,...d})=>{const i=b(R);if(!n&&!m)return null;const s=Object.keys(i?.markdocOptions||{}).length?i?.markdocOptions:c,a=s&&{tags:s?.tags,nodes:s?.nodes,partials:s?.partials,variables:s?.variables,functions:s?.functions},u=s&&{components:s?.components};let r;if(n)if(_(n)){const t=i?.unstable_hooks?.sanitize?i.unstable_hooks?.sanitize?.(n):i?.sanitize?y.sanitize(n):n,o=e.parse(t);r=e.transform(o,a)}else{const t=e.Ast.fromJSON(typeof n.result=="object"?JSON.stringify(n.result):n.result);Array.isArray(t)?r=e.transform(t,a):r=e.transform(t,a)}else m&&(r=e.transform(m,a));const p=t=>{const o=e.renderers.react(t,g,u);return l(z,{...d,children:o,as:"div"})};if(!f)return p(r);const O=t=>t.attributes?.htmlWrap!==!1&&!S.includes(t?.name),k=(t,o)=>t?f(p(o)):p(o);return r=Array.isArray(r)?r:r.children,l(A,{children:r.map((t,o)=>l(h,{children:k(O(t),t)},t?.attributes?.id||o))})};export{W as Markdown};
