Quick reStructuredText

http://docutils.sourceforge.net/docs/rst/quickref.html
Being a cheat-sheet for reStructuredText
Updated 2003-06-10

Copyright: This document has been placed in the public domain.

マークアップの完全な詳細はreStructuredTextページにあります。このドキュメントは心覚えとして意図しているだけです。

"(details)"のようなリンクは完全なreStructuredText specificationドキュメントのHTMLバージョンの中を指しています。これらは相対リンクです。つながらない場合は、master "Quick reStructuredText"ドキュメントを使ってください。

目次

インラインマークアップ

(詳細)

インラインマークアップはテキスト内部の語と句が(イタリック体とボールド体のような)字体と(ハイパーリンクのような)機能を持てるようにします。

平文 典型的な結果 注釈
*emphasis* emphasis 通常イタリック体にされます。
**strong emphasis** strong emphasis 通常ボールド体にされます。
`interpreted text` (右の注釈を参照) 解釈されたテキストのレンダリングと意味は範囲もしくは用途に依存します。インデックスのエントリや(プログラム識別子のような)説明的マークアップのようなものに使うことができます。
``inline literal`` inline literal 通常固定スペーステキストにされます。スペースは維持されるはずですが、改行はそうではないでしょう。
reference_ reference 単純な一語ハイパーリンク参照。ハイパーリンクを参照してください。
`phrase reference`_ phrase reference 空白または句読点をもつハイパーリンク参照はバッククオートで引用される必要があります。ハイパーリンクを参照してください。
anonymous__ anonymous 一つではなく二つの下線を使い、単純参照と句参照の両方を無名にすることができます(参照テキストの参照先は重複しません)。ハイパーリンクを参照してください。
_`inline internal target` inline internal target テキスト内部の相互参照。ハイパーリンクを参照してください。
|substitution reference| (右の注釈を参照) 置換定義から結果を置き換えます。それはテキスト、画像、ハイパーリンク、あるいは、これらと他のものの組み合わせであってもよい。
footnote reference [1]_ footnote reference 1 脚注を参照してください。
citation reference [CIT2002]_ citation reference [CIT2002] 引用を参照してください。
http://docutils.sf.net/ http://docutils.sf.net/ スタンドアロンのハイパーリンク。

アスタリスク、バッククオート、垂直バーおよび下線はインラインの区切り文字です。アスタリスク、バッククオートおよび垂直バーはクオート記号のように振る舞います。マークアップされた語や句を取り巻く文字にマッチングし、空白や他のクオートが外側に必要です。そして、空白がその内部に存在することはできません。インラインの区切り文字をその文字のまま使いたい場合は、バックスラッシュでエスケープするか、もしくはバッククオートでそれらをクオートする、すなわちインラインリテラルを使用してください。

詳しく説明すると、reStructuredText仕様書によれば、インラインマークアップの中では以下のルールが開始文字列と終了文字列(インラインマークアップ区切り文字)に適用する:

  1. 開始文字列はテキストブロックの先頭になければならない。もしくは、空白または  ' " ( [ {のいずれか、あるいは <がその直前になければならない。
  2. 開始文字列のすぐ後に非空白文字が続かなければなりません。
  3. 終了文字列のすぐ前に非空白文字がなければなりません。
  4. 終了文字列は(ドキュメントの最後または空行が続く)テキストブロックの最後になければならない。もしくは、すぐ後ろに空白か ' " . , : ; ! ? - ) ] } / \あるいは >が続いていなければならない。
  5. 開始文字列のすぐ前に ' " ( [ {あるいは <の一つがある場合、 ' " ) ] }あるいは >の中の対応する文字がすく後に続いてはならない。
  6. 終了文字列は開始文字列から少なくとも一つの文字によって隔てられていなければならない。
  7. 開始文字列や終了文字列に先立つエスケープされていないバックスラッシュはインラインリテラルの終了文字列を除いたマークアップの認識を無効にします。

インラインマークアップは入れ子にできないかもしれないことも覚えておいてください(ただし、インラインリテラルはその他のインラインマークアップ区切り文字のどれかを含むことができることは除きます。しかし、それは重要でありません。なぜなら、何も処理されないからです)。

バックスラッシュを使ったエスケープ

(詳細)

