= {
"1": `text-lg sm:text-xl font-extrabold ${isDark ? 'text-white' : 'text-ink-900'} mt-4 mb-2 border-b border-slate-700/50 pb-1`,
"2": `text-base sm:text-lg font-extrabold ${isDark ? 'text-white' : 'text-ink-900'} mt-3 mb-1.5`,
"3": `text-sm sm:text-base font-bold ${isDark ? 'text-emerald-400' : 'text-ink-900'} mt-2.5 mb-1`,
"4": `text-xs sm:text-sm font-bold ${isDark ? 'text-emerald-300' : 'text-ink-800'} mt-2 mb-1`,
"5": `text-xs font-bold ${isDark ? 'text-slate-200' : 'text-ink-800'} mt-1.5 mb-1`,
"6": `text-xs font-bold ${isDark ? 'text-slate-300' : 'text-ink-700'} mt-1 mb-0.5`,
};
const Component = block.type as any;
return (
{renderInlineText(block.content, isDark)}
);
};
const renderTableBlock = (block: MarkdownBlock, key: string, isDark: boolean): React.ReactNode => {
if (!block.headers || block.headers.length === 0) return null;
return (
{block.headers.map((h, i) => (
|
{renderInlineText(h, isDark)}
|
))}
{(block.rows || []).map((row, rIdx) => (
{row.map((cell, cIdx) => (
|
{renderInlineText(cell, isDark)}
|
))}
))}
);
};
const renderBlock = (block: MarkdownBlock, index: number, isDark: boolean): React.ReactNode => {
const key = `${block.type}-${index}`;
if (block.type.startsWith("h") && block.type.length === 2 && block.type !== "hr") {
return renderHeadingBlock(block, key, isDark);
}
switch (block.type) {
case "table":
return renderTableBlock(block, key, isDark);
case "blockquote":
return (
{renderInlineText(block.content, isDark)}
);
case "ul":
case "ol":
return renderListBlock(block, key, isDark);
case "code":
return (
{block.language && (
{block.language}
)}
{block.content}
);
case "hr":
return
;
default:
return (
{renderInlineText(block.content, isDark)}
);
}
};
export interface MarkdownViewerProps {
markdown: string;
variant?: 'light' | 'dark' | 'auto';
}
export const MarkdownViewer: React.FC = ({ markdown, variant = 'auto' }) => {
const blocks = parseMarkdown(markdown);
const isDark = variant === 'dark';
return (
{blocks.map((block, idx) => renderBlock(block, idx, isDark))}
);
};
export default MarkdownViewer;