Skip to content

Commit e807042

Browse files
Add a quick reference for rst markup. (#916)
* Add a quick reference for rst markup. * Address review comments. * Address review comments. * Address review comments. Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM> * Apply suggestions from code review. Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent f9ab9e4 commit e807042

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

documentation/markup.rst

+43-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ This document describes the custom reStructuredText markup introduced by Sphinx
1010
to support Python documentation and how it should be used.
1111

1212

13+
Quick Reference
14+
===============
15+
16+
This table summarizes which markup should be used for some commonly used
17+
elements:
18+
19+
======================= =========================================== ====================
20+
Element Markup See also
21+
======================= =========================================== ====================
22+
arguments/parameters ``*arg*`` :ref:`inline-markup`
23+
variables/literals/code ````foo````, ````42````, ````len(s) - 1```` :ref:`inline-markup`
24+
True/False/None ````True````, ````False````, ````None```` :ref:`inline-markup`
25+
functions definitions ``.. function:: print(*args)`` :ref:`directives`
26+
functions references ``:func:`print``` :ref:`roles`
27+
reference labels ``.. _label-name:`` :ref:`doc-ref-role`
28+
internal references ``:ref:`label-name``` :ref:`doc-ref-role`
29+
external links ```Link text <https://example.com>`_`` :ref:`hyperlinks`
30+
roles w/ custom text ``:role:`custom text <target>``` :ref:`roles`
31+
roles w/ only last part ``:role:`~hidden.hidden.visible``` :ref:`roles`
32+
roles w/o link ``:role:`!target``` :ref:`roles`
33+
comments ``.. a comment`` :ref:`comments`
34+
======================= =========================================== ====================
35+
36+
1337
.. _rst-primer:
1438

1539
reStructuredText Primer
@@ -34,6 +58,7 @@ chunks of text separated by one or more blank lines. As in Python, indentation
3458
is significant in reST, so all lines of the same paragraph must be left-aligned
3559
to the same level of indentation.
3660

61+
.. _inline-markup:
3762

3863
Inline markup
3964
-------------
@@ -42,7 +67,7 @@ The standard reST inline markup is quite simple: use
4267

4368
* one asterisk: ``*text*`` for emphasis (italics),
4469
* two asterisks: ``**text**`` for strong emphasis (boldface), and
45-
* backquotes: ````text```` for code samples.
70+
* backquotes: ````text```` for code samples, variables, and literals.
4671

4772
If asterisks or backquotes appear in running text and could be confused with
4873
inline markup delimiters, they have to be escaped with a backslash.
@@ -132,6 +157,7 @@ The handling of the ``::`` marker is smart:
132157
That way, the second sentence in the above example's first paragraph would be
133158
rendered as "The next paragraph is a code sample:".
134159

160+
.. _hyperlinks:
135161

136162
Hyperlinks
137163
----------
@@ -185,6 +211,7 @@ indentation. (There needs to be a blank line between explicit markup and normal
185211
paragraphs. This may all sound a bit complicated, but it is intuitive enough
186212
when you write it.)
187213

214+
.. _directives:
188215

189216
Directives
190217
----------
@@ -229,12 +256,15 @@ body at the bottom of the document after a "Footnotes" rubric heading, like so::
229256

230257
You can also explicitly number the footnotes for better context.
231258

259+
.. _comments:
232260

233261
Comments
234262
--------
235263

236-
Every explicit markup block which isn't a valid markup construct (like the
237-
footnotes above) is regarded as a comment.
264+
Every explicit markup block (starting with :literal:`.. \ `) which isn't a
265+
:ref:`valid markup construct <directives>` is regarded as a comment::
266+
267+
.. This is a comment
238268

239269

240270
Source encoding
@@ -636,17 +666,20 @@ The file name is relative to the current file's path. Documentation-specific
636666
include files should be placed in the ``Doc/includes`` subdirectory.
637667

638668
.. _rest-inline-markup:
669+
.. _roles:
639670

640-
Inline markup
641-
-------------
671+
Roles
672+
-----
642673

643-
As said before, Sphinx uses interpreted text roles to insert semantic markup in
644-
documents.
674+
As :ref:`previously mentioned <inline-markup>`, Sphinx uses
675+
interpreted text roles of the form ``:rolename:`content```
676+
to insert semantic markup in documents.
645677

646-
Names of local variables, such as function/method arguments, are an exception,
647-
they should be marked simply with ``*var*``.
678+
In the CPython documentation, there are a couple common cases
679+
where simpler markup should be used:
648680

649-
For all other roles, you have to write ``:rolename:`content```.
681+
* ``*arg*`` (rendered as *arg*) for function and method arguments.
682+
* ````True````/````False````/````None```` for ``True``/``False``/``None``.
650683

651684
There are some additional facilities that make cross-referencing roles more
652685
versatile:

0 commit comments

Comments
 (0)