Fix RST TOC for existing ids, incidentally enabling RDoc/Textile

What does this MR do and why?

Fixes Some headings missing from TOC dropdown in RST (#604075).

Cause

When an .rst file has headings not immediately followed by body text, docutils appends id attributes:

Click to expand
$ ./gitlab-markup/lib/github/commands/rest2html << RST
Heading A
=========

Heading B
---------

Heading C
~~~~~~~~~

Heading D
^^^^^^^^^

Heading E
'''''''''

Heading F
"""""""""
RST
<h1 class="title">Heading A</h1>
<h2 class="subtitle" id="heading-b">Heading B</h2>
<a name="heading-c"></a>
<h2 class="with-subtitle">Heading C</h2>
<h2 class="section-subtitle" id="heading-d"><span class="section-subtitle">Heading D</span></h2>
<a name="heading-e"></a>
<h3 class="with-subtitle">Heading E</h3>
<h3 class="section-subtitle" id="heading-f"><span class="section-subtitle">Heading F</span></h3>

MarkupHeadingAnchorFilter was skipping any heading that already had an id, so no anchor link (<a class="anchor">) was added. Downstream sanitization then stripped the bare id, leaving those headings invisible to the TOC dropdown.

Approach

Building on !241282 (merged) and !238950 (merged), MarkupHeadingAnchorFilter is now extended to apply the user-content- prefix to existing id attributes on headings, so they survive sanitization and the TOC dropdown can pick them up.

As a side effect, TOC dropdowns are now available for other markup with pre-existing heading ids handled by MarkupPipeline, such as RDoc and custom-ID Textile.

Red → Green Cycle

  1. 25d8d95a: Add spec for existing ids → 🔴 RED (job log)
  2. 612e0ead: Extend to handle existing ids → 🟢 GREEN

Screenshots

Manually verified on GDK-in-a-box:

Markup Before After
RST (with subtitle) rst_secsubtitle_before rst_secsubtitle_after
RDoc toc-rdoc-before toc-rdoc-after
Textile (with custom IDs) toc-textile-before toc-textile-after

Sources

Click to expand
RST (with subtitle):
Heading A
=========

Heading B
---------

Heading C
~~~~~~~~~

Heading D
^^^^^^^^^

Heading E
'''''''''

Heading F
"""""""""
RDoc:
= Heading 1

== Heading 2
Textile (with custom IDs):
h1(#custom-h1). Heading 1

h2(#custom-h2). Heading 2

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.

Edited by skkzsh

Merge request reports

Loading