Hubbry Logo
ReStructuredTextReStructuredTextMain
Open search
ReStructuredText
Community hub
ReStructuredText
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contribute something
ReStructuredText
ReStructuredText
from Wikipedia
reStructuredText
reStructuredText logo
Filename extension
.rst
Internet media type
  • text/x-rst
  • text/prs.fallenstein.rst
Developed byDavid Goodger
Initial releaseJune 1, 2001; 24 years ago (2001-06-01)[1]
Latest release
Revision 8407
October 29, 2019; 5 years ago (2019-10-29)
Open format?Public domain
Websitedocutils.sourceforge.io/rst.html

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.[2]

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

[edit]

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

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.[6]

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

Reference implementation

[edit]

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, text/prs.fallenstein.rst, 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

[edit]

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][needs update]

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

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

Examples

[edit]
Text using rST syntax Corresponding HTML produced by an rST processor Text viewed in a browser
================
Document Heading
================

Heading
=======

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

Paragraphs are separated 
by a blank line.
<h1>Document Heading</h1>

<h2>Heading</h2>

<h3>Sub-heading</h3>

<p>Paragraphs are separated
by a blank line.</p>
Document Heading
Heading
Sub-heading

Paragraphs are separated by a blank line.

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

Horizontal rule:

----
<p>Text attributes <em>emphasis</em>,
<strong>strong emphasis</strong>, <code>monospace</code>.</p>

<p>Horizontal rule:</p>

<hr />
Text attributes emphasis, strong emphasis, monospace.

Horizontal rule:


Bullet list:

* apples
* oranges
* pears

Numbered list:

1. lather
2. rinse
3. repeat

Nested lists:

1. fruits

   * apple
   * banana

2. vegetables

   * carrot
   * broccoli
<p>Bullet list:</p>

<ul>
  <li>apples</li>
  <li>oranges</li>
  <li>pears</li>
</ul>

<p>Numbered list:</p>

<ol>
  <li>lather</li>
  <li>rinse</li>
  <li>repeat</li>
</ol>

<p>Nested lists:</p>

<ol>
  <li>fruits
    <ul>
      <li>apple</li>
      <li>banana</li>
    </ul>
  </li>
  <li>vegetables
    <ul>
      <li>carrot</li>
      <li>broccoli</li>
    </ul>
  </li>
</ol>
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 <http://example.com>`_.

.. 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 can
| span in tables
| with a pipe character.
<p>An <a href="http://example.com">example</a>.</p>

<p><img alt="Image" src="Icon-pictures.png" /></p>

<p>If text is indented, it is treated as a block quotation, and the final attribution line is handled automatically:</p>
<blockquote>
Should array indices start at 0 or 1?
My suggested compromise of 0.5 was rejected without, I thought, proper consideration.
-- Stan Kelly-Bootle</blockquote>

<p>reST uses :: at the end of the paragraph prior to a pre-formatted code block:</p>
<pre class="literal-block">
Y = lambda f: (lambda x: f(x(x)))(lambda x: f(x(x)))
</pre>

<p>Multi-line text can<br/>span in tables<br/>with a pipe character.</p>
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:

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

[edit]

References

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
reStructuredText () is an easy-to-read, what-you-see-is-what-you-get markup syntax and parser system designed for creating structured documents that are both human-readable in their source form and convertible to output formats such as , , or XML. It uses simple, unobtrusive constructs to denote elements like headings, lists, and emphasis, making it suitable for inline program , standalone articles, and across various domains. Developed as part of the Docutils project, reStructuredText emphasizes principles of readability, simplicity, intuitiveness, and extensibility, ensuring unambiguous parsing with a single possible output interpretation. Originating from revisions to earlier lightweight markup systems like StructuredText (introduced in 1996 by Jim Fulton for Zope documentation) and Setext, reStructuredText was spearheaded by David Goodger in the late 1990s within the Python community. The first draft specification was posted in November 2000 to the Doc-SIG (Documentation ), followed by refinements in 2001 that addressed ambiguities in predecessors and incorporated feedback for Python docstring standards (as outlined in 256, 257, and 258). By April 2002, it was integrated into the initial release of Docutils (version 0.1), evolving into a core component of this open-source Python documentation processing framework. Key features of reStructuredText include support for hierarchical section structures (using underlined titles), bulleted and enumerated , definition and field lists, literal blocks for code, and interpreted text roles for semantic markup like hyperlinks or citations. Directives extend its functionality for complex elements such as tables, images, and admonitions (e.g., notes or warnings), while the parser handles inline markup for emphasis (italics), strong text (bold), and literal text (code). These elements enable scalable use from short docstrings to full-length books, with the system remaining language-neutral and adaptable to non-technical content. Widely adopted in the Python ecosystem, reStructuredText serves as the default markup for tools like Sphinx (a ) and is integral to projects such as the Python standard library documentation. Its parser, implemented in Python, processes source files into Docutils' internal Document Tree representation, facilitating transformations via writers for diverse outputs and promoting reusable, maintainable documentation workflows. Despite its origins in Python, reStructuredText's design allows broad applicability, including simple web pages and collaborative editing environments where plain text remains the primary authoring medium.

