balibabu commited on
Commit
4e17625
·
1 Parent(s): af41fbc

Feat: Support for formulas #1954 (#3747)

Browse files

### What problem does this PR solve?

Feat: Support for formulas #1954

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/package-lock.json CHANGED
@@ -66,8 +66,10 @@
66
  "react18-json-view": "^0.2.8",
67
  "reactflow": "^11.11.2",
68
  "recharts": "^2.12.4",
 
69
  "rehype-raw": "^7.0.0",
70
  "remark-gfm": "^4.0.0",
 
71
  "tailwind-merge": "^2.5.4",
72
  "tailwindcss-animate": "^1.0.7",
73
  "umi": "^4.0.90",
@@ -6379,6 +6381,11 @@
6379
  "resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
6380
  "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="
6381
  },
 
 
 
 
 
6382
  "node_modules/@types/lodash": {
6383
  "version": "4.17.6",
6384
  "resolved": "https://registry.npmmirror.com/@types/lodash/-/lodash-4.17.6.tgz",
@@ -15156,6 +15163,48 @@
15156
  "node": ">= 0.4"
15157
  }
15158
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15159
  "node_modules/hast-util-from-html": {
15160
  "version": "2.0.3",
15161
  "resolved": "https://registry.npmmirror.com/hast-util-from-html/-/hast-util-from-html-2.0.3.tgz",
@@ -15173,6 +15222,21 @@
15173
  "url": "https://opencollective.com/unified"
15174
  }
15175
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15176
  "node_modules/hast-util-from-parse5": {
15177
  "version": "8.0.1",
15178
  "resolved": "https://registry.npmmirror.com/hast-util-from-parse5/-/hast-util-from-parse5-8.0.1.tgz",
@@ -15363,6 +15427,21 @@
15363
  "url": "https://opencollective.com/unified"
15364
  }
15365
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15366
  "node_modules/hast-util-whitespace": {
15367
  "version": "3.0.0",
15368
  "resolved": "https://registry.npmmirror.com/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz",
@@ -19395,6 +19474,21 @@
19395
  "node": ">=12"
19396
  }
19397
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19398
  "node_modules/keyv": {
19399
  "version": "4.5.4",
19400
  "resolved": "https://registry.npmmirror.com/keyv/-/keyv-4.5.4.tgz",
@@ -20577,6 +20671,24 @@
20577
  "mdast-util-to-markdown": "^2.0.0"
20578
  }
20579
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20580
  "node_modules/mdast-util-mdx-expression": {
20581
  "version": "2.0.0",
20582
  "resolved": "https://registry.npmmirror.com/mdast-util-mdx-expression/-/mdast-util-mdx-expression-2.0.0.tgz",
@@ -20877,6 +20989,24 @@
20877
  "micromark-util-types": "^2.0.0"
20878
  }
20879
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20880
  "node_modules/micromark-factory-destination": {
20881
  "version": "2.0.0",
20882
  "resolved": "https://registry.npmmirror.com/micromark-factory-destination/-/micromark-factory-destination-2.0.0.tgz",
@@ -25558,6 +25688,24 @@
25558
  "url": "https://jaywcjlove.github.io/#/sponsor"
25559
  }
25560
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25561
  "node_modules/rehype-parse": {
25562
  "version": "9.0.1",
25563
  "resolved": "https://registry.npmmirror.com/rehype-parse/-/rehype-parse-9.0.1.tgz",
@@ -25759,6 +25907,21 @@
25759
  "webpack": "^5.0.0"
25760
  }
25761
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25762
  "node_modules/remark-parse": {
25763
  "version": "11.0.0",
25764
  "resolved": "https://registry.npmmirror.com/remark-parse/-/remark-parse-11.0.0.tgz",
@@ -29361,6 +29524,19 @@
29361
  "unist-util-visit-parents": "^6.0.0"
29362
  }
29363
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
29364
  "node_modules/unist-util-is": {
29365
  "version": "6.0.0",
29366
  "resolved": "https://registry.npmmirror.com/unist-util-is/-/unist-util-is-6.0.0.tgz",
 
66
  "react18-json-view": "^0.2.8",
67
  "reactflow": "^11.11.2",
68
  "recharts": "^2.12.4",
69
+ "rehype-katex": "^7.0.1",
70
  "rehype-raw": "^7.0.0",
71
  "remark-gfm": "^4.0.0",
72
+ "remark-math": "^6.0.0",
73
  "tailwind-merge": "^2.5.4",
74
  "tailwindcss-animate": "^1.0.7",
75
  "umi": "^4.0.90",
 
6381
  "resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
6382
  "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="
6383
  },
