import { memo } from "react"; import ReactMarkdown from "react-markdown"; import rehypeSanitize from "rehype-sanitize"; import remarkBreaks from "remark-breaks"; import remarkGfm from "remark-gfm"; function safeUrl(value: string) { if (!value.trim()) return ""; try { const url = new URL(value, document.baseURI); return ["http:", "https:", "mailto:", "tel:"].includes(url.protocol) ? url.href : ""; } catch { return ""; } } export const Markdown = memo(function Markdown({ children, }: { children: string; }) { return (
{label} ) : ( label ); }, img({ src, alt, title }) { const safeHref = safeUrl(src ?? ""); const label = alt || "image"; return safeHref ? ( [image: {label}] ) : ( {label} ); }, }} > {children}
); });