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/web markdown UI updates (#14214)
小熊09d45046e5f4
diff --git a/web/package-lock.json b/web/package-lock.jsonindex bfb0aee4f2..38407cfbe3 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -100,6 +100,7 @@"recharts": "^2.12.4","rehype-katex": "^7.0.1","rehype-raw": "^7.0.0",+ "remark-breaks": "^4.0.0","remark-gfm": "^4.0.0","remark-math": "^6.0.0","sonner": "^1.7.4",@@ -18439,6 +18440,20 @@"url": "https://opencollective.com/unified"}},+ "node_modules/mdast-util-newline-to-break": {+ "version": "2.0.0",+ "resolved": "https://registry.npmmirror.com/mdast-util-newline-to-break/-/mdast-util-newline-to-break-2.0.0.tgz",+ "integrity": "sha512-MbgeFca0hLYIEx/2zGsszCSEJJ1JSCdiY5xQxRcLDDGa8EPvlLPupJ4DSajbMPAnC0je8jfb9TiUATnxxrHUog==",+ "license": "MIT",+ "dependencies": {+ "@types/mdast": "^4.0.0",+ "mdast-util-find-and-replace": "^3.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/mdast-util-phrasing": {"version": "4.1.0","resolved": "https://registry.npmmirror.com/mdast-util-phrasing/-/mdast-util-phrasing-4.1.0.tgz",@@ -22539,6 +22554,21 @@"url": "https://opencollective.com/unified"}},+ "node_modules/remark-breaks": {+ "version": "4.0.0",+ "resolved": "https://registry.npmmirror.com/remark-breaks/-/remark-breaks-4.0.0.tgz",+ "integrity": "sha512-IjEjJOkH4FuJvHZVIW0QCDWxcG96kCq7An/KVH2NfJe6rKZU2AsHeB3OEjPNRxi4QC34Xdx7I2KGYn6IpT7gxQ==",+ "license": "MIT",+ "dependencies": {+ "@types/mdast": "^4.0.0",+ "mdast-util-newline-to-break": "^2.0.0",+ "unified": "^11.0.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/unified"+ }+ },"node_modules/remark-gfm": {"version": "4.0.1","resolved": "https://registry.npmmirror.com/remark-gfm/-/remark-gfm-4.0.1.tgz",diff --git a/web/package.json b/web/package.jsonindex 4e0485c6d9..6dbed295b4 100644--- a/web/package.json+++ b/web/package.json@@ -122,6 +122,7 @@"recharts": "^2.12.4","rehype-katex": "^7.0.1","rehype-raw": "^7.0.0",+ "remark-breaks": "^4.0.0","remark-gfm": "^4.0.0","remark-math": "^6.0.0","sonner": "^1.7.4",diff --git a/web/src/components/document-preview/md/index.tsx b/web/src/components/document-preview/md/index.tsxindex bdc30f91bc..13f1af3c2f 100644--- a/web/src/components/document-preview/md/index.tsx+++ b/web/src/components/document-preview/md/index.tsx@@ -1,10 +1,10 @@import { Authorization } from '@/constants/authorization';+import { MarkdownRemarkPluginsLite } from '@/constants/markdown-remark-plugins';import { cn } from '@/lib/utils';import FileError from '@/pages/document-viewer/file-error';import { getAuthorization } from '@/utils/authorization-util';import React, { useEffect, useState } from 'react';import ReactMarkdown from 'react-markdown';-import remarkGfm from 'remark-gfm';interface MdProps {// filePath: string;@@ -34,7 +34,9 @@ export const Md: React.FC<MdProps> = ({ url, className }) => {style={{ padding: 4, overflow: 'scroll' }}className={cn(className, 'markdown-body h-[calc(100vh - 200px)]')}>- <ReactMarkdown remarkPlugins={[remarkGfm]}>{content}</ReactMarkdown>+ <ReactMarkdown remarkPlugins={MarkdownRemarkPluginsLite}>+ {content}+ </ReactMarkdown></div>);};diff --git a/web/src/components/floating-chat-widget-markdown.tsx b/web/src/components/floating-chat-widget-markdown.tsxindex 4237fa1758..51912d72af 100644--- a/web/src/components/floating-chat-widget-markdown.tsx+++ b/web/src/components/floating-chat-widget-markdown.tsx@@ -36,8 +36,7 @@ import {} from 'react-syntax-highlighter/dist/esm/styles/prism';import rehypeKatex from 'rehype-katex';import rehypeRaw from 'rehype-raw';-import remarkGfm from 'remark-gfm';-import remarkMath from 'remark-math';+import { MarkdownRemarkPlugins } from '@/constants/markdown-remark-plugins';import { visitParents } from 'unist-util-visit-parents';import styles from './floating-chat-widget-markdown.module.less';import { useIsDarkTheme } from './theme-provider';@@ -292,7 +291,7 @@ const FloatingChatWidgetMarkdown = ({<div className="floating-chat-widget" dir={dir}><MarkdownrehypePlugins={[rehypeWrapReference, rehypeKatex, rehypeRaw]}- remarkPlugins={[remarkGfm, remarkMath]}+ remarkPlugins={MarkdownRemarkPlugins}className="text-sm leading-relaxed space-y-2 prose-sm max-w-full"components={{diff --git a/web/src/components/highlight-markdown/index.tsx b/web/src/components/highlight-markdown/index.tsxindex b2c5bfaabe..c6ad6f3b6d 100644--- a/web/src/components/highlight-markdown/index.tsx+++ b/web/src/components/highlight-markdown/index.tsx@@ -7,8 +7,7 @@ import {} from 'react-syntax-highlighter/dist/esm/styles/prism';import rehypeKatex from 'rehype-katex';import rehypeRaw from 'rehype-raw';-import remarkGfm from 'remark-gfm';-import remarkMath from 'remark-math';+import { MarkdownRemarkPlugins } from '@/constants/markdown-remark-plugins';import 'katex/dist/katex.min.css'; // `rehype-katex` does not import the CSS for you@@ -33,7 +32,7 @@ const HighLightMarkdown = ({return (<div dir={dir} className={classNames(styles.text)}><Markdown- remarkPlugins={[remarkGfm, remarkMath]}+ remarkPlugins={MarkdownRemarkPlugins}rehypePlugins={[rehypeRaw, rehypeKatex]}components={{diff --git a/web/src/components/markdown-content/index.tsx b/web/src/components/markdown-content/index.tsxindex 9dc1544404..3c6dfd927b 100644--- a/web/src/components/markdown-content/index.tsx+++ b/web/src/components/markdown-content/index.tsx@@ -10,8 +10,7 @@ import Markdown from 'react-markdown';import 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 { MarkdownRemarkPlugins } from '@/constants/markdown-remark-plugins';import { visitParents } from 'unist-util-visit-parents';import { useTranslation } from 'react-i18next';@@ -262,7 +261,7 @@ const MarkdownContent = ({<div dir={dir} className={styles.markdownContentWrapper}><MarkdownrehypePlugins={[rehypeWrapReference, rehypeKatex, rehypeRaw]}- remarkPlugins={[remarkGfm, remarkMath]}+ remarkPlugins={MarkdownRemarkPlugins}components={{p: ({ children, ...props }: any) => <p {...props}>{children}</p>,diff --git a/web/src/components/next-markdown-content/index.tsx b/web/src/components/next-markdown-content/index.tsxindex ebedb0eed6..1bab4440a7 100644--- a/web/src/components/next-markdown-content/index.tsx+++ b/web/src/components/next-markdown-content/index.tsx@@ -10,8 +10,7 @@ import Markdown from 'react-markdown';import 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 { MarkdownRemarkPlugins } from '@/constants/markdown-remark-plugins';import { visitParents } from 'unist-util-visit-parents';import { useTranslation } from 'react-i18next';@@ -355,7 +354,7 @@ function MarkdownContent({<div dir={dir} className={styles.markdownContentWrapper}><MarkdownrehypePlugins={[rehypeWrapReference, rehypeKatex, rehypeRaw]}- remarkPlugins={[remarkGfm, remarkMath]}+ remarkPlugins={MarkdownRemarkPlugins}components={{p: ({ children, ...props }: any) => <p {...props}>{children}</p>,diff --git a/web/src/constants/markdown-remark-plugins.ts b/web/src/constants/markdown-remark-plugins.tsnew file mode 100644index 0000000000..9d797082bb--- /dev/null+++ b/web/src/constants/markdown-remark-plugins.ts@@ -0,0 +1,17 @@+import remarkBreaks from 'remark-breaks';+import remarkGfm from 'remark-gfm';+import remarkMath from 'remark-math';++/**+ * GFM + line breaks only (no TeX). For surfaces that do not wire rehype-katex+ * (e.g. uploaded document preview).+ */+export const MarkdownRemarkPluginsLite = [remarkGfm, remarkBreaks];++/**+ * Shared Markdown pipeline for assistant-style content:+ * - remark-gfm: GFM tables, task lists, strikethrough, autolinks, etc.+ * - remark-math: TeX ($...$ / $$...$$); pair with rehype-katex on render.+ * - remark-breaks: treat single newlines as hard breaks (common in LLM chat).+ */+export const MarkdownRemarkPlugins = [remarkGfm, remarkMath, remarkBreaks];diff --git a/web/src/pages/next-search/markdown-content/index.tsx b/web/src/pages/next-search/markdown-content/index.tsxindex 132f34d5df..7149e2b8f0 100644--- a/web/src/pages/next-search/markdown-content/index.tsx+++ b/web/src/pages/next-search/markdown-content/index.tsx@@ -8,8 +8,7 @@ import Markdown from 'react-markdown';import 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 { MarkdownRemarkPlugins } from '@/constants/markdown-remark-plugins';import { visitParents } from 'unist-util-visit-parents';import { useTranslation } from 'react-i18next';@@ -250,7 +249,7 @@ const MarkdownContent = ({><MarkdownrehypePlugins={[rehypeWrapReference, rehypeKatex, rehypeRaw]}- remarkPlugins={[remarkGfm, remarkMath]}+ remarkPlugins={MarkdownRemarkPlugins}components={{p: ({ children, ...props }: any) => <p {...props}>{children}</p>,