reStructuredText Markup
This document is an introduction to the reStructuredText (rST) markup language. It demonstrates the features of the Moin2 rST support. For details, follow the links to the reStructuredText Markup Specification.
There are two HTML version of this document: one is part of the Wiki Help generated by Moin, the other belongs to the external documentation generated by Sphinx. Some features and links only work in the Wiki Help page.
Section Headings
Section headings are underlined (or over- and underlined) with a printing nonalphanumeric 7-bit ASCII character (details).
The underline/overline must be at least as long as the title text.
A blank line after a heading is optional.
Instead of a fixed order of heading adornment styles, the level is determined by their order in the document:
The first adornment style encountered is registered as page title style (<h1> in HTML), the second style is assigned to level 2, the third style to level 3, and so on.[1]
Once established, adornment styles must be consistent. Skipping a heading level results in a parsing error.
Markup |
Result |
|---|---|
=======
Level 1
=======
|
The first encountered style becomes the page title (if it is unique)[1]. |
Level 2
=======
|
See the heading of this section. |
Level 3
-------
Level 4
*******
Level 5
:::::::
Level 6
+++++++
|
See below. (Section headings may not be nested in body elements like lists, tables, or admonitions. You may use rubrics for informal headings outside the main document structure.) |
Level 3
Level 4
Level 5
Level 6
Thematic Breaks
A thematic break represents a change in subject or emphasis. It is typically rendered as additional space between paragraphs, often with a horizontal line, a row of asterisks, or some other ornament. See below for an example.
HTML represents a thematic break with the <hr /> element.
In reStructuredText, this element is called transition and
represented by a horizontal line of 4 or more repeated punctuation
characters (details).
Markup |
Result |
|---|---|
See below for an example.
------------------------
HTML represents […]
|
See above. (Transitions may not be nested in body elements like lists, tables, admonitions, …). |
Text Formatting
Inline markup can be applied to words or phrases within a text block to format text (details).
Less common styles are obtained via interpreted text roles.
reStructuredText does not support
***Nested** inline markup*. [2]
Markup |
Result |
Notes |
|---|---|---|
|
emphasis |
|
|
strong emphasis |
|
|
|
In literal context, backslashes have no special meaning. |
|
Hamlet |
Interpreted text. The default text role is configurable, it defaults to the “title” role (see below). |
|
abbr. |
Abbreviations, can be styled with custom CSS. |
|
|
For syntax highlight, see custom text roles. |
|
subscript |
Character-level markup … |
|
superscript |
… requires escaped spaces. |
|
Moin |
The title of a creative work (book, opera, coding project, etc.) Analog to HTML <cite>. This is the initial default text role. |
This is a longstanding Docutils TODO issue.
Additional Text Roles
Including the “html-roles.txt” standard definition file adds roles that correspond to HTML elements representing edits to the document and text-level semantics.
Markup |
Result |
Notes |
|---|---|---|
|
removed |
removed content |
|
inserted |
editional additions |
|
keyword |
highlight key words without marking them up as important |
|
dfn |
the defining instance of a term |
|
rôle |
alternate voice |
|
Ctrl X |
user input |
|
up |
highlight a run of text |
|
Tagline! |
content quoted from another source |
|
strike |
text that is inaccurate or no longer relevant |
|
|
computer output |
|
side comments |
|
|
anotation |
unarticulated annotations of, e.g, mispellings |
|
n |
variables |
Custom Text Roles
Custom interpreted text roles can be used to attach CSS class values to inline text and set the code language for syntax highlight (details).
Markup |
Result |
Notes |
|---|---|---|
.. role:: green
|
A dragon. |
Moin pre-defines some CSS classes for background color. Text with other classes can be styled with custom CSS. |
.. role:: blue(emphasis)
|
The Norwegian. |
Custom roles may be based on standard roles. |
.. role:: em-tt(emphasis)
:class: monospaced
|
emphasis and emphasis monospace |
Custom roles may be used as surrogate for nested inline markup. |
.. role:: tex(code)
:language: latex
|
|
There is highlight support for many languages. See also code blocks. |
The examples rely on Moin CSS classes missing in the external documentation.
Hyperlinks
Hyperlinks connect a hyperlink reference to a matching hyperlink target (details).
Matching of named references and targets is done after normalizing whitespace and case.
Anonymous references and targets are matched according to their order.
The target can also be embedded in the reference.
Internal Links
Page-internal links point to an anchor (named element or anonymous target) in the same document.
Markup |
Result |
Notes |
|---|---|---|
|
Simple reference and simple inline target. |
See simple reference names and inline targets. |
|
Links to a named paragraph, the MoinMoin logo, and a table named fruit salad. |
Put phrase references in backticks. |
|
It’s easy. |
Custom link text with embedded alias. |
__ simple_
|
Easy as pie. |
Custom link text with anonymous reference and anonymous indirect target. |
|
Section headings are implicit targets. |
For details, see implicit targets. |
.. _named paragraph:
This paragraph
is a target.
|
This paragraph is a target. |
Empty hyperlink targets mark the following element. |
The Moin rST converter interprets named hyperlink references without matching target as Wiki-internal links (whitespace is normalized).
Caution! Explicit targets, inline targets and section headings with the same name take precedence!
Docutils and Sphinx report unknown target names as errors.
Markup |
Result |
Notes |
|---|---|---|
|
item in default namespace |
|
|
item in specified namespace |
|
|
sibling item in current namespace |
|
|
fragment of a sibling item |
|
|
subitem of the current item |
Wiki-internal link targets may also be specified as URI References.
The syntax for Wiki-internal links differs from POSIX path syntax!
Markup |
Result |
Notes |
|---|---|---|
|
item in default namespace (as embedded URI reference) |
|
|
… with custom text |
|
|
item in specified namespace |
|
__ ../moin
|
sibling item (in an anonymous target) |
|
.. _MoinMoin: ../moin
|
… as image link via substitution reference The substitution text becomes the reference name, an explicit target maps it to a URI reference. |
|
|
subitem (with custom text) In URI context, whitespace is removed by default. Use an escaped space or percent encoding. |
External Links
External links point to an external resource (specified as URI).
Markup |
Result |
Notes |
|---|---|---|
|
Moin (https://moinmo.in/) supports rST. |
URIs and email addresses are turned into standalone hyperlinks. |
.. _moin:
https://moinmo.in/
|
Moin supports rST |
A named hyperlink reference and matching external target keep the details out of the text flow. |
|
Moin supports rST. |
Reference with custom link text and embedded URI. |
__ https://
moin-20.readthedocs.io/
en/latest/user/rest.html
|
Anonymous references and targets are handy for verbose or repeated link texts. |
|
|
||
|
Blockquotes
An indented text block is interpreted as a blockquote, a text part quoted from another source (details).
Blockquotes may contain arbitrary body elements.
To add an attribution, append a paragraph preceded by “
--” or an em-dash.
Markup |
Result |
|---|---|
preceding paragraph
It is my business to know
things. That is my trade.
-- Sherlock Holmes
succeeding paragraph
|
preceding paragraph
succeeding paragraph |
Lists
reStructuredText provides syntax for unordered lists, ordered lists, definition lists, field lists, and option lists. See line blocks for the rST alternative to a “bulletless” list.
Lists must be separated from other body elements by blank lines. Blank lines between list items are optional.
The list marker must not be indented.
List items may contain arbitrary body elements.
Unordered Lists
A text block which begins with a *, +, -, •, ‣, or ⁃,
followed by whitespace, is a bullet list item
(details).
Item content must be left-aligned and indented relative to the marker.
Content may start on the same line as the marker or on the next line.
The first content line sets the indentation level for this item.
Sub-items 2.1 to 2.2.2 show some valid input variants.
Markup |
Result |
|---|---|
- item 1
- item 2
- item 2.1
- item 2.2
- item 2.2.1
-
item
2.2.2
- item 3
|
|
Attention!
* Indented lists
* are nested
in a block quote.
|
Attention!
|
Ordered Lists
Ordered lists are similar to unordered lists, but use enumerators instead of bullets (details).
Ordered lists can be automatically enumerated using the
#character.The first enumerator determines the enumeration sequence, formatting type [3], and start value.
Sub-items 2.1 to 2.2.2 show some valid indentation variants.
Markup |
Result |
|---|---|
#. item 1
#. item 2
(a) item 2.1
(#) item 2.2
i) item
2.2.1
#)
item 2.2.2
#. item 3
|
|
4) item 4 with
C. uppercase
#. letters and
IV) custom
#) start values
|
|
HTML output ignores the formatting style and always uses a trailing period.
Definition Lists
Definition lists are formed by a term on one line followed by an indented definition or description on the next line (details).
Markup |
Result |
|---|---|
term
Description
term 2 : classifier
Optional *classifiers*
may be appended to the term.
|
|
Field Lists
Field lists are mappings from field names to field bodies (details).
Field bodies may start on the same line as the field name or on the next line.
Field list syntax is also used for options in directives and for bibliographic fields.
Markup |
Result |
|---|---|
:Version: 2.0b2
:Release Date: 2001-08-16
:Authors: - Joe Doe
- Erika Mustermann
- Jan Kowalski
|
|
Option lists
Option lists document the options of a command-line program (details).
There must be at least two spaces between the option(s) and the description (which may also start on the next line).
Markup |
Result |
|---|---|
-a Output all.
-c arg Output just arg.
--long Output all day long.
-f FILE, --file=FILE These
two options are synonyms.
|
|
Line Blocks
A line block is the reStructuredText syntax for forced line breaks (details). It resembles a plain (bulletless) list and is commonly used for verse and addresses
Line blocks may contain inline markup and nested line blocks. Block-level markup is not recognized.
Markup |
Result |
|---|---|
| Start lines with a vertical bar.
| Indented lines
| indicate a *nested* line block.
| Long lines may be
continued on the next line
(without vertical bar).
| In the output, all lines may wrap.
|
Start lines with a vertical bar.
Indented lines
indicate a nested line block.
Long lines may be
continued on the next line
(without vertical bar).
In the output, all lines may wrap.
|
Tables
There are four ways to specify tables in reStructuredText:
Simple tables are easy to create but limited.
Grid tables are complete but cumbersome to create.
CSV tables format CSV data as table.
List tables are easy to type and edit but don’t look like tables in the rST source.
Markup within the table cells is supported (you can even nest a table in a table cell). Table directives allow customization and adding a title/caption.
Simple Tables
Simple tables use a compact and easy to type table representation (details):
Equals signs (
=) are used for top and bottom table borders, and to separate header rows from the table body.Each line of text starts a new row, except when there is a blank cell in the first column.
Markup |
Result |
Notes |
|||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
==== ==== ====
.. A B
==== ==== ====
1 A1 B1
2 A2 B2
==== ==== ====
|
|
To start a row without content in the first column, use empty
comments ( |
|||||||||
=== === ===
In Out
------- ---
a b a+b
=== === ===
1 2 3
=== === ===
|
|
Lines of hyphens or equal signs crossing column boundaries indicate column spans. |
|||||||||
===== ================
row 1 a cell with
two *lines*
row 2 a cell with
two *paragraphs*
----- ----------------
row 3 a) list
#) item 2
===== ================
|
|
Cells of the first column must fit on one input line. Other cells may use continuation lines. Blank lines or lines of hyphens may be used to visually separate rows. |
|||||||||
See the “table” directive for styling options.
Grid Tables
Grid tables are a table representation via grid-like “ASCII art” (details).
Markup |
Result |
Notes |
|||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
+---+----+----+
| | A | B |
+===+====+====+
| 1 | A1 | B1 |
+---+----+----+
| 2 | A2 | B2 |
+---+----+----+
|
|
||||||||||
+--------------+
| column span |
+===+==========+
|* A| row span |
|* B| |
+---+ |
|foo| |
+---+----------+
|
|
Grid tables allow arbitrary body elements in all cells and both row and column spans. |
|||||||||
See the “table” directive for styling options.
Table Directives
Table directives use the “directive” syntax to pair the table content with a caption and/or options guiding the presentation.
csv-table
The csv-table directive supports CSV data (details).
Markup |
Result |
Notes |
|||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
.. csv-table::
:header-rows: 1
:stub-columns: 1
, A, B
1, A1, B1
2, A2, B2
|
|
Delimiter, quote character, escape character, and more can be customized with directive options. Cell content is parsed as rST. |
TODO: The :url: option to load data from an external source does not work with the syntax for wiki-internal items.
list-table
The list-table directive creates a table from data in a two-level bullet list (details).
Markup |
Result |
Notes |
|||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
.. list-table::
:header-rows: 1
:stub-columns: 1
* -
- A
- B
* - 1
- A1
- B1
* - 2
- A2
- B2
|
|
List-tables are suited for complex cell content. They are, for example, extensively used in the source of this document. |
table
Use a table directive to attach a table caption, a reference name, or customization options to Simple Tables and Grid Tables (details).
Markup |
Result |
Notes |
||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
.. table:: Fruits
:name:
fruit salad
:class: yellow
moin-sortable
no-borders
===== ====== ===
Fruit Colour #
===== ====== ===
apple red 5
plum purple 3
kiwi brown 17
===== ====== ===
|
|
The “class” option allows styling with Moin CSS classes or custom CSS. (This also works with CSV tables and list tables.) The “name” option provides a target for internal links. |
Limitations
In comparison to other markup formats, you may miss some features that are not supported in reStructuredText:
There is no syntax for text alignment in cells or columns.
There is no syntax for table footer rows.
Attaching colour to individual rows or cells is not supported.
Attaching CSS class values to individual rows or cells is not universally supported.
Some features of reStructuredText tables are currently not supported by Moin (TODO):
The table caption/title is ignored.
The align, width, widths, and stub-columns options are ignored.
Preformatted Text
In a preformatted text block, line breaks and whitespace (except the minimal common indentation) are preserved. The font defaults to “monospace”.
Literal Blocks
A double-colon (::) at the end of a line or on a line of its own
starts a literal block (details).
Markup |
Result |
|---|---|
In a literal block::
Whitespace and line
breaks are preserved.
*Markup* is `ignored\ `_.
|
In a literal block: Whitespace and line
breaks are preserved.
*Markup* is `ignored\ `_.
|
Code Blocks
The “code” directive starts a code block. Specify the content language to enable syntax highlight.
Markup |
Result |
|---|---|
.. code:: rst
.. |registered| replace::
:sup:`®`
:ltrim:
|
.. |registered| replace::
:sup:`®`
:ltrim:
|
Parsed Literal Blocks
The “parsed-literal” directive starts a parsed literal block. The content is parsed for inline markup.
Markup |
Result |
|---|---|
.. parsed-literal::
A *pre*\ formatted block
with `text formatting_`.
|
A preformatted block with text formatting. |
Directives
The directive markup syntax provides an extension mechanism for reStructuredText (details).
A set of standard directives is described in the reStructuredText Directives document. This section introduces a selection. See also Table Directives and Preformatted Text.
Applications may add domain-specific directives. Moin adapts the “contents” and “include” directives and adds the “macro” and “parser” directives.
Admonitions
Admonitions are used to draw the reader’s attention to an important information (details).
There are nine specific admonition types (”attention”, “caution”, “danger”, “error” [4], “hint”, “important”, “note”, “tip”, and “warning”) and one “generic” admonition.
Markup |
Result |
|---|---|
.. attention:: Mind the gap!
|
Attention Mind the gap! |
.. caution:: Use
admonitions sparingly.
|
Caution Use admonitions sparingly. |
.. danger:: Slippery
when wet!
|
Danger Slippery when wet! |
.. error::
Something went wrong
|
Error Something went wrong |
.. hint::
Think before you speak.
|
Hint Think before you speak. |
.. important::
Back up your data!
|
Important Back up your data! |
.. note::
:name: note
The "name" option
provides a target
for `internal links`_.
|
Note The “name” option provides a target for internal links. |
.. tip:: Be consistent.
|
Tip Be consistent. |
.. warning:: Strong prose
may provoke
extreme mental exertion.
|
Warning Strong prose may provoke extreme mental exertion. |
.. admonition:: Custom
The generic `"admonition"
directive`_ expects
a title as argument.
|
Custom The generic “admonition” directive expects a title as argument. |
“Error” admonitions are also used to highlight rST syntax errors.
Images
Images are inserted with the “image” directive. For inline images, use a substitution definition.
Moin does not support length units in the “width” and “height” options. Unitless numbers work fine.
Markup |
Result |
Notes |
|---|---|---|
.. image:: help-common/logo.svg
:width: 100
:height: 150
:alt: [MoinMoin logo]
:name: MoinMoin logo
:target: help-en/Home
|
A block-level image. The “name” option provides a target for internal links. The “target” option makes the image “clickable”. |
|
.. |MoinMoin| image::
help-common/logo.svg
:height: 18
|
The substitution definition may be referenced more than once (cf. Wiki-Internal Links). |
|
.. |Python| image:: https://
docs.python.org/3/_static/py.svg
:height: 18
|
Images from external sources may be blocked by the browser for security or privacy reasons. |
Videos are recognized by the file extension.
TODO: currently, “width” and “alt” options are ignored by Moin.
A right or left aligned image (using the “align” option) lets the following elements float up.
In Moin, images are not enclosed within a block level element so several images declared successively without any positioning will be displayed in a horizontal row:
In the external documentation, most image-URIs do not work and the alternate text is shown.
Figures
A figure consists of an image, a caption, and an optional legend. Figures are declared with the “figure” directive.
Markup |
Result |
|---|---|
.. figure:: help-common/logo.svg
:height: 50
:alt: [white M in blue circle]
Moin Logo
The image URI does not work in
the `external documentation`_.
|
Moin Logo The image URI does not work in the external documentation. |
Inclusions
The “include” directive is adapted by Moin to include Wiki items.
No directive options are supported in Moin.
The special syntax for standard definition files works.
Markup |
Result |
|---|---|
.. include:: help-common/audio.mp3
|
Not shown, because it prevents compilation of the external documentation. |
.. include:: <html-roles.txt>
|
The roles defined in the included file can be used in the document. Cf. additional text roles. |
Table of Contents
The “contents” directive generates a table of contents.
Markup |
Result |
|---|---|
.. contents::
:depth: 3
|
See the ToC at the top. |
Backslash Escapes
A backslash escapes the following character (details).
Markup |
Result |
Notes |
|---|---|---|
|
hot *dogs* C:\WINDOWS |
The escaped character represents itself. |
|
H2O |
Escaped whitespace is removed, … |
|
… except in URI context (where whitespace is removed by default). |
Error Handling
Problems with a severity level above the report level generate system messages.
Markup |
Result |
|---|---|
|
Unbalanced *inline markup triggers a warning. |
Comments
A comment is a text block that starts with “
..” and ends with the first non-indented line (details).An “empty comment” followed by a blank line does not consume any indented text. It serves to terminate a preceding construct.
In Moin, comments may be made visible/invisible by clicking the “Comments” link in the “Item Views” menu/toolbar.
Tip: to prevent mix-up with other “explicit markup blocks”, start the text on the line below the “
..“.Markup
Result
is a citation.