2
0

index.html 17 KB

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