Using reStructuredText Markup

The reStructuredText specification allows for a certain degree of flexibility in markup to achieve your goals. For example, you can use any one of more than a dozen characters for section title underlines, and you have the option of using an overline in addition to an underline.

However, for consistency and ease of use, the Mattermost documentation should use a single convention, despite the existence of allowable alternatives.

For more information about reStructuredText markup, see the reStructuredText Markup Specification. Additional markup constructs are implemented by Sphinx, the documentation generator used by Mattermost. For information about the additional constructs, see Sphinx Markup Constructs.

Use the following markup conventions in Mattermost documentation:

Page titles

For page titles, use the = character for the title underline, with no overline. For example:

Using reStructuredText Markup
=============================

Unlike Markdown, underlines in reStructuredText must be at least as long as the title text.

Section titles

If your document has more than one section, use the - character for the section title underline. For example:

Section titles
--------------

If you do need subsections, use the the ^ character for the first subsection level, and the ` character for the second subsection level. For example:

Subsection One
^^^^^^^^^^^^^^

Subsection Two
``````````````

Inline markup

Bold
Use double asterisks. For example: **bold text**.
Italic
Use single asterisk. For example: *italic text*.
Monospace
Use double backquotes. For example: ``monospace text``

Bullet lists

For bullet lists and sublists, use only the - character. For example:

- list item one
- list item two
  - sublist item one
  - sublist item two
- list item three

Numbered lists and procedure steps

Create numbered lists and procedure steps using arabic numerals for the top-level list and lower case alpha characters for the first nested list. For example:

1. This is item one.
2. This is item two.

  a. This is nested item one.
  b. This is nested item two.

3. This is item three.

Images

Use the following construct to insert an image:

.. image:: ../images/choices.png

You can also add the following image options: alt, height, width, scale, align, and target. For example:

.. image:: ../images/choices.png
  :alt: The choices that you can make.
  :height: 100px
  :width: 200px
  :align: left

Inserting an inline image is a bit more complicated. It’s a two-part construct that consists of a label and the image directive. Surround the label text with vertical bars, the | character. For example:

Some of the emoji that you can use are |emoji|.

Later on in the document, perhaps at the end of the paragraph that contains the label, insert the following image directive:

.. |emoji| image:: ../images/emoji.png
  :alt: Some of the emoji that you can use.
  :align: middle

Literal blocks

In reStructuredText markup, the double colon marks the start of a section of literal text that corresponds to the HTML <pre> tag. However, the Sphinx processor applies syntax highlighting for Python to literal blocks, which is not always desired in Mattermost documentation.

To use a literal block as originally intended in the reStructuredText specification, you must cheat a little, and use the Sphinx code-block directive with the language set to none. For example:

.. code-block:: none

Code blocks with syntax highlighting

To create a code block with syntax highlighting, use the Sphinx code-block directive with the language set to the language that you want highlighted. Many languages are available, but in Mattermost documentation the most likely ones are as follows:

  • go
  • rest
  • html
  • javascript
  • coffee
  • bash

The following example is a block of Go code using the :linenos: option, which causes line numbers to be displayed.

.. code-block:: go
  :linenos:

  newPassword := props["new_password"]
      if err := utils.IsPasswordValid(newPassword); err != nil {
              c.Err = err
              return
      }

The example produces the following output:

1
2
3
4
5
newPassword := props["new_password"]
      if err := utils.IsPasswordValid(newPassword); err != nil {
              c.Err = err
              return
      }

The highlighting is provided by Pygments Python syntax highlighter, which supports a large number of programming and markup languages. For a complete list, see Available lexers