Skip to content

Commit 0a5704b

Browse files
committed
Avoid over-linking
1 parent 1eae014 commit 0a5704b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

documentation/markup.rst

+10
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ external links ```Link text <https://example.com>`_`` :ref:`hyperl
3030
roles w/ custom text ``:role:`custom text <target>``` :ref:`roles`
3131
roles w/ only last part ``:role:`~hidden.hidden.visible``` :ref:`roles`
3232
roles w/o link ``:role:`!target``` :ref:`roles`
33+
roles w/o link, short ``:role:`!visible``` (Note 1) :ref:`roles`
3334
issues ``:gh:`ID```, ``:issue:`ID``` :ref:`roles`
3435
CPython source ``:source:`PATH``` :ref:`roles`
3536
comments ``.. a comment`` :ref:`comments`
3637
======================= =========================================== ====================
3738

39+
Notes:
40+
41+
(1)
42+
For an only-last-part reference with a suppressed link,
43+
``:role:`~!hidden.visible``` makes more semantic sense, but it causes
44+
a warning as Sphinx tries to look up the reference ``!hidden.visible``
45+
which does not exist. The shorter form renders as desired and will build
46+
successfully.
47+
3848

3949
.. _rst-primer:
4050

documentation/style-guide.rst

+29-1
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,39 @@ explanation.
124124
provide context, make connections between topics, and discuss alternative
125125
opinions. There is no section dedicated to explanations but these can be
126126
found throughout Python's documentation, for example the
127-
:ref:`python:unicode-howto`
127+
:ref:`python:unicode-howto`.
128128

129129
Please consult the `Diátaxis <https://diataxis.fr/>`_ guide for more
130130
detail.
131131

132+
Links
133+
=====
134+
135+
Linking words to more information about those words is a powerful tool for
136+
helping people navigate documentation, but links can be over-used.
137+
Links should be used only if they help the reader.
138+
139+
Generally, a link should be provided for the first use of a term in a unit,
140+
such as a section or paragraph. This is not a hard and fast rule. Sometimes
141+
the second mention is more appropriate for a link. Some units are long enough
142+
to have a few repeated links. Use judgement to decide when a link will help
143+
the reader.
144+
145+
Do not use a link when the link would point to the current unit. It's natural
146+
to use the name of a function in the documentation for the function, but a link
147+
on that function name that simply reloads the section the user is already
148+
reading is useless and distracting.
149+
150+
Do not use links in section headers. They distract from the title of the
151+
section. The term will be mentioned in the paragraph text and can be linked
152+
from there.
153+
154+
Sphinx provides ways to automatically add links to references, and a way to
155+
suppress the link. Using roles like ``:func:`map``` will link to the
156+
documentation for ``map``. You can suppress the link while keeping the
157+
semantic presentation of the function name by adding an exclamation point
158+
prefix: ``:func:`!map```.
159+
132160
Affirmative tone
133161
================
134162

0 commit comments

Comments
 (0)