From 9254a9f75b22d56928425f792c093bb6d2aa0c2c Mon Sep 17 00:00:00 2001 From: CplusHua <61106407+CplusHua@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:58:17 +0800 Subject: [PATCH] fix: Markdown base64 image (#206) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bugfix: Markdown base64编码图片支持 修复Markdown中内置base64编码图片的解析错误问题 * style: format code with prettier --------- Co-authored-by: Isla --- src/components/Markdown.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Markdown.tsx b/src/components/Markdown.tsx index 7ff8019b6f..4020e87641 100644 --- a/src/components/Markdown.tsx +++ b/src/components/Markdown.tsx @@ -184,6 +184,10 @@ export function Markdown(props: { content = content.replace(/!\[.*?\]\((.*?)\)/g, (match) => { const name = match.match(/!\[(.*?)\]\(.*?\)/)![1] let url = match.match(/!\[.*?\]\((.*?)\)/)![1] + // 检查是否为 base64 编码的图片 + if (url.startsWith("data:image/")) { + return match // 如果是 base64 编码的图片,直接返回原标签 + } if ( url.startsWith("http://") || url.startsWith("https://") ||