/** * Patch embedded HTML to display correctly inside an iframe. * * Injects CSS that ensures proper sizing and scrolling behavior * when HTML content is rendered via srcDoc in an iframe. */ export function patchHtmlForIframe(html: string): string { const iframeCss = ``; // Insert right after or at the start of the document const headIdx = html.indexOf(''); if (headIdx !== -1) { const insertPos = headIdx + 6; // after return html.substring(0, insertPos) + '\n' + iframeCss + html.substring(insertPos); } const headWithAttrs = html.indexOf('', headWithAttrs); if (closeAngle !== -1) { const insertPos = closeAngle + 1; return html.substring(0, insertPos) + '\n' + iframeCss + html.substring(insertPos); } } // Fallback: prepend return iframeCss + html; }