import ReactMarkdown from 'react-markdown' import 'katex/dist/katex.min.css' import RemarkMath from 'remark-math' import RemarkBreaks from 'remark-breaks' import RehypeKatex from 'rehype-katex' import RemarkGfm from 'remark-gfm' import SyntaxHighlighter from 'react-syntax-highlighter' import { atelierHeathLight } from 'react-syntax-highlighter/dist/esm/styles/hljs' import type { RefObject } from 'react' import { useEffect, useRef, useState } from 'react' import cn from 'classnames' import CopyBtn from '@/app/components/app/chat/copy-btn' import SVGBtn from '@/app/components/app/chat/svg' import Flowchart from '@/app/components/app/chat/mermaid' // Available language https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD const capitalizationLanguageNameMap: Record = { sql: 'SQL', javascript: 'JavaScript', java: 'Java', typescript: 'TypeScript', vbscript: 'VBScript', css: 'CSS', html: 'HTML', xml: 'XML', php: 'PHP', python: 'Python', yaml: 'Yaml', mermaid: 'Mermaid', markdown: 'MarkDown', makefile: 'MakeFile', } const getCorrectCapitalizationLanguageName = (language: string) => { if (!language) return 'Plain' if (language in capitalizationLanguageNameMap) return capitalizationLanguageNameMap[language] return language.charAt(0).toUpperCase() + language.substring(1) } export function PreCode(props: { children: any }) { const ref = useRef(null) return (
       {
          if (ref.current) {
            const code = ref.current.innerText
            // copyToClipboard(code);
          }
        }}
      >
      {props.children}
    
) } const useLazyLoad = (ref: RefObject): boolean => { const [isIntersecting, setIntersecting] = useState(false) useEffect(() => { const observer = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) { setIntersecting(true) observer.disconnect() } }) if (ref.current) observer.observe(ref.current) return () => { observer.disconnect() } }, [ref]) return isIntersecting } export function Markdown(props: { content: string; className?: string }) { const [isSVG, setIsSVG] = useState(false) return (
{languageShowName}
{language === 'mermaid' && }
{(language === 'mermaid' && isSVG) ? () : ( {String(children).replace(/\n$/, '')} )}
) : ( {children} ) }, img({ src, alt, ...props }) { return ( // eslint-disable-next-line @next/next/no-img-element {alt} ) }, p: (paragraph) => { const { node }: any = paragraph if (node.children[0].tagName === 'img') { const image = node.children[0] return ( <> {/* eslint-disable-next-line @next/next/no-img-element */} {image.properties.alt}

{paragraph.children.slice(1)}

) } return

{paragraph.children}

}, }} linkTarget='_blank' > {/* Markdown detect has problem. */} {props.content} ) }