'use client'; import ReactMarkdown, { type Components } from 'react-markdown'; import { isHTMLContent } from '@/lib/content'; interface ContentViewProps { content: string | null | undefined; className?: string; /** * 显式指定内容格式,优先于内容探测。 * - 'html':富文本,dangerouslySetInnerHTML 渲染 * - 'markdown':用 react-markdown 解析 * 不传时回退到 isHTMLContent 自动判断(旧调用方兼容)。 */ format?: 'html' | 'markdown'; } const mdComponents: Components = { pre: ({ children }) => (
{children}
),
code: ({ className: cls, children }) => {
// 行内 code(无 language- 前缀)→ 灰底圆角;块级 code 由 包裹
const isBlock = typeof cls === 'string' && cls.includes('language-');
if (isBlock) {
return {children};
}
return (
{children}
);
},
table: ({ children }) => (