Skip to content

Commit 74627b2

Browse files
timhoffmAA-Turner
andauthored
Use anonymous references for links with embedded URLs (#13615)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
1 parent dc33f98 commit 74627b2

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

doc/usage/restructuredtext/basics.rst

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,39 @@ Hyperlinks
208208
External links
209209
~~~~~~~~~~~~~~
210210

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

215-
.. important:: There must be a space between the link text and the opening \< for the URL.
216+
To create text with a link, the best approach is generally to put the URL
217+
below the paragraph as follows (:duref:`ref <hyperlink-targets>`)::
218+
219+
This is a paragraph that contains `a link`_.
220+
221+
.. _a link: https://domain.invalid/
222+
223+
This keeps the paragraph more readable in source code.
224+
225+
Alternatively, you can embed the URL within the prose for an 'inline link'.
226+
This can lead to longer lines, but has the benefit of keeping the link text
227+
and the URL pointed to in the same place.
228+
This uses the following syntax: ```Link text <https://domain.invalid/>`__``
229+
(:duref:`ref <embedded-uris-and-aliases>`).
230+
231+
.. important::
232+
233+
There must be a space between the link text
234+
and the opening angle bracket ('``<``') for the URL.
235+
236+
.. tip::
237+
238+
Use two trailing underscores when embedding the URL.
239+
Technically, a single underscore works as well,
240+
but that would create a named reference instead of an anonymous one.
241+
Named references typically do not have a benefit when the URL is embedded.
242+
Moreover, they have the disadvantage that you must make sure that you
243+
do not use the same "Link text" for another link in your document.
216244

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

0 commit comments

Comments
 (0)