Skip to content

Don't create links inside heading anchors - #1867

Open
mmporong wants to merge 1 commit into
ruby:masterfrom
mmporong:no-links-inside-heading-anchor
Open

mmporong wants to merge 1 commit into
ruby:masterfrom
mmporong:no-links-inside-heading-anchor

Conversation

@mmporong

Copy link
Copy Markdown

Heading text is wrapped in the heading's own <a href="#label">, but cross references, URLs and rdoc-ref: links inside it were still turned into links. A heading such as = C1 or = EXAMPLE.md therefore rendered as <a href="#c1"><a href="C1.html"><code>C1</code></a></a>, the nested anchors described in #1635.

accept_heading now converts the heading text as a link label, the same way tidy link labels are already handled, so cross references and URLs in it stay plain text. The table of contents already strips cross references from heading text (Heading.to_html), so the body heading now matches it. Links in the rest of the document are unchanged.

handle_TIDYLINK used to reset the label state to false when it finished. It now restores the previous value, so text after an explicit tidy link in a heading also stays unlinked. The explicit tidy link itself is still emitted as before.

Fixes #1635

Heading text is wrapped in the heading's own `<a href="#label">`. Cross
references, URLs and `rdoc-ref:` links in the text were turned into
links too, which produced nested `<a>` tags (invalid HTML).

Convert the heading text as a link label, the way tidy link labels
already are, so it is rendered as plain text. Tidy links now restore the
previous label state instead of clearing it, so text after a tidy link
in a heading stays unlinked as well.

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 with file path text generate nested <a> tags and result in broken link

1 participant