"use client"; import { code } from "@streamdown/code"; import { Streamdown, type Components, type UrlTransform } from "streamdown"; import { cn } from "@/lib/utils"; import { CodeBlock } from "./code-block"; const ALLOWED_LINK_PREFIXES = ["https://", "http://", "mailto:", "#", "/"]; const ALLOWED_IMAGE_PREFIXES = ["https://", "data:image/"]; /** * Whitelist URL scheme to mitigate XSS via javascript:/data: links while * keeping inline fragments and relative paths usable inside the dashboard. */ const safeUrlTransform: UrlTransform = (url, key) => { const lower = url.toLowerCase(); const allowList = key === "src" ? ALLOWED_IMAGE_PREFIXES : ALLOWED_LINK_PREFIXES; return allowList.some((prefix) => lower.startsWith(prefix)) ? url : ""; }; interface MarkdownProps { children: string; className?: string; linkComponent?: Components["a"]; } /** * Thin wrapper around Streamdown that applies our shadcn-friendly typography * and a conservative URL whitelist. Streamdown ships KaTeX, Shiki and GFM out * of the box and repairs partial Markdown during streaming. */ export function Markdown({ children, className, linkComponent, }: MarkdownProps) { return (