6384
+ "node_modules/@types/katex": {
6385
+ "version": "0.16.7",
6386
+ "resolved": "https://registry.npmmirror.com/@types/katex/-/katex-0.16.7.tgz",
6387
+ "integrity": "sha512-HMwFiRujE5PjrgwHQ25+bsLJgowjGjm5Z8FVSf0N6PwgJrwxH0QxzHYDcKsTfV3wva0vzrpqMTJS2jXPr5BMEQ=="
6388
+ },
6389
  "node_modules/@types/lodash": {
6390
  "version": "4.17.6",
6391
  "resolved": "https://registry.npmmirror.com/@types/lodash/-/lodash-4.17.6.tgz",
 
15163
  "node": ">= 0.4"
15164
  }
15165
  },
15166
+ "node_modules/hast-util-from-dom": {
15167
+ "version": "5.0.1",
15168
+ "resolved": "https://registry.npmmirror.com/hast-util-from-dom/-/hast-util-from-dom-5.0.1.tgz",
15169
+ "integrity": "sha512-N+LqofjR2zuzTjCPzyDUdSshy4Ma6li7p/c3pA78uTwzFgENbgbUrm2ugwsOdcjI1muO+o6Dgzp9p8WHtn/39Q==",
15170
+ "dependencies": {
15171
+ "@types/hast": "^3.0.0",
15172
+ "hastscript": "^9.0.0",
15173
+ "web-namespaces": "^2.0.0"
15174
+ },
15175
+ "funding": {
15176
+ "type": "opencollective",
15177
+ "url": "https://opencollective.com/unified"
15178
+ }
15179
+ },
15180
+ "node_modules/hast-util-from-dom/node_modules/hast-util-parse-selector": {
15181
+ "version": "4.0.0",
15182
+ "resolved": "https://registry.npmmirror.com/hast-util-parse-selector/-/hast-util-parse-selector-4.0.0.tgz",
15183
+ "integrity": "sha512-wkQCkSYoOGCRKERFWcxMVMOcYE2K1AaNLU8DXS9arxnLOUEWbOXKXiJUNzEpqZ3JOKpnha3jkFrumEjVliDe7A==",
15184
+ "dependencies": {
15185
+ "@types/hast": "^3.0.0"
15186
+ },
15187
+ "funding": {
15188
+ "type": "opencollective",
15189
+ "url": "https://opencollective.com/unified"
15190
+ }
15191
+ },
15192
+ "node_modules/hast-util-from-dom/node_modules/hastscript": {
15193
+ "version": "9.0.0",
15194
+ "resolved": "https://registry.npmmirror.com/hastscript/-/hastscript-9.0.0.tgz",
15195
+ "integrity": "sha512-jzaLBGavEDKHrc5EfFImKN7nZKKBdSLIdGvCwDZ9TfzbF2ffXiov8CKE445L2Z1Ek2t/m4SKQ2j6Ipv7NyUolw==",
15196
+ "dependencies": {
15197
+ "@types/hast": "^3.0.0",
15198
+ "comma-separated-tokens": "^2.0.0",
15199
+ "hast-util-parse-selector": "^4.0.0",
15200
+ "property-information": "^6.0.0",
15201
+ "space-separated-tokens": "^2.0.0"
15202
+ },
15203
+ "funding": {
15204
+ "type": "opencollective",
15205
+ "url": "https://opencollective.com/unified"
15206
+ }
15207
+ },
15208
  "node_modules/hast-util-from-html": {
15209
  "version": "2.0.3",
15210
  "resolved": "https://registry.npmmirror.com/hast-util-from-html/-/hast-util-from-html-2.0.3.tgz",
 
15222
  "url": "https://opencollective.com/unified"
15223
  }
15224
  },
15225
+ "node_modules/hast-util-from-html-isomorphic": {
15226
+ "version": "2.0.0",
15227
+ "resolved": "https://registry.npmmirror.com/hast-util-from-html-isomorphic/-/hast-util-from-html-isomorphic-2.0.0.tgz",
15228
+ "integrity": "sha512-zJfpXq44yff2hmE0XmwEOzdWin5xwH+QIhMLOScpX91e/NSGPsAzNCvLQDIEPyO2TXi+lBmU6hjLIhV8MwP2kw==",
15229
+ "dependencies": {
15230
+ "@types/hast": "^3.0.0",
15231
+ "hast-util-from-dom": "^5.0.0",
15232
+ "hast-util-from-html": "^2.0.0",
15233
+ "unist-util-remove-position": "^5.0.0"
15234
+ },
15235
+ "funding": {
15236
+ "type": "opencollective",
15237
+ "url": "https://opencollective.com/unified"
15238
+ }
15239
+ },
15240
  "node_modules/hast-util-from-parse5": {
15241
  "version": "8.0.1",
15242
  "resolved": "https://registry.npmmirror.com/hast-util-from-parse5/-/hast-util-from-parse5-8.0.1.tgz",
 
15427
  "url": "https://opencollective.com/unified"
15428
  }
