mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-08 08:28:02 +08:00
fix(markdown): open non-PDF document references in internal viewer (#17971)
This commit is contained in:
@@ -40,7 +40,7 @@ export const TxtPreviewer = ({ className, url }: TxtPreviewerProps) => {
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'relative w-full h-full p-4 bg-background-paper border border-border-normal rounded-md',
|
||||
'relative w-full h-dvh p-4 bg-background-paper border border-border-normal rounded-md overflow-auto',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -86,13 +86,14 @@ const FloatingChatWidgetMarkdown = ({
|
||||
(
|
||||
documentId: string,
|
||||
chunk: IReferenceChunk,
|
||||
isPdf: boolean,
|
||||
fileExtension: string,
|
||||
documentUrl?: string,
|
||||
) =>
|
||||
() => {
|
||||
if (!documentId) return;
|
||||
if (!isPdf && documentUrl) {
|
||||
window.open(documentUrl, '_blank');
|
||||
if (fileExtension !== 'pdf' && documentUrl) {
|
||||
const nextLink = `/document/${documentId}?ext=${fileExtension}&resource=${'document'}`;
|
||||
window.open(nextLink, '_blank');
|
||||
} else if (clickDocumentButton) {
|
||||
clickDocumentButton(documentId, chunk);
|
||||
}
|
||||
@@ -215,7 +216,7 @@ const FloatingChatWidgetMarkdown = ({
|
||||
onClick={handleDocumentButtonClick(
|
||||
documentId,
|
||||
chunkItem,
|
||||
fileExtension === 'pdf',
|
||||
fileExtension,
|
||||
documentUrl,
|
||||
)}
|
||||
disabled={!documentUrl && fileExtension !== 'pdf'}
|
||||
@@ -270,7 +271,7 @@ const FloatingChatWidgetMarkdown = ({
|
||||
onClick={handleDocumentButtonClick(
|
||||
documentId,
|
||||
chunkItem,
|
||||
fileExtension === 'pdf',
|
||||
fileExtension,
|
||||
documentUrl,
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { citationMarkerReg } from '@/utils/citation-utils';
|
||||
import { getExtension } from '@/utils/document-util';
|
||||
import { getDirAttribute } from '@/utils/text-direction';
|
||||
import DOMPurify from 'dompurify';
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import Markdown from 'react-markdown';
|
||||
import SyntaxHighlighter from 'react-syntax-highlighter';
|
||||
import rehypeKatex from 'rehype-katex';
|
||||
@@ -94,15 +94,16 @@ const MarkdownContent = ({
|
||||
(
|
||||
documentId: string,
|
||||
chunk: IReferenceChunk,
|
||||
isPdf: boolean,
|
||||
fileExtension: string,
|
||||
documentUrl?: string,
|
||||
) =>
|
||||
() => {
|
||||
if (!isPdf) {
|
||||
if (fileExtension !== 'pdf') {
|
||||
if (!documentUrl) {
|
||||
return;
|
||||
}
|
||||
window.open(documentUrl, '_blank');
|
||||
const nextLink = `/document/${documentId}?ext=${fileExtension}&resource=${'document'}`;
|
||||
window.open(nextLink, '_blank');
|
||||
} else {
|
||||
clickDocumentButton?.(documentId, chunk);
|
||||
}
|
||||
@@ -226,7 +227,7 @@ const MarkdownContent = ({
|
||||
onClick={handleDocumentButtonClick(
|
||||
documentId,
|
||||
chunkItem,
|
||||
fileExtension === 'pdf',
|
||||
fileExtension,
|
||||
documentUrl,
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -200,15 +200,16 @@ function MarkdownContent({
|
||||
(
|
||||
documentId: string,
|
||||
chunk: IReferenceChunk,
|
||||
isPdf: boolean,
|
||||
fileExtension: string,
|
||||
documentUrl?: string,
|
||||
) =>
|
||||
() => {
|
||||
if (!isPdf) {
|
||||
if (fileExtension !== 'pdf') {
|
||||
if (!documentUrl) {
|
||||
return;
|
||||
}
|
||||
window.open(documentUrl, '_blank');
|
||||
const nextLink = `/document/${documentId}?ext=${fileExtension}&resource=${'document'}`;
|
||||
window.open(nextLink, '_blank');
|
||||
} else {
|
||||
clickDocumentButton?.(documentId, chunk);
|
||||
}
|
||||
@@ -318,7 +319,7 @@ function MarkdownContent({
|
||||
onClick={handleDocumentButtonClick(
|
||||
documentId,
|
||||
chunkItem,
|
||||
fileExtension === 'pdf',
|
||||
fileExtension,
|
||||
documentUrl,
|
||||
)}
|
||||
className="text-ellipsis text-wrap"
|
||||
|
||||
Reference in New Issue
Block a user