2016-06-26 16:34:16 +03:00
---
2017-03-02 14:22:30 +03:00
language: restructured text (RST)
2016-06-26 16:34:16 +03:00
contributors:
- ["DamienVGN", "https://github.com/martin-damien"]
2017-01-14 00:54:30 +03:00
- ["Andre Polykanine", "https://github.com/Oire"]
2016-06-26 16:34:16 +03:00
filename: restructuredtext.rst
---
2020-09-25 18:55:02 +03:00
RST, Restructured Text, is a file format created by the Python community to write documentation. It is part of [Docutils ](https://docutils.sourceforge.io/rst.html ).
2016-06-26 16:34:16 +03:00
2023-09-08 08:33:09 +03:00
RST is a markup language like HTML but is much more lightweight and easier to read.
2016-06-26 16:34:16 +03:00
## Installation
To use Restructured Text, you will have to install [Python ](http://www.python.org ) and the `docutils` package.
`docutils` can be installed using the commandline:
```bash
$ easy_install docutils
```
2017-01-07 00:02:45 +03:00
If your system has `pip` , you can use it too:
2016-06-26 16:34:16 +03:00
```bash
$ pip install docutils
```
2017-01-07 00:02:45 +03:00
## File syntax
2016-06-26 16:34:16 +03:00
A simple example of the file syntax:
2017-07-04 23:23:42 +03:00
```
2022-01-16 05:57:16 +03:00
.. Lines starting with two dots are special commands. But if no command can be found, the line is considered as a comment.
2016-06-26 16:34:16 +03:00
=========================================================
Main titles are written using equals signs over and under
=========================================================
2020-09-25 18:55:02 +03:00
Note that each character, including spaces, needs an equals sign above and below.
2016-06-26 16:34:16 +03:00
2020-09-25 19:05:28 +03:00
Titles also use equals signs but are only underneath
====================================================
2016-06-26 16:34:16 +03:00
Subtitles with dashes
---------------------
2019-04-15 22:46:38 +03:00
You can put text in *italic* or in **bold** , you can "mark" text as code with double backquote ``print()``.
2016-06-26 16:34:16 +03:00
2020-06-24 09:55:02 +03:00
Special characters can be escaped using a backslash, e.g. \\ or \*.
2019-04-15 23:02:39 +03:00
Lists are similar to Markdown, but a little more involved.
2020-06-24 09:55:02 +03:00
Remember to line up list symbols (like - or \*) with the left edge of the previous text block, and remember to use blank lines to separate new lists from parent lists:
2016-06-26 16:34:16 +03:00
- First item
- Second item
2019-04-15 22:46:38 +03:00
- Sub item
- Third item
2016-06-26 16:34:16 +03:00
or
* First item
* Second item
2019-04-15 22:46:38 +03:00
* Sub item
* Third item
2016-06-26 16:34:16 +03:00
Tables are really easy to write:
=========== ========
Country Capital
=========== ========
France Paris
Japan Tokyo
=========== ========
2022-01-16 05:57:16 +03:00
More complex tables can be done easily (merged columns and/or rows) but I suggest you to read the complete doc for this. :)
2016-06-26 16:34:16 +03:00
2017-01-07 00:02:45 +03:00
There are multiple ways to make links:
2016-06-26 16:34:16 +03:00
2020-09-25 18:55:02 +03:00
- By adding an underscore after a word : Github_ and by adding the target URL after the text (this way has the advantage of not inserting unnecessary URLs in the visible text).
2022-01-16 05:57:16 +03:00
- By typing a full comprehensible URL : https://github.com/ (will be automatically converted to a link).
2017-01-07 00:02:45 +03:00
- By making a more Markdown-like link: `Github <https://github.com/>` _ .
2016-06-26 16:34:16 +03:00
2020-06-24 09:55:02 +03:00
.. _Github: https://github.com/
2016-06-26 16:34:16 +03:00
```
2017-01-07 00:02:45 +03:00
## How to Use It
2016-06-26 16:34:16 +03:00
2017-01-07 00:02:45 +03:00
RST comes with docutils where you have `rst2html` , for example:
2016-06-26 16:34:16 +03:00
```bash
$ rst2html myfile.rst output.html
```
*Note : On some systems the command could be rst2html.py*
2017-01-07 00:02:45 +03:00
But there are more complex applications that use the RST format:
2016-06-26 16:34:16 +03:00
- [Pelican ](http://blog.getpelican.com/ ), a static site generator
- [Sphinx ](http://sphinx-doc.org/ ), a documentation generator
- and many others
2017-01-14 00:54:30 +03:00
## Readings
2016-06-26 16:34:16 +03:00
- [Official quick reference ](http://docutils.sourceforge.net/docs/user/rst/quickref.html )