Formatting
Titles
reStructuredText supports multiple levels of section titles, each with its own unique underline style. The following are the most common styles:
= for top-level titles
- for second-level titles
^ for third-level titles
" for fourth-level titles
' for fifth-level titles
~ for sixth-level titles
Example:
============== Title Level 1 ============== Subtitle Level 2 ================= Section Level 3 ---------------- Subsection Level 4 ~~~~~~~~~~~~~~~~~~~ Subsubsection Level 5 ^^^^^^^^^^^^^^^^^^^^^^ Paragraph Level 6 """"""""""""""""""
Paragraphs
Paragraphs are created by writing text without any special formatting. A blank line separates paragraphs.
Example:
This is a paragraph. It contains multiple sentences. This is another paragraph.
Lists
There are two types of lists in reStructuredText: ordered and unordered.
Unordered lists use asterisks, plus signs, or hyphens:
Example |
Syntax |
---|---|
|
|
|
|
Inline Markup
Inline markup is used to apply formatting to text within a paragraph.
Bold: Use double asterisks: **bold text**
Italic: Use single asterisks: *italic text*
Inline code: Use double backticks: `` inline code ``
Links
External links can be created using the following syntax:
Example:
Visit the `Python website <https://www.python.org/>`_ for information about the Python programming language.
Result:
Visit the Python website for information about the Python programming language.
Images
Syntax |
Example |
---|---|
|
Relative URIs
Image URIs are relative to the document. If it's the same folder, just write the image name with the extension. To target the file in another folder, use the path to the file with eventual leading dot.
Syntax |
Example |
---|---|
|
Result |
Literal Blocks
Literal blocks are used to include preformatted text in your document. They are useful for including code snippets, command-line output, or any other text that should be displayed exactly as written, without any reStructuredText formatting applied.
To create a literal block, start a paragraph with "::" followed by a blank line. The text that follows will be included in the literal block.
Example:
::
This is a literal block.
It preserves whitespace and
line breaks exactly as written.
Result:
This is a literal block. It preserves whitespace and line breaks exactly as written.
Example:
def hello_world():
print("Hello, world!")
Code Blocks with Syntax Highlighting
The code-block directive is used to include code snippets with syntax highlighting. Specify the language after code-block:: to enable appropriate highlighting.
.. code-block:: csharp
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, world!");
}
}
Python Result:
def hello_world():
print("Hello, world!")
JavaScript Result:
function helloWorld() {
console.log("Hello, world!");
}
C# Result:
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, world!");
}
}
Tables
Simple tables can be created using the following syntax:
Example:
+-----------+-----------+
| Header 1 | Header 2 |
+===========+===========+
| Cell 1 | Cell 2 |
+-----------+-----------+
| Cell 3 | Cell 4 |
+-----------+-----------+
Result:
Header 1 |
Header 2 |
---|---|
Cell 1 |
Cell 2 |
Cell 3 |
Cell 4 |