doc: Add "restructuredtext" section to usage guide

This is taken from the existing 'rest' documents. Little to no
modifications are necessary, thankfully.

Signed-off-by: Stephen Finucane <stephen@that.guru>
This commit is contained in:
Stephen Finucane
2017-11-03 12:44:39 +00:00
parent 5734d8ad02
commit 9c2ab8c3bb
5 changed files with 85 additions and 59 deletions

View File

@@ -9,10 +9,10 @@ Sphinx documentation contents
usage/installation
usage/quickstart
usage/restructuredtext/index
intro
man/index
rest
markup/index
domains
builders

View File

@@ -206,6 +206,7 @@ Including content based on tags
This directive is designed to control only content of document. It could
not control sections, labels and so on.
.. _table-directives:
Tables
------

View File

@@ -108,9 +108,8 @@ for this document -- use the "Show Source" link in the sidebar.
.. todo:: Update the below link when we add new guides on these.
|more| See :ref:`rst-primer` for a more in-depth introduction to
reStructuredText and :ref:`sphinxmarkup` for a full list of markup added by
Sphinx.
|more| See :doc:`/usage/restructuredtext/index` for a more in-depth
introduction to reStructuredText, including markup added by Sphinx.
Running the build

View File

@@ -1,12 +1,12 @@
.. highlightlang:: rest
.. _rst-primer:
=======================
reStructuredText Primer
=======================
This section is a brief introduction to reStructuredText (reST) concepts and
syntax, intended to provide authors with enough information to author documents
reStructuredText is the default plaintext markup language used by Sphinx. This
section is a brief introduction to reStructuredText (reST) concepts and syntax,
intended to provide authors with enough information to author documents
productively. Since reST was designed to be a simple, unobtrusive markup
language, this will not take too long.
@@ -72,8 +72,8 @@ Lists and Quote-like blocks
---------------------------
List markup (:duref:`ref <bullet-lists>`) is natural: just place an asterisk at
the start of a paragraph and indent properly. The same goes for numbered lists;
they can also be autonumbered using a ``#`` sign::
the start of a paragraph and indent properly. The same goes for numbered
lists; they can also be autonumbered using a ``#`` sign::
* This is a bulleted list.
* It has two items, the second
@@ -85,7 +85,6 @@ they can also be autonumbered using a ``#`` sign::
#. This is a numbered list.
#. It has two items too.
Nested lists are possible, but be aware that they must be separated from the
parent list items by blank lines::
@@ -126,12 +125,13 @@ There are also several more special blocks available:
* doctest blocks (:duref:`ref <doctest-blocks>`)
Source Code
-----------
Literal blocks
--------------
Literal code blocks (:duref:`ref <literal-blocks>`) are introduced by ending a
paragraph with the special marker ``::``. The literal block must be indented
(and, like all paragraphs, separated from the surrounding ones by blank lines)::
(and, like all paragraphs, separated from the surrounding ones by blank
lines)::
This is a normal text paragraph. The next paragraph is a code sample::
@@ -144,8 +144,8 @@ paragraph with the special marker ``::``. The literal block must be indented
The handling of the ``::`` marker is smart:
* If it occurs as a paragraph of its own, that paragraph is completely left
out of the document.
* If it occurs as a paragraph of its own, that paragraph is completely left out
of the document.
* If it is preceded by whitespace, the marker is removed.
* If it is preceded by non-whitespace, the marker is replaced by a single
colon.
@@ -153,15 +153,20 @@ The handling of the ``::`` marker is smart:
That way, the second sentence in the above example's first paragraph would be
rendered as "The next paragraph is a code sample:".
Code highlighting can be enabled for these literal blocks on a document-wide
basis using the :rst:dir:`highlight` directive and on a project-wide basis
using the :confval:`highlight_language` configuration option. The
:rst:dir:`code-block` directive can be used to set highlighting on a
block-by-block basis. These directives are discussed later.
.. _rst-tables:
Tables
------
For *grid tables* (:duref:`ref
<grid-tables>`), you have to "paint" the cell grid yourself. They look like
this::
For *grid tables* (:duref:`ref <grid-tables>`), you have to "paint" the cell
grid yourself. They look like this::
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
@@ -186,17 +191,18 @@ contain multiple lines. They look like this::
===== ===== =======
Two more syntaxes are supported: *CSV tables* and *List tables*. They use an
*explicit markup block*, see `Directives`_ section.
*explicit markup block*. Refer to :ref:`table-directives` for more information.
Hyperlinks
----------
External links
^^^^^^^^^^^^^^
~~~~~~~~~~~~~~
Use ```Link text <https://domain.invalid/>`_`` for inline web links. If the link
text should be the web address, you don't need special markup at all, the parser
finds links and mail addresses in ordinary text.
Use ```Link text <https://domain.invalid/>`_`` for inline web links. If the
link text should be the web address, you don't need special markup at all, the
parser finds links and mail addresses in ordinary text.
.. important:: There must be a space between the link text and the opening \< for the URL.
@@ -207,9 +213,8 @@ You can also separate the link and the target definition (:duref:`ref
.. _a link: https://domain.invalid/
Internal links
^^^^^^^^^^^^^^
~~~~~~~~~~~~~~
Internal linking is done via a special reST role provided by Sphinx, see the
section on specific markup, :ref:`ref-role`.
@@ -253,9 +258,9 @@ specially-highlighted paragraphs, comments, and generic directives.
An explicit markup block begins with a line starting with ``..`` followed by
whitespace and is terminated by the next paragraph at the same level of
indentation. (There needs to be a blank line between explicit markup and normal
paragraphs. This may all sound a bit complicated, but it is intuitive enough
when you write it.)
indentation. (There needs to be a blank line between explicit markup and
normal paragraphs. This may all sound a bit complicated, but it is intuitive
enough when you write it.)
.. _directives:
@@ -264,8 +269,8 @@ Directives
----------
A directive (:duref:`ref <directives>`) is a generic block of explicit markup.
Besides roles, it is one of the extension mechanisms of reST, and Sphinx makes
heavy use of it.
Along with roles, it is one of the extension mechanisms of reST, and Sphinx
makes heavy use of it.
Docutils supports the following directives:
@@ -303,9 +308,9 @@ Docutils supports the following directives:
* Special directives:
- :dudir:`raw <raw-data-pass-through>` (include raw target-format markup)
- :dudir:`include` (include reStructuredText from another file)
-- in Sphinx, when given an absolute include file path, this directive takes
it as relative to the source directory
- :dudir:`include` (include reStructuredText from another file) -- in Sphinx,
when given an absolute include file path, this directive takes it as
relative to the source directory
- :dudir:`class` (assign a class attribute to the next element) [1]_
* HTML specifics:
@@ -321,14 +326,16 @@ Docutils supports the following directives:
Since these are only per-file, better use Sphinx's facilities for setting the
:confval:`default_role`.
Do *not* use the directives :dudir:`sectnum`, :dudir:`header` and
:dudir:`footer`.
.. warning::
Do *not* use the directives :dudir:`sectnum`, :dudir:`header` and
:dudir:`footer`.
Directives added by Sphinx are described in :ref:`sphinxmarkup`.
Basically, a directive consists of a name, arguments, options and content. (Keep
this terminology in mind, it is used in the next chapter describing custom
directives.) Looking at this example, ::
Basically, a directive consists of a name, arguments, options and content.
(Keep this terminology in mind, it is used in the next chapter describing
custom directives.) Looking at this example, ::
.. function:: foo(x)
foo(y, z)
@@ -338,12 +345,12 @@ directives.) Looking at this example, ::
``function`` is the directive name. It is given two arguments here, the
remainder of the first line and the second line, as well as one option
``module`` (as you can see, options are given in the lines immediately following
the arguments and indicated by the colons). Options must be indented to the
same level as the directive content.
``module`` (as you can see, options are given in the lines immediately
following the arguments and indicated by the colons). Options must be indented
to the same level as the directive content.
The directive content follows after a blank line and is indented relative to the
directive start.
The directive content follows after a blank line and is indented relative to
the directive start.
Images
@@ -356,8 +363,8 @@ reST supports an image directive (:dudir:`ref <image>`), used like so::
When used within Sphinx, the file name given (here ``gnu.png``) must either be
relative to the source file, or absolute which means that they are relative to
the top source directory. For example, the file ``sketch/spam.rst`` could refer
to the image ``images/spam.png`` as ``../images/spam.png`` or
the top source directory. For example, the file ``sketch/spam.rst`` could
refer to the image ``images/spam.png`` as ``../images/spam.png`` or
``/images/spam.png``.
Sphinx will automatically copy image files over to a subdirectory of the output
@@ -365,21 +372,22 @@ directory on building (e.g. the ``_static`` directory for HTML output.)
Interpretation of image size options (``width`` and ``height``) is as follows:
if the size has no unit or the unit is pixels, the given size will only be
respected for output channels that support pixels. Other units (like ``pt``
for points) will be used for HTML and LaTeX output (the latter replaces ``pt``
by ``bp`` as this is the TeX unit such that ``72bp=1in``).
respected for output channels that support pixels. Other units (like ``pt`` for
points) will be used for HTML and LaTeX output (the latter replaces ``pt`` by
``bp`` as this is the TeX unit such that ``72bp=1in``).
Sphinx extends the standard docutils behavior by allowing an asterisk for the
extension::
.. image:: gnu.*
Sphinx then searches for all images matching the provided pattern and determines
their type. Each builder then chooses the best image out of these candidates.
For instance, if the file name ``gnu.*`` was given and two files :file:`gnu.pdf`
and :file:`gnu.png` existed in the source tree, the LaTeX builder would choose
the former, while the HTML builder would prefer the latter.
Supported image types and choosing priority are defined at :ref:`builders`.
Sphinx then searches for all images matching the provided pattern and
determines their type. Each builder then chooses the best image out of these
candidates. For instance, if the file name ``gnu.*`` was given and two files
:file:`gnu.pdf` and :file:`gnu.png` existed in the source tree, the LaTeX
builder would choose the former, while the HTML builder would prefer the
latter. Supported image types and choosing priority are defined at
:ref:`builders`.
Note that image file names should not contain spaces.
@@ -446,8 +454,8 @@ for details.
If you want to use some substitutions for all documents, put them into
:confval:`rst_prolog` or put them into a separate file and include it into all
documents you want to use them in, using the :rst:dir:`include` directive. (Be
sure to give the include file a file name extension differing from that of other
source files, to avoid Sphinx finding it as a standalone document.)
sure to give the include file a file name extension differing from that of
other source files, to avoid Sphinx finding it as a standalone document.)
Sphinx defines some default substitutions, see :ref:`default-substitutions`.
@@ -486,8 +494,8 @@ There are some problems one commonly runs into while authoring reST documents:
* **Separation of inline markup:** As said above, inline markup spans must be
separated from the surrounding text by non-word characters, you have to use a
backslash-escaped space to get around that. See
:duref:`the reference <substitution-definitions>` for the details.
backslash-escaped space to get around that. See :duref:`the reference
<substitution-definitions>` for the details.
* **No nested inline markup:** Something like ``*see :func:`foo`*`` is not
possible.

View File

@@ -0,0 +1,18 @@
================
reStructuredText
================
reStructuredText (reST) is the default plaintext markup language used by both
Docutils and Sphinx. Docutils provides the basic reStructuredText syntax, while
Sphinx extends this to support additional functionality.
The below guides go through the most important aspects of reST. For the
authoritative reStructuredText reference, refer to the `docutils
documentation`__.
__ http://docutils.sourceforge.net/rst.html
.. toctree::
:maxdepth: 2
basics