diff --git a/src/components/ImagePreview.tsx b/src/components/ImagePreview.tsx index a693d2a3..7896cc7d 100644 --- a/src/components/ImagePreview.tsx +++ b/src/components/ImagePreview.tsx @@ -29,8 +29,8 @@ const ImagePreview = ({ container, context = "chat" }: Props) => { evt.stopPropagation(); const target = evt.target as HTMLImageElement; if (!target) return; - // 图片 - if (target.nodeName == "IMG") { + // 图片 并且没被 a 标签包裹 + if (target.nodeName == "IMG"&&target.parentElement?.tagName!=="A") { const urlObj = new URL(target.src); const originUrl = `${urlObj.origin}${urlObj.pathname}?file_path=${urlObj.searchParams.get( "file_path" diff --git a/src/components/MarkdownRender.tsx b/src/components/MarkdownRender.tsx index 2b6db712..d4f924ae 100644 --- a/src/components/MarkdownRender.tsx +++ b/src/components/MarkdownRender.tsx @@ -1,6 +1,7 @@ -import { FC, useRef } from "react"; +import { FC, useRef, useEffect } from "react"; import "prismjs/themes/prism.css"; +// @ts-ignore import codeSyntaxHighlight from "@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight-all.js"; import { Viewer } from "@toast-ui/react-editor"; @@ -19,6 +20,15 @@ interface IProps { } const MarkdownRender: FC = ({ content }) => { const mdContainer = useRef(null); + useEffect(() => { + if (mdContainer.current) { + const links = mdContainer.current.querySelectorAll("a"); + [...links].forEach((link) => { + link.setAttribute("target", "_blank"); + }); + } + }, [mdContainer]); + return ( <>