Editing Pages

Warning

../../_images/construction.png

This page is under construction.

To contribute or participate contact support@boost-lab.net

This documentation details how to edit reStructured Text pages. This content has been apropriately extracted from the offical Sphinx documentation available here.

reStructuredText in general

Common Mistakes

Common Mistakes will be populated over time, however according to the documentation, the following are common mistakes:

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.
  • No nested inline markup

The reStructuredText for these pages

A Basic Structure

Below is a very basic template which can be used to begin adding content to the document.:

.. Comment

Page Title
##########

.. toctree::
:maxdepth: 2

Contents Item 1
Contents Item 2

Chapter Title
*************

=======
Heading
=======

-----------
Sub-Heading
-----------

^^^^^^^^^^^^^^^
Sub-sub-Heading
^^^^^^^^^^^^^^^

* :ref:`genindex`
* :ref:`search`

The following items have significance: * maxdepth refers to the depth to which the contents are populated * Contents Items refer to the rst file name e.g. index for index.rst * genindex will create an index of pages * search implements search functionality

Special Characters

To be investigated

Text, Paragraphs and Lists

Text is arranged in paragraphs

It is possible to have bulleted lists like this:

  • Bullet 1

  • Bullet 2
    • Sub-Bullet 1
    • Sub-Bullet 2
  • Bullet 3

It is also possible to have enumerated lists like this:

  1. Point 1
  2. Point 2
  3. Point 3

In ReStructuredText this paragraph is written:

Text is arranged in paragraphs

It is possible to have bulleted lists like this:

* Bullet 1
* Bullet 2
   * Sub-Bullet 1
   * Sub-Bullet 2
* Bullet 3

It is also possible to have enumerated lists like this:

#. Point 1
#. Point 2
#. Point 3

In ReStructuredText this paragraph is written::

   [This code]

Admonitions

Admonitions are specially marked “topics” that can appear anywhere an ordinary body element can. They contain arbitrary body elements. Typically, an admonition is rendered as on offset block in a document, sometimes outlined or shaded, with a tile matching the admonition type.

Attention

Attention

This is an attention admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for an Attention Admonition:

.. attention::
   This is an attention admonition. It can contain any other type of text e.g. lists, or tables

   So long as they are indented accordingly

Caution

Caution

This is a caution admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for a Caution Admonition:

.. caution::
   This is a caution admonition. It can contain any other type of text e.g. lists, or tables

   So long as they are indented accordingly

Danger

Danger

This is a danger admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for an Danger Admonition:

.. danger::
   This is a danger admonition. It can contain any other type of text e.g. lists, or tables

   So long as they are indented accordingly

Error

Error

This is an error admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for an Error Admonition:

.. error::
   This is an error admonition. It can contain any other type of text e.g. lists, or tables

   So long as they are indented accordingly

Hint

Hint

This is a hint admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for a Hint Admonition:

.. hint::
   This is a hint admonition. It can contain any other type of text e.g. lists, or tables

   So long as they are indented accordingly

Important

Important

This is an important admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for an Important Admonition:

.. important::
   This is an important admonition. It can contain any other type of text e.g. lists, or tables

   So long as they are indented accordingly

Note

Note

This is a note admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for a Note Admonition:

.. note::
This is a note admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Tip

Tip

This is a tip admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for a Tip Admonition:

.. tip::
This is a tip admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Warning

Warning

This is a warning admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Below is the ReStructuredText required for a Warning Admonition:

.. warning::
This is a warning admonition. It can contain any other type of text e.g. lists, or tables

So long as they are indented accordingly

Images and Figures

See also Figures and images.

Images and figures can placed anywhere in the rst page. The can be between paragraphs, in tables or in lists. It is best practice that all images reside in the images folder and it can have any name and file extension (that is valid with internet browsers).

To avoid overwriting images from other pages it is recommended that the images are called xxx01.png where xxx is the id of the page e.g. editpages01.png

The following is quoted from the Sphinx Documentation guide (here):

alternate text

reST supports an image directive (ref), used as follows:

.. image:: /images/common/comingsoon.png
        :height: 100px
        :width: 200 px
        :scale: 50 %
        :alt: alternate text
        :align: right
alternate text

Figure 139 The coming soon image

Figures have a text to describe the image otherwise they have the same syntax as images as follows:

.. figure:: /images/common/comingsoon.png
             :height: 100px
             :width: 200 px
             :scale: 50 %
             :alt: alternate text
             :align: right

             The coming soon image

The following options are recognised:

alt

alt:text

Alternate text: a short description of the image, displayed by applications that cannot display images, or spoken by applications for visually impaired users

height

height:length

The desired height of the image. Used to reserve space or scale the image horizontally. As with “height” above, when the “scale” option is also specified, they are combined. For example, a height o 200px and a scale of 50 is equivalent to a height of 100px with no scale

width

width: length or percentage of the current line width

The width of the image. Used to reserve space or scale the image horizontally. As with “height” above, when the “scale” option is also specified, they are combined.

scale

