import React from 'react'; import ReactMarkdown from 'react-markdown'; import type { PluggableList } from 'unified'; import remarkGfm from 'remark-gfm'; import rehypeRaw from 'rehype-raw'; import rehypeSanitize from 'rehype-sanitize'; type MarkdownSize = 'sm' | 'base' | 'lg'; type MarkdownProps = { content?: string; allowHtml?: boolean; className?: string; dir?: 'rtl' | 'ltr'; justify?: boolean; size?: MarkdownSize; }; export default function Markdown({ content = '', allowHtml = false, className = '', dir = 'rtl', justify = false, size = 'sm', }: MarkdownProps) { const rehypePlugins: PluggableList | undefined = allowHtml ? [rehypeRaw, rehypeSanitize] : undefined; const baseSizeClass = size === 'sm' ? 'text-sm' : size === 'lg' ? 'text-lg' : 'text-base'; const hScale = size === 'sm' ? { h1: 'text-xl', h2: 'text-lg', h3: 'text-base', h4: 'text-base' } : size === 'base' ? { h1: 'text-3xl', h2: 'text-2xl', h3: 'text-xl', h4: 'text-lg' } : { h1: 'text-4xl', h2: 'text-3xl', h3: 'text-2xl', h4: 'text-xl' }; const justifyStyle: React.CSSProperties | undefined = justify ? { textAlign: 'justify', textJustify: 'inter-word' } : undefined; return (

, h2: (p) =>

, h3: (p) =>

, h4: (p) =>

, p: (p) =>

, a: (p) => , ul: (p) =>