返回 JoyAI-Echo
MarkdownText.tsx
1 import { Suspense, lazy } from "react";
2
3 import { cn } from "@/lib/utils";
4
5 interface MarkdownTextProps {
6 children: string;
7 className?: string;
8 }
9
10 const loadMarkdownRenderer = () => import("@/components/MarkdownTextRenderer");
11 const LazyMarkdownRenderer = lazy(loadMarkdownRenderer);
12
13 export function preloadMarkdownText(): void {
14 void loadMarkdownRenderer();
15 }
16
17 /**
18 * Lightweight markdown renderer mirroring agent-chat-ui: GFM + math via
19 * ``remark-math`` / ``rehype-katex``, and fenced code blocks delegated to
20 * ``CodeBlock`` for copy-to-clipboard and syntax highlighting.
21 */
22 export function MarkdownText({ children, className }: MarkdownTextProps) {
23 return (
24 <Suspense
25 fallback={
26 <div
27 className={cn(
28 "whitespace-pre-wrap break-words leading-relaxed text-foreground/92",
29 className,
30 )}
31 >
32 {children}
33 </div>
34 }
35 >
36 <LazyMarkdownRenderer className={className}>{children}</LazyMarkdownRenderer>
37 </Suspense>
38 );
39 }
40
40 lines Plain Text