reST.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. .. _reST primer:
  2. ===========
  3. reST primer
  4. ===========
  5. .. sidebar:: KISS_ and readability_
  6. Instead of defining more and more roles, we at searx encourage our
  7. contributors to follow principles like KISS_ and readability_.
  8. We at searx are using reStructuredText (aka reST_) markup for all kind of
  9. documentation, with the builders from the Sphinx_ project a HTML output is
  10. generated and deployed at :docs:`github.io <.>`.
  11. The sources of Searx's documentation are located at :origin:`docs`. Run
  12. :ref:`make docs-live <make docs-live>` to build HTML while editing.
  13. ------
  14. .. contents:: Contents
  15. :depth: 3
  16. :local:
  17. :backlinks: entry
  18. Sphinx_ and reST_ have their place in the python ecosystem. Over that reST is
  19. used in popular projects, e.g the Linux kernel documentation `[kernel doc]`_.
  20. .. _[kernel doc]: https://www.kernel.org/doc/html/latest/doc-guide/sphinx.html
  21. .. sidebar:: Content matters
  22. The readability_ of the reST sources has its value, therefore we recommend to
  23. make sparse usage of reST markup / .. content matters!
  24. **reST** is a plaintext markup language, its markup is *mostly* intuitive and
  25. you will not need to learn much to produce well formed articles with. I use the
  26. word *mostly*: like everything in live, reST has its advantages and
  27. disadvantages, some markups feel a bit grumpy (especially if you are used to
  28. other plaintext markups).
  29. Soft skills
  30. ===========
  31. Before going any deeper into the markup let's face on some **soft skills** a
  32. trained author brings with, to reach a well feedback from readers:
  33. - Documentation is dedicated to an audience and answers questions from the
  34. audience point of view.
  35. - Don't detail things which are general knowledge from the audience point of
  36. view.
  37. - Limit the subject, use cross links for any further reading.
  38. To be more concrete what a *point of view* means. In the (:origin:`docs`)
  39. folder we have three sections (and the *blog* folder), each dedicate to a
  40. different group of audience.
  41. .. sidebar:: Further reading
  42. - Sphinx-Primer_
  43. - `Sphinx markup constructs`_
  44. - reST_, docutils_, `docutils FAQ`_
  45. - Sphinx_, `sphinx-doc FAQ`_
  46. - `sphinx config`_, doctree_
  47. - `sphinx cross references`_
  48. - intersphinx_
  49. - `Sphinx's autodoc`_
  50. - `Sphinx's Python domain`_, `Sphinx's C domain`_
  51. User's POV: :origin:`docs/user`
  52. A typical user knows about search engines and might have heard about
  53. meta crawlers and privacy.
  54. Admin's POV: :origin:`docs/admin`
  55. A typical Admin knows about setting up services on a linux system, but he does
  56. not know all the pros and cons of a searx setup.
  57. Developer's POV: :origin:`docs/dev`
  58. Depending on the readability_ of code, a typical developer is able to read and
  59. understand source code. Describe what a item aims to do (e.g. a function),
  60. describe chronological order matters, describe it. Name the *out-of-limits
  61. condition* and all the side effects a external developer will not know.
  62. .. _reST inline markup:
  63. Basic inline markup
  64. ===================
  65. ``*italics*`` -- *italics*
  66. one asterisk for emphasis
  67. ``**boldface**`` -- **boldface**
  68. two asterisks for strong emphasis and
  69. ````foo()```` -- ``foo()``
  70. backquotes for code samples and literals.
  71. ``\*foo is a pointer`` -- \*foo is a pointer
  72. If asterisks or backquotes appear in running text and could be confused with
  73. inline markup delimiters, they have to be escaped with a backslash (``\*foo is
  74. a pointer``).
  75. Roles
  76. =====
  77. A *custom interpreted text role* (:duref:`ref <roles>`) is an inline piece of
  78. explicit markup. It signifies that that the enclosed text should be interpreted
  79. in a specific way. The general syntax is ``:rolename:`content```.
  80. Docutils supports the following roles:
  81. * :durole:`emphasis` -- equivalent of ``*emphasis*``
  82. * :durole:`strong` -- equivalent of ``**strong**``
  83. * :durole:`literal` -- equivalent of ````literal````
  84. * :durole:`subscript` -- subscript text
  85. * :durole:`superscript` -- superscript text
  86. * :durole:`title-reference` -- for titles of books, periodicals, and other
  87. materials
  88. Refer to `Sphinx Roles`_ for roles added by Sphinx.
  89. Anchors & Links
  90. ===============
  91. .. _reST anchor:
  92. Anchors
  93. -------
  94. .. _ref role:
  95. https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-ref
  96. To refer a point in the documentation a anchor is needed. The :ref:`reST
  97. template <reST template>` shows an example where a chapter titled *"Chapters"*
  98. gets an anchor named ``chapter title``. Another example from *this* document,
  99. where the anchor named ``reST anchor``:
  100. .. code:: reST
  101. .. _reST anchor:
  102. Anchors
  103. -------
  104. To refer a point in the documentation a anchor is needed ...
  105. To refer anchors use the `ref role`_ markup:
  106. .. code:: reST
  107. Visit chapter :ref:`reST anchor`.
  108. Or set hyperlink text manualy :ref:`foo bar <reST anchor>`.
  109. .. admonition:: ``:ref:`` role
  110. :class: rst-example
  111. Visist chapter :ref:`reST anchor`
  112. Or set hyperlink text manualy :ref:`foo bar <reST anchor>`.
  113. .. _reST ordinary ref:
  114. link ordinary URL
  115. -----------------
  116. If you need to reference external URLs use *named* hyperlinks to maintain
  117. readability of reST sources. Here is a example taken from *this* article:
  118. .. code:: reST
  119. .. _Sphinx Field Lists:
  120. https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html
  121. With the *named* hyperlink `Sphinx Field Lists`_, the raw text is much more
  122. readable.
  123. And this shows the alternative (less readable) hyperlink markup `Sphinx Field
  124. Lists
  125. <https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html>`__.
  126. .. admonition:: Named hyperlink
  127. :class: rst-example
  128. With the *named* hyperlink `Sphinx Field Lists`_, the raw text is much more
  129. readable.
  130. And this shows the alternative (less readable) hyperlink markup `Sphinx Field
  131. Lists
  132. <https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html>`__.
  133. .. _reST smart ref:
  134. smart references
  135. ----------------
  136. With the power of sphinx.ext.extlinks_ and intersphinx_ referencing external
  137. content becomes smart. To refer ...
  138. sphinx.ext.extlinks_:
  139. :project's wiki article: :wiki:`Searx-instances`
  140. :to docs public URL: :docs:`dev/reST.html`
  141. :files & folders from origin: :origin:`docs/dev/reST.rst`
  142. :a pull request: :pull:`1756`
  143. :a patch: :patch:`af2cae6`
  144. :a PyPi package: :pypi:`searx`
  145. :a manual page man: :man:`bash`
  146. .. code:: reST
  147. :project's wiki article: :wiki:`Searx-instances`
  148. :to docs public URL: :docs:`dev/reST.html`
  149. :files & folders from origin: :origin:`docs/dev/reST.rst`
  150. :a pull request: :pull:`1756`
  151. :a patch: :patch:`af2cae6`
  152. :a PyPi package: :pypi:`searx`
  153. :a manual page man: :man:`bash`
  154. intersphinx_:
  155. :external anchor: :ref:`python:and`
  156. :external doc anchor: :doc:`jinja:templates`
  157. :python code object: :py:obj:`datetime.datetime`
  158. :flask code object: webapp is a :py:obj:`flask.Flask` app
  159. .. code:: reST
  160. :external anchor: :ref:`python:and`
  161. :external doc anchor: :doc:`jinja:templates`
  162. :python code object: :py:obj:`datetime.datetime`
  163. :flask code object: webapp is a :py:obj:`flask.Flask` app
  164. Intersphinx is configured in :origin:`docs/conf.py`:
  165. .. code:: python
  166. intersphinx_mapping = {
  167. "python": ("https://docs.python.org/3/", None),
  168. "flask": ("https://flask.palletsprojects.com/", None),
  169. "jinja": ("https://jinja.palletsprojects.com/", None),
  170. }
  171. To list all anchors of the inventory (e.g. ``python``) use:
  172. .. code:: sh
  173. $ python -m sphinx.ext.intersphinx https://docs.python.org/3/objects.inv
  174. .. _reST basic structure:
  175. Basic article structure
  176. =======================
  177. The basic structure of an article makes use of heading adornments to markup
  178. chapter, sections and subsections.
  179. #. ``=`` with overline for document title
  180. #. ``=`` for chapters
  181. #. ``-`` for sections
  182. #. ``~`` for subsections
  183. .. _reST template:
  184. .. admonition:: reST template
  185. :class: rst-example
  186. .. code:: reST
  187. .. _document title:
  188. ==============
  189. Document title
  190. ==============
  191. Lorem ipsum dolor sit amet, consectetur adipisici elit ..
  192. Further read :ref:`chapter title`.
  193. .. _chapter title:
  194. Chapters
  195. ========
  196. Ut enim ad minim veniam, quis nostrud exercitation ullamco
  197. laboris nisi ut aliquid ex ea commodi consequat ...
  198. Section
  199. -------
  200. lorem ..
  201. Subsection
  202. ~~~~~~~~~~
  203. lorem ..
  204. .. _reST lists:
  205. List markups
  206. ============
  207. Bullet list
  208. -----------
  209. List markup (:duref:`ref <bullet-lists>`) is simple:
  210. .. code:: reST
  211. - This is a bulleted list.
  212. 1. Nested lists are possible, but be aware that they must be separated from
  213. the parent list items by blank line
  214. 2. Second item of nested list
  215. - It has two items, the second
  216. item uses two lines.
  217. #. This is a numbered list.
  218. #. It has two items too.
  219. .. admonition:: bullet list
  220. :class: rst-example
  221. - This is a bulleted list.
  222. 1. Nested lists are possible, but be aware that they must be separated from
  223. the parent list items by blank line
  224. 2. Second item of nested list
  225. - It has two items, the second
  226. item uses two lines.
  227. #. This is a numbered list.
  228. #. It has two items too.
  229. Definition list
  230. ---------------
  231. .. sidebar:: definition term
  232. Note that the term cannot have more than one line of text.
  233. Definition lists (:duref:`ref <definition-lists>`) are created as follows:
  234. .. code:: reST
  235. term (up to a line of text)
  236. Definition of the term, which must be indented
  237. and can even consist of multiple paragraphs
  238. next term
  239. Description.
  240. .. admonition:: definition list
  241. :class: rst-example
  242. term (up to a line of text)
  243. Definition of the term, which must be indented
  244. and can even consist of multiple paragraphs
  245. next term
  246. Description.
  247. Quoted paragraphs
  248. -----------------
  249. Quoted paragraphs (:duref:`ref <block-quotes>`) are created by just indenting
  250. them more than the surrounding paragraphs. Line blocks (:duref:`ref
  251. <line-blocks>`) are a way of preserving line breaks:
  252. .. code:: reST
  253. normal paragraph ...
  254. lorem ipsum.
  255. Quoted paragraph ...
  256. lorem ipsum.
  257. | These lines are
  258. | broken exactly like in
  259. | the source file.
  260. .. admonition:: Quoted paragraph and line block
  261. :class: rst-example
  262. normal paragraph ...
  263. lorem ipsum.
  264. Quoted paragraph ...
  265. lorem ipsum.
  266. | These lines are
  267. | broken exactly like in
  268. | the source file.
  269. .. _reST field list:
  270. Field Lists
  271. -----------
  272. .. _Sphinx Field Lists:
  273. https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html
  274. .. sidebar:: bibliographic fields
  275. First lines fields are bibliographic fields, see `Sphinx Field Lists`_.
  276. Field lists are used as part of an extension syntax, such as options for
  277. directives, or database-like records meant for further processing. Field lists
  278. are mappings from field names to field bodies. They marked up like this:
  279. .. code:: reST
  280. :fieldname: Field content
  281. :foo: first paragraph in field foo
  282. second paragraph in field foo
  283. :bar: Field content
  284. .. admonition:: Field List
  285. :class: rst-example
  286. :fieldname: Field content
  287. :foo: first paragraph in field foo
  288. second paragraph in field foo
  289. :bar: Field content
  290. They are commonly used in Python documentation:
  291. .. code:: python
  292. def my_function(my_arg, my_other_arg):
  293. """A function just for me.
  294. :param my_arg: The first of my arguments.
  295. :param my_other_arg: The second of my arguments.
  296. :returns: A message (just for me, of course).
  297. """
  298. Further list blocks
  299. -------------------
  300. - field lists (:duref:`ref <field-lists>`, with caveats noted in
  301. :ref:`reST field list`)
  302. - option lists (:duref:`ref <option-lists>`)
  303. - quoted literal blocks (:duref:`ref <quoted-literal-blocks>`)
  304. - doctest blocks (:duref:`ref <doctest-blocks>`)
  305. .. _KISS: https://en.wikipedia.org/wiki/KISS_principle
  306. .. _readability: https://docs.python-guide.org/writing/style/
  307. .. _Sphinx-Primer:
  308. http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
  309. .. _reST: https://docutils.sourceforge.io/rst.html
  310. .. _Sphinx Roles:
  311. https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html
  312. .. _Sphinx: http://www.sphinx-doc.org
  313. .. _`sphinx-doc FAQ`: http://www.sphinx-doc.org/en/stable/faq.html
  314. .. _Sphinx markup constructs:
  315. http://www.sphinx-doc.org/en/stable/markup/index.html
  316. .. _`sphinx cross references`:
  317. http://www.sphinx-doc.org/en/stable/markup/inline.html#cross-referencing-arbitrary-locations
  318. .. _sphinx.ext.extlinks:
  319. https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
  320. .. _intersphinx: http://www.sphinx-doc.org/en/stable/ext/intersphinx.html
  321. .. _sphinx config: http://www.sphinx-doc.org/en/stable/config.html
  322. .. _Sphinx's autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html
  323. .. _Sphinx's Python domain:
  324. http://www.sphinx-doc.org/en/stable/domains.html#the-python-domain
  325. .. _Sphinx's C domain:
  326. http://www.sphinx-doc.org/en/stable/domains.html#cross-referencing-c-constructs
  327. .. _doctree:
  328. http://www.sphinx-doc.org/en/master/extdev/tutorial.html?highlight=doctree#build-phases
  329. .. _docutils: http://docutils.sourceforge.net/docs/index.html
  330. .. _docutils FAQ: http://docutils.sourceforge.net/FAQ.html