Skip to content
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

Add a quick reference for rst markup. #916

Merged
merged 5 commits into from
Aug 6, 2022
Merged
Changes from 2 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
41 changes: 38 additions & 3 deletions documentation/markup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ This document describes the custom reStructuredText markup introduced by Sphinx
to support Python documentation and how it should be used.


Quick Reference
===============

This table summarizes which markup should be used for some commonly used
elements:

===================== =========================================== ====================
Element Markup See also
===================== =========================================== ====================
arguments/parameters ``*arg*`` :ref:`inline-markup`
vars/literals/code ````var````, ````42````, ````len(s) - 1```` :ref:`inline-markup`
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved
True/False/None ````True````, ````False````, ````None```` :ref:`inline-markup`
functions ``:func:`sorted``` :ref:`roles`
func definitions ``.. function:: func(args)`` :ref:`directives`
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved
reference labels ``.. _label-name:`` :ref:`doc-ref-role`
internal ref ``:ref:`label-name``` :ref:`doc-ref-role`
external links ```Link text <https://target>`_`` :ref:`hyperlinks`
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved
roles w/ custom text ``:role:`custom text <target>``` :ref:`roles`
roles w/o link ``:role:`!target``` :ref:`roles`
roles w/o first part ``:role:`~hidden.hidden.visible``` :ref:`roles`
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved
comments ``.. a comment`` :ref:`comments`
===================== =========================================== ====================


.. _rst-primer:

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

.. _inline-markup:

Inline markup
-------------
Expand All @@ -42,7 +67,9 @@ The standard reST inline markup is quite simple: use

* one asterisk: ``*text*`` for emphasis (italics),
* two asterisks: ``**text**`` for strong emphasis (boldface), and
* backquotes: ````text```` for code samples.
* backquotes: ````text```` for code samples, variables, and literals.

Italic is also used for function and method arguments (``*arg*``).
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved

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

.. _hyperlinks:

Hyperlinks
----------
Expand Down Expand Up @@ -185,6 +213,7 @@ indentation. (There needs to be a blank line between explicit markup and normal
paragraphs. This may all sound a bit complicated, but it is intuitive enough
when you write it.)

.. _directives:

Directives
----------
Expand Down Expand Up @@ -229,13 +258,18 @@ body at the bottom of the document after a "Footnotes" rubric heading, like so::

You can also explicitly number the footnotes for better context.

.. _comments:

Comments
--------

Every explicit markup block which isn't a valid markup construct (like the
footnotes above) is regarded as a comment.

Comments are generally preceeded by ``..``::
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved

.. This is a comment


Source encoding
---------------
Expand Down Expand Up @@ -636,9 +670,10 @@ The file name is relative to the current file's path. Documentation-specific
include files should be placed in the ``Doc/includes`` subdirectory.

.. _rest-inline-markup:
.. _roles:

Inline markup
-------------
Roles
-----
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved

As said before, Sphinx uses interpreted text roles to insert semantic markup in
documents.
ezio-melotti marked this conversation as resolved.
Show resolved Hide resolved
Expand Down