import React, { useState } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import rehypeRaw from 'rehype-raw'; import rehypeKatex from 'rehype-katex'; import { ImagesIcon } from '@phosphor-icons/react'; import ImageModal from './ImageModal'; import MermaidDiagram from './MermaidDiagram'; const MarkdownContent = ({ content, components = {}, className = '' }) => { const [modalData, setModalData] = useState(null); const CustomImage = ({ src, alt, ...props }) => { return (
{alt} setModalData({ src, alt })} {...props} /> {alt && (
{alt}
)}
); }; const CodeBlock = ({ node, inline, className, children, ...props }) => { const match = /language-(\w+)/.exec(className || ''); const isMermaid = match && match[1] === 'mermaid'; if (!inline && isMermaid) { return ; } return ( {children} ); }; const defaultComponents = { img: CustomImage, code: CodeBlock, ...components, }; return ( <>
{content}
setModalData(null)} /> ); }; export default MarkdownContent;