Fix TOC #null anchors, incidentally enabling TOC for other markup
What does this MR do and why?
Fixes TOC `#null` anchors break navigation for RST/Me... (#603297 - closed).
Cause
When an .rst file includes a .. contents:: directive,
docutils wraps heading text in <a class="toc-backref"> links:
$ ./gitlab-markup/lib/github/commands/rest2html << RST
.. contents::
Heading A
==========
RST
...
...
<a name="heading-a"></a>
<h2><a class="toc-backref" href="#id1">Heading A</a></h2>
...These links have an href but no id, causing
the frontend TOC to produce a #null anchor.
Approach
Building on Support table of contents button for org-mode f... (!238950 - merged), MarkupHeadingAnchorFilter has been added to
MarkupPipeline to append a.anchor elements to headings.
The frontend TOC targets only a.anchor, filtering out <a> tags that lack an id to prevent the #null anchor.
As a side effect, TOC dropdowns are now available for other markup handled by MarkupPipeline, such as MediaWiki.
Screenshots
Manually verified on GDK-in-a-box:
| Markup | Screenshot |
|---|---|
| RST | ![]() |
RST (with .. contents::) |
![]() |
| MediaWiki | ![]() |
Sources
Click to expand
RST:
Heading 1
=========
Text.
Heading 2
---------RST (with .. contents::):
.. contents::
Heading A
=========
Text.
Heading B
---------MediaWiki:
= Heading 1 =
== Heading 2 ==
=== Heading 3 ===
==== Heading 4 ====Related
Notes
- I don't work on the frontend regularly — a careful look at this approach would be very helpful.
- No docs updates included — this area isn't well covered by existing documentation. If there are specific docs that should be updated, please flag them.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.


