refactor: extract link and image components for Markdown rendering (#119)

This commit is contained in:
Leo Hui
2025-05-14 10:45:34 +08:00
committed by GitHub
parent b85a7592dc
commit a14ca92c36

View File

@@ -19,6 +19,19 @@ import { cn } from "~/lib/utils";
import Image from "./image"; import Image from "./image";
import { Tooltip } from "./tooltip"; import { Tooltip } from "./tooltip";
const components: ReactMarkdownOptions["components"] = {
a: ({ href, children }) => (
<a href={href} target="_blank" rel="noopener noreferrer">
{children}
</a>
),
img: ({ src, alt }) => (
<a href={src as string} target="_blank" rel="noopener noreferrer">
<Image className="rounded" src={src as string} alt={alt ?? ""} />
</a>
),
};
export function Markdown({ export function Markdown({
className, className,
children, children,
@@ -49,18 +62,7 @@ export function Markdown({
<ReactMarkdown <ReactMarkdown
remarkPlugins={[remarkGfm, remarkMath]} remarkPlugins={[remarkGfm, remarkMath]}
rehypePlugins={rehypePlugins} rehypePlugins={rehypePlugins}
components={{ components={components}
a: ({ href, children }) => (
<a href={href} target="_blank" rel="noopener noreferrer">
{children}
</a>
),
img: ({ src, alt }) => (
<a href={src as string} target="_blank" rel="noopener noreferrer">
<Image className="rounded" src={src as string} alt={alt ?? ""} />
</a>
),
}}
{...props} {...props}
> >
{autoFixMarkdown( {autoFixMarkdown(