import { type FC } from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import remarkBreaks from 'remark-breaks' import { cn, safeUrl } from '@/utils' import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area' export interface MarkdownProps { children?: string className?: string } /** * Sanitize URL to prevent XSS attacks * Supports http/https URLs, data URLs (for images), mailto, xmpp, and relative URLs * https://github.com/remarkjs/react-markdown/blob/baad6c53764e34c4ead41e2eaba176acfc87538a/lib/index.js#L293 */ const urlTransform = (value: string) => safeUrl(value) const Markdown: FC = ({ children = '', className }) => { return (
(

), h2: ({ className, ...props }) => (

), h3: ({ className, ...props }) => (

), h4: ({ className, ...props }) => (

), img: ({ className, alt, ...props }) => ( {alt} ), strong: ({ className, ...props }) => , a: ({ className, href, ...props }) => { // Check if link is an image URL const isImage = href && /\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(href) return isImage ? ( ) : ( ) }, ul: ({ className, ...props }) => { Reflect.deleteProperty(props, 'ordered') return
    }, input: ({ className, ...props }) => , table: ({ className, ...props }) => (
    ), tr: ({ className, ...props }) => { return }, th: ({ className, ...props }) => { return (
    ) }, td: ({ className, ...props }) => { return ( ) }, pre: ({ className, ...props }) =>
    ,
              /**
               * TODO: Code highlight
               * @see https://github.com/remarkjs/react-markdown/issues/680
               * @see https://shiki.style/guide/install#usage
               *
               */
              code: ({ className, ...props }) => (
                
                  
                  
                
              )
            }}
            remarkPlugins={[remarkGfm, remarkBreaks]}
          >
            {children}
          
        
      )
    }
    
    Markdown.displayName = 'Markdown'
    
    export { Markdown }