From f464ce2b75aa6cce0ec13f60a13be0cd62214939 Mon Sep 17 00:00:00 2001 From: Note Manager Date: Fri, 8 May 2026 16:28:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DMarkdown=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E4=B8=AD=E5=9B=BE=E7=89=87=E5=92=8C=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E8=A2=ABescapeHtml=E8=BD=AC=E4=B9=89=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/index.html | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/web/index.html b/web/index.html index 0321cc4..64ddfac 100644 --- a/web/index.html +++ b/web/index.html @@ -818,9 +818,7 @@ return placeholder; }); - // 在转义之前处理图片(必须先于链接处理) - // 图片: ![alt](url) 链接: [text](url) - // 先用占位符保护图片,再处理链接 + // 用占位符保护图片,避免被后续处理影响 const imgPlaceholders = []; text = text.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, function(match, alt, src) { const placeholder = '__IMG_' + imgPlaceholders.length + '__'; @@ -828,17 +826,27 @@ return placeholder; }); - // 处理链接 - text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); - - // 恢复图片 - imgPlaceholders.forEach(function(img, i) { - text = text.replace('__IMG_' + i + '__', img); + // 用占位符保护链接 + const linkPlaceholders = []; + text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, function(match, text_, url) { + const placeholder = '__LINK_' + linkPlaceholders.length + '__'; + linkPlaceholders.push('' + text_ + ''); + return placeholder; }); // 转义 HTML(处理代码块内的内容和其他文本) text = escapeHtml(text); + // 恢复链接(在转义之后) + linkPlaceholders.forEach(function(link, i) { + text = text.replace('__LINK_' + i + '__', link); + }); + + // 恢复图片(在转义之后) + imgPlaceholders.forEach(function(img, i) { + text = text.replace('__IMG_' + i + '__', img); + }); + // 处理行内代码 text = text.replace(/`([^`]+)`/g, '$1');