| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526 | <!doctype html><html>  <head>    <title>CodeMirror 2: reStructuredText mode</title>    <link rel="stylesheet" href="../../lib/codemirror.css">    <script src="../../lib/codemirror.js"></script>    <script src="rst.js"></script>    <link rel="stylesheet" href="rst.css">    <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>    <link rel="stylesheet" href="../../css/docs.css">  </head>  <body>    <h1>CodeMirror 2: reStructuredText mode</h1><form><textarea id="code" name="code">.. This is an excerpt from Sphinx documentation: http://sphinx.pocoo.org/_sources/rest.txt.. highlightlang:: rest.. _rst-primer:reStructuredText Primer=======================This section is a brief introduction to reStructuredText (reST) concepts andsyntax, intended to provide authors with enough information to author documentsproductively.  Since reST was designed to be a simple, unobtrusive markuplanguage, this will not take too long... seealso::   The authoritative `reStructuredText User Documentation   <http://docutils.sourceforge.net/rst.html>`_.  The "ref" links in this   document link to the description of the individual constructs in the reST   reference.Paragraphs----------The paragraph (:duref:`ref <paragraphs>`) is the most basic block in a reSTdocument.  Paragraphs are simply chunks of text separated by one or more blanklines.  As in Python, indentation is significant in reST, so all lines of thesame paragraph must be left-aligned to the same level of indentation... _inlinemarkup:Inline markup-------------The standard reST inline markup is quite simple: use* one asterisk: ``*text*`` for emphasis (italics),* two asterisks: ``**text**`` for strong emphasis (boldface), and* backquotes: ````text```` for code samples.If asterisks or backquotes appear in running text and could be confused withinline markup delimiters, they have to be escaped with a backslash.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: ``thisis\ *one*\ word``.These restrictions may be lifted in future versions of the docutils.reST also allows for custom "interpreted text roles"', which signify that theenclosed text should be interpreted in a specific way.  Sphinx uses this toprovide semantic markup and cross-referencing of identifiers, as described inthe appropriate section.  The general syntax is ``:rolename:`content```.Standard reST provides the following roles:* :durole:`emphasis` -- alternate spelling for ``*emphasis*``* :durole:`strong` -- alternate spelling for ``**strong**``* :durole:`literal` -- alternate spelling for ````literal````* :durole:`subscript` -- subscript text* :durole:`superscript` -- superscript text* :durole:`title-reference` -- for titles of books, periodicals, and other  materialsSee :ref:`inline-markup` for roles added by Sphinx.Lists and Quote-like blocks---------------------------List markup (:duref:`ref <bullet-lists>`) is natural: just place an asterisk atthe 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     item uses two lines.   1. This is a numbered list.   2. It has two items too.   #. This is a numbered list.   #. It has two items too.Nested lists are possible, but be aware that they must be separated from theparent list items by blank lines::   * this is   * a list     * with a nested list     * and some subitems   * and here the parent list continuesDefinition lists (:duref:`ref <definition-lists>`) are created as follows::   term (up to a line of text)      Definition of the term, which must be indented      and can even consist of multiple paragraphs   next term      Description.Note that the term cannot have more than one line of text.Quoted paragraphs (:duref:`ref <block-quotes>`) are created by just indentingthem more than the surrounding paragraphs.Line blocks (:duref:`ref <line-blocks>`) are a way of preserving line breaks::   | These lines are   | broken exactly like in   | the source file.There are also several more special blocks available:* field lists (:duref:`ref <field-lists>`)* option lists (:duref:`ref <option-lists>`)* quoted literal blocks (:duref:`ref <quoted-literal-blocks>`)* doctest blocks (:duref:`ref <doctest-blocks>`)Source Code-----------Literal code blocks (:duref:`ref <literal-blocks>`) are introduced by ending aparagraph with the special marker ``::``.  The literal block must be indented(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::      It is not processed in any way, except      that the indentation is removed.      It can span multiple lines.   This is a normal text paragraph again.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 is preceded by whitespace, the marker is removed.* If it is preceded by non-whitespace, the marker is replaced by a single  colon.That way, the second sentence in the above example's first paragraph would berendered as "The next paragraph is a code sample:"... _rst-tables:Tables------Two forms of tables are supported.  For *grid tables* (:duref:`ref<grid-tables>`), you have to "paint" the cell grid yourself.  They look likethis::   +------------------------+------------+----------+----------+   | Header row, column 1   | Header 2   | Header 3 | Header 4 |   | (header rows optional) |            |          |          |   +========================+============+==========+==========+   | body row 1, column 1   | column 2   | column 3 | column 4 |   +------------------------+------------+----------+----------+   | body row 2             | ...        | ...      |          |   +------------------------+------------+----------+----------+*Simple tables* (:duref:`ref <simple-tables>`) are easier to write, butlimited: they must contain more than one row, and the first column cannotcontain multiple lines.  They look like this::   =====  =====  =======   A      B      A and B   =====  =====  =======   False  False  False   True   False  False   False  True   False   True   True   True   =====  =====  =======Hyperlinks----------External links^^^^^^^^^^^^^^Use ```Link text <http://example.com/>`_`` for inline web links.  If the linktext should be the web address, you don't need special markup at all, the parserfinds links and mail addresses in ordinary text.You can also separate the link and the target definition (:duref:`ref<hyperlink-targets>`), like this::   This is a paragraph that contains `a link`_.   .. _a link: http://example.com/Internal links^^^^^^^^^^^^^^Internal linking is done via a special reST role provided by Sphinx, see thesection on specific markup, :ref:`ref-role`.Sections--------Section headers (:duref:`ref <sections>`) are created by underlining (andoptionally overlining) the section title with a punctuation character, at leastas long as the text::   =================   This is a heading   =================Normally, there are no heading levels assigned to certain characters as thestructure is determined from the succession of headings.  However, for thePython documentation, this convention is used which you may follow:* ``#`` with overline, for parts* ``*`` with overline, for chapters* ``=``, for sections* ``-``, for subsections* ``^``, for subsubsections* ``"``, for paragraphsOf course, you are free to use your own marker characters (see the reSTdocumentation), and use a deeper nesting level, but keep in mind that mosttarget formats (HTML, LaTeX) have a limited supported nesting depth.Explicit Markup---------------"Explicit markup" (:duref:`ref <explicit-markup-blocks>`) is used in reST formost constructs that need special handling, such as footnotes,specially-highlighted paragraphs, comments, and generic directives.An explicit markup block begins with a line starting with ``..`` followed bywhitespace and is terminated by the next paragraph at the same level ofindentation.  (There needs to be a blank line between explicit markup and normalparagraphs.  This may all sound a bit complicated, but it is intuitive enoughwhen you write it.).. _directives: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 makesheavy use of it.Docutils supports the following directives:* Admonitions: :dudir:`attention`, :dudir:`caution`, :dudir:`danger`,  :dudir:`error`, :dudir:`hint`, :dudir:`important`, :dudir:`note`,  :dudir:`tip`, :dudir:`warning` and the generic :dudir:`admonition`.  (Most themes style only "note" and "warning" specially.)* Images:  - :dudir:`image` (see also Images_ below)  - :dudir:`figure` (an image with caption and optional legend)* Additional body elements:  - :dudir:`contents` (a local, i.e. for the current file only, table of    contents)  - :dudir:`container` (a container with a custom class, useful to generate an    outer ``<div>`` in HTML)  - :dudir:`rubric` (a heading without relation to the document sectioning)  - :dudir:`topic`, :dudir:`sidebar` (special highlighted body elements)  - :dudir:`parsed-literal` (literal block that supports inline markup)  - :dudir:`epigraph` (a block quote with optional attribution line)  - :dudir:`highlights`, :dudir:`pull-quote` (block quotes with their own    class attribute)  - :dudir:`compound` (a compound paragraph)* Special tables:  - :dudir:`table` (a table with title)  - :dudir:`csv-table` (a table generated from comma-separated values)  - :dudir:`list-table` (a table generated from a list of lists)* Special directives:  - :dudir:`raw` (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:`class` (assign a class attribute to the next element) [1]_* HTML specifics:  - :dudir:`meta` (generation of HTML ``<meta>`` tags)  - :dudir:`title` (override document title)* Influencing markup:  - :dudir:`default-role` (set a new default role)  - :dudir:`role` (create a new role)  Since these are only per-file, better use Sphinx' facilities for setting the  :confval:`default_role`.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. (Keepthis terminology in mind, it is used in the next chapter describing customdirectives.)  Looking at this example, ::   .. function:: foo(x)                 foo(y, z)      :module: some.module.name      Return a line of text input from the user.``function`` is the directive name.  It is given two arguments here, theremainder 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 followingthe arguments and indicated by the colons).  Options must be indented to thesame level as the directive content.The directive content follows after a blank line and is indented relative to thedirective start.Images------reST supports an image directive (:dudir:`ref <image>`), used like so::   .. image:: gnu.png      (options)When used within Sphinx, the file name given (here ``gnu.png``) must either berelative to the source file, or absolute which means that they are relative tothe top source directory.  For example, the file ``sketch/spam.rst`` could referto 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 outputdirectory 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 berespected for output channels that support pixels (i.e. not in LaTeX output).Other units (like ``pt`` for points) will be used for HTML and LaTeX output.Sphinx extends the standard docutils behavior by allowing an asterisk for theextension::   .. image:: gnu.*Sphinx then searches for all images matching the provided pattern and determinestheir 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 choosethe former, while the HTML builder would prefer the latter... versionchanged:: 0.4   Added the support for file names ending in an asterisk... versionchanged:: 0.6   Image paths can now be absolute.Footnotes---------For footnotes (:duref:`ref <footnotes>`), use ``[#name]_`` to mark the footnotelocation, and add the footnote body at the bottom of the document after a"Footnotes" rubric heading, like so::   Lorem ipsum [#f1]_ dolor sit amet ... [#f2]_   .. rubric:: Footnotes   .. [#f1] Text of the first footnote.   .. [#f2] Text of the second footnote.You can also explicitly number the footnotes (``[1]_``) or use auto-numberedfootnotes without names (``[#]_``).Citations---------Standard reST citations (:duref:`ref <citations>`) are supported, with theadditional feature that they are "global", i.e. all citations can be referencedfrom all files.  Use them like so::   Lorem ipsum [Ref]_ dolor sit amet.   .. [Ref] Book or article reference, URL or whatever.Citation usage is similar to footnote usage, but with a label that is notnumeric or begins with ``#``.Substitutions-------------reST supports "substitutions" (:duref:`ref <substitution-definitions>`), whichare pieces of text and/or markup referred to in the text by ``|name|``.  Theyare defined like footnotes with explicit markup blocks, like this::   .. |name| replace:: replacement *text*or this::   .. |caution| image:: warning.png                :alt: Warning!See the :duref:`reST reference for substitutions <substitution-definitions>`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 alldocuments you want to use them in, using the :rst:dir:`include` directive.  (Besure to give the include file a file name extension differing from that of othersource files, to avoid Sphinx finding it as a standalone document.)Sphinx defines some default substitutions, see :ref:`default-substitutions`.Comments--------Every explicit markup block which isn't a valid markup construct (like thefootnotes above) is regarded as a comment (:duref:`ref <comments>`).  Forexample::   .. This is a comment.You can indent text after a comment start to form multiline comments::   ..      This whole indented block      is a comment.      Still in the comment.Source encoding---------------Since the easiest way to include special characters like em dashes or copyrightsigns in reST is to directly write them as Unicode characters, one has tospecify an encoding.  Sphinx assumes source files to be encoded in UTF-8 bydefault; you can change this with the :confval:`source_encoding` config value.Gotchas-------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 `the reference  <http://docutils.sf.net/docs/ref/rst/restructuredtext.html#inline-markup>`_  for the details.* **No nested inline markup:** Something like ``*see :func:`foo`*`` is not  possible... rubric:: Footnotes.. [1] When the default domain contains a :rst:dir:`class` directive, this directive       will be shadowed.  Therefore, Sphinx re-exports it as :rst:dir:`rst-class`.</textarea></form>    <script>      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {        lineNumbers: true,      });    </script>    <p>The reStructuredText mode supports one configuration parameter:</p>    <dl>      <dt><code>verbatim (string)</code></dt>      <dd>A name or MIME type of a mode that will be used for highlighting      verbatim blocks. By default, reStructuredText mode uses uniform color      for whole block of verbatim text if no mode is given.</dd>    </dl>    <p>If <code>python</code> mode is available (not a part of CodeMirror 2 yet),    it will be used for highlighting blocks containing Python/IPython terminal    sessions (blocks starting with <code>>>></code> (for Python) or    <code>In [num]:</code> (for IPython).    <p><strong>MIME types defined:</strong> <code>text/x-rst</code>.</p>  </body></html>
 |