1 =============================
2 reStructuredText Directives
3 =============================
5 :Author: Mark Nodine (for prest-specific implementation)
6 :Contact: goodger@python.org mnodine@alum.mit.edu
7 :Revision: $Revision: 762 $
8 :Date: $Date: 2006-01-27 11:47:47 -0600 (Fri, 27 Jan 2006) $
9 :Copyright: This document has been placed in the public domain.
13 This document describes the directives implemented in the reference
14 reStructuredText parser.
16 Directives have the following syntax::
18 +-------+-------------------------------+
19 | ".. " | directive type "::" directive |
22 +-------------------------------+
24 Directives begin with an explicit markup start (two periods and a
25 space), followed by the directive type and two colons (collectively,
26 the "directive marker"). The directive block begins immediately after
27 the directive marker, and includes all subsequent indented lines. The
28 directive block is divided into arguments, options (a field list), and
29 content (in that order), any of which may appear. See the Directives_
30 section in the `reStructuredText Markup Specification`_ for syntax
33 Descriptions below list "doctree elements" (document tree element
34 names; XML DTD generic identifiers) corresponding to individual
35 directives. For details on the hierarchy of elements, please see `The
36 Docutils Document Tree`_ and the `Docutils Generic DTD`_ XML document
37 type definition. For directive implementation details, see `Creating
38 reStructuredText Directives`_.
40 .. _Directives: ./reStructuredText.html#directives
41 .. _reStructuredText Markup Specification: ./reStructuredText.html
42 .. _The Docutils Document Tree: ../doctree.html
43 .. _Docutils Generic DTD: ../docutils.dtd
44 .. _Creating reStructuredText Directives:
65 :Directive Types: "attention", "caution", "danger", "error", "hint",
66 "important", "note", "tip", "warning", "admonition"
67 :Doctree Elements: attention, caution, danger, error, hint, important,
68 note, tip, warning, admonition, title
69 :Directive Arguments: None.
70 :Directive Options: None.
71 :Directive Content: Interpreted as body elements.
73 Admonitions are specially marked "topics" that can appear anywhere an
74 ordinary body element can. They contain arbitrary body elements.
75 Typically, an admonition is rendered as an offset block in a document,
76 sometimes outlined or shaded, with a title matching the admonition
80 Beware killer rabbits!
82 This directive might be rendered something like this::
84 +------------------------+
87 | Beware killer rabbits! |
88 +------------------------+
90 The following admonition directives have been implemented:
102 Any text immediately following the directive indicator (on the same
103 line and/or indented on following lines) is interpreted as a directive
104 block and is parsed for normal body elements. For example, the
105 following "note" admonition directive contains one paragraph and a
106 bullet list consisting of two list items::
108 .. note:: This is a note admonition.
109 This is the second line of the first paragraph.
111 - The note contains all indented body elements
113 - It includes this bullet list.
121 :Directive Type: "admonition"
122 :Doctree Elements: admonition, title
123 :Directive Arguments: One, required (admonition title)
124 :Directive Options: Possible.
125 :Directive Content: Interpreted as body elements.
127 This is a generic, titled admonition. The title may be anything the
130 The author-supplied title is also used as a "classes" attribute value
131 after being converted into a valid identifier form (down-cased;
132 non-alphanumeric characters converted to single hyphens; "admonition-"
133 prefixed). For example, this admonition::
135 .. admonition:: And, by the way...
137 You can make up your own admonition too.
139 becomes the following document tree (pseudo-XML)::
141 <document source="test data">
142 <admonition classes="admonition-and-by-the-way">
146 You can make up your own admonition too.
148 The following option is recognized:
151 Override the computed "classes" attribute value. See the class_
159 There are two image directives: "image" and "figure".
165 :Directive Type: "image"
166 :Doctree Element: image
167 :Directive Arguments: One, required (image URI).
168 :Directive Options: Possible.
169 :Directive Content: None.
171 An "image" is a simple picture::
173 .. image:: picture.png
175 The URI for the image source file is specified in the directive
176 argument. As with hyperlink targets, the image URI may begin on the
177 same line as the explicit markup start and target name, or it may
178 begin in an indented text block immediately following, with no
179 intervening blank lines. If there are multiple lines in the link
180 block, they are stripped of leading and trailing whitespace and joined
183 Optionally, the image link block may contain a flat field list, the
184 _`image options`. For example::
186 .. image:: picture.jpeg
193 The following options are recognized:
196 Alternate text: a short description of the image, displayed by
197 applications that cannot display images, or spoken by applications
198 for visually impaired users.
201 The height of the image in pixels, used to reserve space or scale
202 the image vertically.
205 The width of the image in pixels, used to reserve space or scale
206 the image horizontally.
209 The uniform scaling factor of the image, a percentage (but no "%"
210 symbol is required or allowed). "100" means full-size.
212 ``align`` : "top", "middle", "bottom", "left", "center", or "right"
213 The alignment of the image, equivalent to the HTML ``<img>`` tag's
214 "align" attribute. The values "top", "middle", and "bottom"
215 control an image's vertical alignment (relative to the text
216 baseline); they are only useful for inline images (substitutions).
217 The values "left", "center", and "right" control an image's
218 horizontal alignment, allowing the image to float and have the
219 text flow around it. The specific behavior depends upon the
220 browser or rendering software used.
222 ``target`` : text (URI or reference name)
223 Makes the image into a hyperlink reference ("clickable"). The
224 option argument may be a URI (relative or absolute), or a
225 reference name with underscore suffix (e.g. ``name_``).
228 Set a "classes" attribute value on the image element. See the
229 class_ directive below.
232 Specifies the name of a map to be used with HTML's ``<usemap>``
233 tag so that clicking on the image can traverse a URI.
238 :Directive Type: "figure"
239 :Doctree Elements: figure, image, caption, legend
240 :Directive Arguments: One, required (image URI).
241 :Directive Options: Possible.
242 :Directive Content: Interpreted as the figure caption and an optional
245 A "figure" consists of image_ data (including `image options`_), an
246 optional caption (a single paragraph), and an optional legend
247 (arbitrary body elements)::
249 .. figure:: picture.png
251 :alt: map to buried treasure
253 This is the caption of the figure (a simple paragraph).
255 The legend consists of all elements after the caption. In this
256 case, the legend consists of this paragraph and the following
259 +-----------------------+-----------------------+
261 +=======================+=======================+
262 | .. image:: tent.png | Campground |
263 +-----------------------+-----------------------+
264 | .. image:: waves.png | Lake |
265 +-----------------------+-----------------------+
266 | .. image:: peak.png | Mountain |
267 +-----------------------+-----------------------+
269 There must be blank lines before the caption paragraph and before the
270 legend. To specify a legend without a caption, use an empty comment
271 ("..") in place of the caption.
273 The "figure" directive supports all of the options of the "image"
274 directive (see `image options`_ above). In addition, the following
275 options are recognized:
277 ``figwidth`` : integer or "image"
278 The width of the figure in pixels, to limit the horizontal space
279 used. A special value of "image" is allowed, in which case the
280 included image's actual width is used (requires PIL [#PIL]_). If
281 the image file is not found or the required software is
282 unavailable, this option is ignored.
284 Sets the "width" attribute of the "figure" doctree element.
286 This option does not scale the included image; use the "width"
287 `image`_ option for that. ::
289 +---------------------------+
292 |<------ figwidth --------->|
294 | +---------------------+ |
297 | |<--- width --------->| |
298 | +---------------------+ |
300 |The figure's caption should|
301 |wrap at this width. |
302 +---------------------------+
305 Set a "classes" attribute value on the figure element. See the
306 class_ directive below.
308 ``align`` : "left", "center", or "right"
309 The horizontal alignment of the figure, allowing the image to
310 float and have the text flow around it. The specific behavior
311 depends upon the browser or rendering software used.
313 .. [#PIL] `Python Imaging Library`_.
315 .. _Python Imaging Library: http://www.pythonware.com/products/pil/
325 :Directive Type: "topic"
326 :Doctree Element: topic
327 :Directive Arguments: 1, required (topic title).
328 :Directive Options: Possible.
329 :Directive Content: Interpreted as the topic body.
331 A topic is like a block quote with a title, or a self-contained
332 section with no subsections. Use the "topic" directive to indicate a
333 self-contained idea that is separate from the flow of the document.
334 Topics may occur anywhere a section or transition may occur. Body
335 elements and topics may not contain nested topics.
337 The directive's sole argument is interpreted as the topic title; the
338 next line must be blank. All subsequent lines make up the topic body,
339 interpreted as body elements. For example::
341 .. topic:: Topic Title
343 Subsequent indented lines comprise
344 the body of the topic, and are
345 interpreted as body elements.
347 The following option is recognized:
350 Set a "classes" attribute value on the topic element. See the
351 class_ directive below.
357 :Directive Type: "sidebar"
358 :Doctree Element: sidebar
359 :Directive Arguments: One, required (sidebar title).
360 :Directive Options: Possible.
361 :Directive Content: Interpreted as the sidebar body.
363 Sidebars are like miniature, parallel documents that occur inside
364 other documents, providing related or reference material. A sidebar
365 is typically offset by a border and "floats" to the side of the page;
366 the document's main text may flow around it. Sidebars can also be
367 likened to super-footnotes; their content is outside of the flow of
368 the document's main text.
370 Sidebars may occur anywhere a section or transition may occur. Body
371 elements (including sidebars) may not contain nested sidebars.
373 The directive's sole argument is interpreted as the sidebar title,
374 which may be followed by a subtitle option (see below); the next line
375 must be blank. All subsequent lines make up the sidebar body,
376 interpreted as body elements. For example::
378 .. sidebar:: Sidebar Title
379 :subtitle: Optional Sidebar Subtitle
381 Subsequent indented lines comprise
382 the body of the sidebar, and are
383 interpreted as body elements.
385 The following options are recognized:
388 The sidebar's subtitle.
391 Set a "classes" attribute value on the sidebar element. See the
392 class_ directive below.
398 .. admonition:: Deprecated
400 The "line-block" directive is deprecated. Use the `line block
403 .. _line block syntax: restructuredtext.html#line-blocks
405 :Directive Type: "line-block"
406 :Doctree Element: line_block
407 :Directive Arguments: None.
408 :Directive Options: Possible.
409 :Directive Content: Becomes the body of the line block.
411 The "line-block" directive constructs an element where line breaks and
412 initial indentation is significant and inline markup is supported. It
413 is equivalent to a `parsed literal block`_ with different rendering:
414 typically in an ordinary serif typeface instead of a
415 typewriter/monospaced face, and not automatically indented. (Have the
416 line-block directive begin a block quote to get an indented line
417 block.) Line blocks are useful for address blocks and verse (poetry,
418 song lyrics), where the structure of lines is significant. For
419 example, here's a classic::
421 "To Ma Own Beloved Lassie: A Poem on her 17th Birthday", by
422 Ewan McTeagle (for Lassie O'Shea):
426 Lend us a couple of bob till Thursday.
427 I'm absolutely skint.
428 But I'm expecting a postal order and I can pay you back
432 The following option is recognized:
435 Set a "classes" attribute value on the line_block element. See the
436 class_ directive below.
444 :Directive Type: "parsed-literal"
445 :Doctree Element: literal_block
446 :Directive Arguments: None.
447 :Directive Options: Possible.
448 :Directive Content: Becomes the body of the literal block.
450 Unlike an ordinary literal block, the "parsed-literal" directive
451 constructs a literal block where the text is parsed for inline markup.
452 It is equivalent to a `line block`_ with different rendering:
453 typically in a typewriter/monospaced typeface, like an ordinary
454 literal block. Parsed literal blocks are useful for adding hyperlinks
457 However, care must be taken with the text, because inline markup is
458 recognized and there is no protection from parsing. Backslash-escapes
459 may be necessary to prevent unintended parsing. And because the
460 markup characters are removed by the parser, care must also be taken
461 with vertical alignment. Parsed "ASCII art" is tricky, and extra
462 whitespace may be necessary.
464 For example, all the element names in this content model are links::
468 ( (title_, subtitle_?)?,
470 (docinfo_, transition_?)?,
471 `%structure.model;`_ )
473 The following option is recognized:
476 Set a "classes" attribute value on the literal_block element. See
477 the class_ directive below.
483 :Directive Type: "rubric"
484 :Doctree Element: rubric
485 :Directive Arguments: 1, required (rubric text).
486 :Directive Options: Possible.
487 :Directive Content: None.
491 rubric n. 1. a title, heading, or the like, in a manuscript,
492 book, statute, etc., written or printed in red or otherwise
493 distinguished from the rest of the text. ...
495 -- Random House Webster's College Dictionary, 1991
497 The "rubric" directive inserts a "rubric" element into the document
498 tree. A rubric is like an informal heading that doesn't correspond to
499 the document's structure.
501 The following option is recognized:
504 Set a "classes" attribute value on the rubric element. See the
505 class_ directive below.
512 :Directive Type: "compound"
513 :Doctree Element: compound
514 :Directive Arguments: None.
515 :Directive Options: Possible.
516 :Directive Content: Interpreted as body elements.
518 (New in Docutils 0.3.6)
520 The "compound" directive is used to create a compound paragraph, which
521 is a single logical paragraph containing multiple physical body
522 elements such as simple paragraphs, literal blocks, tables, lists,
523 etc., instead of directly containing text and inline elements. For
528 The 'rm' command is very dangerous. If you are logged
529 in as root and enter ::
534 you will erase the entire contents of your file system.
536 In the example above, a literal block is "embedded" within a sentence
537 that begins in one physical paragraph and ends in another.
541 The "compound" directive is *not* a generic block-level container
542 like HTML's ``<div>`` element. Do not use it only to group a
543 sequence of elements, or you may get unexpected results.
545 If you need a generic block-level container, please use the
546 container_ directive, described below.
548 Compound paragraphs are typically rendered as multiple distinct text
549 blocks, with the possibility of variations to emphasize their logical
552 * If paragraphs are rendered with a first-line indent, only the first
553 physical paragraph of a compound paragraph should have that indent
554 -- second and further physical paragraphs should omit the indents;
555 * vertical spacing between physical elements may be reduced;
558 The following option is recognized:
561 Set a "classes" attribute value on the compound element. See the
562 class_ directive below.
567 Mathematical Equations
568 ======================
570 :Directive Type: "ascii-mathml", "mathml"
571 :Doctree Element: mathml
572 :Directive Arguments: Possible.
573 :Directive Options: Possible.
574 :Directive Content: Possible.
576 This directive is used to create mathematical markup from `ASCIIMathML`_.
577 Unlike the ``mathml`` and ``ascii-mathml`` roles, which produce
578 inline-style mathematical markup, the directive produces display-style
579 markup unless it is used in a substitution definition, in which case
580 it also defaults to inline-style markup. However, the style can be
581 overridden by means of the directive options.
583 .. _AsciiMathML: ascii-mathml.xhtml
585 The following options are recognized:
588 Specifies to attach a label to a mathml equation that becomes
589 a substitution definition of name annotated with the equation number.
591 ``mstyle`` : field list text
592 The field list gives a set of key/value pairs for the `mstyle
593 attribute`_ of the generated mathml markup. For example, the
594 following directive would not use display style and would have the
595 math equation in green::
597 .. ascii-mathml:: E = mc^2
602 .. _mstyle attribute: ascii-mathml.xhtml#attributes-for-mstyle
607 :Directive Type: "container"
608 :Doctree Element: container
609 :Directive Arguments: One or more, optional (class names).
610 :Directive Options: None.
611 :Directive Content: Interpreted as body elements.
613 (New in Docutils 0.3.10)
615 The "container" directive surrounds its contents (arbitrary body
616 elements) with a generic block-level "container" element. Combined
617 with the optional "class_" attribute argument(s), this is an extension
618 mechanism for users & applications. For example::
620 .. container:: custom
622 This paragraph might be rendered in a custom way.
624 Parsing the above results in the following pseudo-XML::
626 <container classes="custom">
628 This paragraph might be rendered in a custom way.
630 The "container" directive is the equivalent of HTML's ``<div>``
631 element. It may be used to group a sequence of elements for user- or
632 application-specific purposes.
639 Formal tables need more structure than the reStructuredText syntax
640 supplies. Tables may be given titles with the table_ directive.
641 Sometimes reStructuredText tables are inconvenient to write, or table
642 data in a standard format is readily available. The csv-table_
643 directive supports CSV data.
649 :Directive Type: "table"
650 :Doctree Element: table
651 :Directive Arguments: 1, optional (table title).
652 :Directive Options: Possible.
653 :Directive Content: A normal reStructuredText table.
655 (New in Docutils 0.3.1)
657 The "table" directive is used to create a titled table, to associate a
660 .. table:: Truth table for "not"
669 The following option is recognized:
672 Set a "classes" attribute value on the table element. See the
673 class_ directive below.
681 :Directive Type: "csv-table"
682 :Doctree Element: table
683 :Directive Arguments: 1, optional (table title).
684 :Directive Options: Possible.
685 :Directive Content: A CSV (comma-separated values) table.
689 The "csv-table" directive's ":file:" and ":url:" options represent
690 a potential security holes. They can be disabled with the
691 "file_insertion_enabled" runtime setting.
693 (New in Docutils 0.3.4)
695 The "csv-table" directive is used to create a table from CSV
696 (comma-separated values) data. CSV is a common data format generated
697 by spreadsheet applications and commercial databases. The data may be
698 internal (an integral part of the document) or external (a separate
703 .. csv-table:: Frozen Delights!
704 :header: "Treat", "Quantity", "Description"
707 "Albatross", 2.99, "On a stick!"
708 "Crunchy Frog", 1.49, "If we took the bones out, it wouldn't be
709 crunchy, now would it?"
710 "Gannet Ripple", 1.99, "On a stick!"
712 Block markup and inline markup within cells is supported. Line ends
713 are recognized within cells.
717 * Whitespace delimiters are supported only for external CSV files.
719 * There is no support for checking that the number of columns in each
720 row is the same. However, this directive supports CSV generators
721 that do not insert "empty" entries at the end of short rows, by
722 automatically adding empty entries.
724 .. Add "strict" option to verify input?
726 The following options are recognized:
729 Set a "classes" attribute value on the table element. See the
730 class_ directive below.
732 ``widths`` : integer [, integer...]
733 A comma- or space-separated list of relative column widths. The
734 default is equal-width columns (100%/#columns).
736 ``header-rows`` : integer
737 The number of rows of CSV data to use in the table header.
740 ``stub-columns`` : integer
741 The number of table columns to use as stubs (row titles, on the
742 left). Defaults to 0.
744 ``header`` : CSV data
745 Supplemental data for the table header, added independently of and
746 before any ``header-rows`` from the main CSV data. Must use the
747 same CSV format as the main CSV data.
749 ``file`` : string (newlines removed)
750 The local filesystem path to a CSV data file.
752 ``url`` : string (whitespace removed)
753 An Internet URL reference to a CSV data file.
755 ``encoding`` : name of text encoding
756 The text encoding of the external CSV data (file or URL).
757 Defaults to the document's encoding (if specified).
759 ``delim`` : char | "tab" | "space"
760 A one-character string used to separate fields. Defaults to ``,``
761 (comma). May be specified as a Unicode code point; see the
762 unicode_ directive for syntax details.
765 A one-character string used to quote elements containing the
766 delimiter or which start with the quote character. Defaults to
767 ``"`` (quote). May be specified as a Unicode code point; see the
768 unicode_ directive for syntax details.
771 Treat whitespace immediately following the delimiter as
772 significant. The default is to ignore such whitespace.
775 A one-character string used to escape the delimiter or quote
776 characters. May be specified as a Unicode code point; see the
777 unicode_ directive for syntax details. Used when the delimiter is
778 used in an unquoted field, or when quote characters are used
779 within a field. The default is to double-up the character,
780 e.g. "He said, ""Hi!"""
782 .. Add another possible value, "double", to explicitly indicate
789 :Directive Type: "list-table"
790 :Doctree Element: table
791 :Directive Arguments: 1, optional (table title).
792 :Directive Options: Possible.
793 :Directive Content: A uniform two-level bullet list.
795 (New in Docutils 0.3.8. This is an initial implementation; `further
796 ideas`__ may be implemented in the future.)
798 __ http://docutils.sf.net/docs/dev/rst/alternatives.html#list-driven-tables
800 The "list-table" directive is used to create a table from data in a
801 uniform two-level bullet list. "Uniform" means that each sublist
802 (second-level list) must contain the same number of list items.
806 .. list-table:: Frozen Delights!
818 - If we took the bones out, it wouldn't be
819 crunchy, now would it?
824 The following options are recognized:
827 Set a "classes" attribute value on the table element. See the
828 class_ directive below.
830 ``widths`` : integer [integer...]
831 A comma- or space-separated list of relative column widths. The
832 default is equal-width columns (100%/#columns).
834 ``header-rows`` : integer
835 The number of rows of list data to use in the table header.
838 ``stub-columns`` : integer
839 The number of table columns to use as stubs (row titles, on the
840 left). Defaults to 0.
852 :Directive Type: "contents"
853 :Doctree Elements: pending, topic
854 :Directive Arguments: One, optional: title.
855 :Directive Options: Possible.
856 :Directive Content: None.
858 The "contents" directive generates a table of contents (TOC) in a
859 topic_. Topics, and therefore tables of contents, may occur anywhere
860 a section or transition may occur. Body elements and topics may not
861 contain tables of contents.
863 Here's the directive in its simplest form::
867 Language-dependent boilerplate text will be used for the title. The
868 English default title text is "Contents".
870 An explicit title may be specified::
872 .. contents:: Table of Contents
874 The title may span lines, although it is not recommended::
876 .. contents:: Here's a very long Table of
879 Options may be specified for the directive, using a field list::
881 .. contents:: Table of Contents
884 If the default title is to be used, the options field list may begin
885 on the same line as the directive marker::
887 .. contents:: :depth: 2
889 The following options are recognized:
892 The number of section levels that are collected in the table of
893 contents. The default is unlimited depth.
895 ``local`` : flag (empty)
896 Generate a local table of contents. Entries will only include
897 subsections of the section in which the directive is given. If no
898 explicit title is given, the table of contents will not be titled.
900 ``backlinks`` : "entry" or "top" or "none"
901 Generate links from section headers back to the table of contents
902 entries, the table of contents itself, or generate no backlinks.
905 Set a "classes" attribute value on the topic element. See the
906 class_ directive below.
910 .. _section-autonumbering:
912 Automatic Section Numbering
913 ===========================
915 :Directive Type: "sectnum" or "section-autonumbering" (synonyms)
916 :Doctree Elements: pending, generated
917 :Directive Arguments: None.
918 :Directive Options: Possible.
919 :Directive Content: None.
921 The "sectnum" (or "section-autonumbering") directive automatically
922 numbers sections and subsections in a document. Section numbers are
923 of the "multiple enumeration" form, where each level has a number,
924 separated by periods. For example, the title of section 1, subsection
925 2, subsubsection 3 would have "1.2.3" prefixed.
927 The "sectnum" directive does its work in two passes: the initial parse
928 and a transform. During the initial parse, a "pending" element is
929 generated which acts as a placeholder, storing any options internally.
930 At a later stage in the processing, the "pending" element triggers a
931 transform, which adds section numbers to titles. Section numbers are
932 enclosed in a "generated" element, and titles have their "auto"
933 attribute set to "1".
935 The following options are recognized:
938 The number of section levels that are numbered by this directive.
939 The default is unlimited depth.
942 A space-separated list of number formats to use for each level of
943 hierarchy, where each of the number formats contains one of the
947 Lowercase Roman numerals
949 Uppercase Roman numerals
957 Any missing format item defaults to ``1``. For example, the
958 string ``I A (i)`` formats top-level section numbers using uppercase
959 Roman numerals, the second level using uppercase alphabetic, the
960 third using lowercase Roman numerals in parentheses and the rest
961 using Arabic numerals.
964 An arbitrary string that is prefixed to the automatically
965 generated section numbers. It may be something like "3.2.", which
966 will produce "3.2.1", "3.2.2", "3.2.2.1", and so on. Note that
967 any separating punctuation (in the example, a period, ".") must be
968 explicitly provided. The default is no prefix.
970 ``prefix-title`` : flag
971 Specifies whether a prefix should also be appended to the title
975 An arbitrary string that is appended to the automatically
976 generated section numbers. The default is no suffix.
979 The value that will be used for the first section number.
980 Combined with ``prefix``, this may be used to force the right
981 numbering for a document split over several source files. The
988 Document Header & Footer
989 ========================
991 :Directive Types: "header" and "footer"
992 :Doctree Elements: decoration, header, footer
993 :Directive Arguments: None.
994 :Directive Options: None.
995 :Directive Content: Interpreted as body elements.
997 (New in Docutils 0.3.8)
999 The "header" and "footer" directives create document decorations,
1000 useful for page navigation, notes, time/datestamp, etc. For example::
1002 .. header:: This space for rent.
1004 This will add a paragraph to the document header, which will appear at
1005 the top of the generated web page or at the top of every printed page.
1007 These directives may be used multiple times, cumulatively. There is
1008 currently support for only one header and footer.
1012 While it is possible to use the "header" and "footer" directives to
1013 create navigational elements for web pages, you should be aware
1014 that Docutils is meant to be used for *document* processing, and
1015 that a navigation bar is not typically part of a document.
1017 Thus, you may soon find Docutils' abilities to be insufficient for
1018 these purposes. At that time, you should consider using a
1019 templating system (like ht2html_) rather than the "header" and
1020 "footer" directives.
1022 .. _ht2html: http://ht2html.sourceforge.net/
1024 In addition to the use of these directives to populate header and
1025 footer content, content may also be added automatically by the
1026 processing system. For example, if certain runtime settings are
1027 enabled, the document footer is populated with processing information
1028 such as a datestamp, a link to `the Docutils website`_, etc.
1030 .. _the Docutils website: http://docutils.sourceforge.net
1042 :Directive Type: "target-notes"
1043 :Doctree Elements: pending, footnote, footnote_reference
1044 :Directive Arguments: None.
1045 :Directive Options: None.
1046 :Directive Content: None.
1048 The "target-notes" directive creates a footnote for each external
1049 target in the text, and corresponding footnote references after each
1050 reference. For every explicit target (of the form, ``.. _target name:
1051 URL``) in the text, a footnote will be generated containing the
1052 visible URL as content.
1058 **NOT IMPLEMENTED YET**
1060 :Directive Type: "footnotes"
1061 :Doctree Elements: pending, topic
1062 :Directive Arguments: None?
1063 :Directive Options: Possible?
1064 :Directive Content: None.
1072 **NOT IMPLEMENTED YET**
1074 :Directive Type: "citations"
1075 :Doctree Elements: pending, topic
1076 :Directive Arguments: None?
1077 :Directive Options: Possible?
1078 :Directive Content: None.
1090 :Directive Type: "meta"
1091 :Doctree Element: meta (non-standard)
1092 :Directive Arguments: None.
1093 :Directive Options: None.
1094 :Directive Content: Must contain a flat field list.
1096 The "meta" directive is used to specify HTML metadata stored in HTML
1097 META tags. "Metadata" is data about data, in this case data about web
1098 pages. Metadata is used to describe and classify web pages in the
1099 World Wide Web, in a form that is easy for search engines to extract
1102 Within the directive block, a flat field list provides the syntax for
1103 metadata. The field name becomes the contents of the "name" attribute
1104 of the META tag, and the field body (interpreted as a single string
1105 without inline markup) becomes the contents of the "content"
1106 attribute. For example::
1109 :description: The reStructuredText plaintext markup language
1110 :keywords: plaintext, markup language
1112 This would be converted to the following HTML::
1114 <meta name="description"
1115 content="The reStructuredText plaintext markup language">
1116 <meta name="keywords" content="plaintext, markup language">
1118 Support for other META attributes ("http-equiv", "scheme", "lang",
1119 "dir") are provided through field arguments, which must be of the form
1123 :description lang=en: An amusing story
1124 :description lang=fr: Un histoire amusant
1126 And their HTML equivalents::
1128 <meta name="description" lang="en" content="An amusing story">
1129 <meta name="description" lang="fr" content="Un histoire amusant">
1131 Some META tags use an "http-equiv" attribute instead of the "name"
1132 attribute. To specify "http-equiv" META tags, simply omit the name::
1135 :http-equiv=Content-Type: text/html; charset=ISO-8859-1
1139 <meta http-equiv="Content-Type"
1140 content="text/html; charset=ISO-8859-1">
1146 **NOT IMPLEMENTED YET**
1148 Non-standard element: imagemap.
1151 -----------------------------------------
1152 Directives for Substitution Definitions
1153 -----------------------------------------
1155 The directives in this section may only be used in substitution
1156 definitions. They may not be used directly, in standalone context.
1157 The `image`_ directive may be used both in substitution definitions
1158 and in the standalone context.
1166 :Directive Type: "replace"
1167 :Doctree Element: Text & inline elements
1168 :Directive Arguments: None.
1169 :Directive Options: None.
1170 :Directive Content: A single paragraph; may contain inline markup.
1172 The "replace" directive is used to indicate replacement text for a
1173 substitution reference. It may be used within substitution
1174 definitions only. For example, this directive can be used to expand
1177 .. |reST| replace:: reStructuredText
1179 Yes, |reST| is a long word, so I can't blame anyone for wanting to
1182 As reStructuredText doesn't support nested inline markup, the only way
1183 to create a reference with styled text is to use substitutions with
1184 the "replace" directive::
1186 I recommend you try |Python|_.
1188 .. |Python| replace:: Python, *the* best language around
1189 .. _Python: http://www.python.org/
1194 Unicode Character Codes
1195 =======================
1197 :Directive Type: "unicode"
1198 :Doctree Element: Text
1199 :Directive Arguments: One or more, required (Unicode character codes,
1200 optional text, and comments).
1201 :Directive Options: Possible.
1202 :Directive Content: None.
1204 The "unicode" directive converts Unicode character codes (numerical
1205 values) to characters, and may be used in substitution definitions
1208 The arguments, separated by spaces, can be:
1210 * **character codes** as
1212 - decimal numbers or
1214 - hexadecimal numbers, prefixed by ``0x``, ``x``, ``\x``, ``U+``,
1215 ``u``, or ``\u`` or as XML-style hexadecimal character entities,
1218 * **text**, which is used as-is.
1220 Text following " .. " is a comment and is ignored. The spaces between
1221 the arguments are ignored and thus do not appear in the output.
1222 Hexadecimal codes are case-insensitive.
1224 For example, the following text::
1226 Copyright |copy| 2003, |BogusMegaCorp (TM)| |---|
1227 all rights reserved.
1229 .. |copy| unicode:: 0xA9 .. copyright sign
1230 .. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122
1231 .. with trademark sign
1232 .. |---| unicode:: U+02014 .. em dash
1237 Copyright |copy| 2003, |BogusMegaCorp (TM)| |---|
1238 all rights reserved.
1240 .. |copy| unicode:: 0xA9 .. copyright sign
1241 .. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122
1242 .. with trademark sign
1243 .. |---| unicode:: U+02014 .. em dash
1246 The following options are recognized:
1249 Whitespace to the left of the substitution reference is removed.
1252 Whitespace to the right of the substitution reference is removed.
1255 Equivalent to ``ltrim`` plus ``rtrim``; whitespace on both sides
1256 of the substitution reference is removed.
1259 -----------------------
1260 Executable Directives
1261 -----------------------
1263 The directives in this section are specific to the trip implementation
1264 of the reStructuredText parser. All of the directives in this section
1265 involve executing code. To prevent an unknown document from running
1266 malicious code, all of these directives will return an error and not
1267 run the code unless trip is invoked with the define ``-D trusted``.
1268 All these directives are implemented externally in the ``Directive``
1269 subdirectory of the bin directory where ``trip`` is installed. To
1270 disable them permanently, simply remove or rename the ``Directive``
1276 :Directive Type: "if"
1277 :Doctree Elements: depend on data being included
1278 :Directive Arguments: One, required.
1279 :Directive Options: None.
1280 :Directive Content: Required.
1282 The "if" directive executes its argument as a Perl expression. If the
1283 Perl expression evaluates to true, then the directive's content is
1284 parsed as reStructuredText input and included in the document. If the
1285 Perl expression evaluates to false, then the content of the directive
1286 is omitted. This behavior can be useful for putting comments in a
1287 reStructuredText document that should not be propagated to the output
1290 The "if" directive defines the following global variables:
1293 The name of the source file containing the perl directive.
1295 The line number of the perl directive within ``$SOURCE``.
1297 The top-level file being processed.
1299 Array of reference to array of [file name, line number] pairs that
1300 have included the current file.
1301 ``$opt_<x>`` or ``$opt{x}``
1302 The ``<x>`` option from the command line.
1304 The "if" directive processes the following define:
1307 Specifies some perl code that is executed prior
1308 to evaluating the first perl directive. This
1309 option can be used to specify variables on the
1310 command line; for example::
1312 -D perl='$a=1; $b=2'
1314 defines constants ``$a`` and ``$b`` that can
1315 be used in the perl expression.
1320 :Directive Type: "perl"
1321 :Doctree Elements: depend on data being included
1322 :Directive Arguments: Possible
1323 :Directive Options: Possible.
1324 :Directive Content: Possible.
1326 The "perl" directive executes perl code and interpolates whatever is
1327 returned by the execution. The perl code can be placed either in
1328 the arguments or the contents section (or both).
1330 The "perl" directive defines the following global variables:
1333 The name of the source file containing the perl directive.
1335 The line number of the perl directive within ``$SOURCE``.
1337 The literal text of the perl directive.
1339 The name of a substitution definition being defined by the perl
1340 directive, or undefined if not within a substitution definition
1342 Array of reference to array of [file name, line number] pairs that
1343 have included the current file.
1344 ``$opt_<x>`` or ``$opt{x}``
1345 The ``<x>`` option from the command line. Changing one of these
1346 variables has no effect upon the parser. However, you can
1347 effectively set the ``-D x=y`` option, possibly affecting
1348 subsequent parsing, by assigning ``y`` to ``$PARSER->{opt}{D}{x}``.
1350 The Text::Restructured parser object to allow text parsing within a
1353 The top-level file being processed.
1355 The version of prest.
1357 The following defines are processed by the "perl" directive:
1360 Specifies some perl code that is executed prior
1361 to evaluating the first perl directive. This
1362 option can be used to specify variables on the
1363 command line; for example::
1365 -D perl='$a=1; $b=2'
1367 defines constants ``$a`` and ``$b`` that can
1368 be used in a perl block.
1370 The following options are recognized:
1373 Uses the text from the file represented by the string. Both
1374 arguments and contents must be empty if :file: is used.
1376 ``literal`` : flag (empty)
1377 The entire returned text is inserted into the document as a single
1378 literal block (useful for debugging).
1379 If this option is not present, the return value is interpreted
1380 based on its type. If you return a text string, the text is
1381 interpreted as reStructuredText and is parsed again. If you
1382 return an internal DOM object (or list of them), the object is
1383 included directly into the parsed DOM structure. (This latter
1384 option requires knowledge of trip internals, but is the only way
1385 to create a pending DOM object for execution at transformation
1386 time rather than parse time.)
1388 ``lenient`` : flag (empty)
1389 Any errors encountered are returned as text instead of causing a
1390 system message to be generated.
1395 :Directive Type: "system"
1396 :Doctree Elements: depend on data being included
1397 :Directive Arguments: Required
1398 :Directive Options: Possible.
1399 :Directive Content: None.
1401 The "system" directive executes its arguments as a system (shell)
1402 command and interpolates whatever is returned by the execution.
1404 The following options are recognized:
1406 ``literal`` : flag (empty)
1407 The entire returned text is inserted into the document as a single
1408 literal block (useful for debugging).
1410 ``lenient`` : flag (empty)
1411 Any errors encountered are returned as text instead of causing a
1412 system message to be generated.
1420 Including an External Document Fragment
1421 =======================================
1423 :Directive Type: "include"
1424 :Doctree Elements: depend on data being included
1425 :Directive Arguments: One, required (path to the file to include).
1426 :Directive Options: Possible.
1427 :Directive Content: None.
1431 The "include" directive represents a potential security hole. It
1432 can be disabled with the "file_insertion_enabled_" runtime setting.
1434 .. _file_insertion_enabled: ../../user/config.html#file-insertion-enabled
1436 The "include" directive reads a reStructuredText-formatted text file
1437 and parses it in the current document's context at the point of the
1438 directive. The directive argument is the path to the file to be
1439 included, relative to the document containing the directive. For
1442 This first example will be parsed at the document level, and can
1443 thus contain any construct, including section headers.
1445 .. include:: inclusion.txt
1447 Back in the main document.
1449 This second example will be parsed in a block quote context.
1450 Therefore it may only contain body elements. It may not
1451 contain section headers.
1453 .. include:: inclusion.txt
1455 If an included document fragment contains section structure, the title
1456 adornments must match those of the master document.
1458 The following options are recognized:
1460 ``literal`` : flag (empty)
1461 The entire included text is inserted into the document as a single
1462 literal block (useful for program listings).
1464 ``encoding`` : name of text encoding
1465 The text encoding of the external data file. Defaults to the
1466 document's encoding (if specified).
1471 Including a Marked-Up Code Block
1472 ================================
1474 :Directive Type: "code-block"
1475 :Doctree Elements: literal-block or parsed-literal
1476 :Directive Arguments: One, optional (source language of the code block).
1477 :Directive Options: Possible.
1478 :Directive Content: Possible.
1480 The "code-block" directive formats a block of text as a code block.
1481 This directive depends upon the availability of the "states" program,
1482 part of the Unix "enscript" suite, to mark up the code; otherwise the
1483 code block will be returned as a simple literal block. The argument
1484 is optional and specifies the source language of the code block. If the code
1485 block is read from a file, the language will usually default
1486 correctly. The following language specifications are recognized:
1488 ada asm awk c changelog cpp elisp fortran generic haskell html idl
1489 java javascript mail makefile nroff objc pascal perl postscript
1490 python scheme sh states synopsys tcl vba verilog vhdl
1492 The ``generic`` specification has markup that defaults to nothing, but
1493 is controllable using the ``:states-flags:`` option.
1495 The following options are recognized:
1497 ``:file: <filename>``
1498 Reads the code sample from a file rather than using the content block.
1501 Associates the name as a class of the code block.
1504 Specifies that "color" markup should be done. What this actually
1505 means is that the following interpreted-text roles are used for
1506 parts of the code markup:
1508 =============== ================
1509 comment A comment in the language
1510 function-name A function name
1511 variable-name A variable name
1512 keyword A reserved keyword
1513 reference-name A reference name
1514 string A quoted string
1515 builtin Variable names built into language
1516 type-name Names associated with the language's type system
1517 =============== ================
1519 If any of these roles is undefined before processing the macro, a
1520 null (``inline``) definition is entered for them.
1523 The level of markup. ``<level>`` can be one of ``none``, ``light``,
1524 or ``heavy`` (default ``heavy``). Ignored if ``:color:`` is specified.
1527 Number the lines of the code block.
1530 Specifies the name of a non-standard formatting file to be used by
1531 the ``states`` program in doing markup. If specified, overrides the
1532 value of the ``-D code-block-states-file`` command-line option.
1535 Specifies a set of additional flags to be passed to the ``states``
1536 program when doing markup. If specified, overrides the value of the
1537 ``-D code-block-states-flags`` command-line option.
1541 Raw Data Pass-Through
1542 =====================
1544 :Directive Type: "raw"
1545 :Doctree Element: raw
1546 :Directive Arguments: One or more, required (output format types).
1547 :Directive Options: Possible.
1548 :Directive Content: Stored verbatim, uninterpreted. None (empty) if a
1549 "file" or "url" option given.
1553 The "raw" directive represents a potential security hole. It can
1554 be disabled with the "raw_enabled" or "file_insertion_enabled"
1559 The "raw" directive is a stop-gap measure allowing the author to
1560 bypass reStructuredText's markup. It is a "power-user" feature
1561 that should not be overused or abused. The use of "raw" ties
1562 documents to specific output formats and makes them less portable.
1564 If you often need to use the "raw" directive or a "raw"-derived
1565 interpreted text role, that is a sign either of overuse/abuse or
1566 that functionality may be missing from reStructuredText. Please
1567 describe your situation in a message to the Docutils-users_ mailing
1570 .. _Docutils-users: ../../user/mailing-lists.html#docutils-users
1572 The "raw" directive indicates non-reStructuredText data that is to be
1573 passed untouched to the Writer. The names of the output formats are
1574 given in the directive arguments. The interpretation of the raw data
1575 is up to the Writer. A Writer may ignore any raw output not matching
1578 For example, the following input would be passed untouched by an HTML
1583 <hr width=50 size=10>
1585 A LaTeX Writer could insert the following raw content into its
1590 \setlength{\parindent}{0pt}
1592 Raw data can also be read from an external file, specified in a
1593 directive option. In this case, the content block must be empty. For
1597 :file: inclusion.html
1599 The following options are recognized:
1601 ``file`` : string (newlines removed)
1602 The local filesystem path of a raw data file to be included.
1604 ``url`` : string (whitespace removed)
1605 An Internet URL reference to a raw data file to be included.
1607 ``encoding`` : name of text encoding
1608 The text encoding of the external raw data (file or URL).
1609 Defaults to the document's encoding (if specified).
1611 ``head`` : flag (empty)
1612 The raw text gets put into the head material of the document rather
1613 than the body (if applicable).
1620 :Directive Type: "class"
1621 :Doctree Element: pending
1622 :Directive Arguments: One or more, required (class names / attribute
1624 :Directive Options: Possible.
1625 :Directive Content: None.
1627 The "class" directive sets the "classes" attribute value on
1628 the first immediately following non-comment element [#]_. For
1629 details of the "classes" attribute, see `its entry`__ in `The Docutils
1630 Document Tree`_. The directive argument consists of one or more
1631 space-separated class names, which are converted to lowercase and all
1632 non-alphanumeric characters are converted to hyphens. (For the
1633 rationale, see below.)
1635 __ ../doctree.html#classes
1641 This is a "special" paragraph.
1643 .. class:: exceptional remarkable
1645 An Exceptional Section
1646 ======================
1648 This is an ordinary paragraph.
1650 The text above is parsed and transformed into this doctree fragment::
1652 <paragraph classes="special">
1653 This is a "special" paragraph.
1654 <section classes="exceptional remarkable">
1656 An Exceptional Section
1658 This is an ordinary paragraph.
1660 .. [#] To set a "classes" attribute value on a block quote, the
1661 "class" directive must be followed by an empty comment::
1663 .. class:: highlights
1668 The directive doesn't allow content, therefore an empty comment is
1669 required to terminate the directive. Without the empty comment,
1670 the block quote text would be interpreted as the "class"
1671 directive's content, and the parser would complain.
1673 The following options are recognized:
1675 ``parent`` : parent selector
1677 Attach the class to a containing element rather than the next
1678 element. The parent selector is an optional space-separated list
1679 of parent elements. Each element is either a number, which
1680 indicates how many levels to go up, or the name of an element.
1681 For example, "entry" would attach the class to the first
1682 containing table entry, and "row 2" would attach the class to
1683 whatever is two levels above the first containing table row. The
1684 default parent selector is "1".
1686 .. topic:: Rationale for "classes" Attribute Value Conversion
1688 Docutils identifiers are converted to conform to the regular
1689 expression ``[a-z](-?[a-z0-9]+)*``. For CSS compatibility,
1690 identifiers (the "classes" and "id" attributes) should have no
1691 underscores, colons, or periods. Hyphens may be used.
1693 - The `HTML 4.01 spec`_ defines identifiers based on SGML tokens:
1695 ID and NAME tokens must begin with a letter ([A-Za-z]) and
1696 may be followed by any number of letters, digits ([0-9]),
1697 hyphens ("-"), underscores ("_"), colons (":"), and periods
1700 - However the `CSS1 spec`_ defines identifiers based on the "name"
1701 token, a tighter interpretation ("flex" tokenizer notation
1702 below; "latin1" and "escape" 8-bit characters have been replaced
1705 unicode \\[0-9a-f]{1,4}
1706 latin1 [¡-ÿ]
1707 escape {unicode}|\\[ -~¡-ÿ]
1708 nmchar [-a-z0-9]|{latin1}|{escape}
1711 The CSS1 "nmchar" rule does not include underscores ("_"), colons
1712 (":"), or periods ("."), therefore "classes" and "id" attributes
1713 should not contain these characters. They should be replaced with
1714 hyphens ("-"). Combined with HTML's requirements (the first
1715 character must be a letter; no "unicode", "latin1", or "escape"
1716 characters), this results in the ``[a-z](-?[a-z0-9]+)*`` pattern.
1718 .. _HTML 4.01 spec: http://www.w3.org/TR/html401/
1719 .. _CSS1 spec: http://www.w3.org/TR/REC-CSS1
1724 Custom Interpreted Text Roles
1725 =============================
1727 :Directive Type: "role"
1728 :Doctree Element: None; affects subsequent parsing.
1729 :Directive Arguments: Two; one required (new role name), one optional
1730 (base role name, in parentheses).
1731 :Directive Options: Possible (depends on base role).
1732 :Directive Content: depends on base role.
1734 (New in Docutils 0.3.2)
1736 The "role" directive dynamically creates a custom interpreted text
1737 role and registers it with the parser. This means that after
1738 declaring a role like this::
1742 the document may use the new "custom" role::
1744 An example of using :custom:`interpreted text`
1746 This will be parsed into the following document tree fragment::
1750 <inline classes="custom">
1753 The role must be declared in a document before it can be used.
1755 The new role may be based on an existing role, specified as a second
1756 argument in parentheses (whitespace optional)::
1758 .. role:: custom(emphasis)
1762 The parsed result is as follows::
1765 <emphasis classes="custom">
1768 If no base role is explicitly specified, a generic custom role is
1769 automatically used. Subsequent interpreted text will produce an
1770 "inline" element with a "classes" attribute, as in the first example
1773 With most roles, the ":class:" option can be used to set a "classes"
1774 attribute that is different from the role name. For example::
1779 :custom:`interpreted text`
1781 This is the parsed result::
1784 <inline classes="special">
1789 The following options are recognized by the "role" directive for most
1793 Set a "class" attribute value on the element produced (``inline``,
1794 or element associated with a base class) when the custom
1795 interpreted text role is used. If no directive options are
1796 specified, a "class" option with the directive argument (role
1797 name) as the value is implied. See the class_ directive above.
1799 ``prefix`` : field list text
1800 Specifies raw text that will be prepended to the interpreted text
1801 depending upon the output format. A field name is the output
1802 format (writer) name and its field value is the raw text to
1803 be prepended for that format. A field name of ``default`` can be
1804 used to specify text to prepend if the output format matches no other
1807 ``suffix`` : field list text
1808 Specifies raw text that will be appended to the interpreted text
1809 depending upon the output format. A field name is the output
1810 format (writer) name and its field value is the raw text that will
1811 be appended for that format. A field name of ``default`` can be
1812 used to specify text to append if the output format matches no other
1815 For example, red text could be accomplished in html and latex by saying::
1819 :html: <font color="red">
1820 :latex: {\color{red}
1825 This text has a :red:`red` word in it.
1827 Specific roles may support other options and/or directive content.
1828 See the `reStructuredText Interpreted Text Roles`_ document for
1831 .. _reStructuredText Interpreted Text Roles: roles.html
1836 Setting the Default Interpreted Text Role
1837 =========================================
1839 :Directive Type: "default-role"
1840 :Doctree Element: None; affects subsequent parsing.
1841 :Directive Arguments: One, optional (new default role name).
1842 :Directive Options: None.
1843 :Directive Content: None.
1845 (New in Docutils 0.3.10)
1847 The "default-role" directive sets the default interpreted text role,
1848 the role that is used for interpreted text without an explicit role.
1849 For example, after setting the default role like this::
1851 .. default-role:: subscript
1853 any subsequent use of implicit-role interpreted text in the document
1854 will use the "subscript" role::
1856 An example of a `default` role.
1858 This will be parsed into the following document tree fragment::
1866 Custom roles may be used (see the "role_" directive above), but it
1867 must have been declared in a document before it can be set as the
1868 default role. See the `reStructuredText Interpreted Text Roles`_
1869 document for details of built-in roles.
1871 The directive may be used without an argument to restore the initial
1872 default interpreted text role, which is application-dependent. The
1873 initial default interpreted text role of the standard reStructuredText
1874 parser is "title-reference".
1879 Metadata Document Title
1880 =======================
1882 :Directive Type: "title"
1883 :Doctree Element: None.
1884 :Directive Arguments: 1, required (the title text).
1885 :Directive Options: None.
1886 :Directive Content: None.
1888 The "title" directive specifies the document title as metadata, which
1889 does not become part of the document body. It overrides a
1890 document-supplied title. For example, in HTML output the metadata
1891 document title appears in the title bar of the browser window.
1894 Restructuredtext-Test-Directive
1895 ===============================
1897 :Directive Type: "restructuredtext-test-directive"
1898 :Doctree Element: system_warning
1899 :Directive Arguments: None.
1900 :Directive Options: None.
1901 :Directive Content: Interpreted as a literal block.
1903 This directive is provided for test purposes only. (Nobody is
1904 expected to type in a name *that* long!) It is converted into a
1905 level-1 (info) system message showing the directive data, possibly
1906 followed by a literal block containing the rest of the directive
1913 indent-tabs-mode: nil
1914 sentence-end-double-space: t