From 21e53310f8a4c1a7aebf44e5b4a12877cf0451fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=89=E9=91=AB=E5=8D=87?= Date: Fri, 12 Jun 2026 21:49:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20HTML=20=E9=A2=84=E8=A7=88=E9=94=9A?= =?UTF-8?q?=E7=82=B9=E7=82=B9=E5=87=BB=E5=90=8C=E6=AD=A5=20hash=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E9=A1=B5=E9=9D=A2=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E5=AD=90=E9=A1=B5=E9=9D=A2=E5=88=87=E6=8D=A2=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 预览 iframe 注入的锚点拦截脚本只 preventDefault + scrollIntoView, URL hash 从未改变,html-multipage 技能基于 CSS :target 的子页面 切换永远不命中,子页面 section 保持隐藏,点击无效。改为拦截后 同步 location.hash 触发 :target 切页,仅当目标元素已渲染时再平滑滚动。 Co-Authored-By: Claude Fable 5 --- frontend-web/src/core/utils/markdown.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/frontend-web/src/core/utils/markdown.ts b/frontend-web/src/core/utils/markdown.ts index 96060708..4ab819ce 100644 --- a/frontend-web/src/core/utils/markdown.ts +++ b/frontend-web/src/core/utils/markdown.ts @@ -100,9 +100,16 @@ function candidateTextFromHref(href: string): string { /** * Injects a small runtime script into generated HTML so that clicking an - * in-page anchor (``) scrolls within the iframe instead of - * navigating it. The preview iframe loads from a sandboxed `blob:` URL, where a - * fragment navigation blanks the frame; intercepting the click avoids that. + * in-page anchor (``) works inside the preview iframe. + * + * The hash MUST really change on click: multi-page documents (the + * html-multipage skill) show/hide their sub-page `
` + * blocks with CSS `:target` rules, which only fire on a fragment navigation. + * Intercepting with preventDefault + scrollIntoView alone leaves the hash + * untouched, so sub-pages stay `display:none` and clicks look dead. The + * handler therefore syncs `location.hash` (a same-document navigation — + * safe in the sandboxed blob: frame) and only smooth-scrolls afterwards when + * the target is actually rendered. */ export function injectInPageAnchorHandler(html: string): string { const script = ``; if (/<\/body>/i.test(html)) {