fix: add _blank to all markdown link
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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<IProps> = ({ content }) => {
|
||||
const mdContainer = useRef<HTMLDivElement | null>(null);
|
||||
useEffect(() => {
|
||||
if (mdContainer.current) {
|
||||
const links = mdContainer.current.querySelectorAll("a");
|
||||
[...links].forEach((link) => {
|
||||
link.setAttribute("target", "_blank");
|
||||
});
|
||||
}
|
||||
}, [mdContainer]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ImagePreview container={mdContainer.current} context="markdown" />
|
||||
|
||||
Reference in New Issue
Block a user