ReStructuredText explained

ReStructuredText should not be confused with Representational state transfer.

reStructuredText
Extension:.rst
Mime:
  • text/x-rst
  • text/prs.fallenstein.rst
Owner:David Goodger
Latest Release Version:Revision 8407
Open:Public domain

reStructuredText (RST, ReST, or reST) is a file format for textual data used primarily in the Python programming language community for technical documentation.

It is part of the Docutils project of the Python Doc-SIG (Documentation Special Interest Group), aimed at creating a set of tools for Python similar to Javadoc for Java or Plain Old Documentation (POD) for Perl. Docutils can extract comments and information from Python programs, and format them into various forms of program documentation.[1]

In this sense, reStructuredText is a lightweight markup language designed to be both processable by documentation-processing software such as Docutils, and be easily readable by human programmers who are reading and writing Python source code.

History

reStructuredText evolved from an earlier lightweight markup language called StructuredText[2] (developed by Zope). There were a number of problems with StructuredText, and reST was developed to address them.[3] The name reStructuredText was chosen to indicate that reST is a "revised, reworked, and reinterpreted StructuredText."[4]

Parts of the reST syntax were inspired by the Setext language from the early 1990s. Elements of the common RFC822 Internet Message Format and Javadoc formats were also considered for inclusion in the design.[5]

reStructuredText was first released in June 2001.[6] It began to see significant use in the Python community in 2002.[7]

Reference implementation

The reference implementation of the reST parser is a component of the Docutils text processing framework in the Python programming language, but other parsers are available.

The Docutils project has not registered any MIME type for reStructuredText nor designated any unregistered MIME type as official, but documents the MIME type text/x-rst as in de facto use by, for example, the build system for the Python website.[8] The same MIME type is used in the freedesktop.org file type database used by desktop environments on Linux.[9] Another MIME type,, was registered as a vanity MIME type by a third party in 2003 to represent reStructuredText, and remains the only IANA-registered MIME type for reStructuredText,[10] although it is not acknowledged as such by the Docutils project.[8]

Applications

reStructuredText is commonly used for technical documentation, for example, in documentation of Python libraries.[11] However, it is suitable for a wide range of texts.

Since 2008, reST has been a core component of Python's Sphinx document generation system.

Trac also supports reStructuredText,[12] as do GitHub and Bitbucket.

In 2011, Distributed Proofreaders, which prepared texts for Project Gutenberg, was considering adoption of reST as a basic format from which other ebook formats could be generated.[13]

In July 2016 the Linux kernel project decided to transition from DocBook based documentation to reStructuredText and the Sphinx toolchain.[14] [15]

The software build tool CMake switched from a custom markup language to reStructuredText in version 3.0 for its documentation.[16]

Examples

Text using rST syntaxCorresponding HTML produced by an rST processorText viewed in a browser
=Document Heading

=

Heading

Sub-heading-----------

Paragraphs are separated by a blank line.

Document Heading

Heading

Sub-heading

Paragraphs are separatedby a blank line.

Document Heading

Heading

Sub-heading

Paragraphs are separatedby a blank line.

Text attributes *emphasis*, **strong emphasis**, ``monospace``.

Horizontal rule:

----

Text attributes emphasis,strong emphasis, monospace.

Horizontal rule:


Text attributes emphasis,strong emphasis, monospace.

Horizontal rule:


Bullet list:
  • apples
  • oranges
  • pears

Numbered list:

1. lather2. rinse3. repeat

Nested lists:

1. fruits

* apple * banana

2. vegetables

* carrot * broccoli

Bullet list:

  • apples
  • oranges
  • pears

Numbered list:

  1. lather
  2. rinse
  3. repeat

Nested lists:

  1. fruits
    • apple
    • banana
  2. vegetables
    • carrot
    • broccoli

Bullet list:
  • apples
  • oranges
  • pears

Numbered list:

  1. lather
  2. rinse
  3. repeat

