feat: deal with broken images

This commit is contained in:
Li Xin 2025-04-19 10:01:03 +08:00
parent 6ffe46e39b
commit a4ccdfce22

View File

@ -39,6 +39,10 @@ export function Markdown({
}
return [rehypeKatex];
}, [animate]);
const handleImgError = (e: React.SyntheticEvent<HTMLImageElement>) => {
e.currentTarget.style.display = "none";
console.warn(`Markdown: Image "${e.currentTarget.src}" failed to load`);
};
return (
<div
className={cn(className, "markdown flex flex-col gap-4")}
@ -53,6 +57,9 @@ export function Markdown({
{children}
</a>
),
img: ({ src, alt }) => (
<img src={src} alt={alt} onError={handleImgError} />
),
}}
{...props}
>