blob: 69a6f125516793c660c368e65f562457812eb158 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. highlightlang:: rest
2
3Additional Markup Constructs
4============================
5
6Sphinx adds a lot of new directives and interpreted text roles to standard reST
7markup. This section contains the reference material for these facilities.
8Documentation for "standard" reST constructs is not included here, though
9they are used in the Python documentation.
10
Benjamin Petersonf608c612008-11-16 18:33:53 +000011.. note::
Georg Brandl116aa622007-08-15 14:28:22 +000012
Benjamin Petersonf608c612008-11-16 18:33:53 +000013 This is just an overview of Sphinx' extended markup capabilities; full
14 coverage can be found in `its own documentation
15 <http://sphinx.pocoo.org/contents.html>`_.
Georg Brandl116aa622007-08-15 14:28:22 +000016
17
18Meta-information markup
19-----------------------
20
21.. describe:: sectionauthor
22
23 Identifies the author of the current section. The argument should include
24 the author's name such that it can be used for presentation (though it isn't)
25 and email address. The domain name portion of the address should be lower
26 case. Example::
27
28 .. sectionauthor:: Guido van Rossum <guido@python.org>
29
30 Currently, this markup isn't reflected in the output in any way, but it helps
31 keep track of contributions.
32
33
34Module-specific markup
35----------------------
36
37The markup described in this section is used to provide information about a
38module being documented. Each module should be documented in its own file.
39Normally this markup appears after the title heading of that file; a typical
40file might start like this::
41
42 :mod:`parrot` -- Dead parrot access
43 ===================================
44
45 .. module:: parrot
46 :platform: Unix, Windows
47 :synopsis: Analyze and reanimate dead parrots.
48 .. moduleauthor:: Eric Cleese <eric@python.invalid>
49 .. moduleauthor:: John Idle <john@python.invalid>
50
51As you can see, the module-specific markup consists of two directives, the
52``module`` directive and the ``moduleauthor`` directive.
53
54.. describe:: module
55
Brett Cannondf501062009-01-20 02:09:18 +000056 This directive marks the beginning of the description of a module, package,
57 or submodule. The name should be fully qualified (i.e. including the
58 package name for submodules).
Georg Brandl116aa622007-08-15 14:28:22 +000059
60 The ``platform`` option, if present, is a comma-separated list of the
61 platforms on which the module is available (if it is available on all
62 platforms, the option should be omitted). The keys are short identifiers;
63 examples that are in use include "IRIX", "Mac", "Windows", and "Unix". It is
64 important to use a key which has already been used when applicable.
65
66 The ``synopsis`` option should consist of one sentence describing the
67 module's purpose -- it is currently only used in the Global Module Index.
68
Guido van Rossumda27fd22007-08-17 00:24:54 +000069 The ``deprecated`` option can be given (with no value) to mark a module as
70 deprecated; it will be designated as such in various locations then.
71
Georg Brandl116aa622007-08-15 14:28:22 +000072.. describe:: moduleauthor
73
74 The ``moduleauthor`` directive, which can appear multiple times, names the
75 authors of the module code, just like ``sectionauthor`` names the author(s)
76 of a piece of documentation. It too does not result in any output currently.
77
Georg Brandl116aa622007-08-15 14:28:22 +000078.. note::
79
80 It is important to make the section title of a module-describing file
81 meaningful since that value will be inserted in the table-of-contents trees
82 in overview files.
83
84
85Information units
86-----------------
87
88There are a number of directives used to describe specific features provided by
89modules. Each directive requires one or more signatures to provide basic
90information about what is being described, and the content should be the
91description. The basic version makes entries in the general index; if no index
92entry is desired, you can give the directive option flag ``:noindex:``. The
93following example shows all of the features of this directive type::
94
95 .. function:: spam(eggs)
96 ham(eggs)
97 :noindex:
98
99 Spam or ham the foo.
100
101The signatures of object methods or data attributes should always include the
102type name (``.. method:: FileInput.input(...)``), even if it is obvious from the
103context which type they belong to; this is to enable consistent
104cross-references. If you describe methods belonging to an abstract protocol,
105such as "context managers", include a (pseudo-)type name too to make the
106index entries more informative.
107
108The directives are:
109
Georg Brandl60203b42010-10-06 10:11:56 +0000110.. describe:: c:function
Georg Brandl116aa622007-08-15 14:28:22 +0000111
112 Describes a C function. The signature should be given as in C, e.g.::
113
Georg Brandl60203b42010-10-06 10:11:56 +0000114 .. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
Georg Brandl116aa622007-08-15 14:28:22 +0000115
116 This is also used to describe function-like preprocessor macros. The names
117 of the arguments should be given so they may be used in the description.
118
119 Note that you don't have to backslash-escape asterisks in the signature,
120 as it is not parsed by the reST inliner.
121
Georg Brandl60203b42010-10-06 10:11:56 +0000122.. describe:: c:member
Georg Brandl116aa622007-08-15 14:28:22 +0000123
124 Describes a C struct member. Example signature::
125
Georg Brandl60203b42010-10-06 10:11:56 +0000126 .. c:member:: PyObject* PyTypeObject.tp_bases
Georg Brandl116aa622007-08-15 14:28:22 +0000127
128 The text of the description should include the range of values allowed, how
129 the value should be interpreted, and whether the value can be changed.
130 References to structure members in text should use the ``member`` role.
131
Georg Brandl60203b42010-10-06 10:11:56 +0000132.. describe:: c:macro
Georg Brandl116aa622007-08-15 14:28:22 +0000133
134 Describes a "simple" C macro. Simple macros are macros which are used
135 for code expansion, but which do not take arguments so cannot be described as
136 functions. This is not to be used for simple constant definitions. Examples
Georg Brandl60203b42010-10-06 10:11:56 +0000137 of its use in the Python documentation include :c:macro:`PyObject_HEAD` and
138 :c:macro:`Py_BEGIN_ALLOW_THREADS`.
Georg Brandl116aa622007-08-15 14:28:22 +0000139
Georg Brandl60203b42010-10-06 10:11:56 +0000140.. describe:: c:type
Georg Brandl116aa622007-08-15 14:28:22 +0000141
142 Describes a C type. The signature should just be the type name.
143
Georg Brandl60203b42010-10-06 10:11:56 +0000144.. describe:: c:var
Georg Brandl116aa622007-08-15 14:28:22 +0000145
146 Describes a global C variable. The signature should include the type, such
147 as::
148
149 .. cvar:: PyObject* PyClass_Type
150
151.. describe:: data
152
153 Describes global data in a module, including both variables and values used
154 as "defined constants." Class and object attributes are not documented
155 using this environment.
156
157.. describe:: exception
158
159 Describes an exception class. The signature can, but need not include
160 parentheses with constructor arguments.
161
162.. describe:: function
163
164 Describes a module-level function. The signature should include the
165 parameters, enclosing optional parameters in brackets. Default values can be
166 given if it enhances clarity. For example::
167
168 .. function:: Timer.repeat([repeat=3[, number=1000000]])
169
170 Object methods are not documented using this directive. Bound object methods
171 placed in the module namespace as part of the public interface of the module
172 are documented using this, as they are equivalent to normal functions for
173 most purposes.
174
175 The description should include information about the parameters required and
176 how they are used (especially whether mutable objects passed as parameters
177 are modified), side effects, and possible exceptions. A small example may be
178 provided.
179
Georg Brandl8a1caa22010-07-29 16:01:11 +0000180.. describe:: decorator
181
182 Describes a decorator function. The signature should *not* represent the
183 signature of the actual function, but the usage as a decorator. For example,
184 given the functions
185
186 .. code-block:: python
187
188 def removename(func):
189 func.__name__ = ''
190 return func
191
192 def setnewname(name):
193 def decorator(func):
194 func.__name__ = name
195 return func
196 return decorator
197
198 the descriptions should look like this::
199
200 .. decorator:: removename
201
202 Remove name of the decorated function.
203
204 .. decorator:: setnewname(name)
205
206 Set name of the decorated function to *name*.
207
Georg Brandlbfc8fe42010-08-02 12:54:24 +0000208 There is no ``deco`` role to link to a decorator that is marked up with
209 this directive; rather, use the ``:func:`` role.
210
Georg Brandl116aa622007-08-15 14:28:22 +0000211.. describe:: class
212
213 Describes a class. The signature can include parentheses with parameters
214 which will be shown as the constructor arguments.
215
216.. describe:: attribute
217
218 Describes an object data attribute. The description should include
219 information about the type of the data to be expected and whether it may be
220 changed directly.
221
222.. describe:: method
223
224 Describes an object method. The parameters should not include the ``self``
225 parameter. The description should include similar information to that
226 described for ``function``.
227
Georg Brandl8a1caa22010-07-29 16:01:11 +0000228.. describe:: decoratormethod
229
230 Same as ``decorator``, but for decorators that are methods.
231
Georg Brandlbfc8fe42010-08-02 12:54:24 +0000232 Refer to a decorator method using the ``:meth:`` role.
233
Georg Brandl116aa622007-08-15 14:28:22 +0000234.. describe:: opcode
235
Georg Brandl9afde1c2007-11-01 20:32:30 +0000236 Describes a Python :term:`bytecode` instruction.
237
238.. describe:: cmdoption
239
Georg Brandlf5ae1ef2010-07-26 21:12:13 +0000240 Describes a Python command line option or switch. Option argument names
241 should be enclosed in angle brackets. Example::
Georg Brandl9afde1c2007-11-01 20:32:30 +0000242
243 .. cmdoption:: -m <module>
244
245 Run a module as a script.
246
247.. describe:: envvar
248
249 Describes an environment variable that Python uses or defines.
Georg Brandl116aa622007-08-15 14:28:22 +0000250
251
252There is also a generic version of these directives:
253
254.. describe:: describe
255
256 This directive produces the same formatting as the specific ones explained
257 above but does not create index entries or cross-referencing targets. It is
258 used, for example, to describe the directives in this document. Example::
259
260 .. describe:: opcode
261
262 Describes a Python bytecode instruction.
263
264
265Showing code examples
266---------------------
267
268Examples of Python source code or interactive sessions are represented using
269standard reST literal blocks. They are started by a ``::`` at the end of the
270preceding paragraph and delimited by indentation.
271
272Representing an interactive session requires including the prompts and output
273along with the Python code. No special markup is required for interactive
274sessions. After the last line of input or output presented, there should not be
275an "unused" primary prompt; this is an example of what *not* to do::
276
277 >>> 1 + 1
278 2
279 >>>
280
281Syntax highlighting is handled in a smart way:
282
283* There is a "highlighting language" for each source file. Per default,
284 this is ``'python'`` as the majority of files will have to highlight Python
285 snippets.
286
287* Within Python highlighting mode, interactive sessions are recognized
288 automatically and highlighted appropriately.
289
290* The highlighting language can be changed using the ``highlightlang``
291 directive, used as follows::
292
293 .. highlightlang:: c
294
295 This language is used until the next ``highlightlang`` directive is
296 encountered.
297
Benjamin Petersonf608c612008-11-16 18:33:53 +0000298* The values normally used for the highlighting language are:
Georg Brandl116aa622007-08-15 14:28:22 +0000299
300 * ``python`` (the default)
301 * ``c``
302 * ``rest``
303 * ``none`` (no highlighting)
304
305* If highlighting with the current language fails, the block is not highlighted
306 in any way.
307
308Longer displays of verbatim text may be included by storing the example text in
309an external file containing only plain text. The file may be included using the
310``literalinclude`` directive. [1]_ For example, to include the Python source file
311:file:`example.py`, use::
312
313 .. literalinclude:: example.py
314
315The file name is relative to the current file's path. Documentation-specific
316include files should be placed in the ``Doc/includes`` subdirectory.
317
318
319Inline markup
320-------------
321
322As said before, Sphinx uses interpreted text roles to insert semantic markup in
323documents.
324
Benjamin Petersonaa069002009-01-23 03:26:36 +0000325Names of local variables, such as function/method arguments, are an exception,
326they should be marked simply with ``*var*``.
Georg Brandl116aa622007-08-15 14:28:22 +0000327
328For all other roles, you have to write ``:rolename:`content```.
329
Benjamin Petersonc4bbc8d2009-01-30 03:39:35 +0000330There are some additional facilities that make cross-referencing roles more
331versatile:
Guido van Rossumf10aa982007-08-17 18:30:38 +0000332
Benjamin Petersonc4bbc8d2009-01-30 03:39:35 +0000333* You may supply an explicit title and reference target, like in reST direct
334 hyperlinks: ``:role:`title <target>``` will refer to *target*, but the link
335 text will be *title*.
336
337* If you prefix the content with ``!``, no reference/hyperlink will be created.
338
339* For the Python object roles, if you prefix the content with ``~``, the link
340 text will only be the last component of the target. For example,
341 ``:meth:`~Queue.Queue.get``` will refer to ``Queue.Queue.get`` but only
342 display ``get`` as the link text.
343
344 In HTML output, the link's ``title`` attribute (that is e.g. shown as a
345 tool-tip on mouse-hover) will always be the full target name.
Guido van Rossumf10aa982007-08-17 18:30:38 +0000346
Georg Brandl116aa622007-08-15 14:28:22 +0000347The following roles refer to objects in modules and are possibly hyperlinked if
348a matching identifier is found:
349
350.. describe:: mod
351
352 The name of a module; a dotted name may be used. This should also be used for
353 package names.
354
355.. describe:: func
356
357 The name of a Python function; dotted names may be used. The role text
Christian Heimesa342c012008-04-20 21:01:16 +0000358 should not include trailing parentheses to enhance readability. The
359 parentheses are stripped when searching for identifiers.
Georg Brandl116aa622007-08-15 14:28:22 +0000360
361.. describe:: data
362
Benjamin Petersonaa069002009-01-23 03:26:36 +0000363 The name of a module-level variable or constant.
Georg Brandl116aa622007-08-15 14:28:22 +0000364
365.. describe:: const
366
367 The name of a "defined" constant. This may be a C-language ``#define``
368 or a Python variable that is not intended to be changed.
369
370.. describe:: class
371
372 A class name; a dotted name may be used.
373
374.. describe:: meth
375
376 The name of a method of an object. The role text should include the type
Christian Heimesa342c012008-04-20 21:01:16 +0000377 name and the method name. A dotted name may be used.
Georg Brandl116aa622007-08-15 14:28:22 +0000378
379.. describe:: attr
380
381 The name of a data attribute of an object.
382
383.. describe:: exc
384
385 The name of an exception. A dotted name may be used.
386
387The name enclosed in this markup can include a module name and/or a class name.
388For example, ``:func:`filter``` could refer to a function named ``filter`` in
389the current module, or the built-in function of that name. In contrast,
390``:func:`foo.filter``` clearly refers to the ``filter`` function in the ``foo``
391module.
392
Guido van Rossumda27fd22007-08-17 00:24:54 +0000393Normally, names in these roles are searched first without any further
394qualification, then with the current module name prepended, then with the
395current module and class name (if any) prepended. If you prefix the name with a
396dot, this order is reversed. For example, in the documentation of the
397:mod:`codecs` module, ``:func:`open``` always refers to the built-in function,
398while ``:func:`.open``` refers to :func:`codecs.open`.
399
Georg Brandl116aa622007-08-15 14:28:22 +0000400A similar heuristic is used to determine whether the name is an attribute of
401the currently documented class.
402
403The following roles create cross-references to C-language constructs if they
404are defined in the API documentation:
405
Georg Brandl60203b42010-10-06 10:11:56 +0000406.. describe:: c:data
Georg Brandl116aa622007-08-15 14:28:22 +0000407
408 The name of a C-language variable.
409
Georg Brandl60203b42010-10-06 10:11:56 +0000410.. describe:: c:func
Georg Brandl116aa622007-08-15 14:28:22 +0000411
412 The name of a C-language function. Should include trailing parentheses.
413
Georg Brandl60203b42010-10-06 10:11:56 +0000414.. describe:: c:macro
Georg Brandl116aa622007-08-15 14:28:22 +0000415
416 The name of a "simple" C macro, as defined above.
417
Georg Brandl60203b42010-10-06 10:11:56 +0000418.. describe:: c:type
Georg Brandl116aa622007-08-15 14:28:22 +0000419
420 The name of a C-language type.
421
Georg Brandl60203b42010-10-06 10:11:56 +0000422.. describe:: c:member
423
424 The name of a C type member, as defined above.
425
Georg Brandl116aa622007-08-15 14:28:22 +0000426
427The following role does possibly create a cross-reference, but does not refer
428to objects:
429
430.. describe:: token
431
432 The name of a grammar token (used in the reference manual to create links
433 between production displays).
434
Guido van Rossumf10aa982007-08-17 18:30:38 +0000435
436The following role creates a cross-reference to the term in the glossary:
437
438.. describe:: term
439
440 Reference to a term in the glossary. The glossary is created using the
441 ``glossary`` directive containing a definition list with terms and
442 definitions. It does not have to be in the same file as the ``term``
443 markup, in fact, by default the Python docs have one global glossary
444 in the ``glossary.rst`` file.
445
446 If you use a term that's not explained in a glossary, you'll get a warning
447 during build.
448
Georg Brandl116aa622007-08-15 14:28:22 +0000449---------
450
451The following roles don't do anything special except formatting the text
452in a different style:
453
454.. describe:: command
455
456 The name of an OS-level command, such as ``rm``.
457
458.. describe:: dfn
459
460 Mark the defining instance of a term in the text. (No index entries are
461 generated.)
462
463.. describe:: envvar
464
465 An environment variable. Index entries are generated.
466
467.. describe:: file
468
469 The name of a file or directory. Within the contents, you can use curly
470 braces to indicate a "variable" part, for example::
471
472 ... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
473
474 In the built documentation, the ``x`` will be displayed differently to
475 indicate that it is to be replaced by the Python minor version.
476
477.. describe:: guilabel
478
479 Labels presented as part of an interactive user interface should be marked
480 using ``guilabel``. This includes labels from text-based interfaces such as
481 those created using :mod:`curses` or other text-based libraries. Any label
482 used in the interface should be marked with this role, including button
483 labels, window titles, field names, menu and menu selection names, and even
484 values in selection lists.
485
486.. describe:: kbd
487
488 Mark a sequence of keystrokes. What form the key sequence takes may depend
489 on platform- or application-specific conventions. When there are no relevant
490 conventions, the names of modifier keys should be spelled out, to improve
491 accessibility for new users and non-native speakers. For example, an
492 *xemacs* key sequence may be marked like ``:kbd:`C-x C-f```, but without
493 reference to a specific application or platform, the same sequence should be
494 marked as ``:kbd:`Control-x Control-f```.
495
496.. describe:: keyword
497
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000498 The name of a keyword in Python.
Georg Brandl116aa622007-08-15 14:28:22 +0000499
500.. describe:: mailheader
501
502 The name of an RFC 822-style mail header. This markup does not imply that
503 the header is being used in an email message, but can be used to refer to any
504 header of the same "style." This is also used for headers defined by the
505 various MIME specifications. The header name should be entered in the same
506 way it would normally be found in practice, with the camel-casing conventions
507 being preferred where there is more than one common usage. For example:
508 ``:mailheader:`Content-Type```.
509
510.. describe:: makevar
511
512 The name of a :command:`make` variable.
513
514.. describe:: manpage
515
516 A reference to a Unix manual page including the section,
517 e.g. ``:manpage:`ls(1)```.
518
519.. describe:: menuselection
520
521 Menu selections should be marked using the ``menuselection`` role. This is
522 used to mark a complete sequence of menu selections, including selecting
523 submenus and choosing a specific operation, or any subsequence of such a
524 sequence. The names of individual selections should be separated by
525 ``-->``.
526
527 For example, to mark the selection "Start > Programs", use this markup::
528
529 :menuselection:`Start --> Programs`
530
531 When including a selection that includes some trailing indicator, such as the
532 ellipsis some operating systems use to indicate that the command opens a
533 dialog, the indicator should be omitted from the selection name.
534
535.. describe:: mimetype
536
537 The name of a MIME type, or a component of a MIME type (the major or minor
538 portion, taken alone).
539
540.. describe:: newsgroup
541
542 The name of a Usenet newsgroup.
543
544.. describe:: option
545
Georg Brandla5ed4012010-07-19 06:57:52 +0000546 A command-line option of Python. The leading hyphen(s) must be included.
547 If a matching ``cmdoption`` directive exists, it is linked to. For options
548 of other programs or scripts, use simple ````code```` markup.
Georg Brandl116aa622007-08-15 14:28:22 +0000549
550.. describe:: program
551
552 The name of an executable program. This may differ from the file name for
553 the executable for some platforms. In particular, the ``.exe`` (or other)
554 extension should be omitted for Windows programs.
555
556.. describe:: regexp
557
558 A regular expression. Quotes should not be included.
559
560.. describe:: samp
561
562 A piece of literal text, such as code. Within the contents, you can use
563 curly braces to indicate a "variable" part, as in ``:file:``.
564
565 If you don't need the "variable part" indication, use the standard
Georg Brandl48310cd2009-01-03 21:18:54 +0000566 ````code```` instead.
Georg Brandl116aa622007-08-15 14:28:22 +0000567
Georg Brandl116aa622007-08-15 14:28:22 +0000568
569The following roles generate external links:
570
571.. describe:: pep
572
573 A reference to a Python Enhancement Proposal. This generates appropriate
574 index entries. The text "PEP *number*\ " is generated; in the HTML output,
575 this text is a hyperlink to an online copy of the specified PEP.
576
577.. describe:: rfc
578
579 A reference to an Internet Request for Comments. This generates appropriate
580 index entries. The text "RFC *number*\ " is generated; in the HTML output,
581 this text is a hyperlink to an online copy of the specified RFC.
582
583
584Note that there are no special roles for including hyperlinks as you can use
585the standard reST markup for that purpose.
586
587
588.. _doc-ref-role:
589
590Cross-linking markup
591--------------------
592
593To support cross-referencing to arbitrary sections in the documentation, the
594standard reST labels are "abused" a bit: Every label must precede a section
595title; and every label name must be unique throughout the entire documentation
596source.
597
598You can then reference to these sections using the ``:ref:`label-name``` role.
599
600Example::
601
602 .. _my-reference-label:
603
604 Section to cross-reference
605 --------------------------
606
607 This is the text of the section.
608
609 It refers to the section itself, see :ref:`my-reference-label`.
610
611The ``:ref:`` invocation is replaced with the section title.
612
Raymond Hettingercfee0e82010-12-21 20:52:12 +0000613Alternatively, you can reference any label (not just section titles)
614if you provide the link text ``:ref:`link text`<reference-label>```.
Georg Brandl116aa622007-08-15 14:28:22 +0000615
616Paragraph-level markup
617----------------------
618
619These directives create short paragraphs and can be used inside information
620units as well as normal text:
621
622.. describe:: note
623
624 An especially important bit of information about an API that a user should be
625 aware of when using whatever bit of API the note pertains to. The content of
626 the directive should be written in complete sentences and include all
627 appropriate punctuation.
628
629 Example::
630
631 .. note::
632
633 This function is not suitable for sending spam e-mails.
634
635.. describe:: warning
636
Georg Brandle720c0a2009-04-27 16:20:50 +0000637 An important bit of information about an API that a user should be aware of
638 when using whatever bit of API the warning pertains to. The content of the
639 directive should be written in complete sentences and include all appropriate
Benjamin Peterson4ac9ce42009-10-04 14:49:41 +0000640 punctuation. In the interest of not scaring users away from pages filled
641 with warnings, this directive should only be chosen over ``note`` for
642 information regarding the possibility of crashes, data loss, or security
643 implications.
Georg Brandl116aa622007-08-15 14:28:22 +0000644
645.. describe:: versionadded
646
647 This directive documents the version of Python which added the described
648 feature to the library or C API. When this applies to an entire module, it
649 should be placed at the top of the module section before any prose.
650
651 The first argument must be given and is the version in question; you can add
652 a second argument consisting of a *brief* explanation of the change.
653
654 Example::
655
Georg Brandl277a1502009-01-04 00:28:14 +0000656 .. versionadded:: 3.1
Georg Brandl36ab1ef2009-01-03 21:17:04 +0000657 The *spam* parameter.
Georg Brandl116aa622007-08-15 14:28:22 +0000658
659 Note that there must be no blank line between the directive head and the
660 explanation; this is to make these blocks visually continuous in the markup.
661
662.. describe:: versionchanged
663
664 Similar to ``versionadded``, but describes when and what changed in the named
665 feature in some way (new parameters, changed side effects, etc.).
666
667--------------
668
Georg Brandl495f7b52009-10-27 15:28:25 +0000669.. describe:: impl-detail
670
671 This directive is used to mark CPython-specific information. Use either with
672 a block content or a single sentence as an argument, i.e. either ::
673
674 .. impl-detail::
675
676 This describes some implementation detail.
677
678 More explanation.
679
680 or ::
681
682 .. impl-detail:: This shortly mentions an implementation detail.
683
684 "\ **CPython implementation detail:**\ " is automatically prepended to the
685 content.
686
Georg Brandl116aa622007-08-15 14:28:22 +0000687.. describe:: seealso
688
689 Many sections include a list of references to module documentation or
690 external documents. These lists are created using the ``seealso`` directive.
691
692 The ``seealso`` directive is typically placed in a section just before any
693 sub-sections. For the HTML output, it is shown boxed off from the main flow
694 of the text.
695
696 The content of the ``seealso`` directive should be a reST definition list.
697 Example::
698
699 .. seealso::
700
701 Module :mod:`zipfile`
702 Documentation of the :mod:`zipfile` standard module.
703
704 `GNU tar manual, Basic Tar Format <http://link>`_
705 Documentation for tar archive files, including GNU tar extensions.
706
707.. describe:: rubric
708
709 This directive creates a paragraph heading that is not used to create a
710 table of contents node. It is currently used for the "Footnotes" caption.
711
712.. describe:: centered
713
714 This directive creates a centered boldfaced paragraph. Use it as follows::
715
716 .. centered::
717
718 Paragraph contents.
719
720
721Table-of-contents markup
722------------------------
723
724Since reST does not have facilities to interconnect several documents, or split
725documents into multiple output files, Sphinx uses a custom directive to add
726relations between the single files the documentation is made of, as well as
727tables of contents. The ``toctree`` directive is the central element.
728
729.. describe:: toctree
730
731 This directive inserts a "TOC tree" at the current location, using the
732 individual TOCs (including "sub-TOC trees") of the files given in the
733 directive body. A numeric ``maxdepth`` option may be given to indicate the
734 depth of the tree; by default, all levels are included.
735
736 Consider this example (taken from the library reference index)::
737
738 .. toctree::
739 :maxdepth: 2
740
Benjamin Petersond7c3ed52010-06-27 22:32:30 +0000741 intro
742 strings
743 datatypes
744 numeric
Georg Brandl116aa622007-08-15 14:28:22 +0000745 (many more files listed here)
746
747 This accomplishes two things:
748
749 * Tables of contents from all those files are inserted, with a maximum depth
750 of two, that means one nested heading. ``toctree`` directives in those
751 files are also taken into account.
Benjamin Petersond7c3ed52010-06-27 22:32:30 +0000752 * Sphinx knows that the relative order of the files ``intro``,
753 ``strings`` and so forth, and it knows that they are children of the
Georg Brandl116aa622007-08-15 14:28:22 +0000754 shown file, the library index. From this information it generates "next
755 chapter", "previous chapter" and "parent chapter" links.
756
757 In the end, all files included in the build process must occur in one
758 ``toctree`` directive; Sphinx will emit a warning if it finds a file that is
759 not included, because that means that this file will not be reachable through
760 standard navigation.
761
762 The special file ``contents.rst`` at the root of the source directory is the
763 "root" of the TOC tree hierarchy; from it the "Contents" page is generated.
764
765
766Index-generating markup
767-----------------------
768
769Sphinx automatically creates index entries from all information units (like
770functions, classes or attributes) like discussed before.
771
772However, there is also an explicit directive available, to make the index more
773comprehensive and enable index entries in documents where information is not
774mainly contained in information units, such as the language reference.
775
776The directive is ``index`` and contains one or more index entries. Each entry
777consists of a type and a value, separated by a colon.
778
779For example::
780
781 .. index::
Thomas Wouters89d996e2007-09-08 17:39:28 +0000782 single: execution; context
Georg Brandl116aa622007-08-15 14:28:22 +0000783 module: __main__
784 module: sys
785 triple: module; search; path
786
787This directive contains five entries, which will be converted to entries in the
788generated index which link to the exact location of the index statement (or, in
789case of offline media, the corresponding page number).
790
791The possible entry types are:
792
793single
794 Creates a single index entry. Can be made a subentry by separating the
Thomas Wouters89d996e2007-09-08 17:39:28 +0000795 subentry text with a semicolon (this notation is also used below to describe
796 what entries are created).
Georg Brandl116aa622007-08-15 14:28:22 +0000797pair
798 ``pair: loop; statement`` is a shortcut that creates two index entries,
799 namely ``loop; statement`` and ``statement; loop``.
800triple
801 Likewise, ``triple: module; search; path`` is a shortcut that creates three
802 index entries, which are ``module; search path``, ``search; path, module`` and
803 ``path; module search``.
804module, keyword, operator, object, exception, statement, builtin
805 These all create two index entries. For example, ``module: hashlib`` creates
806 the entries ``module; hashlib`` and ``hashlib; module``.
807
Thomas Wouters89d996e2007-09-08 17:39:28 +0000808For index directives containing only "single" entries, there is a shorthand
809notation::
810
811 .. index:: BNF, grammar, syntax, notation
812
813This creates four index entries.
814
Georg Brandl116aa622007-08-15 14:28:22 +0000815
816Grammar production displays
817---------------------------
818
819Special markup is available for displaying the productions of a formal grammar.
820The markup is simple and does not attempt to model all aspects of BNF (or any
821derived forms), but provides enough to allow context-free grammars to be
822displayed in a way that causes uses of a symbol to be rendered as hyperlinks to
823the definition of the symbol. There is this directive:
824
825.. describe:: productionlist
826
827 This directive is used to enclose a group of productions. Each production is
828 given on a single line and consists of a name, separated by a colon from the
829 following definition. If the definition spans multiple lines, each
830 continuation line must begin with a colon placed at the same column as in the
831 first line.
832
833 Blank lines are not allowed within ``productionlist`` directive arguments.
834
835 The definition can contain token names which are marked as interpreted text
Georg Brandl36ab1ef2009-01-03 21:17:04 +0000836 (e.g. ``unaryneg ::= "-" `integer```) -- this generates cross-references
Georg Brandl116aa622007-08-15 14:28:22 +0000837 to the productions of these tokens.
838
839 Note that no further reST parsing is done in the production, so that you
840 don't have to escape ``*`` or ``|`` characters.
841
842
Georg Brandl48310cd2009-01-03 21:18:54 +0000843.. XXX describe optional first parameter
Georg Brandl116aa622007-08-15 14:28:22 +0000844
845The following is an example taken from the Python Reference Manual::
846
847 .. productionlist::
848 try_stmt: try1_stmt | try2_stmt
849 try1_stmt: "try" ":" `suite`
850 : ("except" [`expression` ["," `target`]] ":" `suite`)+
851 : ["else" ":" `suite`]
852 : ["finally" ":" `suite`]
853 try2_stmt: "try" ":" `suite`
854 : "finally" ":" `suite`
855
856
857Substitutions
858-------------
859
860The documentation system provides three substitutions that are defined by default.
Benjamin Petersonf608c612008-11-16 18:33:53 +0000861They are set in the build configuration file :file:`conf.py`.
Georg Brandl116aa622007-08-15 14:28:22 +0000862
863.. describe:: |release|
864
865 Replaced by the Python release the documentation refers to. This is the full
866 version string including alpha/beta/release candidate tags, e.g. ``2.5.2b3``.
867
868.. describe:: |version|
869
870 Replaced by the Python version the documentation refers to. This consists
871 only of the major and minor version parts, e.g. ``2.5``, even for version
872 2.5.1.
873
874.. describe:: |today|
875
876 Replaced by either today's date, or the date set in the build configuration
877 file. Normally has the format ``April 14, 2007``.
878
879
880.. rubric:: Footnotes
881
882.. [1] There is a standard ``.. include`` directive, but it raises errors if the
883 file is not found. This one only emits a warning.