Writing Documents in reStructuredText (RST)¶
reStructuredText is a lightweight markup language that’s commonly used for documenting code, software projects, and technical documents. It’s simple and easy to learn. Here’s a basic overview of how to use RST:
- Headers: Use underlines to create headers. For example:
rst
My Document Title
=================
- Sections: Use colons and indentation for sections. For example:
```rst Section 1 =========
Subsection 1.1
```
- Lists: Use asterisks for bullet points and numbers for ordered lists.
```rst * Item 1 * Item 2
- First item
-
Second item ```
-
Links: Create links with backticks and angle brackets.
rst
`OpenAI Website <https://www.openai.com>`_
- Code Blocks: Use double colons for code blocks.
```rst ::
def my_function():
return "Hello, world!"
```
- Emphasis: Use asterisks or underscores for emphasis.
rst
*italic* or _italic_
**bold** or __bold__
- References: Create references with double colons.
```rst .. _my-reference-label:
This is a reference to :ref:my-reference-label
.
```
- Images: Include images with double colons.
rst
.. image:: path/to/image.png
:width: 200
- Tables: Create tables using the
+
character for borders.
rst
+---------------+------------+
| Header 1 | Header 2 |
+===============+============+
| Data 1 | Data 2 |
+---------------+------------+
Using RST Linters¶
Linters help ensure that your RST documents are formatted correctly and adhere
to best practices. Here’s how you can use three popular RST linters: rst-lint
,
doc8
, and rstcheck
.
rst-lint¶
rst-lint
is a tool that checks your RST files for compliance with the Docutils
stylesheet and reports any issues.
To use rst-lint
:
- Install it using pip:
shell
pip install rst-lint
- Run
rst-lint
on your RST file:
shell
rst-lint your_document.rst
rst-lint
will provide feedback and suggestions for improvements in your RST file.
doc8¶
doc8
is a style checker for RST documents that enforces the style guide
specified in the OpenStack project.
To use doc8
:
- Install it using pip:
shell
pip install doc8
- Run
doc8
on your RST file:
shell
doc8 your_document.rst
doc8
will check your document for style violations and provide a report.
rstcheck¶
rstcheck
is a linter that checks RST files for syntax errors and style issues.
To use rstcheck
:
- Install it using pip:
shell
pip install rstcheck
- Run
rstcheck
on your RST file:
shell
rstcheck your_document.rst
rstcheck
will identify syntax errors and suggest improvements.
By following these guidelines and using these linters, you can create well-structured and error-free RST documents for your daily work.