1 rst Structural Element Examples¶
Here’s the quick reference for RST.
Table of Contents
1.2 Inline Markup¶
Paragraphs contain text and may contain inline markup: emphasis,
strong emphasis, inline literals
, standalone hyperlinks
(http://www.python.org), external hyperlinks (Python), internal
cross-references (example), external hyperlinks with embedded URIs
(Python web site), footnote references
(manually numbered [1], anonymous auto-numbered [3], labeled
auto-numbered [2], or symbolic [*]), citation references
([CIT2002]), and inline
hyperlink targets (see Targets below for a reference back to here).
Character-level inline markup is also possible (although exceedingly
ugly!) in reStructured
Text.
The default role for interpreted text is Title Reference. Here are
some explicit interpreted text roles: a PEP reference (PEP 287); an
RFC reference (RFC 2822); a subscript; a superscript;
and explicit roles for standard inline
markup
.
Let’s test wrapping and whitespace significance in inline literals:
This is an example of --inline-literal --text, --including some--
strangely--hyphenated-words. Adjust-the-width-of-your-browser-window
to see how the text is wrapped. -- ---- -------- Now note the spacing between the words of this sentence (words should be grouped in pairs).
If the --pep-references
option was supplied, there should be a
live link to PEP 258 here.
1.3 Body Elements¶
1.3.1 Section Title¶
That’s a section title: the text just above this line.
1.3.2 Paragraphs¶
A paragraph.
1.3.3 Bullet Lists¶
A bullet list
- Nested bullet list.
- Nested item 2.
Item 2.
Paragraph 2 of item 2.
- Nested bullet list.
- Nested item 2.
- Third level.
- Item 2.
- Nested item 3.
1.3.4 Enumerated Lists¶
Arabic numerals.
- lower alpha)
- (lower roman)
- upper alpha.
- upper roman)
- upper alpha.
- (lower roman)
- lower alpha)
Lists that don’t start at 1:
- Three
- Four
- C
- D
- iii
- iv
List items may also be auto-enumerated.
1.3.5 Definition Lists¶
- Term
- Definition
- Term : classifier
Definition paragraph 1.
Definition paragraph 2.
- Term
- Definition
1.4 Formatting¶
Double-dashes – “–” – must be escaped somehow in HTML output.
1.4.1 Field Lists¶
what: | Field lists map field names to field bodies, like database records. They are often part of an extension syntax. They are an unambiguous variant of RFC 2822 fields. |
---|---|
how arg1 arg2: | The field marker is a colon, the field name, and a colon. The field body may contain one or more body elements, indented relative to the field marker. |
Here’s an example of a field list:
Field List: |
some text |
---|---|
Field List 2: | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor |
1.4.2 Option Lists¶
For listing command-line options:
-a | command-line option “a” |
-b file | options can have arguments and long descriptions |
--long | options can be long also |
--input=file | long options can also have arguments |
--very-long-option | |
The description can also start on the next line. The description may contain multiple body elements, regardless of where it starts. | |
-x, -y, -z | Multiple options are an “option group”. |
-v, --verbose | Commonly-seen: short & long options. |
-1 file, --one=file, --two file | |
Multiple options with arguments. | |
/V | DOS/VMS-style options too |
There must be at least two spaces between the option and the description.
1.5 Literal Blocks¶
Literal blocks are indicated with a double-colon (”::”) at the end of
the preceding paragraph (over there -->
). They can be indented:
if literal_block:
text = 'is left as-is'
spaces_and_linebreaks = 'are preserved'
markup_processing = None
Or they can be quoted without indentation:
>> Great idea!
>
> Why didn't I think of that?
1.5.1 Line Blocks¶
Take it away, Eric the Orchestra Leader!
A one, two, a one two three fourHalf a bee, philosophically,must, ipso facto, half not be.But half the bee has got to be,vis a vis its entity. D’you see?But can a bee be said to beor not to be an entire bee,when half the bee is not a bee,due to some ancient injury?Singing...
1.5.2 Block Quotes¶
Block quotes consist of indented body elements:
My theory by A. Elk. Brackets Miss, brackets. This theory goes as follows and begins now. All brontosauruses are thin at one end, much much thicker in the middle and then thin again at the far end. That is my theory, it is mine, and belongs to me and I own it, and what it is too.
—Anne Elk (Miss)
1.5.3 Doctest Blocks¶
>>> print 'Python-specific usage examples; begun with ">>>"'
Python-specific usage examples; begun with ">>>"
>>> print '(cut and pasted from interactive Python sessions)'
(cut and pasted from interactive Python sessions)
1.6 Tables¶
Here’s a grid table followed by a simple table:
Header row, column 1 (header rows optional) | Header 2 | Header 3 | Header 4 |
---|---|---|---|
body row 1, column 1 | column 2 | column 3 | column 4 |
body row 2 | Cells may span columns. | ||
body row 3 | Cells may span rows. |
|
|
body row 4 | |||
body row 5 | Cells may also be
empty: --> |
Inputs | Output | |
---|---|---|
A | B | A or B |
False | False | False |
True | False | True |
False | True | True |
True | True | True |
1.7 Footnotes¶
[1] | (1, 2) A footnote contains body elements, consistently indented by at least 3 spaces. This is the footnote’s second paragraph. |
[2] | (1, 2) Footnotes may be numbered, either manually (as in [1]) or automatically using a “#”-prefixed label. This footnote has a label so it can be referred to from multiple places, both as a footnote reference ([2]) and as a hyperlink reference (label). |
[3] | This footnote is numbered automatically and anonymously using a label of “#” only. |
[*] | Footnotes may also use symbols, specified with a “*” label. Here’s a reference to the next footnote: [†]. |
[†] | This footnote shows the next symbol in the sequence. |
[4] | Here’s an unreferenced footnote |
1.8 Citations¶
[CIT2002] | (1, 2) Citations are text-labeled footnotes. They may be rendered separately and differently from footnotes. |
Here’s a reference to the above, [CIT2002]
1.9 Targets¶
This paragraph is pointed to by the explicit _example
target. A
reference can be found under Inline Markup, above. Inline
hyperlink targets are also possible.
Section headers are implicit targets, referred to by name. See Targets, which is a subsection of Body Elements.
1.9.1 External targets¶
Explicit external targets are interpolated into references such as “Python”.
Here’s a reference to the Definitinve RST Reference documentation.
You can refer to another rst document within the site with a Sphinx directive. A reference to the 1 Examples of Code in rst like this: :ref:`rst_code`
Targets may be indirect and anonymous. Thus this phrase may also refer to the Targets section.
1.9.2 Target Footnotes¶
If you use the .. target-notes::
directive, footnotes for all external references will be generated, and the
footnotes themselves will be put after that directive.
(Thus you usually want to put the directive at the bottom of a document so the footnotes will be at the bottom – the foot of the document.
Target footnoes are not used in this document. But you can see it in action in this one <rst_tiny>.
1.10 Directives¶
These are just a sample of the many reStructuredText Directives. For others, please see http://docutils.sourceforge.net/docs/ref/rst/directives.html.
An example of the “contents” directive can be seen above this section (a local, untitled table of contents) and at the beginning of the document (a document-wide table of contents).
1.11 Images¶
An image directive with a link (target) to the Targets section. (The image is a clickable link):
A figure is an image with a caption and/or a legend:
A figure directive with center alignment and width of 100. (If you click on it, you’ll see the lovely full-sized image.)
1.12 Admonition Boxes¶
Attention
Attention - Directives at large.
Caution
Don’t take any wooden nickels.
Danger
Mad scientist at work!
Error
Does not compute.
Hint
It’s bigger than a bread box.
Important
These things are imporant: - Wash behind your ears. - Be nice. - Clean up your room. - Back up your data.
Note
This is a note.
Tip
15% if the service is good.
Warning
Strong prose may provoke extreme mental exertion. Reader discretion is strongly advised.
And, by the way...
You can make up your own admonition too.
1.13 Topics, Sidebars, and Rubrics¶
Topic Title
This is a topic.
This is a rubric
This paragraph contains a literal block:
Connecting... OK
Transmitting data... OK
Disconnecting... OK
and thus consists of a simple paragraph, a literal block, and another simple paragraph. Nonetheless it is semantically one paragraph.
This construct is called a compound paragraph and can be produced with the “compound” directive.
1.14 Substitution¶
An inline image example: Instead of showing the words biohazard
, show ()
The code to accomplish a substitution (a.k.a. replacement) is:
An inline image example: Instead of showing the words ``biohazard``, show (|biohazard|)
.. |biohazard| image:: static/tiny-Biohazard_symbol.png
I recommend that you try Smalltalk, the best language around.
In the preceding text, |`Python web site <http://www.python.org>`__|
was replaced with `Smalltalk <http://c2.com/cgi/wiki?SmalltalkLanguage>`__
1.15 Comments¶
Here’s one:
Of course you can’t see it, because it’s a comment in the source for this file. Here’s the what the rst for the comment looks like in the rst source for this file:
.. Comments begin with two dots and a space. Anything may
follow, except for the syntax of footnotes, hyperlink
targets, directives, or substitution definitions.