scale: integer percentage (the “%” symbol is optional)

The uniform scaling factor of the image. The default is “100%”, i.e. no scaling

If no “height” or “width” options are specified, the Python Imaging Library (PIL) may be used to determine them, if it is installed and the image file is available.

align

align: “top”, “middle”, “bottom”, “left”, “center”, or “right”

The alignment of the image, equivalent to the HTML <img> tag’s deprecated “align” attribute or the corresponding “vertical-align” and “text-align” CSS properties.

target

target: text (URI or reference name)

Makes the image into a hyperlink reference (“clickable”). The option argument may be a URI (relative or absolute), or a reference name with underscore suffix.

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 /images/spam.png.

Sphinx will automatically copy image files over to a subdirectory of the output 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).

Sphinx extends the standard docutils behaviour 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 gnu.pdf and 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 Available builders.

Note that image file names should not contain spaces.

Videos

Videos are either referenced from the internet (e.g. for youtube) or stored in the _static and referenced from the pages.

To reference a local video the following should be used, where the path is the relative path from the page to the video:

.. raw:: html

        <video width="560" height="315" controls src="../../../_static/videos/architectures01.mp4">

To refence a youtube video the following should be used.

.. raw:: html

        <iframe width="560" height="315" src="https://www.youtube.com/embed/ncMlaE48HlA" frameborder="0" allowfullscreen></iframe>

Tip

The complete iframe text can be copied from the youtube page for the video.

../../_images/edityoutube01.png

The result looks as follows:

Tables

There are two forms of tables that are supported in reStructuredText:

Grid Tables

To create a grid table, you have to “paint” the cell grid yourself.

Header Column 1 (header rows optional) Header Column 2 Header Column 3 Header Column 4
Body Row 1, Column 1 Body Row 1, Column 2 Body Row 1, Column 3 Body Row 1, Column 4
Body Row 2, Column 1 Body Row 2, Column 2 Body Row 2, Column 3 Body Row 2, Column 4
+------------------------+----------------------+----------------------+----------------------+
| Header Column 1        | Header Column 2      | Header Column 3      | Header Column 4      |
| (header rows optional) |                      |                      |                      |
+========================+======================+======================+======================+
| Body Row 1, Column 1   | Body Row 1, Column 2 | Body Row 1, Column 3 | Body Row 1, Column 4 |
+------------------------+----------------------+----------------------+----------------------+
| Body Row 2, Column 1   | Body Row 2, Column 2 | Body Row 2, Column 3 | Body Row 2, Column 4 |
+------------------------+----------------------+----------------------+----------------------+

Simple Tables

Simple tables are much easier to create, however they must contain more than one row, and the first column cannot contain multiple lines. (Auto formating in Eclipse does not work for these types of tables)

Header Column 1 Header Column 2 Header Column 3
Row 1, Column 1 Row 1, Column 2 Row 1, Column 3
Row 2, Column 1 Row 2, Column 2 Row 2, Column 3
===============   ===============   ===============
Header Column 1   Header Column 2   Header Column 3
===============   ===============   ===============
Row 1, Column 1   Row 1, Column 2   Row 1, Column 3
Row 2, Column 1   Row 2, Column 2   Row 2, Column 3
===============   ===============   ===============

Code Fragments

Code Fragments are written into ReStructuredText bt ending a paragraph with the marker ::. The code must then be indented and be separated from other paragraphs by blank lines. The following example was extracted from the Sphinx Documentation:

This is a normal text paragraph. The next paragraph is a code sample::

   It is not processed in any way, except that indentation is removed.

   It can span multiple lines.

This is a normal text paragraph

Expanding Sections

This section is an expanding section, to create an expanding section add

.. rst-class:: expand

before any section header.

Directory Structure and other files

Where to place files

There is a basic file structure that should be adhered to when adding pages to the documentation. The source folder should consist of the files ‘index.rst’ and ‘conf.py’ with the folders ‘_static’, ‘_templates’, and ‘objects’. These should not be changed.

Root Folder Sub Folder Sub Folder 2 Content
_static     This contains fixed attached files, any files inserted here are not processed by the compiler, only copied into the build folder
_static videos   This folder contains any videos that are held in the documentation
_themes     This contains Sphinx theme files
images     This the images that form this documentation
pages     This folder contains rst files that form this documentation

Authors

These can be added using the sectionauthor and optionally keywords. e.g.

.. sectionauthor:: |Judith Crockford|
.. sectionauthor:: `Judith Crockford <mailto:judith.crockford@airbus.com?subject=STEPlib Documentation>`_

Either of these return:

Section author: Judith Crockford

Sphinx Themes

Sphinx Themes are either imported in the conf.py or referenced from the folder:

\source\_themes

Within these a themes’ CSS and JavaScript functions can be created and integrated.

Sphinx Builds are constructed using the conf.py file within the source, editing this determines how HTML, PDF, ePub etc builds are created.

Watermark

The watermark is provided by the sphinxmark extension.

The watermark can be text or an image; controlled by settings in the conf.py

Section author: Judith Crockford (AP243)