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