diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index 989e2889b..805af7b8b 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -13,6 +13,7 @@ import LoadingIcon from "../icons/three-dots.svg"; import React from "react"; import { useDebouncedCallback } from "use-debounce"; import { showImageModal } from "./ui-lib"; +import { nanoid } from "nanoid"; export function Mermaid(props: { code: string }) { const ref = useRef(null); @@ -62,6 +63,31 @@ export function Mermaid(props: { code: string }) { export function HTMLPreview(props: { code: string }) { const ref = useRef(null); + const frameId = useRef(nanoid()); + const [height, setHeight] = useState(600); + /* + * https://stackoverflow.com/questions/19739001/what-is-the-difference-between-srcdoc-and-src-datatext-html-in-an + * 1. using srcdoc + * 2. using src with dataurl: + * easy to share + * length limit (Data URIs cannot be larger than 32,768 characters.) + */ + + useEffect(() => { + window.addEventListener("message", (e) => { + const { id, height } = e.data; + if (id == frameId.current) { + console.log("setHeight", height); + if (height < 600) { + setHeight(height + 40); + } + } + }); + }, []); + + const script = encodeURIComponent( + ``, + ); return (
console.log("click")} + onClick={(e) => e.stopPropapation()} >
); @@ -108,10 +136,6 @@ export function PreCode(props: { children: any }) { return ( <> - {mermaidCode.length > 0 && ( - - )} - {htmlCode.length > 0 && }
         
         {props.children}
       
+ {mermaidCode.length > 0 && ( + + )} + {htmlCode.length > 0 && } ); }