From c7c75c0a8796fd5b212115988ea54bd8e9936508 Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 25 May 2026 19:02:03 +0800 Subject: [PATCH] Feat: Enable agent messages to display base64 images (#15212) ### What problem does this PR solve? Feat: Enable agent messages to display base64 images ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- .../document-preview/ppt-preview.tsx | 1 - .../next-markdown-content/index.tsx | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/web/src/components/document-preview/ppt-preview.tsx b/web/src/components/document-preview/ppt-preview.tsx index d95e05c46d..f6ac8e9886 100644 --- a/web/src/components/document-preview/ppt-preview.tsx +++ b/web/src/components/document-preview/ppt-preview.tsx @@ -24,7 +24,6 @@ export const PptPreviewer: React.FC = ({ console.error('Error loading document:', url); }, }); - console.log(res); try { const arrayBuffer = await res.data.arrayBuffer(); diff --git a/web/src/components/next-markdown-content/index.tsx b/web/src/components/next-markdown-content/index.tsx index 1bab4440a7..0e8e3f8230 100644 --- a/web/src/components/next-markdown-content/index.tsx +++ b/web/src/components/next-markdown-content/index.tsx @@ -1,16 +1,16 @@ import Image from '@/components/image'; import SvgIcon from '@/components/svg-icon'; +import { MarkdownRemarkPlugins } from '@/constants/markdown-remark-plugins'; import { IReferenceChunk, IReferenceObject } from '@/interfaces/database/chat'; import { getExtension } from '@/utils/document-util'; import { downloadFileFromBlob } from '@/utils/file-util'; import request from '@/utils/request'; import DOMPurify from 'dompurify'; import { memo, useCallback, useEffect, useMemo, useState } from 'react'; -import Markdown from 'react-markdown'; +import Markdown, { defaultUrlTransform } from 'react-markdown'; import SyntaxHighlighter from 'react-syntax-highlighter'; import rehypeKatex from 'rehype-katex'; import rehypeRaw from 'rehype-raw'; -import { MarkdownRemarkPlugins } from '@/constants/markdown-remark-plugins'; import { visitParents } from 'unist-util-visit-parents'; import { useTranslation } from 'react-i18next'; @@ -178,7 +178,11 @@ function MarkdownContent({ text = t('chat.searching'); } const nextText = replaceTextByOldReg(text); - return pipe(replaceThinkToSection, replaceRetrievingToSection, preprocessLaTeX)(nextText); + return pipe( + replaceThinkToSection, + replaceRetrievingToSection, + preprocessLaTeX, + )(nextText); }, [content, t]); useEffect(() => { @@ -355,6 +359,15 @@ function MarkdownContent({ { + if ( + key === 'src' && + /^data:image\/(png|jpe?g|gif|webp|svg\+xml);base64,/.test(url) + ) { + return url; + } + return defaultUrlTransform(url); + }} components={ { p: ({ children, ...props }: any) =>

{children}

,