import React, { useMemo } from 'react'; import { Text } from '@/components/ui/Typography'; interface MarkdownRendererProps { text: string; } const MarkdownRenderer = ({ text }: MarkdownRendererProps) => { const content = useMemo(() => { if (!text) return null; const blocks = text.split(/(\n{2,})/g); return blocks.map((block, i) => { if (/^\s*$/.test(block)) { return null; } const lines = block.trim().split('\n'); const isList = lines.length > 0 && lines.every((line) => line.trim().startsWith('* ') || line.trim().startsWith('- ')); if (isList) { return ( ); } else { const boldRegex = /\*\*(.*?)\*\*/g; return (
{lines.map((line, j) => ( {line .split(boldRegex) .map((part, k) => (k % 2 === 1 ? {part} : part))} ))}
); } }); }, [text]); return <>{content}; }; export default React.memo(MarkdownRenderer);