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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions doc/usage/restructuredtext/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,39 @@ Hyperlinks
External links
~~~~~~~~~~~~~~

Use ```Link text <https://domain.invalid/>`_`` for inline web links. If the
link text should be the web address, you don't need special markup at all, the
parser finds links and mail addresses in ordinary text.
URLs and email addresses in text are automatically linked and do not need
explicit markup at all.
For example, https://domain.invalid/ is written with no special markup
in the source of this document, and is recognised as an external hyperlink.

.. important:: There must be a space between the link text and the opening \< for the URL.
To create text with a link, the best approach is generally to put the URL
below the paragraph as follows (:duref:`ref <hyperlink-targets>`)::

This is a paragraph that contains `a link`_.

.. _a link: https://domain.invalid/
Comment on lines +219 to +221
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)


This keeps the paragraph more readable in source code.

Alternatively, you can embed the URL within the prose for an 'inline link'.
This can lead to longer lines, but has the benefit of keeping the link text
and the URL pointed to in the same place.
This uses the following syntax: ```Link text <https://domain.invalid/>`__``
(:duref:`ref <embedded-uris-and-aliases>`).

.. important::

There must be a space between the link text
and the opening angle bracket ('``<``') for the URL.

.. tip::

Use two trailing underscores when embedding the URL.
Technically, a single underscore works as well,
but that would create a named reference instead of an anonymous one.
Named references typically do not have a benefit when the URL is embedded.
Moreover, they have the disadvantage that you must make sure that you
do not use the same "Link text" for another link in your document.

You can also separate the link and the target definition (:duref:`ref
<hyperlink-targets>`), like this::
Expand Down