reStructuredText

reStructuredText (reST) is a markup language. The developers of many projects, including Python, use it to write documentation. It’s also what I’m using to write this website. It has unobtrusive syntax similar to Markdown, while supporting many things you would otherwise need HTML for.

I’ll be primarily referencing the reStructuredText Primer.

The basics

If you’ve written Markdown before, the basic concept is similar. A reStructuredText document is a plain text file, typically with the .rst file extension. A paragraph can continue across multiple lines, with a blank line between paragraphs.

Headings

A heading is a line of text underlined, and optionally overlined, with a punctuation symbol of your choice. As long as you’re consistent about what style you use for each level heading, they can be pretty much anything you want, though there are conventions you can follow if you like. If you’re wondering, this is what I use:

=========
Heading 1
=========

~~~~~~~~~
Heading 2
~~~~~~~~~

Heading 3
---------

I haven’t used a fourth-level heading yet, but I’d probably underline it with carets.

Formatted blocks

Code

The blank line between the code-block:: directive and the beginning of the actual code is necessary, as is the indentation of the actual code block. Specifying the language and caption are optional.

.. code-block:: python
  :caption: hello.py

  name = 'reST'
  print('Hello ' + name + '!')

Tip

Syntax highlighting can be applied for any of the languages Pygments supports, and other formatting options are available.

Notices

Any of the following keywords can be used. Themes may have their own styles for each.

  • note

  • tip

  • hint

  • seealso

  • attention

  • important

  • caution

  • danger

  • warning

  • error

.. attention:: This is a message.
  This text is part of the same message.

This is a new paragraph.