reStructuredText and Sphinx Reference

Example based gentle reference of the reStructuredText and Sphinx syntax, directives, roles and common issues. It demonstrates almost all the markup making it also good for testing Sphinx themes. Free and open-source.

Admonitions

Admonitions are visually bold blocks like “tip”, “note”, “important”. They can appear anywhere an ordinary body element can. Readers will appreciate if you spice up your text with admonitions like tip for extra information or warning to raise their attention.

Specific or generic?

reStructuredText contains one generic and ten specific admonitions: attention, caution, danger, error, hint, important, note, tip, warning, and seealso.

Specific admonitions are often rendered in colors according to their severity. Their title is their name and can’t be changed.

 1.. attention:: I'm attention.
 2
 3.. caution:: I'm caution.
 4
 5.. danger:: I'm danger.
 6
 7.. error:: I'm error.
 8
 9.. hint:: I'm hint.
10
11.. important:: I'm important.
12
13.. note:: I'm note.
14
15.. tip:: I'm tip.
16
17.. warning:: I'm warning.
18
19.. seealso:: I'm seealso.

Attention

I’m attention.

Caution

I’m caution.

Danger

I’m danger.

Error

I’m error.

Hint

I’m hint.

Important

I’m important.

Note

I’m note.

Tip

I’m tip.

Warning

I’m warning.

See also

I’m seealso.

Generic admonition has a title and usually neutral appearance.

1.. admonition:: Generic admonitions has a title
2
3   Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Generic admonitions has a title

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Admonitions in uppercase

Admonition directives are case insensitive (like all directive and role names). Most documentation and book authors prefer typing directives and roles all in lowercase.

1.. important:: Most reStructuredText authors write directives like note in lowercase

However, writing admonitions directive in uppercase corresponds with their “raise attention” objective.

1.. IMPORTANT:: However writing admonitions uppercase can be considered as reasonable exception to "everything-lowercase" rule.

Complex admonition

Any reStructuredText elements can be in admonition content. As always, you need only to keep correct indentation.

1.. admonition:: Generic admonitions has a title
2
3   Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Generic admonitions has a title

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Content on the same line, or bellow

You can’t type specific admonition incorrectly. They accept its text in on the same line, bellow (optionally separated by a blank line), or on both places (strings are concatenated).

The following specific admonition markups are all valid. For example, attention admonition:

1.. attention:: I'm attention text on the same line
1.. attention::
2   I'm attention text on the line bellow
1.. attention::
2
3   I'm attention text bellow separated by the blank line
1.. attention:: I'm attention text
2   that continues bellow
1.. attention:: I'm attention text
2
3   that continues bellow after the blank line

Previous: Tools and editors | Next: Body elements