15429
  },
15430
+ "node_modules/hast-util-to-text": {
15431
+ "version": "4.0.2",
15432
+ "resolved": "https://registry.npmmirror.com/hast-util-to-text/-/hast-util-to-text-4.0.2.tgz",
15433
+ "integrity": "sha512-KK6y/BN8lbaq654j7JgBydev7wuNMcID54lkRav1P0CaE1e47P72AWWPiGKXTJU271ooYzcvTAn/Zt0REnvc7A==",
15434
+ "dependencies": {
15435
+ "@types/hast": "^3.0.0",
15436
+ "@types/unist": "^3.0.0",
15437
+ "hast-util-is-element": "^3.0.0",
15438
+ "unist-util-find-after": "^5.0.0"
15439
+ },
15440
+ "funding": {
15441
+ "type": "opencollective",
15442
+ "url": "https://opencollective.com/unified"
15443
+ }
15444
+ },
15445
  "node_modules/hast-util-whitespace": {
15446
  "version": "3.0.0",
15447
  "resolved": "https://registry.npmmirror.com/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz",
 
19474
  "node": ">=12"
19475
  }
19476
  },
19477
+ "node_modules/katex": {
19478
+ "version": "0.16.11",
19479
+ "resolved": "https://registry.npmmirror.com/katex/-/katex-0.16.11.tgz",
19480
+ "integrity": "sha512-RQrI8rlHY92OLf3rho/Ts8i/XvjgguEjOkO1BEXcU3N8BqPpSzBNwV/G0Ukr+P/l3ivvJUE/Fa/CwbS6HesGNQ==",
19481
+ "funding": [
19482
+ "https://opencollective.com/katex",
19483
+ "https://github.com/sponsors/katex"
19484
+ ],
19485
+ "dependencies": {
19486
+ "commander": "^8.3.0"
19487
+ },
19488
+ "bin": {
19489
+ "katex": "cli.js"
19490
+ }
19491
+ },
19492
  "node_modules/keyv": {
19493
  "version": "4.5.4",
19494
  "resolved": "https://registry.npmmirror.com/keyv/-/keyv-4.5.4.tgz",
 
20671
  "mdast-util-to-markdown": "^2.0.0"
20672
  }
20673
  },
20674
+ "node_modules/mdast-util-math": {
20675
+ "version": "3.0.0",
20676
+ "resolved": "https://registry.npmmirror.com/mdast-util-math/-/mdast-util-math-3.0.0.tgz",
20677
+ "integrity": "sha512-Tl9GBNeG/AhJnQM221bJR2HPvLOSnLE/T9cJI9tlc6zwQk2nPk/4f0cHkOdEixQPC/j8UtKDdITswvLAy1OZ1w==",
20678
+ "dependencies": {
20679
+ "@types/hast": "^3.0.0",
20680
+ "@types/mdast": "^4.0.0",
20681
+ "devlop": "^1.0.0",
20682
+ "longest-streak": "^3.0.0",
20683
+ "mdast-util-from-markdown": "^2.0.0",
20684
+ "mdast-util-to-markdown": "^2.1.0",
20685
+ "unist-util-remove-position": "^5.0.0"
20686
+ },
20687
+ "funding": {
20688
+ "type": "opencollective",
20689
+ "url": "https://opencollective.com/unified"
20690
+ }
20691
+ },
20692
  "node_modules/mdast-util-mdx-expression": {
20693
  "version": "2.0.0",
20694
  "resolved": "https://registry.npmmirror.com/mdast-util-mdx-expression/-/mdast-util-mdx-expression-2.0.0.tgz",
 
20989
  "micromark-util-types": "^2.0.0"
20990
  }
20991
  },
20992
+ "node_modules/micromark-extension-math": {
20993
+ "version": "3.1.0",
20994
+ "resolved": "https://registry.npmmirror.com/micromark-extension-math/-/micromark-extension-math-3.1.0.tgz",
20995
+ "integrity": "sha512-lvEqd+fHjATVs+2v/8kg9i5Q0AP2k85H0WUOwpIVvUML8BapsMvh1XAogmQjOCsLpoKRCVQqEkQBB3NhVBcsOg==",
20996
+ "dependencies": {
20997
+ "@types/katex": "^0.16.0",
20998
+ "devlop": "^1.0.0",
20999
+ "katex": "^0.16.0",
21000
+ "micromark-factory-space": "^2.0.0",
21001
+ "micromark-util-character": "^2.0.0",
21002
+ "micromark-util-symbol": "^2.0.0",
21003
+ "micromark-util-types": "^2.0.0"
21004
+ },
21005
+ "funding": {
21006
+ "type": "opencollective",
21007
+ "url": "https://opencollective.com/unified"
21008
+ }
21009
+ },
21010
  "node_modules/micromark-factory-destination": {
21011
  "version": "2.0.0",
21012
  "resolved": "https://registry.npmmirror.com/micromark-factory-destination/-/micromark-factory-destination-2.0.0.tgz",
 
25688
  "url": "https://jaywcjlove.github.io/#/sponsor"
25689
  }
25690
  },
25691
+ "node_modules/rehype-katex": {
25692
+ "version": "7.0.1",
25693
+ "resolved": "https://registry.npmmirror.com/rehype-katex/-/rehype-katex-7.0.1.tgz",
25694
+ "integrity": "sha512-OiM2wrZ/wuhKkigASodFoo8wimG3H12LWQaH8qSPVJn9apWKFSH3YOCtbKpBorTVw/eI7cuT21XBbvwEswbIOA==",
25695
+ "dependencies": {
25696
+ "@types/hast": "^3.0.0",
25697
+ "@types/katex": "^0.16.0",
25698
+ "hast-util-from-html-isomorphic": "^2.0.0",
25699
+ "hast-util-to-text": "^4.0.0",
25700
+ "katex": "^0.16.0",
25701
+ "unist-util-visit-parents": "^6.0.0",
25702
+ "vfile": "^6.0.0"
25703
+ },
25704
+ "funding": {
25705
+ "type": "opencollective",
25706
+ "url": "https://opencollective.com/unified"
25707
+ }
25708
+ },
25709
  "node_modules/rehype-parse": {
25710
  "version": "9.0.1",
25711
  "resolved": "https://registry.npmmirror.com/rehype-parse/-/rehype-parse-9.0.1.tgz",
 
25907
  "webpack": "^5.0.0"
25908
  }
25909
  },
25910
+ "node_modules/remark-math": {
25911
+ "version": "6.0.0",
25912
+ "resolved": "https://registry.npmmirror.com/remark-math/-/remark-math-6.0.0.tgz",
25913
+ "integrity": "sha512-MMqgnP74Igy+S3WwnhQ7kqGlEerTETXMvJhrUzDikVZ2/uogJCb+WHUg97hK9/jcfc0dkD73s3LN8zU49cTEtA==",
25914
+ "dependencies": {
25915
+ "@types/mdast": "^4.0.0",
25916
+ "mdast-util-math": "^3.0.0",
25917
+ "micromark-extension-math": "^3.0.0",
25918
+ "unified": "^11.0.0"
25919
+ },
25920
+ "funding": {
25921
+ "type": "opencollective",
25922
+ "url": "https://opencollective.com/unified"
25923
+ }
25924
+ },
25925
  "node_modules/remark-parse": {
25926
  "version": "11.0.0",
25927
  "resolved": "https://registry.npmmirror.com/remark-parse/-/remark-parse-11.0.0.tgz",
 
29524
  "unist-util-visit-parents": "^6.0.0"
29525
  }
29526
  },
