diff --git a/apps/sanity/components/HTMLPreview.tsx b/apps/sanity/components/HTMLPreview.tsx index 5d5f0f131..3e408d84f 100644 --- a/apps/sanity/components/HTMLPreview.tsx +++ b/apps/sanity/components/HTMLPreview.tsx @@ -1,13 +1,37 @@ -import React from "react"; -// TODO: Add stronger typing -const HTMLPreview = (props: any) => { +import React, { useEffect, useRef } from "react"; + +const STEGA_REGEX = /[\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFEFF]|\uDB40[\uDC20-\uDC7F]/g; + +interface HTMLPreviewProps { + html?: string; +} + +const HTMLPreview = (props: HTMLPreviewProps) => { const { html } = props; - if (!html) { + const containerRef = useRef(null); + const cleanHtml = typeof html === "string" ? html.replace(STEGA_REGEX, "") : ""; + + useEffect(() => { + const container = containerRef.current; + if (!container || !cleanHtml) return; + + // Re-execute any inline