refactor: 替换 Markdown 渲染组件为 markdown-to-jsx

This commit is contained in:
2026-06-03 13:13:04 +08:00
parent 5b09a16bc3
commit 02a202290f
8 changed files with 8 additions and 262 deletions

View File

@@ -1,38 +1,22 @@
import { XMarkdown } from "@ant-design/x-markdown";
import "@ant-design/x-markdown/themes/dark.css";
import "@ant-design/x-markdown/themes/light.css";
import { Typography } from "antd";
import Markdown from "markdown-to-jsx/react";
import type { PartProps } from "./types";
import { useIsDark } from "../../../shared/hooks/use-is-dark";
import { CodeBlockWithCopy } from "./CodeBlockWithCopy";
interface TextPartProps extends PartProps {
isStreaming: boolean;
role: string;
}
const xmarkdownComponents = {
code: CodeBlockWithCopy,
pre: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
};
export function TextPart({ isStreaming, part, role }: TextPartProps) {
const text = typeof part["text"] === "string" ? part["text"] : "";
const isDark = useIsDark();
return (
<div className="part-body">
{role === "user" ? (
<Typography.Paragraph className="message-body-text">{text}</Typography.Paragraph>
) : (
<XMarkdown
className={isDark ? "x-markdown-dark" : "x-markdown-light"}
components={xmarkdownComponents}
content={text}
streaming={{ hasNextChunk: isStreaming }}
/>
<Markdown options={{ optimizeForStreaming: isStreaming }}>{text}</Markdown>
)}
</div>
);