Restructured text FAQ

restructuredText is a lightweight markup language (file format) that is commonly used to create documentation. The langauge is designed to be both: (a) processable by documentation-processing software such as Docutils, and (b) easily readable by human programmers who are reading and writing source code.

See these links for a guide to the rst file format.

To find out about the differences between reST, docutils, readthedocs, sphinx, and extensions, see this link.

Guide to setting up a sphinx project

Examples of well documented code repositories

  • http://libcellml.readthedocs.io/
  • http://morphic.readthedocs.io/

Commenting restructuredText files

..
   _This: is a comment!

..
   [and] this!

..
   this:: too!

..
   |even| this:: !

Avoid putting comments on the same line as the double dots:

.. Avoid this type of comment

This is considered bad practice since it may lead to unintended consequences if the comment matches a proper markup construct.

Showing example code

Code blocks

.. code-block:: language

   code

Inline code block with syntax highlighting

First define a custom role. e.g.:

.. role:: bash(code)
   :language: bash

This then allows use inline code e.g.

Here is some awesome bash code :bash:`a = b + c`.

Forcing syntax highlighting for a code snippet.

e.g. for a partial snippet of json code:

.. code-block:: json-object
   :force:
   
    "scripts": {
      "build": "webpack",
      "serve": "webpack-dev-server"
    },

Add images

Use the image directive, for example:

.. image:: example.png

The path to the image is relative to the file. See the Sphinx documentation for more information.