MarkdownRenderer.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Markdown renderer component using react-markdown
  2. import ReactMarkdown from 'react-markdown'
  3. import remarkGfm from 'remark-gfm'
  4. interface MarkdownRendererProps {
  5. content: string
  6. className?: string
  7. /** If true, renders in a compact single-line style for table cells */
  8. compact?: boolean
  9. }
  10. export default function MarkdownRenderer({
  11. content,
  12. className = '',
  13. compact = false,
  14. }: MarkdownRendererProps) {
  15. if (!content) return null
  16. if (compact) {
  17. // For table cells, render a truncated plain text version
  18. // Strip markdown syntax for preview
  19. const plainText = content
  20. .replace(/[#*_~`>\[\]()!]/g, '')
  21. .replace(/\n+/g, ' ')
  22. .trim()
  23. return (
  24. <span className={`truncate ${className}`} title={plainText}>
  25. {plainText.length > 100 ? plainText.slice(0, 100) + '...' : plainText}
  26. </span>
  27. )
  28. }
  29. return (
  30. <div className={`prose prose-sm max-w-none ${className}`}>
  31. <ReactMarkdown remarkPlugins={[remarkGfm]}>{content}</ReactMarkdown>
  32. </div>
  33. )
  34. }