mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-10 13:45:44 +08:00
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)
This commit is contained in:
@@ -24,7 +24,6 @@ export const PptPreviewer: React.FC<PptPreviewerProps> = ({
|
||||
console.error('Error loading document:', url);
|
||||
},
|
||||
});
|
||||
console.log(res);
|
||||
try {
|
||||
const arrayBuffer = await res.data.arrayBuffer();
|
||||
|
||||
|
||||
@@ -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({
|
||||
<Markdown
|
||||
rehypePlugins={[rehypeWrapReference, rehypeKatex, rehypeRaw]}
|
||||
remarkPlugins={MarkdownRemarkPlugins}
|
||||
urlTransform={(url, key) => {
|
||||
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) => <p {...props}>{children}</p>,
|
||||
|
||||
Reference in New Issue
Block a user