Skip to content

Don't generate empty heading ids - #1885

Open
sourya2704 wants to merge 1 commit into
ruby:masterfrom
sourya2704:fix-empty-heading-id
Open

sourya2704 wants to merge 1 commit into
ruby:masterfrom
sourya2704:fix-empty-heading-id

Conversation

@sourya2704

Copy link
Copy Markdown

Fixes #1882.

RDoc::Text.to_anchor keeps only ASCII letters, digits, spaces and hyphens. A heading with none of those, like ### `$=` in globals.md or a heading in Japanese, gets id="", and later ones get -1, -2 and so on:

<span id="label-24-3D" class="legacy-anchor"></span>
<h3 id=""><a href="#"><code>$=</code></a></h3>

When nothing is left, to_anchor now falls back to the legacy label format, so $= becomes label-24-3D and 日本語 becomes label-E6-97-A5-E6-9C-AC-E8-AA-9E. The heading id then equals its legacy anchor, so accept_heading skips the separate legacy span. The legacy id is still registered for deduplication as before:

<h3 id="label-24-3D"><a href="#label-24-3D"><code>$=</code></a></h3>

Every heading that got a non-empty id before keeps the same id, so existing links don't change. Old #label-24-3D links now point at the heading itself. The fallback is in to_anchor, so the table of contents, section anchors and @label cross-references use the same id.

bundle exec rake normal_test and RuboCop on the changed files pass.

Text.to_anchor removes every character except ASCII letters, digits,
spaces and hyphens, so a heading made only of symbols or non-ASCII
characters, like `$=` in globals.md, got `id=""`, and later ones got
`-1`, `-2` and so on.

When nothing is left, fall back to the legacy label format, so `$=`
becomes `label-24-3D`. The heading then has the same id as its legacy
anchor, so the separate legacy anchor is skipped. Headings that already
had an id are unchanged.

Fixes ruby#1882

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heading element has empty id attribute value

1 participant