-
Couldn't load subscription status.
- Fork 876
fix: use textContent to get header titles
#10790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The modern template currently uses `innerText` to get the text from h2 and h3 tags for the "In This Article" section of the affix. However, this can cause links with empty text content to be generated for headers which are not visible at the moment the navigation is generated, such as those in a `<details>` element. Using `textContent` instead will still properly retrieve the text from these headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where navigation links in the "In This Article" section appear empty for headers that are not visible when the navigation is generated (e.g., headers inside collapsed <details> elements). The fix changes from using innerText to textContent to properly extract text from all headers regardless of their visibility state.
- Replace
innerTextwithtextContentfor extracting header text in navigation generation - Ensure navigation links display properly for headers in collapsed sections
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
The modern template currently uses
innerTextto get the text from h2 and h3 tags for the "In This Article" section of the affix. However, this can cause links with empty text content to be generated for headers which are not visible at the moment the navigation is generated, such as those in a<details>element. UsingtextContentinstead will still properly retrieve the text from these headers.I've created a repository containing a small example where the use of
innerTextcauses a problem. The example uses a custom template alongside the custom containers and attributes Markdig extensions to render each version in a changelog inside a<details>element, expanding only the first of them by default. When the navigation is generated, anchor elements are created for the headers inside the collapsed sections, but they do not appear because they do not have any text content.