29527
+ "node_modules/unist-util-find-after": {
29528
+ "version": "5.0.0",
29529
+ "resolved": "https://registry.npmmirror.com/unist-util-find-after/-/unist-util-find-after-5.0.0.tgz",
29530
+ "integrity": "sha512-amQa0Ep2m6hE2g72AugUItjbuM8X8cGQnFoHk0pGfrFeT9GZhzN5SW8nRsiGKK7Aif4CrACPENkA6P/Lw6fHGQ==",
29531
+ "dependencies": {
29532
+ "@types/unist": "^3.0.0",
29533
+ "unist-util-is": "^6.0.0"
29534
+ },
29535
+ "funding": {
29536
+ "type": "opencollective",
29537
+ "url": "https://opencollective.com/unified"
29538
+ }
29539
+ },
29540
  "node_modules/unist-util-is": {
29541
  "version": "6.0.0",
29542
  "resolved": "https://registry.npmmirror.com/unist-util-is/-/unist-util-is-6.0.0.tgz",
web/package.json CHANGED
@@ -77,8 +77,10 @@
77
  "react18-json-view": "^0.2.8",
78
  "reactflow": "^11.11.2",
79
  "recharts": "^2.12.4",
 
80
  "rehype-raw": "^7.0.0",
81
  "remark-gfm": "^4.0.0",
 
82
  "tailwind-merge": "^2.5.4",
83
  "tailwindcss-animate": "^1.0.7",
84
  "umi": "^4.0.90",
 
77
  "react18-json-view": "^0.2.8",
78
  "reactflow": "^11.11.2",
79
  "recharts": "^2.12.4",
80
+ "rehype-katex": "^7.0.1",
81
  "rehype-raw": "^7.0.0",
82
  "remark-gfm": "^4.0.0",
83
+ "remark-math": "^6.0.0",
84
  "tailwind-merge": "^2.5.4",
85
  "tailwindcss-animate": "^1.0.7",
86
  "umi": "^4.0.90",
web/src/components/highlight-markdown/index.tsx CHANGED
@@ -1,8 +1,12 @@
1
  import classNames from 'classnames';
2
  import Markdown from 'react-markdown';
3
  import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
 
4
  import rehypeRaw from 'rehype-raw';
5
  import remarkGfm from 'remark-gfm';
 
 
 
6
 
7
  import styles from './index.less';
8
 
@@ -13,8 +17,8 @@ const HightLightMarkdown = ({
13
  }) => {
14
  return (
15
  <Markdown
16
- remarkPlugins={[remarkGfm]}
17
- rehypePlugins={[rehypeRaw]}
18
  className={classNames(styles.text)}
19
  components={
20
  {
 
1
  import classNames from 'classnames';
2
  import Markdown from 'react-markdown';
3
  import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
4
+ import rehypeKatex from 'rehype-katex';
5
  import rehypeRaw from 'rehype-raw';
6
  import remarkGfm from 'remark-gfm';
7
+ import remarkMath from 'remark-math';
8
+
9
+ import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
10
 
11
  import styles from './index.less';
12
 
 
17
  }) => {
18
  return (
19
  <Markdown
20
+ remarkPlugins={[remarkGfm, remarkMath]}
21
+ rehypePlugins={[rehypeRaw, rehypeKatex]}
22
  className={classNames(styles.text)}
23
  components={
24
  {
web/src/pages/chat/markdown-content/index.tsx CHANGED
@@ -10,11 +10,16 @@ import { useCallback, useEffect, useMemo } from 'react';
10
  import Markdown from 'react-markdown';
11
  import reactStringReplace from 'react-string-replace';
12
  import SyntaxHighlighter from 'react-syntax-highlighter';
 
13
  import remarkGfm from 'remark-gfm';
 
14
  import { visitParents } from 'unist-util-visit-parents';
15
 
16
  import { useFetchDocumentThumbnailsByIds } from '@/hooks/document-hooks';
17
  import { useTranslation } from 'react-i18next';
 
 
 
18
  import styles from './index.less';
19
 
20
  const reg = /(#{2}\d+\${2})/g;
@@ -171,8 +176,8 @@ const MarkdownContent = ({
171
 
172
  return (
173
  <Markdown
174
- rehypePlugins={[rehypeWrapReference]}
175
- remarkPlugins={[remarkGfm]}
176
  components={
177
  {
178
  'custom-typography': ({ children }: { children: string }) =>
 
10
  import Markdown from 'react-markdown';
11
  import reactStringReplace from 'react-string-replace';
12
  import SyntaxHighlighter from 'react-syntax-highlighter';
13
+ import rehypeKatex from 'rehype-katex';
14
  import remarkGfm from 'remark-gfm';
15
+ import remarkMath from 'remark-math';
16
  import { visitParents } from 'unist-util-visit-parents';
17
 
18
  import { useFetchDocumentThumbnailsByIds } from '@/hooks/document-hooks';
19
  import { useTranslation } from 'react-i18next';
20
+
21
+ import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you
22
+
23
  import styles from './index.less';
24
 
25
  const reg = /(#{2}\d+\${2})/g;
 
176
 
177
  return (
178
  <Markdown
179
+ rehypePlugins={[rehypeWrapReference, rehypeKatex]}
180
+ remarkPlugins={[remarkGfm, remarkMath]}
181
  components={
182
  {
183
  'custom-typography': ({ children }: { children: string }) =>