mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00
63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
import { Box, Link } from '@chakra-ui/react';
|
|
import ReactMarkdown from 'react-markdown';
|
|
import RemarkGfm from 'remark-gfm';
|
|
import RemarkMath from 'remark-math';
|
|
import RehypeKatex from 'rehype-katex';
|
|
import RemarkBreaks from 'remark-breaks';
|
|
import { event } from '@/utils/plugin/eventbus';
|
|
|
|
import 'katex/dist/katex.min.css';
|
|
import styles from '../index.module.scss';
|
|
import Image from '../img/Image';
|
|
|
|
function MyLink(e: any) {
|
|
const href = e.href;
|
|
const text = String(e.children);
|
|
|
|
return !!href ? (
|
|
<Link href={href} target={'_blank'}>
|
|
{text}
|
|
</Link>
|
|
) : (
|
|
<Box as={'ul'} mt={'0 !important'}>
|
|
<Box as={'li'} mb={1}>
|
|
<Box
|
|
as={'span'}
|
|
color={'blue.600'}
|
|
textDecoration={'underline'}
|
|
cursor={'pointer'}
|
|
onClick={() => {
|
|
event.emit('guideClick', { text });
|
|
}}
|
|
>
|
|
{text}
|
|
</Box>
|
|
</Box>
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
const Guide = ({ text }: { text: string }) => {
|
|
const formatText = useMemo(
|
|
() => text.replace(/\[(.*?)\]($|\n)/g, '[$1]()\n').replace(/\\n/g, '\n '),
|
|
[text]
|
|
);
|
|
return (
|
|
<ReactMarkdown
|
|
className={`markdown ${styles.markdown}`}
|
|
remarkPlugins={[RemarkGfm, RemarkMath, RemarkBreaks]}
|
|
rehypePlugins={[RehypeKatex]}
|
|
components={{
|
|
a: MyLink,
|
|
p: 'div',
|
|
img: Image
|
|
}}
|
|
>
|
|
{formatText}
|
|
</ReactMarkdown>
|
|
);
|
|
};
|
|
|
|
export default React.memo(Guide);
|