index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <!doctype html>
  2. <title>CodeMirror: reStructuredText mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="../../addon/mode/overlay.js"></script>
  8. <script src="rst.js"></script>
  9. <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  10. <div id=nav>
  11. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  12. <ul>
  13. <li><a href="../../index.html">Home</a>
  14. <li><a href="../../doc/manual.html">Manual</a>
  15. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  16. </ul>
  17. <ul>
  18. <li><a href="../index.html">Language modes</a>
  19. <li><a class=active href="#">reStructuredText</a>
  20. </ul>
  21. </div>
  22. <article>
  23. <h2>reStructuredText mode</h2>
  24. <form><textarea id="code" name="code">
  25. .. This is an excerpt from Sphinx documentation: http://sphinx.pocoo.org/_sources/rest.txt
  26. .. highlightlang:: rest
  27. .. _rst-primer:
  28. reStructuredText Primer
  29. =======================
  30. This section is a brief introduction to reStructuredText (reST) concepts and
  31. syntax, intended to provide authors with enough information to author documents
  32. productively. Since reST was designed to be a simple, unobtrusive markup
  33. language, this will not take too long.
  34. .. seealso::
  35. The authoritative `reStructuredText User Documentation
  36. &lt;http://docutils.sourceforge.net/rst.html&gt;`_. The "ref" links in this
  37. document link to the description of the individual constructs in the reST
  38. reference.
  39. Paragraphs
  40. ----------
  41. The paragraph (:duref:`ref &lt;paragraphs&gt;`) is the most basic block in a reST
  42. document. Paragraphs are simply chunks of text separated by one or more blank
  43. lines. As in Python, indentation is significant in reST, so all lines of the
  44. same paragraph must be left-aligned to the same level of indentation.
  45. .. _inlinemarkup:
  46. Inline markup
  47. -------------
  48. The standard reST inline markup is quite simple: use
  49. * one asterisk: ``*text*`` for emphasis (italics),
  50. * two asterisks: ``**text**`` for strong emphasis (boldface), and
  51. * backquotes: ````text```` for code samples.
  52. If asterisks or backquotes appear in running text and could be confused with
  53. inline markup delimiters, they have to be escaped with a backslash.
  54. Be aware of some restrictions of this markup:
  55. * it may not be nested,
  56. * content may not start or end with whitespace: ``* text*`` is wrong,
  57. * it must be separated from surrounding text by non-word characters. Use a
  58. backslash escaped space to work around that: ``thisis\ *one*\ word``.
  59. These restrictions may be lifted in future versions of the docutils.
  60. reST also allows for custom "interpreted text roles"', which signify that the
  61. enclosed text should be interpreted in a specific way. Sphinx uses this to
  62. provide semantic markup and cross-referencing of identifiers, as described in
  63. the appropriate section. The general syntax is ``:rolename:`content```.
  64. Standard reST provides the following roles:
  65. * :durole:`emphasis` -- alternate spelling for ``*emphasis*``
  66. * :durole:`strong` -- alternate spelling for ``**strong**``
  67. * :durole:`literal` -- alternate spelling for ````literal````
  68. * :durole:`subscript` -- subscript text
  69. * :durole:`superscript` -- superscript text
  70. * :durole:`title-reference` -- for titles of books, periodicals, and other
  71. materials
  72. See :ref:`inline-markup` for roles added by Sphinx.
  73. Lists and Quote-like blocks
  74. ---------------------------
  75. List markup (:duref:`ref &lt;bullet-lists&gt;`) is natural: just place an asterisk at
  76. the start of a paragraph and indent properly. The same goes for numbered lists;
  77. they can also be autonumbered using a ``#`` sign::
  78. * This is a bulleted list.
  79. * It has two items, the second
  80. item uses two lines.
  81. 1. This is a numbered list.
  82. 2. It has two items too.
  83. #. This is a numbered list.
  84. #. It has two items too.
  85. Nested lists are possible, but be aware that they must be separated from the
  86. parent list items by blank lines::
  87. * this is
  88. * a list
  89. * with a nested list
  90. * and some subitems
  91. * and here the parent list continues
  92. Definition lists (:duref:`ref &lt;definition-lists&gt;`) are created as follows::
  93. term (up to a line of text)
  94. Definition of the term, which must be indented
  95. and can even consist of multiple paragraphs
  96. next term
  97. Description.
  98. Note that the term cannot have more than one line of text.
  99. Quoted paragraphs (:duref:`ref &lt;block-quotes&gt;`) are created by just indenting
  100. them more than the surrounding paragraphs.
  101. Line blocks (:duref:`ref &lt;line-blocks&gt;`) are a way of preserving line breaks::
  102. | These lines are
  103. | broken exactly like in
  104. | the source file.
  105. There are also several more special blocks available:
  106. * field lists (:duref:`ref &lt;field-lists&gt;`)
  107. * option lists (:duref:`ref &lt;option-lists&gt;`)
  108. * quoted literal blocks (:duref:`ref &lt;quoted-literal-blocks&gt;`)
  109. * doctest blocks (:duref:`ref &lt;doctest-blocks&gt;`)
  110. Source Code
  111. -----------
  112. Literal code blocks (:duref:`ref &lt;literal-blocks&gt;`) are introduced by ending a
  113. paragraph with the special marker ``::``. The literal block must be indented
  114. (and, like all paragraphs, separated from the surrounding ones by blank lines)::
  115. This is a normal text paragraph. The next paragraph is a code sample::
  116. It is not processed in any way, except
  117. that the indentation is removed.
  118. It can span multiple lines.
  119. This is a normal text paragraph again.
  120. The handling of the ``::`` marker is smart:
  121. * If it occurs as a paragraph of its own, that paragraph is completely left
  122. out of the document.
  123. * If it is preceded by whitespace, the marker is removed.
  124. * If it is preceded by non-whitespace, the marker is replaced by a single
  125. colon.
  126. That way, the second sentence in the above example's first paragraph would be
  127. rendered as "The next paragraph is a code sample:".
  128. .. _rst-tables:
  129. Tables
  130. ------
  131. Two forms of tables are supported. For *grid tables* (:duref:`ref
  132. &lt;grid-tables&gt;`), you have to "paint" the cell grid yourself. They look like
  133. this::
  134. +------------------------+------------+----------+----------+
  135. | Header row, column 1 | Header 2 | Header 3 | Header 4 |
  136. | (header rows optional) | | | |
  137. +========================+============+==========+==========+
  138. | body row 1, column 1 | column 2 | column 3 | column 4 |
  139. +------------------------+------------+----------+----------+
  140. | body row 2 | ... | ... | |
  141. +------------------------+------------+----------+----------+
  142. *Simple tables* (:duref:`ref &lt;simple-tables&gt;`) are easier to write, but
  143. limited: they must contain more than one row, and the first column cannot
  144. contain multiple lines. They look like this::
  145. ===== ===== =======
  146. A B A and B
  147. ===== ===== =======
  148. False False False
  149. True False False
  150. False True False
  151. True True True
  152. ===== ===== =======
  153. Hyperlinks
  154. ----------
  155. External links
  156. ^^^^^^^^^^^^^^
  157. Use ```Link text &lt;http://example.com/&gt;`_`` for inline web links. If the link
  158. text should be the web address, you don't need special markup at all, the parser
  159. finds links and mail addresses in ordinary text.
  160. You can also separate the link and the target definition (:duref:`ref
  161. &lt;hyperlink-targets&gt;`), like this::
  162. This is a paragraph that contains `a link`_.
  163. .. _a link: http://example.com/
  164. Internal links
  165. ^^^^^^^^^^^^^^
  166. Internal linking is done via a special reST role provided by Sphinx, see the
  167. section on specific markup, :ref:`ref-role`.
  168. Sections
  169. --------
  170. Section headers (:duref:`ref &lt;sections&gt;`) are created by underlining (and
  171. optionally overlining) the section title with a punctuation character, at least
  172. as long as the text::
  173. =================
  174. This is a heading
  175. =================
  176. Normally, there are no heading levels assigned to certain characters as the
  177. structure is determined from the succession of headings. However, for the
  178. Python documentation, this convention is used which you may follow:
  179. * ``#`` with overline, for parts
  180. * ``*`` with overline, for chapters
  181. * ``=``, for sections
  182. * ``-``, for subsections
  183. * ``^``, for subsubsections
  184. * ``"``, for paragraphs
  185. Of course, you are free to use your own marker characters (see the reST
  186. documentation), and use a deeper nesting level, but keep in mind that most
  187. target formats (HTML, LaTeX) have a limited supported nesting depth.
  188. Explicit Markup
  189. ---------------
  190. "Explicit markup" (:duref:`ref &lt;explicit-markup-blocks&gt;`) is used in reST for
  191. most constructs that need special handling, such as footnotes,
  192. specially-highlighted paragraphs, comments, and generic directives.
  193. An explicit markup block begins with a line starting with ``..`` followed by
  194. whitespace and is terminated by the next paragraph at the same level of
  195. indentation. (There needs to be a blank line between explicit markup and normal
  196. paragraphs. This may all sound a bit complicated, but it is intuitive enough
  197. when you write it.)
  198. .. _directives:
  199. Directives
  200. ----------
  201. A directive (:duref:`ref &lt;directives&gt;`) is a generic block of explicit markup.
  202. Besides roles, it is one of the extension mechanisms of reST, and Sphinx makes
  203. heavy use of it.
  204. Docutils supports the following directives:
  205. * Admonitions: :dudir:`attention`, :dudir:`caution`, :dudir:`danger`,
  206. :dudir:`error`, :dudir:`hint`, :dudir:`important`, :dudir:`note`,
  207. :dudir:`tip`, :dudir:`warning` and the generic :dudir:`admonition`.
  208. (Most themes style only "note" and "warning" specially.)
  209. * Images:
  210. - :dudir:`image` (see also Images_ below)
  211. - :dudir:`figure` (an image with caption and optional legend)
  212. * Additional body elements:
  213. - :dudir:`contents` (a local, i.e. for the current file only, table of
  214. contents)
  215. - :dudir:`container` (a container with a custom class, useful to generate an
  216. outer ``&lt;div&gt;`` in HTML)
  217. - :dudir:`rubric` (a heading without relation to the document sectioning)
  218. - :dudir:`topic`, :dudir:`sidebar` (special highlighted body elements)
  219. - :dudir:`parsed-literal` (literal block that supports inline markup)
  220. - :dudir:`epigraph` (a block quote with optional attribution line)
  221. - :dudir:`highlights`, :dudir:`pull-quote` (block quotes with their own
  222. class attribute)
  223. - :dudir:`compound` (a compound paragraph)
  224. * Special tables:
  225. - :dudir:`table` (a table with title)
  226. - :dudir:`csv-table` (a table generated from comma-separated values)
  227. - :dudir:`list-table` (a table generated from a list of lists)
  228. * Special directives:
  229. - :dudir:`raw` (include raw target-format markup)
  230. - :dudir:`include` (include reStructuredText from another file)
  231. -- in Sphinx, when given an absolute include file path, this directive takes
  232. it as relative to the source directory
  233. - :dudir:`class` (assign a class attribute to the next element) [1]_
  234. * HTML specifics:
  235. - :dudir:`meta` (generation of HTML ``&lt;meta&gt;`` tags)
  236. - :dudir:`title` (override document title)
  237. * Influencing markup:
  238. - :dudir:`default-role` (set a new default role)
  239. - :dudir:`role` (create a new role)
  240. Since these are only per-file, better use Sphinx' facilities for setting the
  241. :confval:`default_role`.
  242. Do *not* use the directives :dudir:`sectnum`, :dudir:`header` and
  243. :dudir:`footer`.
  244. Directives added by Sphinx are described in :ref:`sphinxmarkup`.
  245. Basically, a directive consists of a name, arguments, options and content. (Keep
  246. this terminology in mind, it is used in the next chapter describing custom
  247. directives.) Looking at this example, ::
  248. .. function:: foo(x)
  249. foo(y, z)
  250. :module: some.module.name
  251. Return a line of text input from the user.
  252. ``function`` is the directive name. It is given two arguments here, the
  253. remainder of the first line and the second line, as well as one option
  254. ``module`` (as you can see, options are given in the lines immediately following
  255. the arguments and indicated by the colons). Options must be indented to the
  256. same level as the directive content.
  257. The directive content follows after a blank line and is indented relative to the
  258. directive start.
  259. Images
  260. ------
  261. reST supports an image directive (:dudir:`ref &lt;image&gt;`), used like so::
  262. .. image:: gnu.png
  263. (options)
  264. When used within Sphinx, the file name given (here ``gnu.png``) must either be
  265. relative to the source file, or absolute which means that they are relative to
  266. the top source directory. For example, the file ``sketch/spam.rst`` could refer
  267. to the image ``images/spam.png`` as ``../images/spam.png`` or
  268. ``/images/spam.png``.
  269. Sphinx will automatically copy image files over to a subdirectory of the output
  270. directory on building (e.g. the ``_static`` directory for HTML output.)
  271. Interpretation of image size options (``width`` and ``height``) is as follows:
  272. if the size has no unit or the unit is pixels, the given size will only be
  273. respected for output channels that support pixels (i.e. not in LaTeX output).
  274. Other units (like ``pt`` for points) will be used for HTML and LaTeX output.
  275. Sphinx extends the standard docutils behavior by allowing an asterisk for the
  276. extension::
  277. .. image:: gnu.*
  278. Sphinx then searches for all images matching the provided pattern and determines
  279. their type. Each builder then chooses the best image out of these candidates.
  280. For instance, if the file name ``gnu.*`` was given and two files :file:`gnu.pdf`
  281. and :file:`gnu.png` existed in the source tree, the LaTeX builder would choose
  282. the former, while the HTML builder would prefer the latter.
  283. .. versionchanged:: 0.4
  284. Added the support for file names ending in an asterisk.
  285. .. versionchanged:: 0.6
  286. Image paths can now be absolute.
  287. Footnotes
  288. ---------
  289. For footnotes (:duref:`ref &lt;footnotes&gt;`), use ``[#name]_`` to mark the footnote
  290. location, and add the footnote body at the bottom of the document after a
  291. "Footnotes" rubric heading, like so::
  292. Lorem ipsum [#f1]_ dolor sit amet ... [#f2]_
  293. .. rubric:: Footnotes
  294. .. [#f1] Text of the first footnote.
  295. .. [#f2] Text of the second footnote.
  296. You can also explicitly number the footnotes (``[1]_``) or use auto-numbered
  297. footnotes without names (``[#]_``).
  298. Citations
  299. ---------
  300. Standard reST citations (:duref:`ref &lt;citations&gt;`) are supported, with the
  301. additional feature that they are "global", i.e. all citations can be referenced
  302. from all files. Use them like so::
  303. Lorem ipsum [Ref]_ dolor sit amet.
  304. .. [Ref] Book or article reference, URL or whatever.
  305. Citation usage is similar to footnote usage, but with a label that is not
  306. numeric or begins with ``#``.
  307. Substitutions
  308. -------------
  309. reST supports "substitutions" (:duref:`ref &lt;substitution-definitions&gt;`), which
  310. are pieces of text and/or markup referred to in the text by ``|name|``. They
  311. are defined like footnotes with explicit markup blocks, like this::
  312. .. |name| replace:: replacement *text*
  313. or this::
  314. .. |caution| image:: warning.png
  315. :alt: Warning!
  316. See the :duref:`reST reference for substitutions &lt;substitution-definitions&gt;`
  317. for details.
  318. If you want to use some substitutions for all documents, put them into
  319. :confval:`rst_prolog` or put them into a separate file and include it into all
  320. documents you want to use them in, using the :rst:dir:`include` directive. (Be
  321. sure to give the include file a file name extension differing from that of other
  322. source files, to avoid Sphinx finding it as a standalone document.)
  323. Sphinx defines some default substitutions, see :ref:`default-substitutions`.
  324. Comments
  325. --------
  326. Every explicit markup block which isn't a valid markup construct (like the
  327. footnotes above) is regarded as a comment (:duref:`ref &lt;comments&gt;`). For
  328. example::
  329. .. This is a comment.
  330. You can indent text after a comment start to form multiline comments::
  331. ..
  332. This whole indented block
  333. is a comment.
  334. Still in the comment.
  335. Source encoding
  336. ---------------
  337. Since the easiest way to include special characters like em dashes or copyright
  338. signs in reST is to directly write them as Unicode characters, one has to
  339. specify an encoding. Sphinx assumes source files to be encoded in UTF-8 by
  340. default; you can change this with the :confval:`source_encoding` config value.
  341. Gotchas
  342. -------
  343. There are some problems one commonly runs into while authoring reST documents:
  344. * **Separation of inline markup:** As said above, inline markup spans must be
  345. separated from the surrounding text by non-word characters, you have to use a
  346. backslash-escaped space to get around that. See `the reference
  347. &lt;http://docutils.sf.net/docs/ref/rst/restructuredtext.html#inline-markup&gt;`_
  348. for the details.
  349. * **No nested inline markup:** Something like ``*see :func:`foo`*`` is not
  350. possible.
  351. .. rubric:: Footnotes
  352. .. [1] When the default domain contains a :rst:dir:`class` directive, this directive
  353. will be shadowed. Therefore, Sphinx re-exports it as :rst:dir:`rst-class`.
  354. </textarea></form>
  355. <script>
  356. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  357. lineNumbers: true,
  358. });
  359. </script>
  360. <p>
  361. The <code>python</code> mode will be used for highlighting blocks
  362. containing Python/IPython terminal sessions: blocks starting with
  363. <code>&gt;&gt;&gt;</code> (for Python) or <code>In [num]:</code> (for
  364. IPython).
  365. Further, the <code>stex</code> mode will be used for highlighting
  366. blocks containing LaTex code.
  367. </p>
  368. <p><strong>MIME types defined:</strong> <code>text/x-rst</code>.</p>
  369. </article>