| 1 |
reStructuredText |
| 2 |
================ |
| 3 |
|
| 4 |
.. toctree:: |
| 5 |
:maxdepth: 1 |
| 6 |
|
| 7 |
restructuredtext_demo/index |
| 8 |
|
| 9 |
For the language syntax documentation, read the `ReST docutils syntax reference <https://docutils.sourceforge.io/docs/user/rst/quickref.html>`_. |
| 10 |
|
| 11 |
Fields |
| 12 |
------ |
| 13 |
|
| 14 |
See :ref:`fields section <codedoc-fields>`. |
| 15 |
|
| 16 |
In addition to the standard set of fields, the reStructuredText |
| 17 |
parser also supports **consolidated fields**, which combine the documentation |
| 18 |
for several objects into a single field. |
| 19 |
|
| 20 |
These consolidated fields may be written using either a `bulleted list <http://docutils.sourceforge.net/docs/user/rst/quickref.html#bullet-lists>`_ |
| 21 |
or a `definition list <http://docutils.sourceforge.net/docs/user/rst/quickref.html#definition-lists>`_. |
| 22 |
|
| 23 |
- If a consolidated field is written as a bulleted list, then each list item must begin with the field's argument, |
| 24 |
marked as `interpreted text <http://docutils.sourceforge.net/docs/user/rst/quickref.html#inline-markup>`_, and followed by a colon or dash. |
| 25 |
- If a consolidated field is written as a definition list, then each definition item's term should contain the field's argument, (it is not mandatory for it being marked as interpreted text). |
| 26 |
|
| 27 |
The following example shows the use of a definition list to define the ``Parameters`` consolidated field with type definition. |
| 28 |
Note that *docutils* requires a space before and after the ``:`` used to mark classifiers. |
| 29 |
|
| 30 |
.. code:: python |
| 31 |
|
| 32 |
def fox_speed(size, weight, age): |
| 33 |
""" |
| 34 |
:Parameters: |
| 35 |
size |
| 36 |
The size of the fox (in meters) |
| 37 |
weight : float |
| 38 |
The weight of the fox (in stones) |
| 39 |
age : int |
| 40 |
The age of the fox (in years) |
| 41 |
""" |
| 42 |
|
| 43 |
Using a bulleted list. |
| 44 |
|
| 45 |
.. code:: python |
| 46 |
|
| 47 |
def fox_speed(size:float, weight:float, age:int): |
| 48 |
""" |
| 49 |
:Parameters: |
| 50 |
- `size`: The size of the fox (in meters) |
| 51 |
- `weight`: The weight of the fox (in stones) |
| 52 |
- `age`: The age of the fox (in years) |
| 53 |
""" |
| 54 |
|
| 55 |
The following consolidated fields are currently supported by PyDoctor: |
| 56 |
|
| 57 |
.. table:: Consolidated Fields |
| 58 |
|
| 59 |
============================== ============================== |
| 60 |
Consolidated Field Tag Corresponding Base Field Tag |
| 61 |
============================== ============================== |
| 62 |
``:Parameters:`` ``:param:`` |
| 63 |
``:Keywords:`` ``:keyword:`` |
| 64 |
``:Exceptions:`` ``:except:`` |
| 65 |
``:Variables:`` ``:var:`` |
| 66 |
``:IVariables:`` ``:ivar:`` |
| 67 |
``:CVariables:`` ``:cvar:`` |
| 68 |
``:Types:`` ``:type:`` |
| 69 |
============================== ============================== |
| 70 |
|
| 71 |
Fields are case *insensitive*. |
| 72 |
|
| 73 |
Cross-references |
| 74 |
---------------- |
| 75 |
|
| 76 |
PyDoctor replaces the Docutils' default `interpreted text role <http://docutils.sourceforge.net/docs/ref/rst/roles.html>`_ with the creation of |
| 77 |
`documentation cross-reference links <http://epydoc.sourceforge.net/epydoc.html#documentation-crossreference-links>`_. If you want to create a cross-reference link |
| 78 |
to the ``module.Example`` class, simply put backticks around it, typing:: |
| 79 |
|
| 80 |
`module.Example` |
| 81 |
|
| 82 |
.. note:: Sphinx interpreted text roles for code references like ``:obj:`` or ``:meth:`` are not required and will be ignored. |
| 83 |
|
| 84 |
Directives |
| 85 |
---------- |
| 86 |
|
| 87 |
Here is a list of the supported ReST directives by package of origin: |
| 88 |
|
| 89 |
- `docutils`: ``.. include::``, ``.. contents::``, ``.. image::``, |
| 90 |
``.. figure::``, ``.. unicode::``, ``.. raw::``, ``.. math::``, |
| 91 |
``.. role::``, ``.. table::``, ``.. code::``, ``.. warning::``, ``.. note::`` |
| 92 |
and other admonitions, and a few others. |
| 93 |
- `epydoc`: None yet. |
| 94 |
- `Sphinx`: ``.. deprecated::``, ``.. versionchanged::``, ``.. versionadded::``, ``.. code-block::`` |
| 95 |
- `pydoctor`: ``.. python::`` |
| 96 |
|
| 97 |
`Full list of supported and unsupported directives <list-restructuredtext-support.html>`_ |
| 98 |
|
| 99 |
Colorized snippets directive |
| 100 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 101 |
|
| 102 |
Using reStructuredText markup it is possible to specify Python snippets in a |
| 103 |
`doctest block <https://docutils.sourceforge.io/docs/user/rst/quickref.html#doctest-blocks>`_. |
| 104 |
|
| 105 |
|
| 106 |
If the Python prompt gets in your way when you try to copy and paste and you are not interested |
| 107 |
in self-testing docstrings, the python directive will let you obtain a simple block of colorized text. |
| 108 |
Directives ``.. code::`` and ``.. code-block::`` acts exactly the same. |
| 109 |
|
| 110 |
:: |
| 111 |
|
| 112 |
.. python:: |
| 113 |
|
| 114 |
def fib(n): |
| 115 |
"""Print a Fibonacci series.""" |
| 116 |
a, b = 0, 1 |
| 117 |
while b < n: |
| 118 |
print b, |
| 119 |
a, b = b, a+b |
| 120 |
|
| 121 |
.. note:: HTML element's classes generated by our custom ``HTMLTranslator`` have a ``"rst-"`` prefix |
| 122 |
|
| 123 |
.. note:: In any case, *plaintext* docstring format will be used if docstrings can't be parsed with *restructuredtext* parser. |