import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { cn } from "@/lib/utils"; type AnnouncementContentProps = { content: string; className?: string; }; /** * 公告由管理员输入但会在所有用户页面展示,因此不启用原始 HTML,避免直接注入 HTML。 * 链接强制新窗口打开,并且只允许 http/https 协议。 */ export function AnnouncementContent({ content, className }: AnnouncementContentProps) { return (
{ const safeURL = safeHref(href); return safeURL ? {children} : <>{children}; }, table: ({ children }) =>
{children}
, }} > {content}
); } function safeHref(value?: string) { if (!value || typeof window === "undefined") return null; try { const url = new URL(value, window.location.href); return url.protocol === "http:" || url.protocol === "https:" ? url.href : null; } catch { return null; } }