fix: hasNonTextContent 从存在性判定改为位置性判定,避免行内 favicon 角标导致整段拒翻 (#55) - #63
Merged
Conversation
…消息 (#54) - 所有 String(e) 站点改为 e instanceof Error ? e.message : String(e) 覆盖 entrypoints/content.ts、entrypoints/background.ts、src/engines/router.ts 共 7 处,确保 DOMException 的 name/message 正确展示在 toast 与日志中 - walker.ts 逐元素判定包裹 try-catch,Web Components 上 DOM 属性访问 抛异常时安全跳过当前节点,宁可漏翻单个可疑节点也不要整页崩溃 - doTranslate 增加阶段标记 [collect]/[render idx=N],缩小错误排查范围 - 版本号 0.6.19 → 0.6.20 Co-Authored-By: zhexuancai-uts <261878103+zhexuancai-uts@users.noreply.github.com>
Teeeeeeeerry
commented
Aug 8, 2026
Teeeeeeeerry
left a comment
Owner
Author
There was a problem hiding this comment.
上一个pr版本的GitHub翻译貌似直接炸了
NON_TEXT_SELECTOR 含 img 与 [role="button"],而 hasNonTextContent() 使用 el.querySelector() 做全子树匹配不问深度。当段落内嵌行内角标 (<span role="button"><img src="favicon">)时,isTranslationUnit() 返回 true(img 在 INLINE_SET),但 hasNonTextContent() 也返回 true, 后者覆盖前者,采集与段落按钮双双拒绝。 修复:沿非文本命中节点上溯至目标元素,若路径上每一层均为 INLINE_SET 标签则视为行内装饰予以放行;否则仍视为独立媒体块拒绝。三处调用点 (collect / closestUnit / render)共用同一函数,改一处即可。 Co-Authored-By: zhexuancai-uts <261878103+zhexuancai-uts@users.noreply.github.com>
Teeeeeeeerry
force-pushed
the
fix/55-inline-nontext-content-rejection
branch
from
August 8, 2026 13:43
e8ec930 to
f54c3a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
修复
hasNonTextContent()的判定逻辑:从 存在性(任意后代匹配即拒绝)改为 位置性(仅当非文本节点不在行内文本流中才拒绝)。问题
NON_TEXT_SELECTOR 包含
img与[role="button"],而hasNonTextContent()使用el.querySelector()做全子树匹配,不问深度。当段落内嵌行内角标(<span role="button"><img src="favicon">)时:isTranslationUnit()返回true(img在 INLINE_SET,不阻断段落判定)hasNonTextContent()返回true(全子树匹配到img)影响面:Google AI 概览来源角标、维基百科行内图标、文档站 badge 等任何「正文段落 + 行内图标」的排版。
修复逻辑
沿非文本命中节点上溯至目标元素:若路径上每一层都是
INLINE_SET标签,则视为行内装饰(favicon、badge),放行翻译;否则仍视为独立媒体块,拒绝。三处调用点(
collect/closestUnit/render)共用同一函数,#50 确立的「采集与渲染准入一致」不变式保持不变。受影响场景
p > span[role=button] > img)figure > img)Closes #55