reStructuredTextはマークアップ文字に与えられた特別な意味を上書きしてリテラル文字自身を得るためにバックスラッシュ("\")を使います。リテラルのバックスラッシュを得るためには、エスケープされたバックスラッシュ("\\")を仕様してください。例えば:

Raw reStructuredText Typical result
*escape* ``with`` "\" escape with ""
\*escape* \``with`` "\\" *escape* ``with`` "\"

In Python strings it will, of course, be necessary to escape any backslash characters so that they actually reach reStructuredText. The simplest way to do this is to use raw strings:

Python string Typical result
r"""\*escape* \`with` "\\"""" *escape* `with` "\"
 """\\*escape* \\`with` "\\\\"""" *escape* `with` "\"
 """\*escape* \`with` "\\"""" escape with ""

Section Structure

(details)

Plain text Typical result
=====
Title
=====
Subtitle
--------
Titles are underlined (or over-
and underlined) with a printing
nonalphanumeric 7-bit ASCII
character. Recommended choices
are "``= - ` : ' " ~ ^ _ * + # < >``".
The underline/overline must be at
least as long as the title text.
Title

Subtitle

Titles are underlined (or over- and underlined) with a printing nonalphanumeric 7-bit ASCII character. Recommended choices are "= - ` : ' " ~ ^ _ * + # < >". The underline/overline must be at least as long as the title text.

Paragraphs

(details)

Plain text Typical result

This is a paragraph.

Paragraphs line up at their left
edges, and are normally separated
by blank lines.

This is a paragraph.

Paragraphs line up at their left edges, and are normally separated by blank lines.

Bullet Lists

(details)

Plain text Typical result
Bullet lists:

- This is item 1
- This is item 2

- Bullets are "-", "*" or "+".
  Continuing text must be aligned
  after the bullet and whitespace.

Note that a blank line is required
before the first item and after the
last, but is optional between items.

Bullet lists:
  • This is item 1
  • This is item 2
  • Bullets are "-", "*" or "+". Continuing text must be aligned after the bullet and whitespace.

Note that a blank line is required before the first item and after the last, but is optional between items.

Enumerated Lists

(details)

Plain text Typical result
Enumerated lists:

3. This is the first item
4. This is the second item
5. Enumerators are arabic numbers,
   single letters, or roman numerals
6. List items should be sequentially
   numbered, but need not start at 1
   (although not all formatters will
   honour the first index).

Enumerated lists:
  1. This is the first item
  2. This is the second item
  3. Enumerators are arabic numbers, single letters, or roman numerals
  4. List items should be sequentially numbered, but need not start at 1 (although not all formatters will honour the first index).

Definition Lists

(details)

Plain text Typical result
Definition lists:

what
  Definition lists associate a term with
  a definition.

how
  The term is a one-line phrase, and the
  definition is one or more paragraphs or
  body elements, indented relative to the
  term. Blank lines are not allowed
  between term and definition.
Definition lists:
what
Definition lists associate a term with a definition.
how
The term is a one-line phrase, and the definition is one or more paragraphs or body elements, indented relative to the term. Blank lines are not allowed between term and definition.

Field Lists

(details)

Plain text Typical result
:Authors:
    Tony J. (Tibs) Ibbs,
    David Goodger

    (and sundry other good-natured folks)

:Version: 1.0 of 2001/08/08
:Dedication: To my father.

Authors: Tony J. (Tibs) Ibbs, David Goodger
(and sundry other good-natured folks)
Version:1.0 of 2001/08/08
Dedication:To my father.

Field lists are used as part of an extension syntax, such as options for directives, or database-like records meant for further processing. Field lists may also be used as generic two-column table constructs in documents.

Option Lists

(details)

Plain text Typical result

-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
/V            DOS/VMS-style options too

-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

/V

DOS/VMS-style options too

There must be at least two spaces between the option and the description.

Literal Blocks

(details)

Plain text Typical result
A paragraph containing only two colons
indicates that the following indented
text is a literal block.

::

  Whitespace, newlines, blank lines, and
  all kinds of markup (like *this* or
  \this) is preserved by literal blocks.

  The paragraph containing only '::'
  will be omitted from the result.

The ``::`` may be tacked onto the very
end of any paragraph. The ``::`` will be
omitted if it is preceded by whitespace.
The ``::`` will be converted to a single
colon if preceded by text, like this::

  It's very convenient to use this form.

Literal blocks end when text returns to
the preceding paragraph's indentation.
This means that something like::

      We start here
    and continue here
  and end here.

is possible.

A paragraph containing only two colons indicates that the following indented text is a literal block.

  Whitespace, newlines, blank lines, and
  all kinds of markup (like *this* or
  \this) is preserved by literal blocks.

  The paragraph containing only '::'
  will be omitted from the result.

The :: may be tacked onto the very end of any paragraph. The :: will be omitted if it is preceded by whitespace. The :: will be converted to a single colon if preceded by text, like this:

  It's very convenient to use this form.

Literal blocks end when text returns to the preceding paragraph's indentation. This means that something like:

      We start here
    and continue here
  and end here.

is possible.

Block Quotes

(details)

Plain text Typical result
Block quotes are just:

    Indented paragraphs,

        and they may nest.

Block quotes are just:

Indented paragraphs,

and they may nest.

Doctest Blocks

(details)

Plain text Typical result

Doctest blocks are interactive
Python sessions. They begin with
"``>>>``" and end with a blank line.

>>> print "This is a doctest block."
This is a doctest block.

Doctest blocks are interactive Python sessions. They begin with ">>>" and end with a blank line.

>>> print "This is a doctest block."
This is a doctest block.

"The doctest module searches a module's docstrings for text that looks like an interactive Python session, then executes all such sessions to verify they still work exactly as shown." (From the doctest docs.)

Tables

(details)

There are two syntaxes for tables in reStructuredText. Grid tables are complete but cumbersome to create. Simple tables are easy to create but limited (no row spans, etc.).

Plain text Typical result

Grid table:

+------------+------------+-----------+
| Header 1   | Header 2   | Header 3  |
+============+============+===========+
| body row 1 | column 2   | column 3  |
+------------+------------+-----------+
| body row 2 | Cells may span columns.|
+------------+------------+-----------+
| body row 3 | Cells may  | - Cells   |
+------------+ span rows. | - contain |
| body row 4 |            | - blocks. |
+------------+------------+-----------+

Grid table:

Header 1 Header 2 Header 3
body row 1 column 2 column 3
body row 2 Cells may span columns.
body row 3 Cells may
span rows.
  • Cells
  • contain
  • blocks.
body row 4

Simple table:

=====  =====  ======
   Inputs     Output
------------  ------
  A      B    A or B
=====  =====  ======
False  False  False
True   False  True
False  True   True
True   True   True
=====  =====  ======

Simple table:

Inputs Output
A B A or B
False False False
True False True
False True True
True True True

Transitions

(details)

Plain text Typical result

A transition marker is a horizontal line
of 4 or more repeated punctuation
characters.

------------

A transition should not begin or end a
section or document, nor should two
transitions be immediately adjacent.

A transition marker is a horizontal line of 4 or more repeated punctuation characters.


A transition should not begin or end a section or document, nor should two transitions be immediately adjacent.

Transitions are commonly seen in novels and short fiction, as a gap spanning one or more lines, marking text divisions or signaling changes in subject, time, point of view, or emphasis.

Explicit Markup

Explicit markup blocks are used for constructs which float (footnotes), have no direct paper-document representation (hyperlink targets, comments), or require specialized processing (directives). They all begin with two periods and whitespace, the "explicit markup start".

Footnotes

(details)

Plain text Typical result
Footnote references, like [5]_.
Note that footnotes may get
rearranged, e.g., to the bottom of
the "page".

.. [5] A numerical footnote. Note
   there's no colon after the ``]``.

Footnote references, like 5. Note that footnotes may get rearranged, e.g., to the bottom of the "page".


[5] A numerical footnote. Note there's no colon after the ].

Autonumbered footnotes are
possible, like using [#]_ and [#]_.

.. [#] This is the first one.
.. [#] This is the second one.

They may be assigned 'autonumber
labels' - for instance,
[#fourth]_ and [#third]_.

.. [#third] a.k.a. third_

.. [#fourth] a.k.a. fourth_

Autonumbered footnotes are possible, like using 1 and 2.

They may be assigned 'autonumber labels' - for instance, 4 and 3.


[1] This is the first one.
[2] This is the second one.
[3] a.k.a. third
[4] a.k.a. fourth

Auto-symbol footnotes are also
possible, like this: [*]_ and [*]_.

.. [*] This is the first one.
.. [*] This is the second one.

Auto-symbol footnotes are also possible, like this: * and .


[*] This is the first symbol footnote
[†] This is the second one.

The numbering of auto-numbered footnotes is determined by the order of the footnotes, not of the references. For auto-numbered footnote references without autonumber labels ("[#]_"), the references and footnotes must be in the same relative order. Similarly for auto-symbol footnotes ("[*]_").

Citations

(details)

Plain text Typical result
Citation references, like [CIT2002]_.
Note that citations may get
rearranged, e.g., to the bottom of
the "page".

.. [CIT2002] A citation
   (as often used in journals).

Citation labels contain alphanumerics,
underlines, hyphens and fullstops.
Case is not significant.

Given a citation like [this]_, one
can also refer to it like this_.

.. [this] here.

Citation references, like [CIT2002]. Note that citations may get rearranged, e.g., to the bottom of the "page".

Citation labels contain alphanumerics, underlines, hyphens and fullstops. Case is not significant.

Given a citation like [this], one can also refer to it like this.


[CIT2002] A citation (as often used in journals).
[this] here.

ハイパーリンクターゲット

(details)

External Hyperlink Targets

Plain text Typical result
External hyperlinks, like Python_.

.. _Python: http://www.python.org/

Fold-in form
Indirect hyperlinks, like Python.
Call-out form
External hyperlinks, like Python.


Python: http://www.python.org/

"Fold-in" is the representation typically used in HTML documents (think of the indirect hyperlink being "folded in" like ingredients into a cake), and "call-out" is more suitable for printed documents, where the link needs to be presented explicitly, for example as a footnote.

Internal Hyperlink Targets

Plain text Typical result
Internal crossreferences, like example_.

.. _example:

This is an example crossreference target.

Fold-in form
Internal crossreferences, like example

This is an example crossreference target.

Call-out form
Internal crossreferences, like example

example:
This is an example crossreference target.

Indirect Hyperlink Targets

(details)

Plain text Typical result
Python_ is `my favourite
programming language`__.

.. _Python: http://www.python.org/

__ Python_

Python is my favourite programming language.

The second hyperlink target (the line beginning with "__") is both an indirect hyperlink target (indirectly pointing at the Python website via the "Python_" reference) and an anonymous hyperlink target. In the text, a double-underscore suffix is used to indicate an anonymous hyperlink reference. In an anonymous hyperlink target, the reference text is not repeated. This is useful for references with long text or throw-away references, but the target should be kept close to the reference to prevent them going out of sync.

Implicit Hyperlink Targets

(details)

Section titles, footnotes, and citations automatically generate hyperlink targets (the title text or footnote/citation label is used as the hyperlink name).

Plain text Typical result
Titles are targets, too
=======================
Implict references, like `Titles are
targets, too`_.
Titles are targets, too

Implict references, like Titles are targets, too.

Directives

(details)

Directives are a general-purpose extension mechanism, a way of adding support for new constructs without adding new syntax. For a description of all standard directives, see reStructuredText Directives.

Plain text Typical result
For instance:

.. image:: images/ball1.gif

For instance:

ball1

Substitution References and Definitions

(details)

Substitutions are like inline directives, allowing graphics and arbitrary constructs within text.

Plain text Typical result
The |biohazard| symbol must be used on containers used to dispose of medical waste.

.. |biohazard| image:: biohazard.png

The biohazard symbol must be used on containers used to dispose of medical waste.

Comments

(details)

Any text which begins with an explicit markup start but doesn't use the syntax of any of the constructs above, is a comment.

Plain text Typical result
.. This text will not be shown
   (but, for instance, in HTML might be
   rendered as an HTML comment)
 
An empty "comment" does not
"consume" following blocks.

..

        So this block is not "lost",
        despite its indentation.

An empty "comment" does not "consume" following blocks.
So this block is not "lost", despite its indentation.

Getting Help

Users who have questions or need assistance with Docutils or reStructuredText should post a message to the Docutils-Users mailing list. The Docutils project web site has more information.


Authors: Tibs (tibs@tibsnjoan.co.uk) and David Goodger (goodger@users.sourceforge.net)