Catalog / reStructuredText Cheat Sheet

reStructuredText Cheat Sheet

A quick reference for reStructuredText (reST) markup, covering common elements for creating structured documents.

Basic Syntax

Paragraphs and Text Formatting

Paragraphs are separated by blank lines.

Example:

This is the first paragraph.

This is the second paragraph.

Emphasis (italics)

Example:

*This text is emphasized.* 

Strong emphasis (bold)

Example:

**This text is strongly emphasized.**

Literal text (monospace)

Example:

``This text is literal.``

inline literals

Example:

Use ``code samples`` inline.

References

Example:

__This is reference text__

Lists

Bulleted lists:

* Item 1
* Item 2
* Item 3

Numbered lists:

1. Item 1
2. Item 2
3. Item 3

Nested lists:

* Item 1
  1. Subitem 1
  2. Subitem 2
* Item 2

Definition lists:

Term
  Definition

Headings

Headings are created by underlining (or overlining and underlining) with punctuation characters.

Example:

Title
=====

Section
-------

Subsection
~~~~~~~~~~

Note: The length of the underline must be at least the length of the heading text.

Links and References

Internal Links

Internal links allow you to navigate to different parts of the same document.

Syntax:

.. _my-reference-label:

Section content.

See :ref:`my-reference-label` for details.

The :ref: role creates a link to the section with the specified label.

External Links

External links point to resources outside the current document.

Syntax:

`Link text <URL>`_

Example:

`Python <https://www.python.org>`_

Alternatively, using reference names:

`Link text`_

.. _Link text: https://www.python.org

Footnotes

Footnotes add explanatory notes to your document.

Syntax:

.. [1] This is the footnote text.

Text with a footnote reference [1]_.

Directives

Image Directive

The image directive includes an image in your document.

Syntax:

.. image:: path/to/image.png
   :alt: Alternate text

Options like :alt:, :width:, :height:, and :scale: can be used.

Code Directive

The code-block directive includes a code block with syntax highlighting.

Syntax:

.. code-block:: python

   def hello_world():
       print("Hello, world!")

Specify the language after the directive (e.g., python, c++, javascript).

Admonitions

Admonitions are used to highlight important information.

Example:

.. note:: This is a note.

.. warning:: This is a warning.

.. tip:: This is a tip.

Tables

Grid Tables

Grid tables are created using a grid of characters.

Example:

+------------+------------+------------+
| Header 1   | Header 2   | Header 3   |
+============+============+============+
| Row 1, Col 1| Row 1, Col 2| Row 1, Col 3|
+------------+------------+------------+
| Row 2, Col 1| Row 2, Col 2| Row 2, Col 3|
+------------+------------+------------+

Simple Tables

Simple tables are easier to read and write for basic tabular data.

Example:

Header 1  Header 2
========  ========
Row 1, Col 1  Row 1, Col 2
Row 2, Col 1  Row 2, Col 2

CSV Tables

CSV tables allow you to include tabular data from a CSV file.

Syntax:

.. csv-table:: data.csv
   :header-rows: 1

Use the :header-rows: option to specify the number of header rows.