imetting_frontend/src/components/MarkdownRenderer.jsx

33 lines
931 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import React from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import rehypeRaw from 'rehype-raw';
import rehypeSanitize from 'rehype-sanitize';
import './MarkdownRenderer.css';
/**
* 统一的Markdown渲染组件
*
* @param {string} content - Markdown内容
* @param {string} className - 自定义CSS类名可选
* @param {string} emptyMessage - 内容为空时显示的消息(可选)
*/
const MarkdownRenderer = ({ content, className = '', emptyMessage = '暂无内容' }) => {
if (!content || content.trim() === '') {
return <div className="markdown-empty">{emptyMessage}</div>;
}
return (
<div className={`markdown-renderer ${className}`}>
<ReactMarkdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeRaw, rehypeSanitize]}
>
{content}
</ReactMarkdown>
</div>
);
};
export default MarkdownRenderer;