Nested lists:

  1. fruits
    • apple
    • banana
  2. vegetables
    • carrot
    • broccoli
An `example `_.

.. image:: Icon-pictures.png :alt: Image

If text is indented, it is treated as a block quotation:

Should array indices start at 0 or 1? My suggested compromise of 0.5 was rejected without, I thought, proper consideration. -- Stan Kelly-Bootle

reST uses :: at the end of the paragraph prior to a pre-formatted code block::

Y = lambda f: (lambda x: f(x(x)))(lambda x: f(x(x)))

Multi-line text canspan in tableswith a pipe character.

An example.

Image

If text is indented, it is treated as a block quotation, and the final attribution line is handled automatically:

Should array indices start at 0 or 1?My suggested compromise of 0.5 was rejected without, I thought, proper consideration.-- Stan Kelly-Bootle

reST uses :: at the end of the paragraph prior to a pre-formatted code block:

class="literal-block">
Y = lambda f: (lambda x: f(x(x)))(lambda x: f(x(x)))

Multi-line text can
span in tables
with a pipe character.

An example.

If text is indented, it is treated as a block quotation, and the final attribution line is handled automatically:

Should array indices start at 0 or 1?My suggested compromise of 0.5 was rejected without, I thought, proper consideration.-- Stan Kelly-Bootle

reST uses :: at the end of the paragraph prior to a pre-formatted code block:

class="literal-block">
Y = lambda f: (lambda x: f(x(x)))(lambda x: f(x(x)))

Multi-line text can
span in tables
with a pipe character.

See also

External links

Notes and References

  1. Web site: Mertz . David . XML Matters: reStructuredText . . 2003-02-01 . 2016-10-05 .
  2. Web site: zope.structuredtext Documentation . Read the Docs . 2022-08-16.
  3. Web site: Goodger . David . Problems With StructuredText . Docutils Project . 2016-05-24 . 2022-08-16.
  4. Web site: Goodger . David . Docutils FAQ (Frequently Asked Questions) . Docutils Project . 2016-02-26 . 2016-10-05.
  5. Web site: Goodger . David . A Record of reStructuredText Syntax Alternatives . Docutils Project . docutils.sourceforge.io . 2022-08-16 . 2022-04-02.
  6. Web site: Project: reStructuredText - File List . live . https://web.archive.org/web/20011019081106/http://sourceforge.net/project/showfiles.php?group_id=7050 . 19 October 2001 . 5 February 2023 . SourceForge.
  7. Web site: Introduction to reStructuredText . Write The Docs . 2022-06-25.
  8. Web site: What's the official MIME type for reStructuredText data? in Docutils FAQ. . Docutils Project . 2017-12-20 .
  9. Web site: freedesktop.org.xml.in . shared-mime-info . freedesktop.org.
  10. Web site: text/prs.fallenstein.rst . . 2003-10-02 . Benja . Fallenstein . ReStructuredText was designed and implemented by David Goodger, not by the registrant of this media type. The registrant just happened to have need of a registered media type for it. […] Change control for this registration is currently with Benja Fallenstein. (If anybody more intimately involved with ReStructuredText wants to take it over, it will be surrendered gladly.).
  11. Web site: Goodger. David. PEP 287 -- reStructuredText Docstring Format. 2002-04-02. Python Software Foundation. 2016-10-05.
  12. Web site: reStructuredText Support in Trac. 2016-09-13. Trac. 2016-10-05.
  13. Web site: Newby . Greg . Minutes of 2010 December 11 meeting . Distributed Proofreaders . 2011-01-08 . registration . 2011-01-08 .
  14. Web site: Kernel documentation with Sphinx, part 1: how we got here . LWN.net . 2016-07-06 . 2016-10-27 .
  15. Web site: Sphinx. Linux kernel. Wikipedia. 2024-04-02. 2024-04-02.
  16. Web site: CMake 3.0.0 Release Notes . Kitware, Inc. . 2014-06-10 . 2016-10-05 .