Steps to replicate the issue (include links if applicable):
- Go to https://test.wikipedia.org/wiki/TOC_active_section_and_wrappers.
- Scroll down.
What happens?:
"Beginning" is highlighted as active.
What should have happened instead?:
The current section should be highlighted as active.
There is a lot of cases when sections are wrapped in a tag (among them template documentations, archived discussions, sections with a different text direction). There is no way for such sections to get selected as active because of the bug.
Why it happens?
Because of the selector used for matching section headings: .mw-parser-output > ${tag}, not .mw-parser-output ${tag} (for example).
@Jdlrobson introduced this, arguing: "Headings can also appear in templates inside divs and subtitles. These do not get rendered in the table of contents and should not be tracked." But headings inside divs do indeed get rendered in the TOC.