fix: use textContent to get header titles#10790
Merged
yufeih merged 2 commits intodotnet:mainfrom Sep 2, 2025
Merged
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.
Contributor
There was a problem hiding this comment.
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.
yufeih
approved these changes
Sep 2, 2025
This was referenced Oct 24, 2025
This was referenced Dec 1, 2025
This was referenced Dec 8, 2025
This was referenced Dec 15, 2025
This was referenced Dec 22, 2025
This was referenced Jan 5, 2026
This was referenced Jan 13, 2026
This was referenced Jan 26, 2026
This was referenced Feb 4, 2026
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.
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.