1.2.2. Directives

A directive is a generic block of Explicit Markup. Besides roles, it is one of the extension mechanisms of reStructuredText, and Sphinx makes heavy use of it.

Basically, a directive consists of a name, arguments, options and content. Keep this terminology in mind, it is used in section Explicit Markup describing custom directives. Looking at this example, that allows marking a block of content with special meaning.

basic directive syntax looks like this

the example
1
2
3
4
5
6
7
8
.. directive:: arg1 arg2 ...
   :option1: value
   :option2: value
   :option5: value
   ...

   Multiline content of the directive,
   ...

This line is no longer part of the block controlled by the directive.

directive

That is the directive name. It is given two arguments here.

arg1, arg2, ...

Arguments. The last argument can contain spaces (depending on the directive implementation).

:option0:, :option1:, ... :option9:

Options are optional. As you can see, options are given in the lines immediately following the arguments and indicated by the colons.

Multiline content of the directive,

The directive content follows after a blank line and is indented relative to the directive start.

Directives are supplied not only by Docutils, but Sphinx and custom extensions can add their own. Directives are written as a block.

Docutils supports the following directives (incomplete list):

Warning

Do not use the directives sectnum, header and footer.

See also

Footnotes

1

When the default domain contains a class directive, this directive will be shadowed. Therefore, Sphinx re-exports it as rst-class.