From acf8d99d6a3c8ecf29c39c129c5ef277bb04cba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=99=AE?= <18691763612@163.com> Date: Fri, 10 Apr 2026 14:45:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=85=B1=E6=80=A7?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E7=9A=84=E7=9B=AE=E5=BD=95=E8=81=94=E5=8A=A8=E5=92=8C?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E6=A1=86=E7=BA=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为标题补充锚点id解决marked新版不自动生成id导致目录跳转失效 - 向iframe注入表格框线及排版样式 - 添加滚动监听实现目录高亮联动 Co-Authored-By: Claude Opus 4.6 --- md-viewer.html | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/md-viewer.html b/md-viewer.html index 762829a..d3584ea 100644 --- a/md-viewer.html +++ b/md-viewer.html @@ -78,25 +78,59 @@ if (filePath) { /* 检测是否为自带 HTML 结构的文件(如共性需求说明.md) */ const isRawHtml = /^\s*<(?:style|div|!doctype|html)/i.test(md); if (isRawHtml) { - /* 文件混合了 HTML 结构和 Markdown 内容,需先解析 Markdown 再渲染 */ + /* 为标题生成锚点 id(marked 新版不再自动生成) */ + function addHeadingIds(html) { + return html.replace(/([\s\S]*?)<\/h\1>/g, function(_, lvl, inner) { + var plain = inner.replace(/<[^>]*>/g, ''); + var id = plain.toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu, '').trim().replace(/\s+/g, '-'); + return '' + inner + ''; + }); + } let processed = md; if (typeof marked !== 'undefined') { - /* 保留 '; + /* iframe 内注入:滚动时高亮当前目录项 */ + const tocScript = '