mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 04:14:46 +08:00
refactor: extract link and image components for Markdown rendering (#119)
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user