diff --git a/web/src/components/common/markdown/MarkdownRenderer.jsx b/web/src/components/common/markdown/MarkdownRenderer.jsx index 05419f8cc..6a71c695f 100644 --- a/web/src/components/common/markdown/MarkdownRenderer.jsx +++ b/web/src/components/common/markdown/MarkdownRenderer.jsx @@ -93,6 +93,49 @@ export function Mermaid(props) { ); } +function SandboxedHtmlPreview({ code }) { + const iframeRef = useRef(null); + const [iframeHeight, setIframeHeight] = useState(150); + + useEffect(() => { + const iframe = iframeRef.current; + if (!iframe) return; + + const handleLoad = () => { + try { + const doc = iframe.contentDocument || iframe.contentWindow?.document; + if (doc) { + const height = + doc.documentElement.scrollHeight || doc.body.scrollHeight; + setIframeHeight(Math.min(Math.max(height + 16, 60), 600)); + } + } catch { + // sandbox restrictions may prevent access, that's fine + } + }; + + iframe.addEventListener('load', handleLoad); + return () => iframe.removeEventListener('load', handleLoad); + }, [code]); + + return ( +