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;
});
- // 在转义之前处理图片(必须先于链接处理)
- // 图片:  链接: [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');