Overview

Definition and Purpose

reStructuredText (reST) is a lightweight, markup syntax designed primarily for technical , especially within the Python programming community. It functions as an easy-to-read, what-you-see-is-what-you-get format that uses simple and intuitive constructs to indicate document structure, making it suitable for inline program like Python docstrings, web pages, and standalone documents. The core purpose of reStructuredText is to enable the creation of highly readable source files that establish standard conventions for plaintext structure and can be processed into structured data formats. Through parsers such as those provided by the Docutils project, it facilitates conversion to various output formats, including , PDF, , and , allowing developers and writers to produce professional documentation from maintainable, human-focused text. reStructuredText files commonly use the .rst extension and are placed in the , which imposes no license requirements or restrictions on use. It was initiated by David Goodger, with the first draft specification posted in November 2000, later becoming a key component of the Docutils project upon its release in 2002, aimed at standardizing documentation practices in Python. In comparison to predecessors like , which offers no built-in structural elements, or , which often results in verbose and less source-readable code, reStructuredText achieves a balance of simplicity, readability, and expressive power for structured content.

Design Principles

reStructuredText (reST) is designed with a strong emphasis on readability, ensuring that the marked-up remains accessible and intuitive for authors without requiring specialized knowledge of the . This what-you-see-is-what-you-get () approach prioritizes minimal processing overhead, allowing documents to function as even before conversion, while unobtrusive markup elements blend seamlessly into the content for casual readers. A core principle is extensibility, achieved through directives and roles that enable users to introduce custom markup and functionality without modifying the fundamental syntax. This supports the addition of complex or domain-specific elements, such as custom interpretations or substitutions, fostering adaptability for diverse needs while maintaining a consistent core. Influenced by longstanding plain text conventions, including those from email signatures, files, and earlier systems like Setext, reST ensures backward compatibility with unstructured text by treating unmarked content as literal . This heritage allows legacy documents to be incrementally enhanced without disruption, promoting a smooth transition to structured markup. The system favors semantic markup over purely presentational elements, focusing on content structure and meaning to facilitate conversion to multiple output formats, such as , , or XML, without tying the source to a specific rendering. This output-format-neutral enables versatile processing pipelines, where the emphasis on logical and metadata supports rich, context-aware transformations. Adopting a dedication for its specification and in the Docutils project encourages broad adoption, modification, and integration across tools and communities, eliminating licensing barriers to in workflows.

History

Origins and Influences

reStructuredText originated from StructuredText, a developed by Jim Fulton of Zope Corporation (formerly Digital Creations) and first released in 1996 as part of the Zope documentation system. StructuredText aimed to enable simple, readable plaintext markup for generating structured documents, but it suffered from significant limitations, including inconsistent parsing across implementations and a lack of extensibility that made it difficult to adapt for evolving needs. These shortcomings became evident in discussions on the Python Doc-SIG starting in 1996, where users highlighted the complexity of extending StructuredText without breaking existing functionality. In response to these issues, David Goodger began modifying StructuredText in late 1999 and initiated a full rewrite in 2000 as part of the Docutils project, specifically to create a more robust and extensible system for Python documentation. The redesign drew key influences from existing markup conventions: Setext for underline-style headings and hyperlink targets, providing a clean delimiter-based approach; RFC 822 for structured headers in field lists, offering a precedent for key-value formatting despite concerns over ambiguity; for inline documentation elements like tagged fields, emphasizing unambiguous tagging at the cost of intuitiveness. These influences were evaluated and adapted to prioritize simplicity, consistency, and extensibility while addressing StructuredText's parsing inconsistencies. The first public proposal for reStructuredText emerged in November 2000 with a draft specification posted to the Doc-SIG, followed by revisions in March 2001 based on community feedback, and a project website launch in June 2001. This early development emphasized the needs of the Python community for a standardized, plaintext-based documentation format that could handle inline and structural markup reliably. By April 2002, the project transitioned from its initial proprietary roots in Zope's ecosystem to an open, community-driven effort under the Docutils umbrella, with version 0.1 released and PEP 287 proposing reStructuredText as the standard for Python docstrings.

Major Releases and Developments

