mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Support for formulas #1954 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import classNames from 'classnames';
|
|
import Markdown from 'react-markdown';
|
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
import rehypeKatex from 'rehype-katex';
|
|
import rehypeRaw from 'rehype-raw';
|
|
import remarkGfm from 'remark-gfm';
|
|
import remarkMath from 'remark-math';
|
|
|
|
import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
|
|
|
|
import styles from './index.less';
|
|
|
|
const HightLightMarkdown = ({
|
|
children,
|
|
}: {
|
|
children: string | null | undefined;
|
|
}) => {
|
|
return (
|
|
<Markdown
|
|
remarkPlugins={[remarkGfm, remarkMath]}
|
|
rehypePlugins={[rehypeRaw, rehypeKatex]}
|
|
className={classNames(styles.text)}
|
|
components={
|
|
{
|
|
code(props: any) {
|
|
const { children, className, node, ...rest } = props;
|
|
const match = /language-(\w+)/.exec(className || '');
|
|
return match ? (
|
|
<SyntaxHighlighter
|
|
{...rest}
|
|
PreTag="div"
|
|
language={match[1]}
|
|
// style={dark}
|
|
>
|
|
{String(children).replace(/\n$/, '')}
|
|
</SyntaxHighlighter>
|
|
) : (
|
|
<code {...rest} className={`${className} ${styles.code}`}>
|
|
{children}
|
|
</code>
|
|
);
|
|
},
|
|
} as any
|
|
}
|
|
>
|
|
{children}
|
|
</Markdown>
|
|
);
|
|
};
|
|
|
|
export default HightLightMarkdown;
|