| Server IP : 82.148.16.210 / Your IP : 216.73.216.169 Web Server : nginx/1.29.5 System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/thread-self/root/usr/share/doc/python3-docutils/docs/user/rst/ |
Upload File : |
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<title>A ReStructuredText Primer</title>
<meta name="author" content="Richard Jones" />
<meta name="copyright" content="This document has been placed in the public domain." />
<link rel="stylesheet" href="../../../css/html4css1.css" type="text/css" />
</head>
<body>
<div class="header">
<a class="reference external" href="https://docutils.sourceforge.io">Docutils</a> | <a class="reference external" href="../../index.html">Overview</a> | <a class="reference external" href="../../index.html#project-fundamentals">About</a> | <a class="reference external" href="../../index.html#user">Users</a> | <a class="reference external" href="../../index.html#ref">Reference</a> | <a class="reference external" href="../../index.html#howto">Developers</a>
<hr class="header"/>
</div>
<div class="document" id="a-restructuredtext-primer">
<h1 class="title">A ReStructuredText Primer</h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr><th class="docinfo-name">Author:</th>
<td>Richard Jones</td></tr>
<tr><th class="docinfo-name">Version:</th>
<td>9051</td></tr>
<tr><th class="docinfo-name">Copyright:</th>
<td>This document has been placed in the public domain.</td></tr>
</tbody>
</table>
<!-- Minimal menu bar for inclusion in documentation sources
in ``docutils/docs/*/`` sub-sub-diretories.
Attention: this is not a standalone document. -->
<div class="contents topic" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#structure" id="toc-entry-1">Structure</a></li>
<li><a class="reference internal" href="#text-styles" id="toc-entry-2">Text styles</a></li>
<li><a class="reference internal" href="#lists" id="toc-entry-3">Lists</a></li>
<li><a class="reference internal" href="#preformatting-code-samples" id="toc-entry-4">Preformatting (code samples)</a></li>
<li><a class="reference internal" href="#sections" id="toc-entry-5">Sections</a><ul>
<li><a class="reference internal" href="#document-title-subtitle" id="toc-entry-6">Document Title / Subtitle</a></li>
</ul>
</li>
<li><a class="reference internal" href="#images" id="toc-entry-7">Images</a></li>
<li><a class="reference internal" href="#what-next" id="toc-entry-8">What Next?</a></li>
</ul>
</div>
<p>The text below contains links that look like "(<a class="reference external" href="quickref.html">quickref</a>)". These
are relative links that point to the <a class="reference external" href="quickref.html">Quick reStructuredText</a> user
reference. If these links don't work, please refer to the <a class="reference external" href="https://docutils.sourceforge.io/docs/user/rst/quickref.html">master
quick reference</a> document.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This document is an informal introduction to
reStructuredText. The <a class="reference internal" href="#what-next">What Next?</a> section below has links to
further resources, including a formal reference.</p>
</div>
<div class="section" id="structure">
<h1><a class="toc-backref" href="#toc-entry-1">Structure</a></h1>
<p>From the outset, let me say that "Structured Text" is probably a bit
of a misnomer. It's more like "Relaxed Text" that uses certain
consistent patterns. These patterns are interpreted by a HTML
converter to produce "Very Structured Text" that can be used by a web
browser.</p>
<p>The most basic pattern recognised is a <strong>paragraph</strong> (<a class="reference external" href="quickref.html#paragraphs">quickref</a>).
That's a chunk of text that is separated by blank lines (one is
enough). Paragraphs must have the same indentation -- that is, line
up at their left edge. Paragraphs that start indented will result in
indented quote paragraphs. For example:</p>
<pre class="literal-block">
This is a paragraph. It's quite
short.
This paragraph will result in an indented block of
text, typically used for quoting other text.
This is another one.
</pre>
<p>Results in:</p>
<blockquote>
<p>This is a paragraph. It's quite
short.</p>
<blockquote>
This paragraph will result in an indented block of
text, typically used for quoting other text.</blockquote>
<p>This is another one.</p>
</blockquote>
</div>
<div class="section" id="text-styles">
<h1><a class="toc-backref" href="#toc-entry-2">Text styles</a></h1>
<p>(<a class="reference external" href="quickref.html#inline-markup">quickref</a>)</p>
<p>Inside paragraphs and other bodies of text, you may additionally mark
text for <em>italics</em> with "<tt class="docutils literal">*italics*</tt>" or <strong>bold</strong> with
"<tt class="docutils literal">**bold**</tt>". This is called "inline markup".</p>
<p>If you want something to appear as a fixed-space literal, use
"<tt class="docutils literal">``double <span class="pre">back-quotes``</span></tt>". Note that no further fiddling is done
inside the double back-quotes -- so asterisks "<tt class="docutils literal">*</tt>" etc. are left
alone.</p>
<p>If you find that you want to use one of the "special" characters in
text, it will generally be OK -- reStructuredText is pretty smart.
For example, this lone asterisk * is handled just fine, as is the
asterisk in this equation: 5*6=30. If you actually
want text *surrounded by asterisks* to <strong>not</strong> be italicised, then
you need to indicate that the asterisk is not special. You do this by
placing a backslash just before it, like so "<tt class="docutils literal">\*</tt>" (<a class="reference external" href="quickref.html#escaping">quickref</a>), or
by enclosing it in double back-quotes (inline literals), like this:</p>
<pre class="literal-block">
``*``
</pre>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p class="last">Think of inline markup as a form of (parentheses) and use it
the same way: immediately before and after the text being marked
up. Inline markup by itself (surrounded by whitespace) or in the
middle of a word won't be recognized. See the <a class="reference external" href="../../ref/rst/restructuredtext.html#inline-markup">markup spec</a> for
full details.</p>
</div>
</div>
<div class="section" id="lists">
<h1><a class="toc-backref" href="#toc-entry-3">Lists</a></h1>
<p>Lists of items come in three main flavours: <strong>enumerated</strong>,
<strong>bulleted</strong> and <strong>definitions</strong>. In all list cases, you may have as
many paragraphs, sublists, etc. as you want, as long as the left-hand
side of the paragraph or whatever aligns with the first line of text
in the list item.</p>
<p>Lists must always start a new paragraph -- that is, they must appear
after a blank line.</p>
<dl class="docutils">
<dt><strong>enumerated</strong> lists (numbers, letters or roman numerals; <a class="reference external" href="quickref.html#enumerated-lists">quickref</a>)</dt>
<dd><p class="first">Start a line off with a number or letter followed by a period ".",
right bracket ")" or surrounded by brackets "( )" -- whatever you're
comfortable with. All of the following forms are recognised:</p>
<pre class="literal-block">
1. numbers
A. upper-case letters
and it goes over many lines
with two paragraphs and all!
a. lower-case letters
3. with a sub-list starting at a different number
4. make sure the numbers are in the correct sequence though!
I. upper-case roman numerals
i. lower-case roman numerals
(1) numbers again
1) and again
</pre>
<p>Results in (note: the different enumerated list styles are not
always supported by every web browser, so you may not get the full
effect here):</p>
<ol class="arabic simple">
<li>numbers</li>
</ol>
<ol class="upperalpha">
<li><p class="first">upper-case letters
and it goes over many lines</p>
<p>with two paragraphs and all!</p>
</li>
</ol>
<ol class="loweralpha simple">
<li>lower-case letters<ol class="arabic" start="3">
<li>with a sub-list starting at a different number</li>
<li>make sure the numbers are in the correct sequence though!</li>
</ol>
</li>
</ol>
<ol class="upperroman simple">
<li>upper-case roman numerals</li>
</ol>
<ol class="lowerroman simple">
<li>lower-case roman numerals</li>
</ol>
<ol class="arabic simple">
<li>numbers again</li>
</ol>
<ol class="last arabic simple">
<li>and again</li>
</ol>
</dd>
<dt><strong>bulleted</strong> lists (<a class="reference external" href="quickref.html#bullet-lists">quickref</a>)</dt>
<dd><p class="first">Just like enumerated lists, start the line off with a bullet point
character - either "-", "+" or "*":</p>
<pre class="literal-block">
* a bullet point using "*"
- a sub-list using "-"
+ yet another sub-list
- another item
</pre>
<p>Results in:</p>
<ul class="last simple">
<li>a bullet point using "*"<ul>
<li>a sub-list using "-"<ul>
<li>yet another sub-list</li>
</ul>
</li>
<li>another item</li>
</ul>
</li>
</ul>
</dd>
<dt><strong>definition</strong> lists (<a class="reference external" href="quickref.html#definition-lists">quickref</a>)</dt>
<dd><p class="first">Unlike the other two, the definition lists consist of a term, and
the definition of that term. The format of a definition list is:</p>
<pre class="literal-block">
what
Definition lists associate a term with a definition.
*how*
The term is a one-line phrase, and the definition is one or more
paragraphs or body elements, indented relative to the term.
Blank lines are not allowed between term and definition.
</pre>
<p>Results in:</p>
<dl class="last docutils">
<dt>what</dt>
<dd>Definition lists associate a term with a definition.</dd>
<dt><em>how</em></dt>
<dd>The term is a one-line phrase, and the definition is one or more
paragraphs or body elements, indented relative to the term.
Blank lines are not allowed between term and definition.</dd>
</dl>
</dd>
</dl>
</div>
<div class="section" id="preformatting-code-samples">
<h1><a class="toc-backref" href="#toc-entry-4">Preformatting (code samples)</a></h1>
<p>(<a class="reference external" href="quickref.html#literal-blocks">quickref</a>)</p>
<p>To just include a chunk of preformatted, never-to-be-fiddled-with
text, finish the prior paragraph with "<tt class="docutils literal">::</tt>". The preformatted
block is finished when the text falls back to the same indentation
level as a paragraph prior to the preformatted block. For example:</p>
<pre class="literal-block">
An example::
Whitespace, newlines, blank lines, and all kinds of markup
(like *this* or \this) is preserved by literal blocks.
Lookie here, I've dropped an indentation level
(but not far enough)
no more example
</pre>
<p>Results in:</p>
<blockquote>
<p>An example:</p>
<pre class="literal-block">
Whitespace, newlines, blank lines, and all kinds of markup
(like *this* or \this) is preserved by literal blocks.
Lookie here, I've dropped an indentation level
(but not far enough)
</pre>
<p>no more example</p>
</blockquote>
<p>Note that if a paragraph consists only of "<tt class="docutils literal">::</tt>", then it's removed
from the output:</p>
<pre class="literal-block">
::
This is preformatted text, and the
last "::" paragraph is removed
</pre>
<p>Results in:</p>
<pre class="literal-block">
This is preformatted text, and the
last "::" paragraph is removed
</pre>
</div>
<div class="section" id="sections">
<h1><a class="toc-backref" href="#toc-entry-5">Sections</a></h1>
<p>(<a class="reference external" href="quickref.html#section-structure">quickref</a>)</p>
<p>To break longer text up into sections, you use <strong>section headers</strong>.
These are a single line of text (one or more words) with adornment: an
underline alone, or an underline and an overline together, in dashes
"<tt class="docutils literal"><span class="pre">-----</span></tt>", equals "<tt class="docutils literal"><span class="pre">======</span></tt>", tildes "<tt class="docutils literal"><span class="pre">~~~~~~</span></tt>" or any of the
non-alphanumeric characters <tt class="docutils literal">= - ` : ' " ~ ^ _ * + # < ></tt> that you
feel comfortable with. An underline-only adornment is distinct from
an overline-and-underline adornment using the same character. The
underline/overline must be at least as long as the title text. Be
consistent, since all sections marked with the same adornment style
are deemed to be at the same level:</p>
<pre class="literal-block">
Chapter 1 Title
===============
Section 1.1 Title
-----------------
Subsection 1.1.1 Title
~~~~~~~~~~~~~~~~~~~~~~
Section 1.2 Title
-----------------
Chapter 2 Title
===============
</pre>
<p>This results in the following structure, illustrated by simplified
pseudo-XML:</p>
<pre class="literal-block">
<section>
<title>
Chapter 1 Title
<section>
<title>
Section 1.1 Title
<section>
<title>
Subsection 1.1.1 Title
<section>
<title>
Section 1.2 Title
<section>
<title>
Chapter 2 Title
</pre>
<p>(Pseudo-XML uses indentation for nesting and has no end-tags. It's
not possible to show actual processed output, as in the other
examples, because sections cannot exist inside block quotes. For a
concrete example, compare the section structure of this document's
source text and processed output.)</p>
<p>Note that section headers are available as link targets, just using
their name. To link to the <a class="reference internal" href="#lists">Lists</a> heading, I write "<tt class="docutils literal">Lists_</tt>". If
the heading has a space in it like <a class="reference internal" href="#text-styles">text styles</a>, we need to quote
the heading "<tt class="docutils literal">`text styles`_</tt>".</p>
<div class="section" id="document-title-subtitle">
<h2><a class="toc-backref" href="#toc-entry-6">Document Title / Subtitle</a></h2>
<p>The title of the whole document is distinct from section titles and
may be formatted somewhat differently (e.g. the HTML writer by default
shows it as a centered heading).</p>
<p>To indicate the document title in reStructuredText, use a unique adornment
style at the beginning of the document. To indicate the document subtitle,
use another unique adornment style immediately after the document title. For
example:</p>
<pre class="literal-block">
================
Document Title
================
----------
Subtitle
----------
Section Title
=============
...
</pre>
<p>Note that "Document Title" and "Section Title" above both use equals
signs, but are distict and unrelated styles. The text of
overline-and-underlined titles (but not underlined-only) may be inset
for aesthetics.</p>
</div>
</div>
<div class="section" id="images">
<h1><a class="toc-backref" href="#toc-entry-7">Images</a></h1>
<p>(<a class="reference external" href="quickref.html#directives">quickref</a>)</p>
<p>To include an image in your document, you use the the <tt class="docutils literal">image</tt> <a class="reference external" href="../../ref/rst/directives.html">directive</a>.
For example:</p>
<pre class="literal-block">
.. image:: images/biohazard.png
</pre>
<p>results in:</p>
<img alt="images/biohazard.png" src="images/biohazard.png" />
<p>The <tt class="docutils literal">images/biohazard.png</tt> part indicates the filename of the image
you wish to appear in the document. There's no restriction placed on
the image (format, size etc). If the image is to appear in HTML and
you wish to supply additional information, you may:</p>
<pre class="literal-block">
.. image:: images/biohazard.png
:height: 100
:width: 200
:scale: 50
:alt: alternate text
</pre>
<p>See the full <a class="reference external" href="../../ref/rst/directives.html#images">image directive documentation</a> for more info.</p>
</div>
<div class="section" id="what-next">
<h1><a class="toc-backref" href="#toc-entry-8">What Next?</a></h1>
<p>This primer introduces the most common features of reStructuredText,
but there are a lot more to explore. The <a class="reference external" href="quickref.html">Quick reStructuredText</a>
user reference is a good place to go next. For complete details, the
<a class="reference external" href="../../ref/rst/restructuredtext.html">reStructuredText Markup Specification</a> is the place to go <a class="footnote-reference" href="#footnote-1" id="footnote-reference-1">[1]</a>.</p>
<p>Users who have questions or need assistance with Docutils or
reStructuredText should post a message to the <a class="reference external" href="../mailing-lists.html#docutils-users">Docutils-users</a> mailing
list.</p>
<table class="docutils footnote" frame="void" id="footnote-1" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#footnote-reference-1">[1]</a></td><td>If that relative link doesn't work, try the master document:
<a class="reference external" href="https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html">https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html</a>.</td></tr>
</tbody>
</table>
</div>
</div>
</body>
</html>