The Docutils project, including an initial implementation of the reStructuredText parser, was launched on June 1, 2001. The first stable release, Docutils 0.1, occurred in April 2002, marking the formal launch of the markup specification and its reference parser. By 2002, it gained significant adoption within Python projects, particularly following the proposal in PEP 287 to standardize it as the format for Python docstrings, which facilitated its integration into documentation workflows across the community. In 2003, a vanity type, text/prs.fallenstein.rst, was registered for reStructuredText files, aiding in its recognition as a distinct document format in web and contexts. Key milestones in the early development included the release of Docutils 0.5 on June 25, 2008, which provided a stable reference parser with enhanced input encoding detection and new directives, solidifying reStructuredText's reliability for production use. That same year, Sphinx, a built on reStructuredText, was released (version 0.1 in 2008), establishing deep integration that extended reStructuredText's capabilities for building large-scale documentation sites with features like cross-referencing and theming. Post-2019 updates focused on modernizing compatibility and extensibility. Docutils 0.20, released on May 4, 2023, introduced support for Python 3.11 and improved handling through additions like Ukrainian localization, enhancing internationalization for global efforts. This was followed by Docutils 0.21 on April 9, 2024, which enhanced directives with features such as the "loading" attribute for images and adopted the Flit build system for better package management, while dropping support for older Python versions. Alignment with Sphinx 7.0 (released April 29, 2023) and subsequent versions through 2025 improved compatibility, enabling nested markup experiments that blend reStructuredText with Markdown-like syntax without modifying the core specification. Recent developments from 2020 to 2025 reflect adaptations to the rising popularity of Markdown. The MyST-Parser extension, introduced in 2020, facilitated hybrid use by parsing an extensible flavor of Markdown into reStructuredText via Docutils, allowing seamless mixing in Sphinx projects while preserving backward compatibility with pure reStructuredText documents. Sphinx 8.3.0, released in early 2025, added the doctest_fail_fast option for quicker testing in documentation and full support for Docutils 0.22, which arrived on July 29, 2025, with features like CSS3 unit support and a new XML parser for advanced processing. Subsequent patch releases, such as Docutils 0.22.2 (September 2025) and 0.22.3 (November 2025), provided bug fixes and minor improvements. Community efforts, including those in the Docutils and Sphinx projects, have emphasized maintaining backward compatibility amid Markdown's growth, ensuring reStructuredText remains viable for precise technical authoring.

Syntax

Inline Markup

