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 CopyBtn from '@/app/components/app/chat/copy-btn' // import { copyToClipboard } from "../utils"; // https://txtfiddle.com/~hlshwya/extract-urls-from-text // const urlRegex = /\b((https?|ftp|file):\/\/|(www|ftp)\.)[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/ig // function highlightURL(content: string) { // return content.replace(urlRegex, (url) => { // // fix http:// in [] will be parsed to link agin // const res = `[${url.replace('://', '://')}](${url})` // return res // }) // } 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 }) { const [isCopied, setIsCopied] = useState(false) return (
{ if (language) return language.charAt(0).toUpperCase() + language.substring(1) return 'Plain' })() return (!inline && match) ? (
{languageShowName}
{String(children).replace(/\n$/, '')}
) : ( {children} ) }, }} linkTarget={'_blank'} > {/* Markdown detect has problem. */} {props.content}
) }