Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.tsx 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import classNames from 'classnames';
  2. import Markdown from 'react-markdown';
  3. import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
  4. import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
  5. import rehypeKatex from 'rehype-katex';
  6. import rehypeRaw from 'rehype-raw';
  7. import remarkGfm from 'remark-gfm';
  8. import remarkMath from 'remark-math';
  9. import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
  10. import { preprocessLaTeX } from '@/utils/chat';
  11. import styles from './index.less';
  12. const HightLightMarkdown = ({
  13. children,
  14. dark = false,
  15. }: {
  16. children: string | null | undefined;
  17. dark?: boolean;
  18. }) => {
  19. return (
  20. <Markdown
  21. remarkPlugins={[remarkGfm, remarkMath]}
  22. rehypePlugins={[rehypeRaw, rehypeKatex]}
  23. className={classNames(styles.text)}
  24. components={
  25. {
  26. code(props: any) {
  27. const { children, className, node, ...rest } = props;
  28. const match = /language-(\w+)/.exec(className || '');
  29. return match ? (
  30. <SyntaxHighlighter
  31. {...rest}
  32. PreTag="div"
  33. language={match[1]}
  34. style={dark && oneDark}
  35. >
  36. {String(children).replace(/\n$/, '')}
  37. </SyntaxHighlighter>
  38. ) : (
  39. <code {...rest} className={`${className} ${styles.code}`}>
  40. {children}
  41. </code>
  42. );
  43. },
  44. } as any
  45. }
  46. >
  47. {children ? preprocessLaTeX(children) : children}
  48. </Markdown>
  49. );
  50. };
  51. export default HightLightMarkdown;