Skip to content

Use anonymous references for links with embedded URLs #13615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2025

Conversation

timhoffm
Copy link
Contributor

@timhoffm timhoffm commented Jun 4, 2025

Closes #13613.

The explanation got a bit longer than I would have liked. But I think it's important to make people aware that they should use two underscoes even though one may also work. And if we do that, we need to briefly explain the difference.

@timhoffm timhoffm force-pushed the doc-external-links branch from b0ff0f7 to bd1adac Compare June 4, 2025 22:01
Copy link
Contributor

@jfbu jfbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits.

There is one more syntax but it would be confusing to state it here. It is `Link text <goto_>`__, with the .. _goto: standing after the paragraph. As I reported at #13576 (comment), with Docutils 0.21.2, even with a single underscore one could use this with identical Link text e.g. See `DOI <goto1_>`_ or `DOI <goto2_>`_ without Docutils raising warnings but this is no more true since Docutils r10151.

@AA-Turner AA-Turner changed the title DOC: Use two underscores for links with embedded URLs Use anonymous references for links with embedded URLs Jun 5, 2025
@AA-Turner
Copy link
Member

cc: @gmilde

@timhoffm timhoffm force-pushed the doc-external-links branch from bd1adac to 02cc1df Compare June 5, 2025 20:49
@AA-Turner AA-Turner merged commit 74627b2 into sphinx-doc:master Jun 7, 2025
8 checks passed
@timhoffm timhoffm deleted the doc-external-links branch June 7, 2025 17:50
@mgeier
Copy link
Contributor

mgeier commented Jun 11, 2025

Thanks @timhoffm, I wasn't aware of the single vs. double underscore issue.

For reference, and in case anybody is wondering (as I was), I tried it (with Sphinx master branch and docutils 0.21.2) and observed the following behavior:

When I use multiple embedded URLs with the same link name "link" and identical URLs, everything works as expected and there are no warnings.

When I use different URLs with the same name (and with a single underscore), it still works fine, and the links point to the correct URLs, but I'm getting these messages.

WARNING: Duplicate explicit target name: "link". [docutils]
ERROR: Duplicate target name, cannot be used as a unique reference: "link". [docutils]

Using two underscores made the messages go away.


And another thing: what about "anonymous hyperlinks" as described here: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#anonymous-hyperlinks?

I like using those but they don't seem to be mentioned on the Sphinx doc page (https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html).

Are they discouraged for some reason?

If not, I think it would be great to add them to the docs!

Comment on lines +219 to +221
This is a paragraph that contains `a link`_.

.. _a link: https://domain.invalid/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, the exact same example is repeated below the inserted text, now it appears two times on the page.

Is this intentional?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is rather a leftover from the last edit.
See my comment at #13613 (comment)

@AA-Turner
Copy link
Member

@mgeier happy to look at a PR that adds a mention of the __: <URI> syntax, I also use it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading documentation on rST hyperlink syntax.
5 participants