Inline markup in reStructuredText () allows for the formatting and referencing of words or phrases within paragraphs and other text blocks, enabling emphasis, literal rendering, hyperlinks, and substitutions without interrupting the flow of the surrounding text. This markup is recognized through specific pairs that are interpreted by processors like Docutils, ensuring that inline elements are delimited by whitespace or to avoid ambiguity. The system supports nine primary inline constructs, processed in a specific order to handle overlaps correctly, such as treating potential emphasis markers as literal text when appropriate. Emphasis is applied using single asterisks for italicized text, surrounding the phrase like emphasized text. Strong emphasis, typically rendered as bold, uses double asterisks, as in strong text. These must be bounded by whitespace or punctuation, and the content between delimiters cannot contain unescaped instances of the same delimiter to prevent misinterpretation. For inline literal text, often displayed in a monospaced font to represent or fixed-width content, double backticks are used: literal text. This prevents further markup processing within the literals, ensuring exact reproduction. Hyperlinks in reST can be explicit or implicit, facilitating both external and internal navigation. An explicit hyperlink combines display text with a URL using backticks and an underscore, such as Python website`_<https://www.python.org>`_.[](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#explicit-hyperlink-targets) This defines both the visible phrase and the target in one inline element. Implicit hyperlinks rely on predefined targets; for instance, a phrase like Python_`` links to a prior explicit target defined as .. _Python: https://www.python.org`.[](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#implicit-hyperlink-targets) Reference names for these targets are case-insensitive and normalized for whitespace, consisting of alphanumeric characters, isolated hyphens, underscores, periods, colons, or plus signs, or backquoted phrases for more complex identifiers. Standalone hyperlinks, like raw URLs (e.g., https://www.python.org), are automatically recognized and linked without additional markup. Substitution references enable reusable inline content through vertical bars, allowing dynamic replacement with elements like images or formatted text defined via directives. The syntax is |substitution|, where the label inside the bars corresponds to a definition such as .. |substitution| replace:: This is replaced text. These can also incorporate hyperlinks by appending an underscore, like |substitution|_, linking to a target after substitution. Only inline-compatible directives, such as image or replace, are permitted for substitutions to maintain text flow. Character-level escapes using a () allow literal rendering of markup characters within text, preventing unintended interpretation. For example, to display an without triggering emphasis, write *emphasized*. Escaping whitespace with a backslash removes both the backslash and the space from the output, enabling markup adjacent to punctuation, as in Python``list``\s to produce "Python lists" with "list" as literal. A literal itself requires doubling: \. Footnotes and citations provide inline referencing for annotations, using bracketed labels followed by an underscore. A manual footnote reference appears as , linking to a definition like .. [1] This is the footnote text.. Auto-numbered footnotes use [#], which processors assign sequential numbers starting from 1, while auto-symbolic ones employ [*], using symbols like *, †, and ‡. Citations follow a similar pattern with textual labels, such as [CIT2002], defined as .. [CIT2002] Citation details., and are rendered separately from footnotes. These share the reference namespace with hyperlinks, ensuring unique identifiers. reST enforces strict rules for inline markup interpretation and nesting to ensure predictable parsing. Markup elements cannot nest; for instance, outer inner is invalid and treated as literal. Recognition prioritizes constructs in order: inline internal targets, footnotes/citations, substitutions, and then emphasis/literals, with backslashes overriding potential markup. Delimiters require non-whitespace adjacency, and optional character-level mode (via configuration) allows markup without whitespace boundaries for denser text.

Block Structural Elements

reStructuredText (reST) employs block-level elements to structure documents hierarchically and semantically, enabling the organization of content into logical units such as sections, lists, and tables. These constructs form the foundational body elements, allowing authors to delineate paragraphs, impose structure on data, and embed quotations without relying on higher-level directives. Unlike inline markup, which affects individual words or phrases, block elements operate on entire lines or groups of lines to create a document's overall architecture. Paragraphs in reST are the simplest , formed implicitly by blocks of left-aligned text lines separated by one or more blank lines. Each paragraph must maintain consistent indentation, with lines wrapping naturally, and no special delimiters are required. For instance, consecutive lines of text without blanks constitute a single , while a blank line signals the start of a new one. This implicit formation promotes in sources. Line blocks, denoted by lines prefixed with a (|), preserve exact line breaks and indentation, making them suitable for or addresses where must be maintained verbatim. Continuation lines in line blocks are indented further, and the block terminates with a blank line or the end of the document. Headings establish the document's sectional hierarchy using underline styles composed of non-alphanumeric 7-bit ASCII characters, such as equals signs (=) for top-level sections or hyphens (-) for subsections. The underline must extend at least to the right edge of the heading text and can optionally include a matching for emphasis, though overline-and-underline combinations are reserved for the highest levels to avoid confusion. Hierarchy is determined by the sequence of underline styles encountered in the document, not by a rigid character assignment, allowing flexibility while enforcing consistency within a file. For example:

This is a top-level heading ============================ This is a subsection --------------------

This is a top-level heading ============================ This is a subsection --------------------

Blank lines before or after headings are optional, and each generates an implicit hyperlink target named after the section title. Lists provide mechanisms for enumerating or itemizing content, with bulleted lists initiated by *, +, or - followed by whitespace, and subsequent items following the same pattern at the same indentation level. Enumerated lists use auto-numbered formats like 1., (a), or #. (for automatic numbering), requiring consistent enumerator styles and sequences within the list, such as or lowercase letters. Definition lists pair one-line terms with indented classifiers or definitions, without a blank line between the term and its body, resembling dictionary entries. All list types necessitate a blank line before the first item and proper relative indentation for bodies, which may themselves contain nested lists or paragraphs. An example of a mixed list structure is:

- Bulleted item - Nested bullet 1. First enumerated 2. Second enumerated Term Definition text.

- Bulleted item - Nested bullet 1. First enumerated 2. Second enumerated Term Definition text.

These rules ensure lists are compact yet extensible. Tables in reST support tabular data through grid tables, which use with pipes (|) for columns, plus signs (+) for junctions, and equals signs (=) or hyphens (-) for separators, allowing row and column spans via adjusted cell borders. Simple tables offer a less rigid alternative, employing column separators aligned with equals signs for headers and hyphens for body rows, limited to two or more columns without spans. Both require blank lines before and after the table, with cells containing reST content. CSV tables, while possible via directives, are not core block elements here. A basic grid table example appears as:

+----------+----------+ | Header 1 | Header 2 | +==========+==========+ | Cell 1 | Cell 2 | +----------+----------+

+----------+----------+ | Header 1 | Header 2 | +==========+==========+ | Cell 1 | Cell 2 | +----------+----------+

This format facilitates precise alignment in plain text while rendering to structured outputs. Blockquotes and literal blocks handle indented or verbatim content. Blockquotes are created by indenting text relative to the surrounding paragraph, often with a leading greater-than sign (>) for explicit quoting, and may include an attribution line flush-left with -- or an em dash. They require blank lines for delimitation and can nest. Literal blocks follow a paragraph ending in double colon (::), with subsequent indented lines treated as unprocessed text, preserving whitespace and line breaks; alternatively, quoted literal blocks use :: followed by lines starting with >. These elements are ideal for citations or code snippets, as in:

An example quote:: > "This is quoted text." -- Attributor

An example quote:: > "This is quoted text." -- Attributor

Blank lines are mandatory before and after to isolate the block.

Directives and Roles

Directives in reStructuredText provide an extensible mechanism for embedding specialized content and behaviors within documents, allowing authors to insert elements like images or tables that extend beyond basic markup. The syntax for a directive begins with two periods followed by the directive type, double colons, optional arguments, a field list of options, and indented content if applicable: .. directive-type:: [arguments]\n [options]\n [content]. This structure builds upon fundamental block elements, such as paragraphs, by introducing named, customizable constructs. Common directives include the image directive, which embeds an image from a URI with options for alignment, scaling, and alternate text: .. image:: picture.png\n :alt: Alternate text\n :align: [center](/page/Center). The figure directive extends this by adding a caption and around the image: .. figure:: picture.png\n :align: [center](/page/Center)\n\n This is the figure caption.. For document navigation, the contents directive generates a with customizable depth and backlinks: .. contents:: [Table of Contents](/page/Table_of_contents)\n :depth: 2\n :backlinks: top. Admonition directives, such as note or warning, create highlighted blocks for emphasis: .. note:: This is a note admonition.\n\n Body content here., with predefined types including attention, caution, danger, error, hint, important, tip, and warning. The include directive incorporates external files: .. include:: external.txt\n :encoding: [utf-8](/page/UTF-8), supporting options for literal inclusion or code highlighting. Finally, the raw directive passes through verbatim content in specified formats like or : .. raw:: [html](/page/HTML)\n\n <p>Raw [HTML](/page/HTML) paragraph</p>. Roles enable inline customization of text interpretation, marking phrases with semantic meaning or formatting without disrupting paragraph flow. The syntax uses backquotes around the text, optionally prefixed by a role name: :role:textortext:role:. By default, unmarked interpreted text assumes the title-reference role for book or article titles. Common roles include :math:, which denotes mathematical expressions in notation: :math:E = mc^2``, rendering as inline math. The :pep: role (alias for pep-reference) creates hyperlinks to Python Enhancement Proposals by number: :pep:8` links to PEP 8. Substitution definitions allow reusable content via named references, defined as directives and invoked inline with vertical bars: |name|. For example, .. |logo| image:: logo.png\n :width: 100\n\n The logo image. enables substitution as |logo| anywhere in the text, supporting directives like image, replace for text substitution, unicode for symbols, and date for timestamps. Directives enforce validation rules for arguments and content to ensure parseability; required arguments, such as the URI for image, must be provided, while optional ones like options follow a field list format with unrecognized entries ignored. Content is parsed according to the directive's type—e.g., admonitions expect body elements like paragraphs—and invalid structures trigger system messages for errors or warnings during processing.

Implementation

Docutils Reference Parser

The Docutils project serves as the for reStructuredText (reST), providing a Python-based that processes markup into structured document representations and various output formats. It consists of core components including a parser for interpreting reST syntax, writers for generating outputs such as or , and a frontend that orchestrates the overall processing. This modular design allows Docutils to function as a flexible system for documentation workflows, emphasizing extensibility through plugins and custom components. The processing pipeline in Docutils begins with parsing the input reST source into a Document Object Model (DOM)-like structure known as the doctree, represented as an (AST) of nodes. The docutils.parsers.rst.Parser module handles this initial stage, analyzing the markup to construct the node tree using classes defined in docutils.nodes, such as document, paragraph, and section. Subsequent transformations are applied via the docutils.transforms module, where visitor patterns modify the tree for tasks like resolving references or correcting structure, ensuring the doctree adheres to semantic rules before output. Finally, a selected writer traverses the transformed tree to produce the desired format, such as HTML via docutils.writers.html4css1 or LaTeX via docutils.writers.latex. Configuration of the Docutils pipeline is facilitated through command-line tools like rst2html.py, which convert reST files to , or via configuration files such as docutils.conf for specifying options like input encoding or stylesheet paths. These tools leverage the frontend in docutils.frontend to apply settings, enabling customization without code changes. As of November 2025, the latest stable release is version 0.22.3, which includes enhancements to error reporting—such as downgrading certain section title warnings from severe to error level—and improved support, including a default input encoding of for better handling of international text.

Supporting Tools and Standards

reStructuredText employs the MIME type text/x-rst for file identification in various environments. Additionally, the IANA-registered MIME type text/prs.fallenstein.rst, established in 2003, serves as the official standard, though it is less commonly used in practice. reStructuredText aligns with , adopted in 2002, which designates it as the standard format for Python docstrings to ensure consistent, readable documentation across the ecosystem. The specification undergoes ongoing refinements through the Docutils project, incorporating updates to markup elements, directives, and error handling to maintain compatibility and extensibility. Auxiliary tools extend reStructuredText's utility beyond basic parsing. The rst2ansi utility converts documents to ANSI-escaped output for terminal display, facilitating inline rendering in command-line interfaces. For integration, the numpydoc Sphinx extension processes reStructuredText-formatted docstrings according to NumPy conventions, enabling specialized documentation generation for scientific computing libraries. Validators such as rstcheck analyze syntax and nested code blocks, providing error detection for document integrity during development. Interoperability is supported through editor integrations and linters. Vim features modes like vim-rst for and folding, aiding efficient editing of reStructuredText files. Emacs offers rst-mode, which includes keybindings for section management, list handling, and region manipulation to streamline authoring. Linters including restructuredtext-lint enforce style and syntax rules, integrating into workflows for automated validation. From 2020 to 2025, enhancements to in reStructuredText outputs have advanced through Sphinx extensions, aligning with WCAG 2.1 guidelines. For instance, the PyData Sphinx Theme implements color contrast adjustments for interactive elements to meet WCAG AA and AAA levels, improving compatibility and keyboard navigation in generated documentation.

Applications

Documentation Ecosystems

reStructuredText (reST) has been integral to Sphinx since its in , serving as the default plaintext markup language for generating in Python projects such as and . Sphinx leverages to produce rich, cross-referenced outputs like , PDF, and , enabling automatic extraction of docstrings via extensions like autodoc for . Recent developments, including the planned Sphinx 8.3.0 release in 2025, enhance compatibility with Docutils 0.22 and support hybrid workflows through the Parser extension, allowing seamless mixing of and in projects. Read the Docs, a popular open-source hosting platform, provides dedicated builders for reST-based projects using Sphinx, automating the compilation of .rst files into hosted documentation sites. It integrates directly with repositories, triggering builds on commits to generate and deploy documentation without manual intervention, which streamlines maintenance for collaborative Python workflows. Other documentation generators have adopted , with Pydoctor emerging as a modern static analysis tool that supports markup for API docs, primarily to replace the legacy Epydoc system used in projects like Twisted. Epydoc, while foundational, has been largely supplanted due to its outdated features, though it historically parsed for custom directives and graphs in Python documentation. Modern integrations extend into interactive environments, such as nbsphinx, a Sphinx extension that parses Jupyter notebooks (.ipynb files) and incorporates them into -based documentation, facilitating reproducible examples in computational workflows. reST's plaintext format makes it highly compatible with version control systems like , allowing documentation to be treated as code with diff-friendly changes and collaborative editing. Within Sphinx ecosystems, it enables automatic table-of-contents (TOC) generation via directives like .. toctree:: and robust cross-referencing with roles such as :ref: and :py:func:, reducing manual maintenance and improving navigability in large projects. Since 2019, reST adoption has expanded in AI and documentation, driven by the growth of open-source libraries that rely on Sphinx for structured, versioned outputs; for instance, tools like nbsphinx have enabled reST integration in Jupyter-based ML tutorials, while projects such as maintain comprehensive reST docs for algorithms and APIs. This shift supports scalable workflows in , where reST's semantic markup aids in linking code examples to theoretical explanations.

Broader Software Adoption

reStructuredText (reST) has seen adoption beyond traditional documentation workflows, integrating into core processes, platforms, and hybrid authoring tools, particularly in open-source and enterprise environments. This expansion reflects its robustness for structured content in collaborative settings, where precise markup aids in generating outputs like man pages and build artifacts. A notable example is the project, which transitioned to in July 2016, replacing with Sphinx for processing files into , PDF, and pages. This shift enabled more maintainable, plaintext-based source files under the Documentation directory, with Sphinx handling the conversion. As of 2025, this system remains in active use, supporting ongoing kernel releases and generating pages directly from sources via Sphinx extensions like kernel-doc. Similarly, adopted starting with version 3.0 in 2014, converting its to format and using Sphinx to produce pages and outputs from .rst files. This integration allows projects to embed and generate seamlessly during builds. In and systems, provides an alternative markup for enhanced readability and structure. , an open-source tool, has supported since early versions as a wiki markup option, enabling features like directives and roles alongside traditional wiki syntax. Bitbucket fully parses in README files, rendering them to HTML with support for tables, directives, and links, making it suitable for Python-centric repositories. offers partial support for README.rst files, processing basic syntax to HTML but with limitations on advanced directives compared to . integrates through its wiki and pipelines, with enhanced templates for Sphinx builds introduced in releases around 2023, facilitating automated documentation deployment in workflows. These platforms leverage for cross-project consistency, especially in ecosystems favoring Sphinx-generated outputs. Adoption extends to other languages and tools, such as crates, where parsers like rust-rst enable integration for generation, though primarily via conversions or plugins rather than native mdBook support. Expansions in projects like the and continue to drive broader use, with powering ancillary outputs in build systems. In enterprise settings, tools like rely on for their core , using Sphinx to process .rst files into comprehensive guides and references. From 2020 to 2025, faces competition from 's simplicity in lightweight documentation, particularly in web-focused and quick-start guides, leading to hybrid approaches in some tools. However, it sustains prominence in enterprise and technical domains requiring complex structures, such as directive-based content and cross-format outputs, as seen in sustained use by and kernel projects. Hybrid tools like further bolster this by supporting reST as an output format alongside Markdown and Jupyter, enabling multilingual scientific publishing with reST's precise semantics. This trend underscores reST's role in specialized, high-fidelity documentation amid Markdown's general dominance.

Examples

Basic Markup Illustrations

reStructuredText (reST) employs simple plaintext markup to structure documents, transforming them into formatted outputs like through parsers such as Docutils. This section illustrates foundational elements with self-contained examples, showing the source syntax alongside its typical rendered result in for clarity.

Headings and Paragraphs

Headings in reST are created by underlining text with characters, where the underline length matches or exceeds the title length; common choices include equals signs (=) for level-one headings and hyphens (-) for level-two. Paragraphs form naturally from blocks of text separated by blank lines, rendering as standard paragraphs without additional markup. Source:

My Heading ========== This is a paragraph. It contains [plain text](/page/Plain_text) that flows naturally, wrapping as needed.

My Heading ========== This is a paragraph. It contains [plain text](/page/Plain_text) that flows naturally, wrapping as needed.

Rendered Output:
<h1>My Heading</h1>
<p>This is a paragraph. It contains [plain text](/page/Plain_text) that flows naturally, wrapping as needed.</p>

Lists and Emphasis

Bulleted lists use markers like hyphens (-), asterisks (*), or plus signs (+) at the start of lines, with indentation for nested items; enumerated lists employ numbers or letters followed by periods. Inline emphasis includes double asterisks (text) for bold (strong), single asterisks (text) for italics (emphasis), and double backticks (text) for inline code or literals. Source:

- First item with **bold** text and `code`. - Second item: - Nested with *italics*. 1. Numbered item.

- First item with **bold** text and `code`. - Second item: - Nested with *italics*. 1. Numbered item.

Rendered Output:
<ul>
<li>First item with <strong>bold</strong> text and <code>code</code>.</li>
<li>Second item:
<ul>
<li>Nested with <em>italics</em>.</li>
</ul>
</li>
</ul>
<ol>
<li>Numbered item.</li>
</ol>
Hyperlinks are formed using inline references like text_ paired with an explicit target .. _text: URL, producing clickable anchors. Images use the .. image:: directive, specifying a path or URL, which renders as an embedded graphic with an alt attribute derived from the directive content if provided. Source:

Visit the `Docutils site`_. .. _Docutils site: https://docutils.sourceforge.io .. image:: https://docutils.sourceforge.io/docs/user/rst/images/title.png :alt: reST Title

Visit the `Docutils site`_. .. _Docutils site: https://docutils.sourceforge.io .. image:: https://docutils.sourceforge.io/docs/user/rst/images/title.png :alt: reST Title

Rendered Output:
Visit the <a href="https://docutils.sourceforge.io" rel="nofollow">Docutils site</a>.
<img src="https://docutils.sourceforge.io/docs/user/rst/images/title.png" alt="reST Title">

Footnotes

Footnotes employ inline markers like text[^label]_ followed by a definition block .. [^label]: Note content, generating superscript links to the note at the document's end. Labels can be numeric, alphabetic, or symbolic, with automatic numbering available. Source:

This sentence has a footnote.[^1]_ [^1]: This is the footnote content.

This sentence has a footnote.[^1]_ [^1]: This is the footnote content.

Rendered Output:
This sentence has a footnote.<sup><a href="#1" rel="nofollow" id="1">{{grok:render&&&type=render_inline_citation&&&citation_id=1&&&citation_type=wikipedia}}</a></sup>
(At bottom:) <hr>
<div class="footnote"><p>[<a href="#1" rel="nofollow">1</a>] This is the footnote content.</p></div>

Advanced Feature Demonstrations

reStructuredText's advanced features enable the creation of dynamic, modular, and -rich documents through sophisticated directives and roles, extending its utility in professional workflows. These elements allow for automated content generation, external integrations, and precise formatting control, making reST suitable for complex reports, technical manuals, and web publications. Demonstrations here focus on practical combinations that leverage extensibility, such as automatic generation and embedded , often processed by tools like Docutils or Sphinx for output in , PDF, or formats. The contents directive automates the generation of a (TOC) based on document headings, supporting nested sections for hierarchical navigation. For instance, the syntax .. contents:: Table of Contents :depth: 2 produces a TOC limited to two levels, rendering as an indented list or structure in output formats; options like :backlinks: entry add hyperlinks from headings back to TOC entries, enhancing usability in long . In a with nested headings—such as a top-level section followed by subsections—this directive outputs a like:
  • Main Section
    • Subsection 1
    • Subsection 2
This feature is particularly extensible in Sphinx, where it integrates with global TOCs for multi-file projects. Roles and substitutions provide inline customization, with the math role enabling mathematical expressions via syntax. The markup :math:E = mc^2`` inserts an inline , rendered by MathJax for web outputs or for PDF, displaying as E=mc2E = mc^2 without requiring full math blocks. Substitutions extend this by defining reusable elements, such as .. |logo| image:: /images/logo.png :width: 100px, which allows |logo| to embed the inline, supporting or raster formats for consistent branding across documents. These render seamlessly in as interactive elements or in PDF as static embeds, demonstrating reST's balance of simplicity and expressiveness. The include and raw directives facilitate modular content assembly and direct format passthrough, ideal for maintaining large-scale documents. Using .. include:: other.rst :start-after: Section Start :end-before: Section End, external content from other.rst is merged and parsed as , allowing selective inclusion of sections for versioned reports; the :literal: option treats it as code for verbatim display. Complementarily, .. raw:: html :file: snippet.html embeds raw HTML verbatim, bypassing parsing for custom elements like interactive widgets, resulting in merged outputs where the included reST flows naturally into the host document while raw sections appear as native HTML in web builds. This combination supports hybrid workflows, such as embedding responses or UI previews without markup interference. Admonitions and advanced tables add structured warnings and data presentation, with customizable options for emphasis and dynamism. The warning admonition, invoked as .. warning:: Critical Alert :class: custom-warning, creates an offset block titled "Warning!" containing the body text, rendered as a highlighted sidebar in HTML or a boxed note in PDF; the :class: option applies CSS styling for themed outputs. For tables, the csv-table directive parses comma-separated values dynamically: .. csv-table:: Product Inventory :header: "Item,Price,Stock" :widths: 30, 20, 20 "Widget A,15.99,50" "Widget B,22.50,30", generating a responsive grid with aligned columns, suitable for importing from external CSV files via :file: data.csv. This renders as a clean, bordered table in outputs, enabling data-driven documentation without manual HTML. A full document snippet combining these elements illustrates a mini-report on project metrics:

Project Metrics Report ====================== .. contents:: Report Contents :depth: 2 :backlinks: top Overview -------- This report summarizes key findings. For details, see :math:`E = mc^2` as a placeholder equation. |logo| .. include:: metrics_data.rst :start-line: 5 .. csv-table:: Performance Data :header: "Metric,Value,Unit" :align: center "Speed,120,km/h" "Efficiency,85,%" .. warning:: Data is preliminary; verify sources. .. raw:: html <div class="chart">Embedded visualization here.</div>

Project Metrics Report ====================== .. contents:: Report Contents :depth: 2 :backlinks: top Overview -------- This report summarizes key findings. For details, see :math:`E = mc^2` as a placeholder equation. |logo| .. include:: metrics_data.rst :start-line: 5 .. csv-table:: Performance Data :header: "Metric,Value,Unit" :align: center "Speed,120,km/h" "Efficiency,85,%" .. warning:: Data is preliminary; verify sources. .. raw:: html <div class="chart">Embedded visualization here.</div>

In output via Sphinx, this renders with a navigable TOC, inline , substituted image, included parsed content, centered table, styled warning block, and raw div for custom charts; PDF via shows the equation typeset, table in a float, and as a framed note.

References

  1. Sep 13, 2025 · reStructuredText is an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system. It is useful for in-line program documentation.Quick reStructuredText · A ReStructuredText Primer · Introduction · Markup
Add your contribution
Related Hubs
Contribute something
User Avatar
No comments yet.