Skip to content

fix: 修复左侧导航菜单栏在部分页面不被翻译的问题#221

Open
Levitans wants to merge 1 commit into
Bistutu:mainfrom
Levitans:fix/sidebar-header-translation
Open

fix: 修复左侧导航菜单栏在部分页面不被翻译的问题#221
Levitans wants to merge 1 commit into
Bistutu:mainfrom
Levitans:fix/sidebar-header-translation

Conversation

@Levitans

@Levitans Levitans commented Jun 24, 2026

Copy link
Copy Markdown

根因:Mintlify 等文档框架将侧边栏放置在

标签内,
而 TreeWalker 的 FILTER_REJECT 会跳过 header 及其所有后代节点,
导致侧边栏内容完全不被遍历。

修改内容:

  1. header/footer 的 FILTER_REJECT 改为 FILTER_SKIP,保留遍历子节点
  2. 新增 containerSet 定义块级容器标签集合
  3. isInlineElement 排除容器元素,避免向上穿透过多层级
  4. grabNode 第6步扩展为 containerSet,统一容器元素处理逻辑

Summary by Sourcery

Ensure DOM traversal correctly includes sidebar content nested under header/footer elements while refining handling of container and inline elements during translation.

Bug Fixes:

  • Fix missing translation of sidebar/navigation content when documentation frameworks render it inside header elements by traversing their child nodes instead of skipping them entirely.

Enhancements:

  • Introduce a reusable container element set to standardize handling of block/semantic containers and adjust inline-element detection to avoid over-propagating translations.
  • Unify first-line text handling for container elements in node grabbing logic using the new container element set.

根因:Mintlify 等文档框架将侧边栏放置在 <header> 标签内,
而 TreeWalker 的 FILTER_REJECT 会跳过 header 及其所有后代节点,
导致侧边栏内容完全不被遍历。

修改内容:
1. header/footer 的 FILTER_REJECT 改为 FILTER_SKIP,保留遍历子节点
2. 新增 containerSet 定义块级容器标签集合
3. isInlineElement 排除容器元素,避免向上穿透过多层级
4. grabNode 第6步扩展为 containerSet,统一容器元素处理逻辑
@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts DOM traversal and element classification so header-contained navigation (e.g., Mintlify sidebars) are included in translation, while tightening inline/container handling to avoid over-aggressive parent merging.

File-Level Changes

Change Details Files
Update TreeWalker behavior so header/footer elements themselves are skipped but their descendants are still traversed, enabling translation of content inside them (such as left navigation menus).
  • Change the NodeFilter return value for header/footer from FILTER_REJECT to FILTER_SKIP in grabAllNode so children remain visitable.
  • Clarify the header/footer comment to explain the new behavior and the Mintlify sidebar use case.
entrypoints/main/dom.ts
Introduce a shared container element set and use it to unify handling of block/semantic containers during node grabbing and inline detection.
  • Add a containerSet of common block/semantic container tags (div, nav, aside, menu, section, article, main, header, footer).
  • Update grabNode step 6 to use containerSet for first-line text handling instead of a special case for div/label, broadening consistent container behavior.
  • Tighten isInlineElement so container elements are never treated as inline via child-meta detection by guarding detectChildMeta with a containerSet check and updating the explanatory comment.
entrypoints/main/dom.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Previously grabNode handled both div and label for first-line text, but after switching to containerSet the label tag is no longer included, which may change behavior for labels; consider either adding label to containerSet or explicitly documenting this change in behavior.
  • Since header/footer are now in containerSet, isInlineElement will never use detectChildMeta for them even if they only contain inline children; double-check that this broader container classification for header/footer is intentional and doesn’t cause unexpected skipping of inline-like regions.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Previously `grabNode` handled both `div` and `label` for first-line text, but after switching to `containerSet` the `label` tag is no longer included, which may change behavior for labels; consider either adding `label` to `containerSet` or explicitly documenting this change in behavior.
- Since `header`/`footer` are now in `containerSet`, `isInlineElement` will never use `detectChildMeta` for them even if they only contain inline children; double-check that this broader container classification for `header`/`footer` is intentional and doesn’t cause unexpected skipping of inline-like regions.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant