RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Feat: Support for formulas #1954 (#3747)
balibabu0dafce31c428
diff --git a/web/package-lock.json b/web/package-lock.jsonindex ed605f52f5..9202ed8673 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -66,8 +66,10 @@"react18-json-view": "^0.2.8","reactflow": "^11.11.2","recharts": "^2.12.4",+ "rehype-katex": "^7.0.1","rehype-raw": "^7.0.0","remark-gfm": "^4.0.0",+ "remark-math": "^6.0.0","tailwind-merge": "^2.5.4","tailwindcss-animate": "^1.0.7","umi": "^4.0.90",@@ -6379,6 +6381,11 @@"resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz","integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="},+ "node_modules/@types/katex": {+ "version": "0.16.7",+ "resolved": "https://registry.npmmirror.com/@types/katex/-/katex-0.16.7.tgz",+ "integrity": "sha512-HMwFiRujE5PjrgwHQ25+bsLJgowjGjm5Z8FVSf0N6PwgJrwxH0QxzHYDcKsTfV3wva0vzrpqMTJS2jXPr5BMEQ=="+ },"node_modules/@types/lodash": {"version": "4.17.6","resolved": "https://registry.npmmirror.com/@types/lodash/-/lodash-4.17.6.tgz",@@ -15156,6 +15163,48 @@"node": ">= 0.4"}},+ "node_modules/hast-util-from-dom": {+ "version": "5.0.1",+ "resolved": "https://registry.npmmirror.com/hast-util-from-dom/-/hast-util-from-dom-5.0.1.tgz",+ "integrity": "sha512-N+LqofjR2zuzTjCPzyDUdSshy4Ma6li7p/c3pA78uTwzFgENbgbUrm2ugwsOdcjI1muO+o6Dgzp9p8WHtn/39Q==",+ "dependencies": {+ "@types/hast": "^3.0.0",+ "hastscript": "^9.0.0",+ "web-namespaces": "^2.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },+ "node_modules/hast-util-from-dom/node_modules/hast-util-parse-selector": {+ "version": "4.0.0",+ "resolved": "https://registry.npmmirror.com/hast-util-parse-selector/-/hast-util-parse-selector-4.0.0.tgz",+ "integrity": "sha512-wkQCkSYoOGCRKERFWcxMVMOcYE2K1AaNLU8DXS9arxnLOUEWbOXKXiJUNzEpqZ3JOKpnha3jkFrumEjVliDe7A==",+ "dependencies": {+ "@types/hast": "^3.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },+ "node_modules/hast-util-from-dom/node_modules/hastscript": {+ "version": "9.0.0",+ "resolved": "https://registry.npmmirror.com/hastscript/-/hastscript-9.0.0.tgz",+ "integrity": "sha512-jzaLBGavEDKHrc5EfFImKN7nZKKBdSLIdGvCwDZ9TfzbF2ffXiov8CKE445L2Z1Ek2t/m4SKQ2j6Ipv7NyUolw==",+ "dependencies": {+ "@types/hast": "^3.0.0",+ "comma-separated-tokens": "^2.0.0",+ "hast-util-parse-selector": "^4.0.0",+ "property-information": "^6.0.0",+ "space-separated-tokens": "^2.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/hast-util-from-html": {"version": "2.0.3","resolved": "https://registry.npmmirror.com/hast-util-from-html/-/hast-util-from-html-2.0.3.tgz",@@ -15173,6 +15222,21 @@"url": "https://opencollective.com/unified"}},+ "node_modules/hast-util-from-html-isomorphic": {+ "version": "2.0.0",+ "resolved": "https://registry.npmmirror.com/hast-util-from-html-isomorphic/-/hast-util-from-html-isomorphic-2.0.0.tgz",+ "integrity": "sha512-zJfpXq44yff2hmE0XmwEOzdWin5xwH+QIhMLOScpX91e/NSGPsAzNCvLQDIEPyO2TXi+lBmU6hjLIhV8MwP2kw==",+ "dependencies": {+ "@types/hast": "^3.0.0",+ "hast-util-from-dom": "^5.0.0",+ "hast-util-from-html": "^2.0.0",+ "unist-util-remove-position": "^5.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/hast-util-from-parse5": {"version": "8.0.1","resolved": "https://registry.npmmirror.com/hast-util-from-parse5/-/hast-util-from-parse5-8.0.1.tgz",@@ -15363,6 +15427,21 @@"url": "https://opencollective.com/unified"}},+ "node_modules/hast-util-to-text": {+ "version": "4.0.2",+ "resolved": "https://registry.npmmirror.com/hast-util-to-text/-/hast-util-to-text-4.0.2.tgz",+ "integrity": "sha512-KK6y/BN8lbaq654j7JgBydev7wuNMcID54lkRav1P0CaE1e47P72AWWPiGKXTJU271ooYzcvTAn/Zt0REnvc7A==",+ "dependencies": {+ "@types/hast": "^3.0.0",+ "@types/unist": "^3.0.0",+ "hast-util-is-element": "^3.0.0",+ "unist-util-find-after": "^5.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/hast-util-whitespace": {"version": "3.0.0","resolved": "https://registry.npmmirror.com/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz",@@ -19395,6 +19474,21 @@"node": ">=12"}},+ "node_modules/katex": {+ "version": "0.16.11",+ "resolved": "https://registry.npmmirror.com/katex/-/katex-0.16.11.tgz",+ "integrity": "sha512-RQrI8rlHY92OLf3rho/Ts8i/XvjgguEjOkO1BEXcU3N8BqPpSzBNwV/G0Ukr+P/l3ivvJUE/Fa/CwbS6HesGNQ==",+ "funding": [+ "https://opencollective.com/katex",+ "https://github.com/sponsors/katex"+ ],+ "dependencies": {+ "commander": "^8.3.0"+ },+ "bin": {+ "katex": "cli.js"+ }+ },"node_modules/keyv": {"version": "4.5.4","resolved": "https://registry.npmmirror.com/keyv/-/keyv-4.5.4.tgz",@@ -20577,6 +20671,24 @@"mdast-util-to-markdown": "^2.0.0"}},+ "node_modules/mdast-util-math": {+ "version": "3.0.0",+ "resolved": "https://registry.npmmirror.com/mdast-util-math/-/mdast-util-math-3.0.0.tgz",+ "integrity": "sha512-Tl9GBNeG/AhJnQM221bJR2HPvLOSnLE/T9cJI9tlc6zwQk2nPk/4f0cHkOdEixQPC/j8UtKDdITswvLAy1OZ1w==",+ "dependencies": {+ "@types/hast": "^3.0.0",+ "@types/mdast": "^4.0.0",+ "devlop": "^1.0.0",+ "longest-streak": "^3.0.0",+ "mdast-util-from-markdown": "^2.0.0",+ "mdast-util-to-markdown": "^2.1.0",+ "unist-util-remove-position": "^5.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/mdast-util-mdx-expression": {"version": "2.0.0","resolved": "https://registry.npmmirror.com/mdast-util-mdx-expression/-/mdast-util-mdx-expression-2.0.0.tgz",@@ -20877,6 +20989,24 @@"micromark-util-types": "^2.0.0"}},+ "node_modules/micromark-extension-math": {+ "version": "3.1.0",+ "resolved": "https://registry.npmmirror.com/micromark-extension-math/-/micromark-extension-math-3.1.0.tgz",+ "integrity": "sha512-lvEqd+fHjATVs+2v/8kg9i5Q0AP2k85H0WUOwpIVvUML8BapsMvh1XAogmQjOCsLpoKRCVQqEkQBB3NhVBcsOg==",+ "dependencies": {+ "@types/katex": "^0.16.0",+ "devlop": "^1.0.0",+ "katex": "^0.16.0",+ "micromark-factory-space": "^2.0.0",+ "micromark-util-character": "^2.0.0",+ "micromark-util-symbol": "^2.0.0",+ "micromark-util-types": "^2.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/micromark-factory-destination": {"version": "2.0.0","resolved": "https://registry.npmmirror.com/micromark-factory-destination/-/micromark-factory-destination-2.0.0.tgz",@@ -25558,6 +25688,24 @@"url": "https://jaywcjlove.github.io/#/sponsor"}},+ "node_modules/rehype-katex": {+ "version": "7.0.1",+ "resolved": "https://registry.npmmirror.com/rehype-katex/-/rehype-katex-7.0.1.tgz",+ "integrity": "sha512-OiM2wrZ/wuhKkigASodFoo8wimG3H12LWQaH8qSPVJn9apWKFSH3YOCtbKpBorTVw/eI7cuT21XBbvwEswbIOA==",+ "dependencies": {+ "@types/hast": "^3.0.0",+ "@types/katex": "^0.16.0",+ "hast-util-from-html-isomorphic": "^2.0.0",+ "hast-util-to-text": "^4.0.0",+ "katex": "^0.16.0",+ "unist-util-visit-parents": "^6.0.0",+ "vfile": "^6.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/rehype-parse": {"version": "9.0.1","resolved": "https://registry.npmmirror.com/rehype-parse/-/rehype-parse-9.0.1.tgz",@@ -25759,6 +25907,21 @@"webpack": "^5.0.0"}},+ "node_modules/remark-math": {+ "version": "6.0.0",+ "resolved": "https://registry.npmmirror.com/remark-math/-/remark-math-6.0.0.tgz",+ "integrity": "sha512-MMqgnP74Igy+S3WwnhQ7kqGlEerTETXMvJhrUzDikVZ2/uogJCb+WHUg97hK9/jcfc0dkD73s3LN8zU49cTEtA==",+ "dependencies": {+ "@types/mdast": "^4.0.0",+ "mdast-util-math": "^3.0.0",+ "micromark-extension-math": "^3.0.0",+ "unified": "^11.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/remark-parse": {"version": "11.0.0","resolved": "https://registry.npmmirror.com/remark-parse/-/remark-parse-11.0.0.tgz",@@ -29361,6 +29524,19 @@"unist-util-visit-parents": "^6.0.0"}},+ "node_modules/unist-util-find-after": {+ "version": "5.0.0",+ "resolved": "https://registry.npmmirror.com/unist-util-find-after/-/unist-util-find-after-5.0.0.tgz",+ "integrity": "sha512-amQa0Ep2m6hE2g72AugUItjbuM8X8cGQnFoHk0pGfrFeT9GZhzN5SW8nRsiGKK7Aif4CrACPENkA6P/Lw6fHGQ==",+ "dependencies": {+ "@types/unist": "^3.0.0",+ "unist-util-is": "^6.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/unist-util-is": {"version": "6.0.0","resolved": "https://registry.npmmirror.com/unist-util-is/-/unist-util-is-6.0.0.tgz",diff --git a/web/package.json b/web/package.jsonindex 74932c2400..00882e1613 100644--- a/web/package.json+++ b/web/package.json@@ -77,8 +77,10 @@"react18-json-view": "^0.2.8","reactflow": "^11.11.2","recharts": "^2.12.4",+ "rehype-katex": "^7.0.1","rehype-raw": "^7.0.0","remark-gfm": "^4.0.0",+ "remark-math": "^6.0.0","tailwind-merge": "^2.5.4","tailwindcss-animate": "^1.0.7","umi": "^4.0.90",diff --git a/web/src/components/highlight-markdown/index.tsx b/web/src/components/highlight-markdown/index.tsxindex 490626caa2..8f754fdfc5 100644--- a/web/src/components/highlight-markdown/index.tsx+++ b/web/src/components/highlight-markdown/index.tsx@@ -1,8 +1,12 @@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 youimport styles from './index.less';@@ -13,8 +17,8 @@ const HightLightMarkdown = ({}) => {return (<Markdown- remarkPlugins={[remarkGfm]}- rehypePlugins={[rehypeRaw]}+ remarkPlugins={[remarkGfm, remarkMath]}+ rehypePlugins={[rehypeRaw, rehypeKatex]}className={classNames(styles.text)}components={{diff --git a/web/src/pages/chat/markdown-content/index.tsx b/web/src/pages/chat/markdown-content/index.tsxindex 156a8950db..bf2b5dc01e 100644--- a/web/src/pages/chat/markdown-content/index.tsx+++ b/web/src/pages/chat/markdown-content/index.tsx@@ -10,11 +10,16 @@ import { useCallback, useEffect, useMemo } from 'react';import Markdown from 'react-markdown';import reactStringReplace from 'react-string-replace';import SyntaxHighlighter from 'react-syntax-highlighter';+import rehypeKatex from 'rehype-katex';import remarkGfm from 'remark-gfm';+import remarkMath from 'remark-math';import { visitParents } from 'unist-util-visit-parents';import { useFetchDocumentThumbnailsByIds } from '@/hooks/document-hooks';import { useTranslation } from 'react-i18next';++import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you+import styles from './index.less';const reg = /(#{2}\d+\${2})/g;@@ -171,8 +176,8 @@ const MarkdownContent = ({return (<Markdown- rehypePlugins={[rehypeWrapReference]}- remarkPlugins={[remarkGfm]}+ rehypePlugins={[rehypeWrapReference, rehypeKatex]}+ remarkPlugins={[remarkGfm, remarkMath]}components={{'custom-typography': ({ children }: { children: string }) =>