sphinx.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. .. _sphinx:
  2. Sphinx Syntax
  3. =============
  4. This page contains syntax rules, tips, and tricks for using Sphinx and reStructuredText. For more information, please see this `comprehensive guide to reStructuredText <https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html>`_, as well as the `Sphinx reStructuredText Primer <http://sphinx.pocoo.org/rest.html>`_.
  5. Basic markup
  6. ------------
  7. A reStructuredText document is written in plain text. Without the need for complex formatting, one can be composed simply, just like one would any plain text document. For basic formatting, see this table:
  8. .. list-table::
  9. :widths: 30 40 30
  10. * - **Format**
  11. - **Syntax**
  12. - **Output**
  13. * - Italics
  14. - ``*italics*`` (single asterisk)
  15. - *italics*
  16. * - Bold
  17. - ``**bold**`` (double asterisk)
  18. - **bold**
  19. * - Monospace
  20. - `` ``monospace`` `` (double back quote)
  21. - ``monospace``
  22. Lists
  23. -----
  24. There are two types of lists, bulleted lists and numbered lists. A **bulleted list** looks like this:
  25. * An item
  26. * Another item
  27. * Yet another item
  28. This is accomplished with the following code::
  29. * An item
  30. * Another item
  31. * Yet another item
  32. A **numbered list** looks like this:
  33. #. First item
  34. #. Second item
  35. #. Third item
  36. This is accomplished with the following code::
  37. #. First item
  38. #. Second item
  39. #. Third item
  40. Note that numbers are automatically generated, making it easy to add/remove items.
  41. List-tables
  42. -----------
  43. Bulleted lists can sometimes be cumbersome and hard to follow. When dealing with a long list of items, use list-tables. For example, to talk about a list of options, create a table that looks like this:
  44. .. list-table::
  45. :widths: 20 80
  46. :header-rows: 1
  47. * - Shapes
  48. - Description
  49. * - Square
  50. - Four sides of equal length, 90 degree angles
  51. * - Rectangle
  52. - Four sides, 90 degree angles
  53. This is done with the following code::
  54. .. list-table::
  55. :widths: 20 80
  56. :header-rows: 1
  57. * - Shapes
  58. - Description
  59. * - Square
  60. - Four sides of equal length, 90 degree angles
  61. * - Rectangle
  62. - Four sides, 90 degree angles
  63. Page labels
  64. -----------
  65. **Ensure every page has a label that matches the name of the file.** For example if the page is named ``foo_bar.rst`` then the page should have the label::
  66. .. _foo_bar:
  67. Other pages can then link to that page by using the following code::
  68. :ref:`foo_bar`
  69. .. _linking:
  70. Linking
  71. -------
  72. Links to other pages should never be titled as "here". Sphinx makes this easy by automatically inserting the title of the linked document.
  73. Bad
  74. More information about linking can be found :ref:`here <linking>`.
  75. Good
  76. For more information, please see the section on :ref:`linking`.
  77. To insert a link to an external website::
  78. `Text of the link <http://example.com>`_
  79. The resulting link would look like this: `Text of the link <http://example.com>`_
  80. Sections
  81. --------
  82. Use sections to break up long pages and to help Sphinx generate tables of contents.
  83. The top of the page (i.e. the title) should have a double underline, using an
  84. equals sign (``=``)::
  85. Camel Spotting
  86. ==============
  87. Subsection headers should have a single underline, using a dash character
  88. (``-``)::
  89. Camel Spotting
  90. ==============
  91. Intro to the Camel
  92. ------------------
  93. Finding a Camel
  94. ---------------
  95. Recording its Serial Number
  96. ---------------------------
  97. Should these subsections require subsubsections, use the back quote (`````)::
  98. Intro to the Camel
  99. ------------------
  100. Camel History
  101. `````````````
  102. Camels Today
  103. ````````````
  104. Notes and warnings
  105. ------------------
  106. When it is beneficial to have a section of text stand out from the main text, Sphinx has two such boxes, the note and the warning. They function identically, and only differ in their coloring. You should use notes and warnings sparingly, however, as adding emphasis to everything makes the emphasis less effective.
  107. Here is an example of a note:
  108. .. note:: This is a note.
  109. This note is generated with the following code::
  110. .. note:: This is a note.
  111. Similarly, here is an example of a warning:
  112. .. warning:: Beware of dragons.
  113. This warning is generated by the following code::
  114. .. warning:: Beware of dragons.
  115. Images
  116. ------
  117. Add images to your documentation when possible. Images, such as screenshots, are a very helpful way of making documentation understandable. When making screenshots, try to crop out unnecessary content (browser window, desktop, etc). Avoid scaling the images, as the Sphinx theme automatically resizes large images. It is also helpful to include a caption underneath the image.
  118. .. figure:: pagelogo.png
  119. :align: center
  120. *The GeoServer logo as shown on the homepage.*
  121. This image is generated by the following code::
  122. .. figure:: pagelogo.png
  123. :align: center
  124. *The GeoServer logo as shown on the homepage.*
  125. In this example, the image file exists in the same directory as the source page. If this is not the case, you can insert path information in the above command.
  126. External files
  127. --------------
  128. Text snippets, large blocks of downloadable code, and even zip files or other binary sources can all be included as part of the documentation. To include files as part of the build process, use the following syntax::
  129. :download:`An external file <readme.txt>`
  130. The result of this code will generate a standard link to an :download:`external file <readme.txt>`
  131. Reference files and paths
  132. -------------------------
  133. Use the following syntax to reference files and paths::
  134. :file:`myfile.txt`
  135. This will output: :file:`myfile.txt`.
  136. You can reference paths in the same way::
  137. :file:`path/to/myfile.txt`
  138. This will output: :file:`path/to/myfile.txt`.
  139. For Windows paths, use double backslashes::
  140. :file:`C:\\myfile.txt`
  141. This will output: :file:`C:\\myfile.txt`.
  142. If you want to reference a non-specific path or file name::
  143. :file:`{your/own/path/to}/myfile.txt`
  144. This will output: :file:`{your/own/path/to}/myfile.txt`
  145. Reference commands
  146. ------------------
  147. Reference commands (such as :command:`make`) with the following syntax::
  148. :command:`make`
  149. Reference an element in a GUI
  150. -----------------------------
  151. Use the following syntax to direct a user to click a link or look to a certain area of the GUI::
  152. :guilabel:`Main Menu`
  153. This will output: :guilabel:`Main Menu`.
  154. Menu traversal
  155. --------------
  156. Direct a user through a menu with the following syntax::
  157. :menuselection:`Start Menu --> Programs --> GeoServer`
  158. This will output :menuselection:`Start Menu --> Programs --> GeoServer`.
  159. Show Source
  160. -----------
  161. Every page in the GeoServer documentation has a link for ``Show Source`` under the Table of Contents on the right side of the page. This allows for easy reverse engineering of unfamiliar markup. When in doubt, look at the source!