| 1 |
============================= |
| 2 |
reStructuredText Directives |
| 3 |
============================= |
| 4 |
:Author: David Goodger |
| 5 |
:Contact: [email protected] |
| 6 |
:Revision: $Revision$ |
| 7 |
:Date: $Date$ |
| 8 |
:Copyright: This document has been placed in the public domain. |
| 9 |
|
| 10 |
.. contents:: |
| 11 |
:depth: 2 |
| 12 |
|
| 13 |
This document describes the directives implemented in the reference |
| 14 |
reStructuredText parser. |
| 15 |
|
| 16 |
Directives have the following syntax:: |
| 17 |
|
| 18 |
+-------+-------------------------------+ |
| 19 |
| ".. " | directive type "::" directive | |
| 20 |
+-------+ block | |
| 21 |
| | |
| 22 |
+-------------------------------+ |
| 23 |
|
| 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 |
| 31 |
details. |
| 32 |
|
| 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`_. |
| 39 |
|
| 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: |
| 45 |
../../howto/rst-directives.html |
| 46 |
|
| 47 |
|
| 48 |
------------- |
| 49 |
Admonitions |
| 50 |
------------- |
| 51 |
|
| 52 |
.. From Webster's Revised Unabridged Dictionary (1913) [web1913]: |
| 53 |
Admonition |
| 54 |
Gentle or friendly reproof; counseling against a fault or |
| 55 |
error; expression of authoritative advice; friendly caution |
| 56 |
or warning. |
| 57 |
|
| 58 |
Syn: {Admonition}, {Reprehension}, {Reproof}. |
| 59 |
|
| 60 |
Usage: Admonition is prospective, and relates to moral delinquencies; |
| 61 |
its object is to prevent further transgression. |
| 62 |
|
| 63 |
.. _attention: |
| 64 |
.. _caution: |
| 65 |
.. _danger: |
| 66 |
.. _error: |
| 67 |
.. _hint: |
| 68 |
.. _important: |
| 69 |
.. _note: |
| 70 |
.. _tip: |
| 71 |
.. _warning: |
| 72 |
|
| 73 |
Specific Admonitions |
| 74 |
==================== |
| 75 |
|
| 76 |
:Directive Types: "attention", "caution", "danger", "error", "hint", |
| 77 |
"important", "note", "tip", "warning", "admonition" |
| 78 |
:Doctree Elements: attention, caution, danger, error, hint, important, |
| 79 |
note, tip, warning, admonition_, title_ |
| 80 |
:Directive Arguments: None. |
| 81 |
:Directive Options: class_, name_ |
| 82 |
:Directive Content: Interpreted as body elements. |
| 83 |
|
| 84 |
Admonitions are specially marked "topics" that can appear anywhere an |
| 85 |
ordinary body element can. They contain arbitrary body elements. |
| 86 |
Typically, an admonition is rendered as an offset block in a document, |
| 87 |
sometimes outlined or shaded, with a title matching the admonition |
| 88 |
type. For example:: |
| 89 |
|
| 90 |
.. DANGER:: |
| 91 |
Beware killer rabbits! |
| 92 |
|
| 93 |
This directive might be rendered something like this:: |
| 94 |
|
| 95 |
+------------------------+ |
| 96 |
| !DANGER! | |
| 97 |
| | |
| 98 |
| Beware killer rabbits! | |
| 99 |
+------------------------+ |
| 100 |
|
| 101 |
The following admonition directives have been implemented: |
| 102 |
|
| 103 |
- attention |
| 104 |
- caution |
| 105 |
- danger |
| 106 |
- error |
| 107 |
- hint |
| 108 |
- important |
| 109 |
- note |
| 110 |
- tip |
| 111 |
- warning |
| 112 |
|
| 113 |
Any text immediately following the directive indicator (on the same |
| 114 |
line and/or indented on following lines) is interpreted as a directive |
| 115 |
block and is parsed for normal body elements. For example, the |
| 116 |
following "note" admonition directive contains one paragraph and a |
| 117 |
bullet list consisting of two list items:: |
| 118 |
|
| 119 |
.. note:: This is a note admonition. |
| 120 |
This is the second line of the first paragraph. |
| 121 |
|
| 122 |
- The note contains all indented body elements |
| 123 |
following. |
| 124 |
- It includes this bullet list. |
| 125 |
|
| 126 |
|
| 127 |
Generic Admonition |
| 128 |
================== |
| 129 |
|
| 130 |
:Directive Type: "admonition" |
| 131 |
:Doctree Elements: admonition_, title_ |
| 132 |
:Directive Arguments: One, required (admonition title) |
| 133 |
:Directive Options: class_, name_ |
| 134 |
:Directive Content: Interpreted as body elements. |
| 135 |
|
| 136 |
This is a generic, titled admonition. The title may be anything the |
| 137 |
author desires. |
| 138 |
|
| 139 |
The author-supplied title is also used as a `"classes"`_ attribute value |
| 140 |
after being converted into a valid identifier form (down-cased; |
| 141 |
non-alphanumeric characters converted to single hyphens; "admonition-" |
| 142 |
prefixed). For example, this admonition:: |
| 143 |
|
| 144 |
.. admonition:: And, by the way... |
| 145 |
|
| 146 |
You can make up your own admonition too. |
| 147 |
|
| 148 |
becomes the following document tree (pseudo-XML):: |
| 149 |
|
| 150 |
<document source="test data"> |
| 151 |
<admonition classes="admonition-and-by-the-way"> |
| 152 |
<title> |
| 153 |
And, by the way... |
| 154 |
<paragraph> |
| 155 |
You can make up your own admonition too. |
| 156 |
|
| 157 |
The class_ option overrides the computed `"classes"`_ attribute |
| 158 |
value. |
| 159 |
|
| 160 |
|
| 161 |
-------- |
| 162 |
Images |
| 163 |
-------- |
| 164 |
|
| 165 |
There are two image directives: "image" and "figure". |
| 166 |
|
| 167 |
.. attention:: |
| 168 |
|
| 169 |
It is up to the author to ensure compatibility of the image data format |
| 170 |
with the output format or user agent (LaTeX engine, `HTML browser`__). |
| 171 |
The following, non exhaustive table provides an overview: |
| 172 |
|
| 173 |
=========== ====== ====== ===== ===== ===== ===== ===== ===== ===== ===== |
| 174 |
.. vector image raster image moving image [#]_ |
| 175 |
----------- ------------- ----------------------------- ----------------- |
| 176 |
.. SVG PDF PNG JPG GIF APNG AVIF WebM MP4 OGG |
| 177 |
=========== ====== ====== ===== ===== ===== ===== ===== ===== ===== ===== |
| 178 |
HTML4_ ✓ [#]_ ✓ ✓ ✓ (✓) (✓) |
| 179 |
|
| 180 |
HTML5_ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ |
| 181 |
|
| 182 |
LaTeX_ [#]_ ✓ ✓ ✓ |
| 183 |
|
| 184 |
ODT_ ✓ ✓ ✓ ✓ ✓ |
| 185 |
=========== ====== ====== ===== ===== ===== ===== ===== ===== ===== ===== |
| 186 |
|
| 187 |
.. [#] The `html5 writer`_ uses the ``<video>`` tag if the image URI |
| 188 |
ends with an extension matching one of the listed video formats |
| 189 |
(since Docutils 0.17). |
| 190 |
|
| 191 |
.. [#] The html4 writer uses an ``<object>`` tag for SVG images |
| 192 |
for better compatibility with older browsers. |
| 193 |
|
| 194 |
.. [#] When compiling with ``pdflatex``, ``xelatex``, or ``lualatex``. |
| 195 |
The original ``latex`` engine supports only the EPS image format. |
| 196 |
Some build systems, e.g. rubber_ support additional formats |
| 197 |
via on-the-fly image conversion. |
| 198 |
|
| 199 |
__ https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types |
| 200 |
.. _HTML4: |
| 201 |
.. _html4 writer: ../../user/html.html#html4css1 |
| 202 |
.. _HTML5: |
| 203 |
.. _html5 writer: ../../user/html.html#html5-polyglot |
| 204 |
.. _LaTeX: ../../user/latex.html#image-inclusion |
| 205 |
.. _ODT: ../../user/odt.html |
| 206 |
.. _rubber: https://github.com/petrhosek/rubber |
| 207 |
|
| 208 |
|
| 209 |
Image |
| 210 |
===== |
| 211 |
|
| 212 |
:Directive Type: "image" |
| 213 |
:Doctree Element: image_ |
| 214 |
:Directive Arguments: One, required (image URI). |
| 215 |
:Directive Options: Possible (see below). |
| 216 |
:Directive Content: None. |
| 217 |
|
| 218 |
An "image" is a simple picture:: |
| 219 |
|
| 220 |
.. image:: picture.png |
| 221 |
|
| 222 |
Inline images can be defined with an "image" directive in a `substitution |
| 223 |
definition`_ |
| 224 |
|
| 225 |
The URI for the image source file is specified in the directive |
| 226 |
argument. As with hyperlink targets, the image URI may begin on the |
| 227 |
same line as the explicit markup start and target name, or it may |
| 228 |
begin in an indented text block immediately following, with no |
| 229 |
intervening blank lines. If there are multiple lines in the link |
| 230 |
block, they are stripped of leading and trailing whitespace and joined |
| 231 |
together. |
| 232 |
|
| 233 |
Optionally, the image link block may contain a flat field list, the |
| 234 |
_`image options`. For example:: |
| 235 |
|
| 236 |
.. image:: picture.jpeg |
| 237 |
:height: 100px |
| 238 |
:width: 200 px |
| 239 |
:scale: 50 % |
| 240 |
:alt: alternate text |
| 241 |
:align: right |
| 242 |
|
| 243 |
The following options are recognized: |
| 244 |
|
| 245 |
``alt`` : text |
| 246 |
Alternate text: a short description of the image, displayed by |
| 247 |
applications that cannot display images, or spoken by applications |
| 248 |
for visually impaired users. |
| 249 |
|
| 250 |
``height`` : `length`_ |
| 251 |
The desired height of the image. |
| 252 |
Used to reserve space or scale the image vertically. When the "scale" |
| 253 |
option is also specified, they are combined. For example, a height of |
| 254 |
200px and a scale of 50 is equivalent to a height of 100px with no scale. |
| 255 |
|
| 256 |
``width`` : `length`_ or `percentage`_ of the current line width |
| 257 |
The width of the image. |
| 258 |
Used to reserve space or scale the image horizontally. As with "height" |
| 259 |
above, when the "scale" option is also specified, they are combined. |
| 260 |
|
| 261 |
``scale`` : integer percentage (the "%" symbol is optional) |
| 262 |
The uniform scaling factor of the image. The default is "100 %", i.e. |
| 263 |
no scaling. |
| 264 |
|
| 265 |
If no "height" or "width" options are specified, the `Python |
| 266 |
Imaging Library` (PIL/Pillow_) may be used to determine them, if |
| 267 |
it is installed and the image file is available. |
| 268 |
|
| 269 |
``align`` : "top", "middle", "bottom", "left", "center", or "right" |
| 270 |
The alignment of the image, equivalent to the HTML ``<img>`` tag's |
| 271 |
deprecated "align" attribute or the corresponding "vertical-align" and |
| 272 |
"text-align" CSS properties. |
| 273 |
The values "top", "middle", and "bottom" |
| 274 |
control an image's vertical alignment (relative to the text |
| 275 |
baseline); they are only useful for inline images (substitutions). |
| 276 |
The values "left", "center", and "right" control an image's |
| 277 |
horizontal alignment, allowing the image to float and have the |
| 278 |
text flow around it. The specific behavior depends upon the |
| 279 |
browser or rendering software used. |
| 280 |
|
| 281 |
``target`` : text (URI or reference name) |
| 282 |
Makes the image into a hyperlink reference ("clickable"). The |
| 283 |
option argument may be a URI (relative or absolute), or a |
| 284 |
`reference name`_ with underscore suffix (e.g. ```a name`_``). |
| 285 |
|
| 286 |
and the common options class_ and name_. |
| 287 |
|
| 288 |
|
| 289 |
Figure |
| 290 |
====== |
| 291 |
|
| 292 |
:Directive Type: "figure" |
| 293 |
:Doctree Elements: figure_, image_, caption_, legend_ |
| 294 |
:Directive Arguments: One, required (image URI). |
| 295 |
:Directive Options: Possible (see below). |
| 296 |
:Directive Content: Interpreted as the figure caption and an optional |
| 297 |
legend. |
| 298 |
|
| 299 |
A "figure" consists of image_ data (including `image options`_), an optional |
| 300 |
caption (a single paragraph), and an optional legend (arbitrary body |
| 301 |
elements). For page-based output media, figures might float to a different |
| 302 |
position if this helps the page layout. |
| 303 |
:: |
| 304 |
|
| 305 |
.. figure:: picture.png |
| 306 |
:scale: 50 % |
| 307 |
:alt: map to buried treasure |
| 308 |
|
| 309 |
This is the caption of the figure (a simple paragraph). |
| 310 |
|
| 311 |
The legend consists of all elements after the caption. In this |
| 312 |
case, the legend consists of this paragraph and the following |
| 313 |
table: |
| 314 |
|
| 315 |
+-----------------------+-----------------------+ |
| 316 |
| Symbol | Meaning | |
| 317 |
+=======================+=======================+ |
| 318 |
| .. image:: tent.png | Campground | |
| 319 |
+-----------------------+-----------------------+ |
| 320 |
| .. image:: waves.png | Lake | |
| 321 |
+-----------------------+-----------------------+ |
| 322 |
| .. image:: peak.png | Mountain | |
| 323 |
+-----------------------+-----------------------+ |
| 324 |
|
| 325 |
There must be blank lines before the caption paragraph and before the |
| 326 |
legend. To specify a legend without a caption, use an empty comment |
| 327 |
("..") in place of the caption. |
| 328 |
|
| 329 |
The "figure" directive supports all of the options of the "image" |
| 330 |
directive (see `image options`_ above). These options (except |
| 331 |
"align") are passed on to the contained image. |
| 332 |
|
| 333 |
``align`` : "left", "center", or "right" |
| 334 |
The horizontal alignment of the figure, allowing the image to |
| 335 |
float and have the text flow around it. The specific behavior |
| 336 |
depends upon the browser or rendering software used. |
| 337 |
|
| 338 |
In addition, the following options are recognized: |
| 339 |
|
| 340 |
``figwidth`` : "image", length_, or percentage_ of current line width |
| 341 |
The width of the figure. |
| 342 |
Limits the horizontal space used by the figure. |
| 343 |
A special value of "image" is allowed, in which case the |
| 344 |
included image's actual width is used (requires the `Python Imaging |
| 345 |
Library`_). If the image file is not found or the required software is |
| 346 |
unavailable, this option is ignored. |
| 347 |
|
| 348 |
Sets the "width" attribute of the "figure" doctree element. |
| 349 |
|
| 350 |
This option does not scale the included image; use the "width" |
| 351 |
`image`_ option for that. :: |
| 352 |
|
| 353 |
+---------------------------+ |
| 354 |
| figure | |
| 355 |
| | |
| 356 |
|<------ figwidth --------->| |
| 357 |
| | |
| 358 |
| +---------------------+ | |
| 359 |
| | image | | |
| 360 |
| | | | |
| 361 |
| |<--- width --------->| | |
| 362 |
| +---------------------+ | |
| 363 |
| | |
| 364 |
|The figure's caption should| |
| 365 |
|wrap at this width. | |
| 366 |
+---------------------------+ |
| 367 |
|
| 368 |
``figclass`` : text |
| 369 |
Set a `"classes"`_ attribute value on the figure element. See the |
| 370 |
class_ directive below. |
| 371 |
|
| 372 |
.. _Python Imaging Library: |
| 373 |
.. _Pillow: https://pypi.org/project/Pillow/ |
| 374 |
|
| 375 |
|
| 376 |
--------------- |
| 377 |
Body Elements |
| 378 |
--------------- |
| 379 |
|
| 380 |
Topic |
| 381 |
===== |
| 382 |
|
| 383 |
:Directive Type: "topic" |
| 384 |
:Doctree Element: topic_ |
| 385 |
:Directive Arguments: One, required (topic title). |
| 386 |
:Directive Options: class_, name_ |
| 387 |
:Directive Content: Interpreted as the topic body. |
| 388 |
|
| 389 |
A topic is like a block quote with a title, or a self-contained |
| 390 |
section with no subsections. Use the "topic" directive to indicate a |
| 391 |
self-contained idea that is separate from the flow of the document. |
| 392 |
Topics may occur anywhere a section or transition may occur. Body |
| 393 |
elements and topics may not contain nested topics. |
| 394 |
|
| 395 |
The directive's sole argument is interpreted as the topic title; the |
| 396 |
next line must be blank. All subsequent lines make up the topic body, |
| 397 |
interpreted as body elements. For example:: |
| 398 |
|
| 399 |
.. topic:: Topic Title |
| 400 |
|
| 401 |
Subsequent indented lines comprise |
| 402 |
the body of the topic, and are |
| 403 |
interpreted as body elements. |
| 404 |
|
| 405 |
|
| 406 |
Sidebar |
| 407 |
======= |
| 408 |
|
| 409 |
:Directive Type: "sidebar" |
| 410 |
:Doctree Element: sidebar_ |
| 411 |
:Directive Arguments: One, optional (sidebar title). |
| 412 |
:Directive Options: Possible (see below). |
| 413 |
:Directive Content: Interpreted as the sidebar body. |
| 414 |
|
| 415 |
Sidebars are like miniature, parallel documents that occur inside |
| 416 |
other documents, providing related or reference material. A sidebar |
| 417 |
is typically offset by a border and "floats" to the side of the page; |
| 418 |
the document's main text may flow around it. Sidebars can also be |
| 419 |
likened to super-footnotes; their content is outside of the flow of |
| 420 |
the document's main text. |
| 421 |
|
| 422 |
Sidebars may occur anywhere a section or transition may occur. Body |
| 423 |
elements (including sidebars) may not contain nested sidebars. |
| 424 |
|
| 425 |
The directive's sole argument is interpreted as the sidebar title, |
| 426 |
which may be followed by a subtitle option (see below); the next line |
| 427 |
must be blank. All subsequent lines make up the sidebar body, |
| 428 |
interpreted as body elements. For example:: |
| 429 |
|
| 430 |
.. sidebar:: Optional Sidebar Title |
| 431 |
:subtitle: Optional Sidebar Subtitle |
| 432 |
|
| 433 |
Subsequent indented lines comprise |
| 434 |
the body of the sidebar, and are |
| 435 |
interpreted as body elements. |
| 436 |
|
| 437 |
The following options are recognized: |
| 438 |
|
| 439 |
``subtitle`` : text |
| 440 |
The sidebar's subtitle. |
| 441 |
|
| 442 |
and the common options class_ and name_. |
| 443 |
|
| 444 |
|
| 445 |
Line Block |
| 446 |
========== |
| 447 |
|
| 448 |
.. admonition:: Deprecated |
| 449 |
|
| 450 |
The "line-block" directive is deprecated. Use the `line block |
| 451 |
syntax`_ instead. |
| 452 |
|
| 453 |
.. _line block syntax: restructuredtext.html#line-blocks |
| 454 |
|
| 455 |
:Directive Type: "line-block" |
| 456 |
:Doctree Element: line_block_ |
| 457 |
:Directive Arguments: None. |
| 458 |
:Directive Options: class_, name_ |
| 459 |
:Directive Content: Becomes the body of the line block. |
| 460 |
|
| 461 |
The "line-block" directive constructs an element where line breaks and |
| 462 |
initial indentation is significant and inline markup is supported. It |
| 463 |
is equivalent to a `parsed literal block`_ with different rendering: |
| 464 |
typically in an ordinary serif typeface instead of a |
| 465 |
typewriter/monospaced face, and not automatically indented. (Have the |
| 466 |
line-block directive begin a block quote to get an indented line |
| 467 |
block.) Line blocks are useful for address blocks and verse (poetry, |
| 468 |
song lyrics), where the structure of lines is significant. For |
| 469 |
example, here's a classic:: |
| 470 |
|
| 471 |
"To Ma Own Beloved Lassie: A Poem on her 17th Birthday", by |
| 472 |
Ewan McTeagle (for Lassie O'Shea): |
| 473 |
|
| 474 |
.. line-block:: |
| 475 |
|
| 476 |
Lend us a couple of bob till Thursday. |
| 477 |
I'm absolutely skint. |
| 478 |
But I'm expecting a postal order and I can pay you back |
| 479 |
as soon as it comes. |
| 480 |
Love, Ewan. |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
.. _parsed-literal: |
| 485 |
|
| 486 |
Parsed Literal Block |
| 487 |
==================== |
| 488 |
|
| 489 |
:Directive Type: "parsed-literal" |
| 490 |
:Doctree Element: literal_block_ |
| 491 |
:Directive Arguments: None. |
| 492 |
:Directive Options: class_, name_ |
| 493 |
:Directive Content: Becomes the body of the literal block. |
| 494 |
|
| 495 |
Unlike an ordinary literal block, the "parsed-literal" directive |
| 496 |
constructs a literal block where the text is parsed for inline markup. |
| 497 |
It is equivalent to a `line block`_ with different rendering: |
| 498 |
typically in a typewriter/monospaced typeface, like an ordinary |
| 499 |
literal block. Parsed literal blocks are useful for adding hyperlinks |
| 500 |
to code examples. |
| 501 |
|
| 502 |
However, care must be taken with the text, because inline markup is |
| 503 |
recognized and there is no protection from parsing. Backslash-escapes |
| 504 |
may be necessary to prevent unintended parsing. And because the |
| 505 |
markup characters are removed by the parser, care must also be taken |
| 506 |
with vertical alignment. Parsed "ASCII art" is tricky, and extra |
| 507 |
whitespace may be necessary. |
| 508 |
|
| 509 |
For example, all the element names in this content model are links:: |
| 510 |
|
| 511 |
.. parsed-literal:: |
| 512 |
|
| 513 |
( (title_, subtitle_?)?, |
| 514 |
decoration_?, |
| 515 |
(docinfo_, transition_?)?, |
| 516 |
`%structure.model;`_ ) |
| 517 |
|
| 518 |
Code |
| 519 |
==== |
| 520 |
|
| 521 |
:Directive Type: "code" |
| 522 |
:Doctree Element: literal_block_, `inline elements`_ |
| 523 |
:Directive Arguments: One, optional (formal language). |
| 524 |
:Directive Options: name, class, number-lines. |
| 525 |
:Directive Content: Becomes the body of the literal block. |
| 526 |
:Configuration Setting: syntax_highlight_. |
| 527 |
|
| 528 |
The "code" directive constructs a literal block. If the code language is |
| 529 |
specified, the content is parsed by the Pygments_ syntax highlighter and |
| 530 |
tokens are stored in nested `inline elements`_ with class arguments |
| 531 |
according to their syntactic category. The actual highlighting requires |
| 532 |
a style-sheet (e.g. one `generated by Pygments`__, see the |
| 533 |
`sandbox/stylesheets`__ for examples). |
| 534 |
|
| 535 |
The parsing can be turned off with the syntax_highlight_ configuration |
| 536 |
setting and command line option or by specifying the language as class_ |
| 537 |
option instead of directive argument. This also avoids warnings |
| 538 |
when Pygments_ is not installed or the language is not in the |
| 539 |
`supported languages and markup formats`_. |
| 540 |
|
| 541 |
For inline code, use the `"code" role`_. |
| 542 |
|
| 543 |
__ https://pygments.org/docs/cmdline/#generating-styles |
| 544 |
__ https://docutils.sourceforge.io/sandbox/stylesheets/ |
| 545 |
.. _Pygments: https://pygments.org/ |
| 546 |
.. _syntax_highlight: ../../user/config.html#syntax-highlight |
| 547 |
.. _supported languages and markup formats: https://pygments.org/languages/ |
| 548 |
.. _"code" role: roles.html#code |
| 549 |
|
| 550 |
|
| 551 |
The following options are recognized: |
| 552 |
|
| 553 |
``number-lines`` : [integer] (start line number) |
| 554 |
Precede every line with a line number. |
| 555 |
The optional argument is the number of the first line (default 1). |
| 556 |
|
| 557 |
and the common options class_ and name_. |
| 558 |
|
| 559 |
Example:: |
| 560 |
The content of the following directive :: |
| 561 |
|
| 562 |
.. code:: python |
| 563 |
|
| 564 |
def my_function(): |
| 565 |
"just a test" |
| 566 |
print 8/2 |
| 567 |
|
| 568 |
is parsed and marked up as Python source code. |
| 569 |
|
| 570 |
|
| 571 |
Math |
| 572 |
==== |
| 573 |
|
| 574 |
:Directive Type: "math" |
| 575 |
:Doctree Element: math_block_ |
| 576 |
:Directive Arguments: None. |
| 577 |
:Directive Options: class_, name_ |
| 578 |
:Directive Content: Becomes the body of the math block. |
| 579 |
(Content blocks separated by a blank line are put in |
| 580 |
adjacent math blocks.) |
| 581 |
:Configuration Setting: math_output_ |
| 582 |
|
| 583 |
The "math" directive inserts blocks with mathematical content |
| 584 |
(display formulas, equations) into the document. The input format is |
| 585 |
`LaTeX math syntax`_ with support for Unicode symbols, for example:: |
| 586 |
|
| 587 |
.. math:: |
| 588 |
|
| 589 |
α_t(i) = P(O_1, O_2, … O_t, q_t = S_i λ) |
| 590 |
|
| 591 |
Support is limited to a subset of *LaTeX math* by the conversion |
| 592 |
required for many output formats. For HTML, the `math_output`_ |
| 593 |
configuration setting (or the corresponding ``--math-output`` |
| 594 |
command line option) select between alternative output formats with |
| 595 |
different subsets of supported elements. If a writer does not |
| 596 |
support math typesetting, the content is inserted verbatim. |
| 597 |
|
| 598 |
For inline formulas, use the `"math" role`_. |
| 599 |
|
| 600 |
.. _LaTeX math syntax: ../../ref/rst/mathematics.html |
| 601 |
.. _"math" role: roles.html#math |
| 602 |
.. _math_output: ../../user/config.html#math-output |
| 603 |
|
| 604 |
|
| 605 |
Rubric |
| 606 |
====== |
| 607 |
|
| 608 |
:Directive Type: "rubric" |
| 609 |
:Doctree Element: rubric_ |
| 610 |
:Directive Arguments: One, required (rubric text). |
| 611 |
:Directive Options: class_, name_ |
| 612 |
:Directive Content: None. |
| 613 |
|
| 614 |
.. |
| 615 |
|
| 616 |
rubric n. 1. a title, heading, or the like, in a manuscript, |
| 617 |
book, statute, etc., written or printed in red or otherwise |
| 618 |
distinguished from the rest of the text. ... |
| 619 |
|
| 620 |
-- Random House Webster's College Dictionary, 1991 |
| 621 |
|
| 622 |
The "rubric" directive inserts a "rubric" element into the document |
| 623 |
tree. A rubric is like an informal heading that doesn't correspond to |
| 624 |
the document's structure. |
| 625 |
|
| 626 |
|
| 627 |
Epigraph |
| 628 |
======== |
| 629 |
|
| 630 |
:Directive Type: "epigraph" |
| 631 |
:Doctree Element: block_quote_ |
| 632 |
:Directive Arguments: None. |
| 633 |
:Directive Options: None. |
| 634 |
:Directive Content: Interpreted as the body of the block quote. |
| 635 |
|
| 636 |
An epigraph is an apposite (suitable, apt, or pertinent) short |
| 637 |
inscription, often a quotation or poem, at the beginning of a document |
| 638 |
or section. |
| 639 |
|
| 640 |
The "epigraph" directive produces an "epigraph"-class block quote. |
| 641 |
For example, this input:: |
| 642 |
|
| 643 |
.. epigraph:: |
| 644 |
|
| 645 |
No matter where you go, there you are. |
| 646 |
|
| 647 |
-- Buckaroo Banzai |
| 648 |
|
| 649 |
becomes this document tree fragment:: |
| 650 |
|
| 651 |
<block_quote classes="epigraph"> |
| 652 |
<paragraph> |
| 653 |
No matter where you go, there you are. |
| 654 |
<attribution> |
| 655 |
Buckaroo Banzai |
| 656 |
|
| 657 |
|
| 658 |
Highlights |
| 659 |
========== |
| 660 |
|
| 661 |
:Directive Type: "highlights" |
| 662 |
:Doctree Element: block_quote_ |
| 663 |
:Directive Arguments: None. |
| 664 |
:Directive Options: None. |
| 665 |
:Directive Content: Interpreted as the body of the block quote. |
| 666 |
|
| 667 |
Highlights summarize the main points of a document or section, often |
| 668 |
consisting of a list. |
| 669 |
|
| 670 |
The "highlights" directive produces a "highlights"-class block quote. |
| 671 |
See Epigraph_ above for an analogous example. |
| 672 |
|
| 673 |
|
| 674 |
Pull-Quote |
| 675 |
========== |
| 676 |
|
| 677 |
:Directive Type: "pull-quote" |
| 678 |
:Doctree Element: block_quote_ |
| 679 |
:Directive Arguments: None. |
| 680 |
:Directive Options: None. |
| 681 |
:Directive Content: Interpreted as the body of the block quote. |
| 682 |
|
| 683 |
A pull-quote is a small selection of text "pulled out and quoted", |
| 684 |
typically in a larger typeface. Pull-quotes are used to attract |
| 685 |
attention, especially in long articles. |
| 686 |
|
| 687 |
The "pull-quote" directive produces a "pull-quote"-class block quote. |
| 688 |
See Epigraph_ above for an analogous example. |
| 689 |
|
| 690 |
|
| 691 |
Compound Paragraph |
| 692 |
================== |
| 693 |
|
| 694 |
:Directive Type: "compound" |
| 695 |
:Doctree Element: compound_ |
| 696 |
:Directive Arguments: None. |
| 697 |
:Directive Options: class_, name_ |
| 698 |
:Directive Content: Interpreted as body elements. |
| 699 |
|
| 700 |
The "compound" directive is used to create a compound paragraph, which |
| 701 |
is a single logical paragraph containing multiple physical body |
| 702 |
elements such as simple paragraphs, literal blocks, tables, lists, |
| 703 |
etc., instead of directly containing text and inline elements. For |
| 704 |
example:: |
| 705 |
|
| 706 |
.. compound:: |
| 707 |
|
| 708 |
The 'rm' command is very dangerous. If you are logged |
| 709 |
in as root and enter :: |
| 710 |
|
| 711 |
cd / |
| 712 |
rm -rf * |
| 713 |
|
| 714 |
you will erase the entire contents of your file system. |
| 715 |
|
| 716 |
In the example above, a literal block is "embedded" within a sentence |
| 717 |
that begins in one physical paragraph and ends in another. |
| 718 |
|
| 719 |
.. note:: |
| 720 |
|
| 721 |
The "compound" directive is *not* a generic block-level container |
| 722 |
like HTML's ``<div>`` element. Do not use it only to group a |
| 723 |
sequence of elements, or you may get unexpected results. |
| 724 |
|
| 725 |
If you need a generic block-level container, please use the |
| 726 |
container_ directive, described below. |
| 727 |
|
| 728 |
Compound paragraphs are typically rendered as multiple distinct text |
| 729 |
blocks, with the possibility of variations to emphasize their logical |
| 730 |
unity: |
| 731 |
|
| 732 |
* If paragraphs are rendered with a first-line indent, only the first |
| 733 |
physical paragraph of a compound paragraph should have that indent |
| 734 |
-- second and further physical paragraphs should omit the indents; |
| 735 |
* vertical spacing between physical elements may be reduced; |
| 736 |
* and so on. |
| 737 |
|
| 738 |
|
| 739 |
Container |
| 740 |
========= |
| 741 |
|
| 742 |
:Directive Type: "container" |
| 743 |
:Doctree Element: `container <container element_>`__ |
| 744 |
:Directive Arguments: One or more, optional (class names). |
| 745 |
:Directive Options: name_ |
| 746 |
:Directive Content: Interpreted as body elements. |
| 747 |
|
| 748 |
The "container" directive surrounds its contents (arbitrary body |
| 749 |
elements) with a generic block-level "container" element. Combined |
| 750 |
with the optional "classes_" attribute argument(s), this is an |
| 751 |
extension mechanism for users & applications. For example:: |
| 752 |
|
| 753 |
.. container:: custom |
| 754 |
|
| 755 |
This paragraph might be rendered in a custom way. |
| 756 |
|
| 757 |
Parsing the above results in the following pseudo-XML:: |
| 758 |
|
| 759 |
<container classes="custom"> |
| 760 |
<paragraph> |
| 761 |
This paragraph might be rendered in a custom way. |
| 762 |
|
| 763 |
The "container" directive is the equivalent of HTML's ``<div>`` |
| 764 |
element. It may be used to group a sequence of elements for user- or |
| 765 |
application-specific purposes. |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
-------- |
| 770 |
Tables |
| 771 |
-------- |
| 772 |
|
| 773 |
Formal tables need more structure than the reStructuredText syntax |
| 774 |
supplies. Tables may be given titles with the table_ directive. |
| 775 |
Sometimes reStructuredText tables are inconvenient to write, or table |
| 776 |
data in a standard format is readily available. The csv-table_ |
| 777 |
directive supports CSV data. |
| 778 |
|
| 779 |
|
| 780 |
Table |
| 781 |
===== |
| 782 |
|
| 783 |
:Directive Type: "table" |
| 784 |
:Doctree Element: table_ |
| 785 |
:Directive Arguments: One, optional (table title). |
| 786 |
:Directive Options: Possible (see below). |
| 787 |
:Directive Content: A normal `reStructuredText table`_. |
| 788 |
|
| 789 |
The "table" directive is used to associate a |
| 790 |
title with a table or specify options, e.g.:: |
| 791 |
|
| 792 |
.. table:: Truth table for "not" |
| 793 |
:widths: auto |
| 794 |
|
| 795 |
===== ===== |
| 796 |
A not A |
| 797 |
===== ===== |
| 798 |
False True |
| 799 |
True False |
| 800 |
===== ===== |
| 801 |
|
| 802 |
The following options are recognized: |
| 803 |
|
| 804 |
``align`` : "left", "center", or "right" |
| 805 |
The horizontal alignment of the table (new in Docutils 0.13). |
| 806 |
|
| 807 |
``width`` : `length`_ or `percentage`_ |
| 808 |
Sets the width of the table to the specified length or percentage |
| 809 |
of the line width. If omitted, the renderer determines the width |
| 810 |
of the table based on its contents or the column ``widths``. |
| 811 |
|
| 812 |
.. _column-widths: |
| 813 |
|
| 814 |
``widths`` : "auto", "grid", or a list of integers |
| 815 |
Explicitly set column widths. |
| 816 |
Specifies relative widths if used with the ``width`` option. |
| 817 |
Overrides a `table_style`_ setting or class value "colwidths-auto". |
| 818 |
The default depends on the `table_style`_ configuration setting. |
| 819 |
|
| 820 |
*"auto"* delegates the determination of column widths to the backend |
| 821 |
(LaTeX, the HTML browser, ...). |
| 822 |
Default for the `html5 writer`_ |
| 823 |
|
| 824 |
*"grid"* determines column widths from the widths of the input columns |
| 825 |
(in characters). |
| 826 |
Default for most writers. |
| 827 |
|
| 828 |
A *list of integers* is used instead of the input column widths. |
| 829 |
Implies *"grid"*. |
| 830 |
|
| 831 |
Plus the common options class_ and name_. |
| 832 |
|
| 833 |
.. _reStructuredText table: restructuredtext.html#tables |
| 834 |
.. _table_style: ../../user/config.html#table-style |
| 835 |
|
| 836 |
.. _csv-table: |
| 837 |
|
| 838 |
CSV Table |
| 839 |
========= |
| 840 |
|
| 841 |
:Directive Type: "csv-table" |
| 842 |
:Doctree Element: table_ |
| 843 |
:Directive Arguments: One, optional (table title). |
| 844 |
:Directive Options: Possible (see below). |
| 845 |
:Directive Content: A CSV (comma-separated values) table. |
| 846 |
|
| 847 |
.. WARNING:: |
| 848 |
|
| 849 |
The "csv-table" directive's ":file:" and ":url:" options represent |
| 850 |
a potential security holes. They can be disabled with the |
| 851 |
"file_insertion_enabled_" runtime setting. |
| 852 |
|
| 853 |
The "csv-table" directive is used to create a table from CSV |
| 854 |
(comma-separated values) data. CSV is a common data format generated |
| 855 |
by spreadsheet applications and commercial databases. The data may be |
| 856 |
internal (an integral part of the document) or external (a separate |
| 857 |
file). |
| 858 |
|
| 859 |
* Block markup and inline markup within cells is supported. Line ends |
| 860 |
are recognized within cells. |
| 861 |
|
| 862 |
* There is no support for checking that the number of columns in each |
| 863 |
row is the same. The directive automatically adds empty entries at |
| 864 |
the end of short rows. |
| 865 |
|
| 866 |
.. Add "strict" option to verify input? |
| 867 |
|
| 868 |
Example:: |
| 869 |
|
| 870 |
.. csv-table:: Frozen Delights! |
| 871 |
:header: "Treat", "Quantity", "Description" |
| 872 |
:widths: 15, 10, 30 |
| 873 |
|
| 874 |
"Albatross", 2.99, "On a stick!" |
| 875 |
"Crunchy Frog", 1.49, "If we took the bones out, it wouldn't be |
| 876 |
crunchy, now would it?" |
| 877 |
"Gannet Ripple", 1.99, "On a stick!" |
| 878 |
|
| 879 |
The following options are recognized: |
| 880 |
|
| 881 |
``align`` : "left", "center", or "right" |
| 882 |
The horizontal alignment of the table. (New in Docutils 0.13) |
| 883 |
|
| 884 |
``delim`` : char | "tab" | "space" [#whitespace-delim]_ |
| 885 |
A one-character string\ [#ASCII-char]_ used to separate fields. |
| 886 |
Defaults to ``,`` (comma). May be specified as a Unicode code |
| 887 |
point; see the unicode_ directive for syntax details. |
| 888 |
|
| 889 |
``encoding`` : string |
| 890 |
The text encoding of the external CSV data (file or URL). |
| 891 |
Defaults to the document's input_encoding_. |
| 892 |
|
| 893 |
``escape`` : char |
| 894 |
A one-character\ [#ASCII-char]_ string used to escape the |
| 895 |
delimiter or quote characters. May be specified as a Unicode |
| 896 |
code point; see the unicode_ directive for syntax details. Used |
| 897 |
when the delimiter is used in an unquoted field, or when quote |
| 898 |
characters are used within a field. The default is to double-up |
| 899 |
the character, e.g. "He said, ""Hi!""" |
| 900 |
|
| 901 |
.. Add another possible value, "double", to explicitly indicate |
| 902 |
the default case? |
| 903 |
|
| 904 |
``file`` : string (newlines removed) |
| 905 |
The local filesystem path to a CSV data file. |
| 906 |
|
| 907 |
``header`` : CSV data |
| 908 |
Supplemental data for the table header, added independently of and |
| 909 |
before any ``header-rows`` from the main CSV data. Must use the |
| 910 |
same CSV format as the main CSV data. |
| 911 |
|
| 912 |
``header-rows`` : integer |
| 913 |
The number of rows of CSV data to use in the table header. |
| 914 |
Defaults to 0. |
| 915 |
|
| 916 |
``keepspace`` : flag (empty) |
| 917 |
Treat whitespace immediately following the delimiter as |
| 918 |
significant. The default is to ignore such whitespace. |
| 919 |
|
| 920 |
``quote`` : char |
| 921 |
A one-character string\ [#ASCII-char]_ used to quote elements |
| 922 |
containing the delimiter or which start with the quote |
| 923 |
character. Defaults to ``"`` (quote). May be specified as a |
| 924 |
Unicode code point; see the unicode_ directive for syntax |
| 925 |
details. |
| 926 |
|
| 927 |
``stub-columns`` : integer |
| 928 |
The number of table columns to use as stubs (row titles, on the |
| 929 |
left). Defaults to 0. |
| 930 |
|
| 931 |
``url`` : string (whitespace removed) |
| 932 |
An Internet URL reference to a CSV data file. |
| 933 |
|
| 934 |
``widths`` : integer [integer...] or "auto" |
| 935 |
A list of relative column widths. |
| 936 |
The default is equal-width columns (100%/#columns). |
| 937 |
|
| 938 |
"auto" delegates the determination of column widths to the backend |
| 939 |
(LaTeX, the HTML browser, ...). |
| 940 |
|
| 941 |
``width`` : `length`_ or `percentage`_ |
| 942 |
Sets the width of the table to the specified length or percentage |
| 943 |
of the line width. If omitted, the renderer determines the width |
| 944 |
of the table based on its contents or the column ``widths``. |
| 945 |
|
| 946 |
and the common options class_ and name_. |
| 947 |
|
| 948 |
.. [#whitespace-delim] Whitespace delimiters are supported only for external |
| 949 |
CSV files. |
| 950 |
|
| 951 |
.. [#ASCII-char] With Python 2, the values for the ``delimiter``, |
| 952 |
``quote``, and ``escape`` options must be ASCII characters. (The csv |
| 953 |
module does not support Unicode and all non-ASCII characters are |
| 954 |
encoded as multi-byte utf-8 string). This limitation does not exist |
| 955 |
under Python 3. |
| 956 |
|
| 957 |
|
| 958 |
List Table |
| 959 |
========== |
| 960 |
|
| 961 |
:Directive Type: "list-table" |
| 962 |
:Doctree Element: table_ |
| 963 |
:Directive Arguments: One, optional (table title). |
| 964 |
:Directive Options: Possible (see below). |
| 965 |
:Directive Content: A uniform two-level bullet list. |
| 966 |
|
| 967 |
(This is an initial implementation; `further ideas`__ may be implemented |
| 968 |
in the future.) |
| 969 |
|
| 970 |
__ ../../dev/rst/alternatives.html#list-driven-tables |
| 971 |
|
| 972 |
The "list-table" directive is used to create a table from data in a |
| 973 |
uniform two-level bullet list. "Uniform" means that each sublist |
| 974 |
(second-level list) must contain the same number of list items. |
| 975 |
|
| 976 |
Example:: |
| 977 |
|
| 978 |
.. list-table:: Frozen Delights! |
| 979 |
:widths: 15 10 30 |
| 980 |
:header-rows: 1 |
| 981 |
|
| 982 |
* - Treat |
| 983 |
- Quantity |
| 984 |
- Description |
| 985 |
* - Albatross |
| 986 |
- 2.99 |
| 987 |
- On a stick! |
| 988 |
* - Crunchy Frog |
| 989 |
- 1.49 |
| 990 |
- If we took the bones out, it wouldn't be |
| 991 |
crunchy, now would it? |
| 992 |
* - Gannet Ripple |
| 993 |
- 1.99 |
| 994 |
- On a stick! |
| 995 |
|
| 996 |
The following options are recognized: |
| 997 |
|
| 998 |
|
| 999 |
``align`` : "left", "center", or "right" |
| 1000 |
The horizontal alignment of the table. |
| 1001 |
(New in Docutils 0.13) |
| 1002 |
|
| 1003 |
``header-rows`` : integer |
| 1004 |
The number of rows of list data to use in the table header. |
| 1005 |
Defaults to 0. |
| 1006 |
|
| 1007 |
``stub-columns`` : integer |
| 1008 |
The number of table columns to use as stubs (row titles, on the |
| 1009 |
left). Defaults to 0. |
| 1010 |
|
| 1011 |
.. _table width: |
| 1012 |
|
| 1013 |
``width`` : `length`_ or `percentage`_ |
| 1014 |
Sets the width of the table to the specified length or percentage |
| 1015 |
of the line width. If omitted, the renderer determines the width |
| 1016 |
of the table based on its contents or the column ``widths``. |
| 1017 |
|
| 1018 |
.. _column widths: |
| 1019 |
|
| 1020 |
``widths`` : integer [integer...] or "auto" |
| 1021 |
A list of relative column widths. |
| 1022 |
The default is equal-width columns (100%/#columns). |
| 1023 |
|
| 1024 |
"auto" delegates the determination of column widths to the backend |
| 1025 |
(LaTeX, the HTML browser, ...). |
| 1026 |
|
| 1027 |
and the common options class_ and name_. |
| 1028 |
|
| 1029 |
|
| 1030 |
---------------- |
| 1031 |
Document Parts |
| 1032 |
---------------- |
| 1033 |
|
| 1034 |
.. _contents: |
| 1035 |
|
| 1036 |
Table of Contents |
| 1037 |
================= |
| 1038 |
|
| 1039 |
:Directive Type: "contents" |
| 1040 |
:Doctree Elements: pending_, topic_ |
| 1041 |
:Directive Arguments: One, optional: title. |
| 1042 |
:Directive Options: Possible (see below). |
| 1043 |
:Directive Content: None. |
| 1044 |
|
| 1045 |
The "contents" directive generates a table of contents (TOC) in a |
| 1046 |
topic_. Topics, and therefore tables of contents, may occur anywhere |
| 1047 |
a section or transition may occur. Body elements and topics may not |
| 1048 |
contain tables of contents. |
| 1049 |
|
| 1050 |
Here's the directive in its simplest form:: |
| 1051 |
|
| 1052 |
.. contents:: |
| 1053 |
|
| 1054 |
Language-dependent boilerplate text will be used for the title. The |
| 1055 |
English default title text is "Contents". |
| 1056 |
|
| 1057 |
An explicit title may be specified:: |
| 1058 |
|
| 1059 |
.. contents:: Table of Contents |
| 1060 |
|
| 1061 |
The title may span lines, although it is not recommended:: |
| 1062 |
|
| 1063 |
.. contents:: Here's a very long Table of |
| 1064 |
Contents title |
| 1065 |
|
| 1066 |
Options may be specified for the directive, using a field list:: |
| 1067 |
|
| 1068 |
.. contents:: Table of Contents |
| 1069 |
:depth: 2 |
| 1070 |
|
| 1071 |
If the default title is to be used, the options field list may begin |
| 1072 |
on the same line as the directive marker:: |
| 1073 |
|
| 1074 |
.. contents:: :depth: 2 |
| 1075 |
|
| 1076 |
The following options are recognized: |
| 1077 |
|
| 1078 |
``depth`` : integer |
| 1079 |
The number of section levels that are collected in the table of |
| 1080 |
contents. The default is unlimited depth. |
| 1081 |
|
| 1082 |
``local`` : flag (empty) |
| 1083 |
Generate a local table of contents. Entries will only include |
| 1084 |
subsections of the section in which the directive is given. If no |
| 1085 |
explicit title is given, the table of contents will not be titled. |
| 1086 |
|
| 1087 |
``backlinks`` : "entry" or "top" or "none" |
| 1088 |
Generate links from section headers back to the table of contents |
| 1089 |
entries, the table of contents itself, or generate no back-links. |
| 1090 |
|
| 1091 |
``class`` : text |
| 1092 |
Set a `"classes"`_ attribute value on the topic element. See the |
| 1093 |
class_ directive below. |
| 1094 |
|
| 1095 |
|
| 1096 |
.. _sectnum: |
| 1097 |
.. _section-numbering: |
| 1098 |
|
| 1099 |
Automatic Section Numbering |
| 1100 |
=========================== |
| 1101 |
|
| 1102 |
:Directive Type: "sectnum" or "section-numbering" (synonyms) |
| 1103 |
:Doctree Elements: pending_, generated_ |
| 1104 |
:Directive Arguments: None. |
| 1105 |
:Directive Options: Possible (see below). |
| 1106 |
:Directive Content: None. |
| 1107 |
:Configuration Setting: sectnum_xform_ |
| 1108 |
|
| 1109 |
The "sectnum" (or "section-numbering") directive automatically numbers |
| 1110 |
sections and subsections in a document (if not disabled by the |
| 1111 |
``--no-section-numbering`` command line option or the `sectnum_xform`_ |
| 1112 |
configuration setting). |
| 1113 |
|
| 1114 |
Section numbers are of the "multiple enumeration" form, where each |
| 1115 |
level has a number, separated by periods. For example, the title of section |
| 1116 |
1, subsection 2, subsubsection 3 would have "1.2.3" prefixed. |
| 1117 |
|
| 1118 |
The "sectnum" directive does its work in two passes: the initial parse |
| 1119 |
and a transform. During the initial parse, a "pending" element is |
| 1120 |
generated which acts as a placeholder, storing any options internally. |
| 1121 |
At a later stage in the processing, the "pending" element triggers a |
| 1122 |
transform, which adds section numbers to titles. Section numbers are |
| 1123 |
enclosed in a "generated" element, and titles have their "auto" |
| 1124 |
attribute set to "1". |
| 1125 |
|
| 1126 |
The following options are recognized: |
| 1127 |
|
| 1128 |
``depth`` : integer |
| 1129 |
The number of section levels that are numbered by this directive. |
| 1130 |
The default is unlimited depth. |
| 1131 |
|
| 1132 |
``prefix`` : string |
| 1133 |
An arbitrary string that is prefixed to the automatically |
| 1134 |
generated section numbers. It may be something like "3.2.", which |
| 1135 |
will produce "3.2.1", "3.2.2", "3.2.2.1", and so on. Note that |
| 1136 |
any separating punctuation (in the example, a period, ".") must be |
| 1137 |
explicitly provided. The default is no prefix. |
| 1138 |
|
| 1139 |
``suffix`` : string |
| 1140 |
An arbitrary string that is appended to the automatically |
| 1141 |
generated section numbers. The default is no suffix. |
| 1142 |
|
| 1143 |
``start`` : integer |
| 1144 |
The value that will be used for the first section number. |
| 1145 |
Combined with ``prefix``, this may be used to force the right |
| 1146 |
numbering for a document split over several source files. The |
| 1147 |
default is 1. |
| 1148 |
|
| 1149 |
.. _sectnum_xform: ../../user/config.html#sectnum-xform |
| 1150 |
|
| 1151 |
|
| 1152 |
.. _header: |
| 1153 |
.. _footer: |
| 1154 |
|
| 1155 |
Document Header & Footer |
| 1156 |
======================== |
| 1157 |
|
| 1158 |
:Directive Types: "header" and "footer" |
| 1159 |
:Doctree Elements: decoration_, header, footer |
| 1160 |
:Directive Arguments: None. |
| 1161 |
:Directive Options: None. |
| 1162 |
:Directive Content: Interpreted as body elements. |
| 1163 |
|
| 1164 |
The "header" and "footer" directives create document decorations, |
| 1165 |
useful for page navigation, notes, time/datestamp, etc. For example:: |
| 1166 |
|
| 1167 |
.. header:: This space for rent. |
| 1168 |
|
| 1169 |
This will add a paragraph to the document header, which will appear at |
| 1170 |
the top of the generated web page or at the top of every printed page. |
| 1171 |
|
| 1172 |
These directives may be used multiple times, cumulatively. There is |
| 1173 |
currently support for only one header and footer. |
| 1174 |
|
| 1175 |
.. note:: |
| 1176 |
|
| 1177 |
While it is possible to use the "header" and "footer" directives to |
| 1178 |
create navigational elements for web pages, you should be aware |
| 1179 |
that Docutils is meant to be used for *document* processing, and |
| 1180 |
that a navigation bar is not typically part of a document. |
| 1181 |
|
| 1182 |
Thus, you may soon find Docutils' abilities to be insufficient for |
| 1183 |
these purposes. At that time, you should consider using a |
| 1184 |
documentation generator like Sphinx_ rather than the "header" and |
| 1185 |
"footer" directives. |
| 1186 |
|
| 1187 |
.. _Sphinx: http://sphinx-doc.org/ |
| 1188 |
|
| 1189 |
In addition to the use of these directives to populate header and |
| 1190 |
footer content, content may also be added automatically by the |
| 1191 |
processing system. For example, if certain runtime settings are |
| 1192 |
enabled, the document footer is populated with processing information |
| 1193 |
such as a datestamp, a link to `the Docutils website`_, etc. |
| 1194 |
|
| 1195 |
.. _the Docutils website: https://docutils.sourceforge.io |
| 1196 |
|
| 1197 |
|
| 1198 |
------------ |
| 1199 |
References |
| 1200 |
------------ |
| 1201 |
|
| 1202 |
.. _target-notes: |
| 1203 |
|
| 1204 |
Target Footnotes |
| 1205 |
================ |
| 1206 |
|
| 1207 |
:Directive Type: "target-notes" |
| 1208 |
:Doctree Elements: pending_, footnote_, footnote_reference_ |
| 1209 |
:Directive Arguments: None. |
| 1210 |
:Directive Options: class_, name_ |
| 1211 |
:Directive Options: Possible (see below). |
| 1212 |
:Directive Content: None. |
| 1213 |
|
| 1214 |
The "target-notes" directive creates a footnote for each external |
| 1215 |
target in the text, and corresponding footnote references after each |
| 1216 |
reference. For every explicit target (of the form, ``.. _target name: |
| 1217 |
URL``) in the text, a footnote will be generated containing the |
| 1218 |
visible URL as content. |
| 1219 |
|
| 1220 |
|
| 1221 |
Footnotes |
| 1222 |
========= |
| 1223 |
|
| 1224 |
**NOT IMPLEMENTED YET** |
| 1225 |
|
| 1226 |
:Directive Type: "footnotes" |
| 1227 |
:Doctree Elements: pending_, topic_ |
| 1228 |
:Directive Arguments: None? |
| 1229 |
:Directive Options: Possible? |
| 1230 |
:Directive Content: None. |
| 1231 |
|
| 1232 |
@@@ |
| 1233 |
|
| 1234 |
|
| 1235 |
Citations |
| 1236 |
========= |
| 1237 |
|
| 1238 |
**NOT IMPLEMENTED YET** |
| 1239 |
|
| 1240 |
:Directive Type: "citations" |
| 1241 |
:Doctree Elements: pending_, topic_ |
| 1242 |
:Directive Arguments: None? |
| 1243 |
:Directive Options: Possible? |
| 1244 |
:Directive Content: None. |
| 1245 |
|
| 1246 |
@@@ |
| 1247 |
|
| 1248 |
|
| 1249 |
--------------- |
| 1250 |
HTML-Specific |
| 1251 |
--------------- |
| 1252 |
|
| 1253 |
Imagemap |
| 1254 |
======== |
| 1255 |
|
| 1256 |
**NOT IMPLEMENTED YET** |
| 1257 |
|
| 1258 |
Non-standard element: imagemap. |
| 1259 |
|
| 1260 |
|
| 1261 |
----------------------------------------- |
| 1262 |
Directives for Substitution Definitions |
| 1263 |
----------------------------------------- |
| 1264 |
|
| 1265 |
The directives in this section may only be used in `substitution |
| 1266 |
definitions`_. They may not be used directly, in standalone context. |
| 1267 |
The `image`_ directive may be used both in substitution definitions |
| 1268 |
and in the standalone context. |
| 1269 |
|
| 1270 |
.. _substitution definitions: |
| 1271 |
.. _substitution definition: restructuredtext.html#substitution-definitions |
| 1272 |
|
| 1273 |
.. _replace: |
| 1274 |
|
| 1275 |
Replacement Text |
| 1276 |
================ |
| 1277 |
|
| 1278 |
:Directive Type: "replace" |
| 1279 |
:Doctree Element: Text & `inline elements`_ |
| 1280 |
:Directive Arguments: None. |
| 1281 |
:Directive Options: None. |
| 1282 |
:Directive Content: A single paragraph; may contain inline markup. |
| 1283 |
|
| 1284 |
The "replace" directive is used to indicate replacement text for a |
| 1285 |
substitution reference. It may be used within `substitution |
| 1286 |
definitions`_ only. For example, this directive can be used to expand |
| 1287 |
abbreviations:: |
| 1288 |
|
| 1289 |
.. |reST| replace:: reStructuredText |
| 1290 |
|
| 1291 |
Yes, |reST| is a long word, so I can't blame anyone for wanting to |
| 1292 |
abbreviate it. |
| 1293 |
|
| 1294 |
As reStructuredText doesn't support nested inline markup, the only way |
| 1295 |
to create a reference with styled text is to use substitutions with |
| 1296 |
the "replace" directive:: |
| 1297 |
|
| 1298 |
I recommend you try |Python|_. |
| 1299 |
|
| 1300 |
.. |Python| replace:: Python, *the* best language around |
| 1301 |
.. _Python: https://www.python.org/ |
| 1302 |
|
| 1303 |
|
| 1304 |
.. _unicode: |
| 1305 |
|
| 1306 |
Unicode Character Codes |
| 1307 |
======================= |
| 1308 |
|
| 1309 |
:Directive Type: "unicode" |
| 1310 |
:Doctree Element: Text |
| 1311 |
:Directive Arguments: One or more, required (Unicode character codes, |
| 1312 |
optional text, and comments). |
| 1313 |
:Directive Options: Possible (see below). |
| 1314 |
:Directive Content: None. |
| 1315 |
|
| 1316 |
The "unicode" directive converts Unicode character codes (numerical |
| 1317 |
values) to characters, and may be used in `substitution definitions`_ |
| 1318 |
only. |
| 1319 |
|
| 1320 |
The arguments, separated by spaces, can be: |
| 1321 |
|
| 1322 |
* **character codes** as |
| 1323 |
|
| 1324 |
- decimal numbers or |
| 1325 |
|
| 1326 |
- hexadecimal numbers, prefixed by ``0x``, ``x``, ``\x``, ``U+``, |
| 1327 |
``u``, or ``\u`` or as XML-style hexadecimal character entities, |
| 1328 |
e.g. ``ᨫ`` |
| 1329 |
|
| 1330 |
* **text**, which is used as-is. |
| 1331 |
|
| 1332 |
Text following " .. " is a comment and is ignored. The spaces between |
| 1333 |
the arguments are ignored and thus do not appear in the output. |
| 1334 |
Hexadecimal codes are case-insensitive. |
| 1335 |
|
| 1336 |
For example, the following text:: |
| 1337 |
|
| 1338 |
Copyright |copy| 2003, |BogusMegaCorp (TM)| |---| |
| 1339 |
all rights reserved. |
| 1340 |
|
| 1341 |
.. |copy| unicode:: 0xA9 .. copyright sign |
| 1342 |
.. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122 |
| 1343 |
.. with trademark sign |
| 1344 |
.. |---| unicode:: U+02014 .. em dash |
| 1345 |
:trim: |
| 1346 |
|
| 1347 |
results in: |
| 1348 |
|
| 1349 |
Copyright |copy| 2003, |BogusMegaCorp (TM)| |---| |
| 1350 |
all rights reserved. |
| 1351 |
|
| 1352 |
.. |copy| unicode:: 0xA9 .. copyright sign |
| 1353 |
.. |BogusMegaCorp (TM)| unicode:: BogusMegaCorp U+2122 |
| 1354 |
.. with trademark sign |
| 1355 |
.. |---| unicode:: U+02014 .. em dash |
| 1356 |
:trim: |
| 1357 |
|
| 1358 |
The following options are recognized: |
| 1359 |
|
| 1360 |
``ltrim`` : flag (empty) |
| 1361 |
Whitespace to the left of the substitution reference is removed. |
| 1362 |
|
| 1363 |
``rtrim`` : flag (empty) |
| 1364 |
Whitespace to the right of the substitution reference is removed. |
| 1365 |
|
| 1366 |
``trim`` : flag (empty) |
| 1367 |
Equivalent to ``ltrim`` plus ``rtrim``; whitespace on both sides |
| 1368 |
of the substitution reference is removed. |
| 1369 |
|
| 1370 |
|
| 1371 |
Date |
| 1372 |
==== |
| 1373 |
|
| 1374 |
:Directive Type: "date" |
| 1375 |
:Doctree Element: Text |
| 1376 |
:Directive Arguments: One, optional (date format). |
| 1377 |
:Directive Options: None. |
| 1378 |
:Directive Content: None. |
| 1379 |
|
| 1380 |
The "date" directive generates the current local date and inserts it |
| 1381 |
into the document as text. This directive may be used in substitution |
| 1382 |
definitions only. |
| 1383 |
|
| 1384 |
The optional directive content is interpreted as the desired date |
| 1385 |
format, using the same codes as Python's `time.strftime()`__ function. The |
| 1386 |
default format is "%Y-%m-%d" (ISO 8601 date), but time fields can also |
| 1387 |
be used. Examples:: |
| 1388 |
|
| 1389 |
.. |date| date:: |
| 1390 |
.. |time| date:: %H:%M |
| 1391 |
|
| 1392 |
Today's date is |date|. |
| 1393 |
|
| 1394 |
This document was generated on |date| at |time|. |
| 1395 |
|
| 1396 |
__ https://docs.python.org/3/library/time.html#time.strftime |
| 1397 |
|
| 1398 |
|
| 1399 |
--------------- |
| 1400 |
Miscellaneous |
| 1401 |
--------------- |
| 1402 |
|
| 1403 |
.. _include: |
| 1404 |
|
| 1405 |
Including an External Document Fragment |
| 1406 |
======================================= |
| 1407 |
|
| 1408 |
:Directive Type: "include" |
| 1409 |
:Doctree Elements: Depend on data being included |
| 1410 |
(literal_block_ with ``code`` or ``literal`` option). |
| 1411 |
:Directive Arguments: One, required (path to the file to include). |
| 1412 |
:Directive Options: Possible (see below). |
| 1413 |
:Directive Content: None. |
| 1414 |
:Configuration Setting: file_insertion_enabled_ |
| 1415 |
|
| 1416 |
.. WARNING:: |
| 1417 |
|
| 1418 |
The "include" directive represents a potential security hole. It |
| 1419 |
can be disabled with the "file_insertion_enabled_" runtime setting. |
| 1420 |
|
| 1421 |
.. _file_insertion_enabled: ../../user/config.html#file-insertion-enabled |
| 1422 |
|
| 1423 |
The "include" directive reads a text file. The directive argument is |
| 1424 |
the path to the file to be included, relative to the document containing |
| 1425 |
the directive. Unless the options ``literal``, ``code``, or ``parser`` |
| 1426 |
are given, the file is parsed in the current document's context at the |
| 1427 |
point of the directive. For example:: |
| 1428 |
|
| 1429 |
This first example will be parsed at the document level, and can |
| 1430 |
thus contain any construct, including section headers. |
| 1431 |
|
| 1432 |
.. include:: inclusion.txt |
| 1433 |
|
| 1434 |
Back in the main document. |
| 1435 |
|
| 1436 |
This second example will be parsed in a block quote context. |
| 1437 |
Therefore it may only contain body elements. It may not |
| 1438 |
contain section headers. |
| 1439 |
|
| 1440 |
.. include:: inclusion.txt |
| 1441 |
|
| 1442 |
If an included document fragment contains section structure, the title |
| 1443 |
adornments must match those of the master document. |
| 1444 |
|
| 1445 |
Standard data files intended for inclusion in reStructuredText |
| 1446 |
documents are distributed with the Docutils source code, located in |
| 1447 |
the "docutils" package in the ``docutils/parsers/rst/include`` |
| 1448 |
directory. To access these files, use the special syntax for standard |
| 1449 |
"include" data files, angle brackets around the file name:: |
| 1450 |
|
| 1451 |
.. include:: <isonum.txt> |
| 1452 |
|
| 1453 |
The current set of standard "include" data files consists of sets of |
| 1454 |
substitution definitions. See `reStructuredText Standard Definition |
| 1455 |
Files`__ for details. |
| 1456 |
|
| 1457 |
__ definitions.html |
| 1458 |
|
| 1459 |
The following options are recognized: |
| 1460 |
|
| 1461 |
``start-line`` : integer |
| 1462 |
Only the content starting from this line will be included. |
| 1463 |
(As usual in Python, the first line has index 0 and negative values |
| 1464 |
count from the end.) |
| 1465 |
|
| 1466 |
``end-line`` : integer |
| 1467 |
Only the content up to (but excluding) this line will be included. |
| 1468 |
|
| 1469 |
``start-after`` : text to find in the external data file |
| 1470 |
Only the content after the first occurrence of the specified text |
| 1471 |
will be included. |
| 1472 |
|
| 1473 |
``end-before`` : text to find in the external data file |
| 1474 |
Only the content before the first occurrence of the specified text |
| 1475 |
(but after any ``after`` text) will be included. |
| 1476 |
|
| 1477 |
``parser`` : parser name |
| 1478 |
Parse the included content with the specified parser. |
| 1479 |
(New in Docutils 0.17) |
| 1480 |
|
| 1481 |
``literal`` : flag (empty) |
| 1482 |
The entire included text is inserted into the document as a single |
| 1483 |
literal block. |
| 1484 |
|
| 1485 |
``code`` : [string] (formal language) |
| 1486 |
The argument and the included content are passed to |
| 1487 |
the code_ directive (useful for program listings). |
| 1488 |
|
| 1489 |
``number-lines`` : [integer] (start line number) |
| 1490 |
Precede every code line with a line number. |
| 1491 |
The optional argument is the number of the first line (default 1). |
| 1492 |
Works only with ``code`` or ``literal``. |
| 1493 |
|
| 1494 |
``encoding`` : string |
| 1495 |
The text encoding of the external data file. Defaults to the |
| 1496 |
document's input_encoding_. |
| 1497 |
|
| 1498 |
.. _input_encoding: ../../user/config.html#input-encoding |
| 1499 |
|
| 1500 |
``tab-width`` : integer |
| 1501 |
Number of spaces for hard tab expansion. |
| 1502 |
A negative value prevents expansion of hard tabs. Defaults to the |
| 1503 |
tab_width_ configuration setting. |
| 1504 |
|
| 1505 |
.. _tab_width: ../../user/config.html#tab-width |
| 1506 |
|
| 1507 |
With ``code`` or ``literal`` the common options class_ and |
| 1508 |
name_ are recognized as well. |
| 1509 |
|
| 1510 |
Combining ``start/end-line`` and ``start-after/end-before`` is possible. The |
| 1511 |
text markers will be searched in the specified lines (further limiting the |
| 1512 |
included content). |
| 1513 |
|
| 1514 |
.. _raw-directive: |
| 1515 |
|
| 1516 |
Raw Data Pass-Through |
| 1517 |
===================== |
| 1518 |
|
| 1519 |
:Directive Type: "raw" |
| 1520 |
:Doctree Element: raw_ |
| 1521 |
:Directive Arguments: One or more, required (output format types). |
| 1522 |
:Directive Options: Possible (see below). |
| 1523 |
:Directive Content: Stored verbatim, uninterpreted. None (empty) if a |
| 1524 |
"file" or "url" option given. |
| 1525 |
:Configuration Setting: raw_enabled_ |
| 1526 |
|
| 1527 |
.. WARNING:: |
| 1528 |
|
| 1529 |
The "raw" directive represents a potential security hole. It can |
| 1530 |
be disabled with the "raw_enabled_" or "file_insertion_enabled_" |
| 1531 |
runtime settings. |
| 1532 |
|
| 1533 |
.. _raw_enabled: ../../user/config.html#raw-enabled |
| 1534 |
|
| 1535 |
.. Caution:: |
| 1536 |
|
| 1537 |
The "raw" directive is a stop-gap measure allowing the author to |
| 1538 |
bypass reStructuredText's markup. It is a "power-user" feature |
| 1539 |
that should not be overused or abused. The use of "raw" ties |
| 1540 |
documents to specific output formats and makes them less portable. |
| 1541 |
|
| 1542 |
If you often need to use the "raw" directive or a "raw"-derived |
| 1543 |
interpreted text role, that is a sign either of overuse/abuse or |
| 1544 |
that functionality may be missing from reStructuredText. Please |
| 1545 |
describe your situation in a message to the Docutils-users_ mailing |
| 1546 |
list. |
| 1547 |
|
| 1548 |
.. _Docutils-users: ../../user/mailing-lists.html#docutils-users |
| 1549 |
|
| 1550 |
The "raw" directive indicates non-reStructuredText data that is to be |
| 1551 |
passed untouched to the Writer. The names of the output formats are |
| 1552 |
given in the directive arguments. The interpretation of the raw data |
| 1553 |
is up to the Writer. A Writer may ignore any raw output not matching |
| 1554 |
its format. |
| 1555 |
|
| 1556 |
For example, the following input would be passed untouched by an HTML |
| 1557 |
writer:: |
| 1558 |
|
| 1559 |
.. raw:: html |
| 1560 |
|
| 1561 |
<hr width=50 size=10> |
| 1562 |
|
| 1563 |
A LaTeX Writer could insert the following raw content into its |
| 1564 |
output stream:: |
| 1565 |
|
| 1566 |
.. raw:: latex |
| 1567 |
|
| 1568 |
\setlength{\parindent}{0pt} |
| 1569 |
|
| 1570 |
Raw data can also be read from an external file, specified in a |
| 1571 |
directive option. In this case, the content block must be empty. For |
| 1572 |
example:: |
| 1573 |
|
| 1574 |
.. raw:: html |
| 1575 |
:file: inclusion.html |
| 1576 |
|
| 1577 |
Inline equivalents of the "raw" directive can be defined via |
| 1578 |
`custom interpreted text roles`_ derived from the `"raw" role`_. |
| 1579 |
|
| 1580 |
The following options are recognized: |
| 1581 |
|
| 1582 |
``file`` : string (newlines removed) |
| 1583 |
The local filesystem path of a raw data file to be included. |
| 1584 |
|
| 1585 |
``url`` : string (whitespace removed) |
| 1586 |
An Internet URL reference to a raw data file to be included. |
| 1587 |
|
| 1588 |
``encoding`` : string |
| 1589 |
The text encoding of the external raw data (file or URL). |
| 1590 |
Defaults to the document's encoding (if specified). |
| 1591 |
|
| 1592 |
and the common option class_. |
| 1593 |
|
| 1594 |
|
| 1595 |
.. _"raw" role: roles.html#raw |
| 1596 |
|
| 1597 |
|
| 1598 |
.. _classes: |
| 1599 |
|
| 1600 |
Class |
| 1601 |
===== |
| 1602 |
|
| 1603 |
:Directive Type: "class" |
| 1604 |
:Doctree Element: pending_ |
| 1605 |
:Directive Arguments: One or more, required (class names / attribute |
| 1606 |
values). |
| 1607 |
:Directive Options: None. |
| 1608 |
:Directive Content: Optional. If present, it is interpreted as body |
| 1609 |
elements. |
| 1610 |
|
| 1611 |
The "class" directive sets the `"classes"`_ attribute value on its content |
| 1612 |
or on the first immediately following [#]_ non-comment element [#]_. |
| 1613 |
The directive argument consists of one or more space-separated class |
| 1614 |
names. The names are transformed to conform to the regular expression |
| 1615 |
``[a-z](-?[a-z0-9]+)*`` (see `Identifier Normalization`_ below). |
| 1616 |
|
| 1617 |
Examples:: |
| 1618 |
|
| 1619 |
.. class:: special |
| 1620 |
|
| 1621 |
This is a "special" paragraph. |
| 1622 |
|
| 1623 |
.. class:: exceptional remarkable |
| 1624 |
|
| 1625 |
An Exceptional Section |
| 1626 |
====================== |
| 1627 |
|
| 1628 |
This is an ordinary paragraph. |
| 1629 |
|
| 1630 |
.. class:: multiple |
| 1631 |
|
| 1632 |
First paragraph. |
| 1633 |
|
| 1634 |
Second paragraph. |
| 1635 |
|
| 1636 |
The text above is parsed and transformed into this doctree fragment:: |
| 1637 |
|
| 1638 |
<paragraph classes="special"> |
| 1639 |
This is a "special" paragraph. |
| 1640 |
<section classes="exceptional remarkable"> |
| 1641 |
<title> |
| 1642 |
An Exceptional Section |
| 1643 |
<paragraph> |
| 1644 |
This is an ordinary paragraph. |
| 1645 |
<paragraph classes="multiple"> |
| 1646 |
First paragraph. |
| 1647 |
<paragraph classes="multiple"> |
| 1648 |
Second paragraph. |
| 1649 |
|
| 1650 |
|
| 1651 |
.. [#] This is also true, if the class directive is "nested" at the end of |
| 1652 |
an indented text block, for example:: |
| 1653 |
|
| 1654 |
.. note:: the class values set in this directive-block do not apply to |
| 1655 |
the note but the next paragraph. |
| 1656 |
|
| 1657 |
.. class:: special |
| 1658 |
|
| 1659 |
This is a paragraph with class value "special". |
| 1660 |
|
| 1661 |
This allows the "classification" of individual list items (except the |
| 1662 |
first, as a preceding class directive applies to the list as a whole):: |
| 1663 |
|
| 1664 |
* bullet list |
| 1665 |
|
| 1666 |
.. class:: classy item |
| 1667 |
|
| 1668 |
* second item, with class argument |
| 1669 |
|
| 1670 |
.. [#] To set a "classes" attribute value on a block quote, the |
| 1671 |
"class" directive must be followed by an empty comment:: |
| 1672 |
|
| 1673 |
.. class:: highlights |
| 1674 |
.. |
| 1675 |
|
| 1676 |
Block quote text. |
| 1677 |
|
| 1678 |
Without the empty comment, the indented text would be interpreted as the |
| 1679 |
"class" directive's content, and the classes would be applied to each |
| 1680 |
element (paragraph, in this case) individually, instead of to the block |
| 1681 |
quote as a whole. |
| 1682 |
|
| 1683 |
|
| 1684 |
Identifier Normalization |
| 1685 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1686 |
|
| 1687 |
Docutils `class names`_ and `identifier keys`_ are normalized to conform |
| 1688 |
to the regular expression "``[a-z](-?[a-z0-9]+)*``" by converting |
| 1689 |
|
| 1690 |
* alphabetic characters to lowercase, |
| 1691 |
* accented characters to the base character, |
| 1692 |
* non-alphanumeric characters to hyphens, |
| 1693 |
* consecutive hyphens into one hyphen |
| 1694 |
|
| 1695 |
and stripping |
| 1696 |
|
| 1697 |
* leading hyphens and number characters, and |
| 1698 |
* trailing hyphens. |
| 1699 |
|
| 1700 |
For example ``"Rot.Gelb&Grün:+2008"`` becomes ``"rot-gelb-grun-2008"`` and |
| 1701 |
``"1000_Steps!"`` becomes ``"steps"``. |
| 1702 |
|
| 1703 |
.. topic:: Rationale: |
| 1704 |
|
| 1705 |
Identifier keys must be valid in all supported output formats. |
| 1706 |
|
| 1707 |
For HTML 4.1 + CSS1 compatibility, identifiers should have no |
| 1708 |
underscores, colons, or periods. Hyphens may be used. |
| 1709 |
|
| 1710 |
- The `HTML 4.01 spec`_ defines identifiers based on SGML tokens: |
| 1711 |
|
| 1712 |
ID and NAME tokens must begin with a letter ([A-Za-z]) and |
| 1713 |
may be followed by any number of letters, digits ([0-9]), |
| 1714 |
hyphens ("-"), underscores ("_"), colons (":"), and periods |
| 1715 |
("."). |
| 1716 |
|
| 1717 |
-- https://www.w3.org/TR/html401/types.html#type-name |
| 1718 |
|
| 1719 |
- The `CSS1 spec`_ defines identifiers based on the "name" token |
| 1720 |
("flex" tokenizer notation below; "latin1" and "escape" 8-bit |
| 1721 |
characters have been replaced with XML entities):: |
| 1722 |
|
| 1723 |
unicode \\[0-9a-f]{1,4} |
| 1724 |
latin1 [¡-ÿ] |
| 1725 |
escape {unicode}|\\[ -~¡-ÿ] |
| 1726 |
nmchar [-A-Za-z0-9]|{latin1}|{escape} |
| 1727 |
name {nmchar}+ |
| 1728 |
|
| 1729 |
The CSS1 rule requires underscores ("_"), colons (":"), and |
| 1730 |
periods (".") to be escaped [#]_, |
| 1731 |
therefore `"classes"`_ and `"ids"`_ attributes should not |
| 1732 |
contain these characters. Combined with HTML4.1 requirements (the |
| 1733 |
first character must be a letter; no "unicode", "latin1", or |
| 1734 |
"escape" characters), this results in the regular expression |
| 1735 |
``[A-Za-z][-A-Za-z0-9]*``. Docutils adds a normalization by |
| 1736 |
downcasing and merge of consecutive hyphens. |
| 1737 |
|
| 1738 |
.. [#] CSS identifiers may use underscores ("_") directly in |
| 1739 |
`CSS Level 1`__, `CSS2.1`__, CSS2.2__, and CSS3__. |
| 1740 |
|
| 1741 |
__ https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier |
| 1742 |
__ https://www.w3.org/TR/CSS/#css-level-1 |
| 1743 |
__ https://www.w3.org/TR/CSS22/syndata.html |
| 1744 |
__ https://www.w3.org/TR/css-syntax-3/#typedef-ident-token |
| 1745 |
|
| 1746 |
.. _HTML 4.01 spec: https://www.w3.org/TR/html401/ |
| 1747 |
.. _CSS1 spec: https://www.w3.org/TR/REC-CSS1 |
| 1748 |
|
| 1749 |
.. _role: |
| 1750 |
|
| 1751 |
Custom Interpreted Text Roles |
| 1752 |
============================= |
| 1753 |
|
| 1754 |
:Directive Type: "role" |
| 1755 |
:Doctree Element: None; affects subsequent parsing. |
| 1756 |
:Directive Arguments: Two; one required (new `role name`_), one optional |
| 1757 |
(base role name, in parentheses). |
| 1758 |
:Directive Options: Possible (depends on base role). |
| 1759 |
:Directive Content: depends on base role. |
| 1760 |
|
| 1761 |
The "role" directive dynamically creates a custom `interpreted text |
| 1762 |
role`_ and registers it with the parser. This means that after |
| 1763 |
declaring a role like this:: |
| 1764 |
|
| 1765 |
.. role:: custom |
| 1766 |
|
| 1767 |
the document may use the new "custom" role:: |
| 1768 |
|
| 1769 |
An example of using :custom:`interpreted text` |
| 1770 |
|
| 1771 |
This will be parsed into the following document tree fragment:: |
| 1772 |
|
| 1773 |
<paragraph> |
| 1774 |
An example of using |
| 1775 |
<inline classes="custom"> |
| 1776 |
interpreted text |
| 1777 |
|
| 1778 |
The role must be declared in a document before it can be used. |
| 1779 |
|
| 1780 |
.. _role name: |
| 1781 |
|
| 1782 |
Role names are case insensitive and must conform to the rules of |
| 1783 |
simple `reference names`_ (but do not share a namespace with |
| 1784 |
hyperlinks, footnotes, and citations). |
| 1785 |
|
| 1786 |
The new role may be based on an existing role, specified as a second |
| 1787 |
argument in parentheses (whitespace optional):: |
| 1788 |
|
| 1789 |
.. role:: custom(emphasis) |
| 1790 |
|
| 1791 |
:custom:`text` |
| 1792 |
|
| 1793 |
The parsed result is as follows:: |
| 1794 |
|
| 1795 |
<paragraph> |
| 1796 |
<emphasis classes="custom"> |
| 1797 |
text |
| 1798 |
|
| 1799 |
A special case is the `"raw" role`_: derived roles enable |
| 1800 |
inline `raw data pass-through`_, e.g.:: |
| 1801 |
|
| 1802 |
.. role:: raw-role(raw) |
| 1803 |
:format: html latex |
| 1804 |
|
| 1805 |
:raw-role:`raw text` |
| 1806 |
|
| 1807 |
If no base role is explicitly specified, a generic custom role is |
| 1808 |
automatically used. Subsequent interpreted text will produce an |
| 1809 |
"inline" element with a `"classes"`_ attribute, as in the first example |
| 1810 |
above. |
| 1811 |
|
| 1812 |
With most roles, the ":class:" option can be used to set a "classes" |
| 1813 |
attribute that is different from the role name. For example:: |
| 1814 |
|
| 1815 |
.. role:: custom |
| 1816 |
:class: special |
| 1817 |
|
| 1818 |
:custom:`interpreted text` |
| 1819 |
|
| 1820 |
This is the parsed result:: |
| 1821 |
|
| 1822 |
<paragraph> |
| 1823 |
<inline classes="special"> |
| 1824 |
interpreted text |
| 1825 |
|
| 1826 |
.. _role class: |
| 1827 |
|
| 1828 |
The following option is recognized by the "role" directive for most |
| 1829 |
base roles: |
| 1830 |
|
| 1831 |
``class`` : text |
| 1832 |
Set the `"classes"`_ attribute value on the element produced |
| 1833 |
(``inline``, or element associated with a base class) when the |
| 1834 |
custom interpreted text role is used. If no directive options are |
| 1835 |
specified, a "class" option with the directive argument (role |
| 1836 |
name) as the value is implied. See the class_ directive above. |
| 1837 |
|
| 1838 |
Specific base roles may support other options and/or directive |
| 1839 |
content. See the `reStructuredText Interpreted Text Roles`_ document |
| 1840 |
for details. |
| 1841 |
|
| 1842 |
.. _reStructuredText Interpreted Text Roles: roles.html |
| 1843 |
|
| 1844 |
|
| 1845 |
.. _default-role: |
| 1846 |
|
| 1847 |
Setting the Default Interpreted Text Role |
| 1848 |
========================================= |
| 1849 |
|
| 1850 |
:Directive Type: "default-role" |
| 1851 |
:Doctree Element: None; affects subsequent parsing. |
| 1852 |
:Directive Arguments: One, optional (new default role name). |
| 1853 |
:Directive Options: None. |
| 1854 |
:Directive Content: None. |
| 1855 |
|
| 1856 |
The "default-role" directive sets the default interpreted text role, |
| 1857 |
the role that is used for interpreted text without an explicit role. |
| 1858 |
For example, after setting the default role like this:: |
| 1859 |
|
| 1860 |
.. default-role:: subscript |
| 1861 |
|
| 1862 |
any subsequent use of implicit-role interpreted text in the document |
| 1863 |
will use the "subscript" role:: |
| 1864 |
|
| 1865 |
An example of a `default` role. |
| 1866 |
|
| 1867 |
This will be parsed into the following document tree fragment:: |
| 1868 |
|
| 1869 |
<paragraph> |
| 1870 |
An example of a |
| 1871 |
<subscript> |
| 1872 |
default |
| 1873 |
role. |
| 1874 |
|
| 1875 |
Custom roles may be used (see the "role_" directive above), but it |
| 1876 |
must have been declared in a document before it can be set as the |
| 1877 |
default role. See the `reStructuredText Interpreted Text Roles`_ |
| 1878 |
document for details of built-in roles. |
| 1879 |
|
| 1880 |
The directive may be used without an argument to restore the initial |
| 1881 |
default interpreted text role, which is application-dependent. The |
| 1882 |
initial default interpreted text role of the standard reStructuredText |
| 1883 |
parser is "title-reference". |
| 1884 |
|
| 1885 |
|
| 1886 |
Metadata |
| 1887 |
======== |
| 1888 |
|
| 1889 |
:Directive Type: "meta" |
| 1890 |
:Doctree Element: meta_ |
| 1891 |
:Directive Arguments: None. |
| 1892 |
:Directive Options: None. |
| 1893 |
:Directive Content: Must contain a flat field list. |
| 1894 |
|
| 1895 |
The "meta" directive is used to specify metadata\ [#]_ to be stored |
| 1896 |
in, e.g., `HTML meta elements`_ or as `ODT file properties`_. The |
| 1897 |
LaTeX writer passes it to the ``pdfinfo`` option of the hyperref_ |
| 1898 |
package. If an output format does not support "invisible" metadata, |
| 1899 |
content is silently dropped by the writer. |
| 1900 |
|
| 1901 |
.. note:: Data from some `bibliographic fields`_ is automatically |
| 1902 |
extracted and stored as metadata, too. However, Bibliographic |
| 1903 |
Fields are also displayed in the document's screen rendering or |
| 1904 |
printout. |
| 1905 |
|
| 1906 |
For an "invisible" *document title*, see the `metadata document |
| 1907 |
title`_ directive below. |
| 1908 |
|
| 1909 |
Within the directive block, a flat field list provides the syntax for |
| 1910 |
metadata. The field name becomes the contents of the "name" attribute |
| 1911 |
of the META tag, and the field body (interpreted as a single string |
| 1912 |
without inline markup) becomes the contents of the "content" |
| 1913 |
attribute. For example:: |
| 1914 |
|
| 1915 |
.. meta:: |
| 1916 |
:description: The reStructuredText plaintext markup language |
| 1917 |
:keywords: plaintext, markup language |
| 1918 |
|
| 1919 |
This would be converted to the following HTML:: |
| 1920 |
|
| 1921 |
<meta name="description" |
| 1922 |
content="The reStructuredText plaintext markup language"> |
| 1923 |
<meta name="keywords" content="plaintext, markup language"> |
| 1924 |
|
| 1925 |
Support for other META attributes ("http-equiv", "scheme", "lang", |
| 1926 |
"dir") are provided through field arguments, which must be of the form |
| 1927 |
"attr=value":: |
| 1928 |
|
| 1929 |
.. meta:: |
| 1930 |
:description lang=en: An amusing story |
| 1931 |
:description lang=fr: Une histoire amusante |
| 1932 |
|
| 1933 |
And their HTML equivalents:: |
| 1934 |
|
| 1935 |
<meta name="description" lang="en" content="An amusing story"> |
| 1936 |
<meta name="description" lang="fr" content="Une histoire amusante"> |
| 1937 |
|
| 1938 |
Some META tags use an "http-equiv" attribute instead of the "name" |
| 1939 |
attribute. To specify "http-equiv" META tags, simply omit the name:: |
| 1940 |
|
| 1941 |
.. meta:: |
| 1942 |
:http-equiv=Content-Type: text/html; charset=ISO-8859-1 |
| 1943 |
|
| 1944 |
HTML equivalent:: |
| 1945 |
|
| 1946 |
<meta http-equiv="Content-Type" |
| 1947 |
content="text/html; charset=ISO-8859-1"> |
| 1948 |
|
| 1949 |
.. [#] "Metadata" is data about data, in this case data about the |
| 1950 |
document. Metadata is, e.g., used to describe and classify web |
| 1951 |
pages in the World Wide Web, in a form that is easy for search |
| 1952 |
engines to extract and collate. |
| 1953 |
|
| 1954 |
.. _HTML meta elements: |
| 1955 |
https://html.spec.whatwg.org/multipage/semantics.html#the-meta-element |
| 1956 |
.. _ODT file properties: |
| 1957 |
https://en.wikipedia.org/wiki/OpenDocument_technical_specification#Metadata |
| 1958 |
.. _hyperref: https://ctan.org/pkg/hyperref |
| 1959 |
.. _bibliographic fields: restructuredtext.html#bibliographic-fields |
| 1960 |
|
| 1961 |
|
| 1962 |
Metadata Document Title |
| 1963 |
======================= |
| 1964 |
|
| 1965 |
:Directive Type: "title" |
| 1966 |
:Doctree Element: Sets the document's `title attribute`_. |
| 1967 |
:Directive Arguments: One, required (the title text). |
| 1968 |
:Directive Options: None. |
| 1969 |
:Directive Content: None. |
| 1970 |
|
| 1971 |
The "title" directive specifies the document title as metadata, which |
| 1972 |
does not become part of the document body. It overrides the |
| 1973 |
document-supplied `document title`_ and the `"title" configuration |
| 1974 |
setting`_. For example, in HTML output the metadata document title |
| 1975 |
appears in the title bar of the browser window. |
| 1976 |
|
| 1977 |
.. _document title: restructuredtext.html#document-title |
| 1978 |
.. _"title" configuration setting: ../../user/config.html#title |
| 1979 |
|
| 1980 |
Restructuredtext-Test-Directive |
| 1981 |
=============================== |
| 1982 |
|
| 1983 |
:Directive Type: "restructuredtext-test-directive" |
| 1984 |
:Doctree Element: system_warning |
| 1985 |
:Directive Arguments: None. |
| 1986 |
:Directive Options: None. |
| 1987 |
:Directive Content: Interpreted as a literal block. |
| 1988 |
|
| 1989 |
This directive is provided for test purposes only. (Nobody is |
| 1990 |
expected to type in a name *that* long!) It is converted into a |
| 1991 |
level-1 (info) system message showing the directive data, possibly |
| 1992 |
followed by a literal block containing the rest of the directive |
| 1993 |
block. |
| 1994 |
|
| 1995 |
-------------- |
| 1996 |
Common Options |
| 1997 |
-------------- |
| 1998 |
|
| 1999 |
Most of the directives that generate doctree elements support the following |
| 2000 |
options: |
| 2001 |
|
| 2002 |
.. _class-option: |
| 2003 |
.. _class: |
| 2004 |
|
| 2005 |
``class`` : text (space separated list of `class names`_) |
| 2006 |
Set a `"classes"`_ attribute value on the doctree element generated by |
| 2007 |
the directive. See also the class_ directive. |
| 2008 |
|
| 2009 |
.. _name: |
| 2010 |
|
| 2011 |
``name`` : text |
| 2012 |
Add `text` to the `"names"`_ attribute of the doctree element generated |
| 2013 |
by the directive. This allows `hyperlink references`_ to the element |
| 2014 |
using `text` as `reference name`_. |
| 2015 |
|
| 2016 |
Specifying the `name` option of a directive, e.g., :: |
| 2017 |
|
| 2018 |
.. image:: bild.png |
| 2019 |
:name: my picture |
| 2020 |
|
| 2021 |
is a concise syntax alternative to preceding it with a `hyperlink |
| 2022 |
target`_ :: |
| 2023 |
|
| 2024 |
.. _my picture: |
| 2025 |
|
| 2026 |
.. image:: bild.png |
| 2027 |
|
| 2028 |
|
| 2029 |
.. _reference name: |
| 2030 |
.. _reference names: restructuredtext.html#reference-names |
| 2031 |
.. _hyperlink target: restructuredtext.html#hyperlink-targets |
| 2032 |
.. _hyperlink references: restructuredtext.html#hyperlink-references |
| 2033 |
.. _class names: ../doctree.html#classnames-type |
| 2034 |
.. _"classes": ../doctree.html#classes |
| 2035 |
.. _identifier keys: ../doctree.html#ids-type |
| 2036 |
.. _"ids": ../doctree.html#ids |
| 2037 |
.. _"names": ../doctree.html#names |
| 2038 |
.. _admonition: ../doctree.html#admonition |
| 2039 |
.. _block_quote: ../doctree.html#block-quote |
| 2040 |
.. _caption: ../doctree.html#caption |
| 2041 |
.. _compound: ../doctree.html#compound |
| 2042 |
.. _container element: ../doctree.html#container |
| 2043 |
.. _decoration: ../doctree.html#decoration |
| 2044 |
.. _figure: ../doctree.html#figure |
| 2045 |
.. _footnote: ../doctree.html#footnote |
| 2046 |
.. _footnote_reference: ../doctree.html#footnote-reference |
| 2047 |
.. _generated: ../doctree.html#generated |
| 2048 |
.. _image: ../doctree.html#image |
| 2049 |
.. _inline elements: ../doctree.html#inline-elements |
| 2050 |
.. _interpreted text role: roles.html |
| 2051 |
.. _literal_block: ../doctree.html#literal-block |
| 2052 |
.. _legend: ../doctree.html#legend |
| 2053 |
.. _length: restructuredtext.html#length-units |
| 2054 |
.. _line_block: ../doctree.html#line-block |
| 2055 |
.. _math_block: ../doctree.html#math-block |
| 2056 |
.. _meta: ../doctree.html#meta |
| 2057 |
.. _pending: ../doctree.html#pending |
| 2058 |
.. _percentage: restructuredtext.html#percentage-units |
| 2059 |
.. _raw: ../doctree.html#raw |
| 2060 |
.. _rubric: ../doctree.html#rubric |
| 2061 |
.. _sidebar: ../doctree.html#sidebar |
| 2062 |
.. _table: ../doctree.html#table |
| 2063 |
.. _title: ../doctree.html#title |
| 2064 |
.. _title attribute: ../doctree.html#title-attribute |
| 2065 |
.. _topic: ../doctree.html#topic |
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
.. |
| 2070 |
Local Variables: |
| 2071 |
mode: indented-text |
| 2072 |
indent-tabs-mode: nil |
| 2073 |
sentence-end-double-space: t |
| 2074 |
fill-column: 70 |
| 2075 |
End: |