############################################## Restructured Text (reST) and Sphinx CheatSheet ############################################## .. sidebar:: Summary :Release: |release| :Date: |today| :Authors: **Thomas Cokelaer** :Target: developers and administrators :status: mature .. contents:: :depth: 2 .. seealso:: This documentation is based based upon documentation found in: * `Sphinx `_ * `Docutils `_ .. note:: Sphinx code is written in reST. Nonetheless, sphinx adds many additional directives on top of the reST syntax. Therefore sphinx code may not be fully compatible with reST. ############ Generalities ############ Introduction ============ reStructuredText is an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system. It is useful for in-line program documentation (such as Python docstrings), for quickly creating simple web pages, and for standalone documents. .. warning:: like Python, reST syntax is sensitive to indentation ! .. warning:: reST requires blank lines between paragraphs Text syntax: bold, italic, verbatim and special characters ` ============================================================ :basic usage: * use one asterisk on each side of a text you want to emphasize in *italic* and 2 asterisks in you want to make it **bold**:: *italic* **bold** * double backquotes are used to make a text verbatim. For instance, it you want to use special characters such as ``*``:: This ``*`` character is not interpreted * Finally, the single backquote is used for reST special commands (e.g., hyper links with spaces):: This is how to create hyperlinks (see later) `OpenAlea wiki `_ .. note:: If asterisks or backquotes appear in running text and could be confused with inline markup delimiters, they have to be escaped with a backslash. :advanced usage: Be aware of some restrictions of this markup: * it may not be nested, * content may not start or end with whitespace: ``* text*`` is wrong, * it must be separated from surrounding text by non-word characters. Use a backslash escaped space to work around that: * ``this is a *longish* paragraph`` is correct and gives *longish*. * ``this is a long*ish* paragraph`` is not interpreted as expected. You should use ``this is a long\ *ish* paragraph`` to obtain long\ *ish* paragraph .. warning:: In Python docstrings it will be necessary to escape any backslash characters so that they actually reach reStructuredText. The simplest way to do this is to use raw strings: ===================================== ================================ Python string Typical result ===================================== ================================ ``r"""\*escape* \`with` "\\""""`` ``*escape* `with` "\"`` ``"""\\*escape* \\`with` "\\\\""""`` ``*escape* `with` "\"`` ``"""\*escape* \`with` "\\""""`` ``escape with ""`` ===================================== ================================ Headings ========== In order to write a title, just underline it:: ***** Title ***** subtitle ######## subsubtitle *********** and so on Two rules: * use at least as many characters as the length of the title * characters usage is quite flexible but be consistent Normally, there are no heading levels assigned to certain characters as the structure is determined from the succession of headings. However, for the Python documentation, this convention is used which you may want to follow : * `#` with overline, for parts * `*` with overline, for chapters * `=`, for sections * `-`, for subsections * `^`, for subsubsections * `"`, for paragraphs Directives ============ reST is mainly based on *directives* that are defined as follows:: .. :: :