reST.rst 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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. .. sidebar:: Further reading
  14. - Sphinx-Primer_
  15. - `Sphinx markup constructs`_
  16. - reST_, docutils_, `docutils FAQ`_
  17. - Sphinx_, `sphinx-doc FAQ`_
  18. - `sphinx config`_, doctree_
  19. - `sphinx cross references`_
  20. - linuxdoc_
  21. - intersphinx_
  22. - sphinx-jinja_
  23. - `Sphinx's autodoc`_
  24. - `Sphinx's Python domain`_, `Sphinx's C domain`_
  25. - SVG_, ImageMagick_
  26. - DOT_, `Graphviz's dot`_, Graphviz_
  27. .. contents:: Contents
  28. :depth: 3
  29. :local:
  30. :backlinks: entry
  31. Sphinx_ and reST_ have their place in the python ecosystem. Over that reST is
  32. used in popular projects, e.g the Linux kernel documentation `[kernel doc]`_.
  33. .. _[kernel doc]: https://www.kernel.org/doc/html/latest/doc-guide/sphinx.html
  34. .. sidebar:: Content matters
  35. The readability_ of the reST sources has its value, therefore we recommend to
  36. make sparse usage of reST markup / .. content matters!
  37. **reST** is a plaintext markup language, its markup is *mostly* intuitive and
  38. you will not need to learn much to produce well formed articles with. I use the
  39. word *mostly*: like everything in live, reST has its advantages and
  40. disadvantages, some markups feel a bit grumpy (especially if you are used to
  41. other plaintext markups).
  42. Soft skills
  43. ===========
  44. Before going any deeper into the markup let's face on some **soft skills** a
  45. trained author brings with, to reach a well feedback from readers:
  46. - Documentation is dedicated to an audience and answers questions from the
  47. audience point of view.
  48. - Don't detail things which are general knowledge from the audience point of
  49. view.
  50. - Limit the subject, use cross links for any further reading.
  51. To be more concrete what a *point of view* means. In the (:origin:`docs`)
  52. folder we have three sections (and the *blog* folder), each dedicate to a
  53. different group of audience.
  54. User's POV: :origin:`docs/user`
  55. A typical user knows about search engines and might have heard about
  56. meta crawlers and privacy.
  57. Admin's POV: :origin:`docs/admin`
  58. A typical Admin knows about setting up services on a linux system, but he does
  59. not know all the pros and cons of a searx setup.
  60. Developer's POV: :origin:`docs/dev`
  61. Depending on the readability_ of code, a typical developer is able to read and
  62. understand source code. Describe what a item aims to do (e.g. a function).
  63. If the chronological order matters, describe it. Name the *out-of-limits
  64. conditions* and all the side effects a external developer will not know.
  65. .. _reST inline markup:
  66. Basic inline markup
  67. ===================
  68. .. sidebar:: Inline markup
  69. - :ref:`reST roles`
  70. - :ref:`reST smart ref`
  71. Basic inline markup is done with asterisks and backquotes. If asterisks or
  72. backquotes appear in running text and could be confused with inline markup
  73. delimiters, they have to be escaped with a backslash (``\*pointer``).
  74. .. table:: basic inline markup
  75. :widths: 4 3 7
  76. ================================================ ==================== ========================
  77. description rendered markup
  78. ================================================ ==================== ========================
  79. one asterisk for emphasis *italics* ``*italics*``
  80. two asterisks for strong emphasis **boldface** ``**boldface**``
  81. backquotes for code samples and literals ``foo()`` ````foo()````
  82. quote asterisks or backquotes \*foo is a pointer ``\*foo is a pointer``
  83. ================================================ ==================== ========================
  84. .. _reST basic structure:
  85. Basic article structure
  86. =======================
  87. The basic structure of an article makes use of heading adornments to markup
  88. chapter, sections and subsections.
  89. .. _reST template:
  90. reST template
  91. -------------
  92. reST template for an simple article:
  93. .. code:: reST
  94. .. _doc refname:
  95. ==============
  96. Document title
  97. ==============
  98. Lorem ipsum dolor sit amet, consectetur adipisici elit .. Further read
  99. :ref:`chapter refname`.
  100. .. _chapter refname:
  101. Chapter
  102. =======
  103. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
  104. aliquid ex ea commodi consequat ...
  105. .. _section refname:
  106. Section
  107. -------
  108. lorem ..
  109. .. _subsection refname:
  110. Subsection
  111. ~~~~~~~~~~
  112. lorem ..
  113. Headings
  114. --------
  115. #. title - with overline for document title:
  116. .. code:: reST
  117. ==============
  118. Document title
  119. ==============
  120. #. chapter - with anchor named ``anchor name``:
  121. .. code:: reST
  122. .. _anchor name:
  123. Chapter
  124. =======
  125. #. section
  126. .. code:: reST
  127. Section
  128. -------
  129. #. subsection
  130. .. code:: reST
  131. Subsection
  132. ~~~~~~~~~~
  133. Anchors & Links
  134. ===============
  135. .. _reST anchor:
  136. Anchors
  137. -------
  138. .. _ref role:
  139. https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-ref
  140. To refer a point in the documentation a anchor is needed. The :ref:`reST
  141. template <reST template>` shows an example where a chapter titled *"Chapters"*
  142. gets an anchor named ``chapter title``. Another example from *this* document,
  143. where the anchor named ``reST anchor``:
  144. .. code:: reST
  145. .. _reST anchor:
  146. Anchors
  147. -------
  148. To refer a point in the documentation a anchor is needed ...
  149. To refer anchors use the `ref role`_ markup:
  150. .. code:: reST
  151. Visit chapter :ref:`reST anchor`. Or set hyperlink text manualy :ref:`foo
  152. bar <reST anchor>`.
  153. .. admonition:: ``:ref:`` role
  154. :class: rst-example
  155. Visist chapter :ref:`reST anchor`. Or set hyperlink text manualy :ref:`foo
  156. bar <reST anchor>`.
  157. .. _reST ordinary ref:
  158. Link ordinary URL
  159. -----------------
  160. If you need to reference external URLs use *named* hyperlinks to maintain
  161. readability of reST sources. Here is a example taken from *this* article:
  162. .. code:: reST
  163. .. _Sphinx Field Lists:
  164. https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html
  165. With the *named* hyperlink `Sphinx Field Lists`_, the raw text is much more
  166. readable.
  167. And this shows the alternative (less readable) hyperlink markup `Sphinx Field
  168. Lists
  169. <https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html>`__.
  170. .. admonition:: Named hyperlink
  171. :class: rst-example
  172. With the *named* hyperlink `Sphinx Field Lists`_, the raw text is much more
  173. readable.
  174. And this shows the alternative (less readable) hyperlink markup `Sphinx Field
  175. Lists
  176. <https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html>`__.
  177. .. _reST smart ref:
  178. Smart refs
  179. ----------
  180. With the power of sphinx.ext.extlinks_ and intersphinx_ referencing external
  181. content becomes smart.
  182. .. table:: smart refs with sphinx.ext.extlinks_ and intersphinx_
  183. :widths: 4 3 7
  184. ========================== ================================== ====================================
  185. refer ... rendered example markup
  186. ========================== ================================== ====================================
  187. :rst:role:`rfc` :rfc:`822` ``:rfc:`822```
  188. :rst:role:`pep` :pep:`8` ``:pep:`8```
  189. sphinx.ext.extlinks_
  190. --------------------------------------------------------------------------------------------------
  191. project's wiki article :wiki:`Searx-instances` ``:wiki:`Searx-instances```
  192. to docs public URL :docs:`dev/reST.html` ``:docs:`dev/reST.html```
  193. files & folders origin :origin:`docs/dev/reST.rst` ``:origin:`docs/dev/reST.rst```
  194. pull request :pull:`1756` ``:pull:`1756```
  195. patch :patch:`af2cae6` ``:patch:`af2cae6```
  196. PyPi package :pypi:`searx` ``:pypi:`searx```
  197. manual page man :man:`bash` ``:man:`bash```
  198. intersphinx_
  199. --------------------------------------------------------------------------------------------------
  200. external anchor :ref:`python:and` ``:ref:`python:and```
  201. external doc anchor :doc:`jinja:templates` ``:doc:`jinja:templates```
  202. python code object :py:obj:`datetime.datetime` ``:py:obj:`datetime.datetime```
  203. flask code object :py:obj:`flask.Flask` ``:py:obj:`flask.Flask```
  204. ========================== ================================== ====================================
  205. Intersphinx is configured in :origin:`docs/conf.py`:
  206. .. code:: python
  207. intersphinx_mapping = {
  208. "python": ("https://docs.python.org/3/", None),
  209. "flask": ("https://flask.palletsprojects.com/", None),
  210. "jinja": ("https://jinja.palletsprojects.com/", None),
  211. "linuxdoc" : ("https://return42.github.io/linuxdoc/", None),
  212. "sphinx" : ("https://www.sphinx-doc.org/en/master/", None),
  213. }
  214. To list all anchors of the inventory (e.g. ``python``) use:
  215. .. code:: sh
  216. $ python -m sphinx.ext.intersphinx https://docs.python.org/3/objects.inv
  217. .. _reST roles:
  218. Roles
  219. =====
  220. .. sidebar:: Further reading
  221. - `Sphinx Roles`_
  222. - :doc:`sphinx:usage/restructuredtext/domains`
  223. A *custom interpreted text role* (:duref:`ref <roles>`) is an inline piece of
  224. explicit markup. It signifies that that the enclosed text should be interpreted
  225. in a specific way.
  226. The general markup is one of:
  227. .. code:: reST
  228. :rolename:`ref-name`
  229. :rolename:`ref text <ref-name>`
  230. .. table:: smart refs with sphinx.ext.extlinks_ and intersphinx_
  231. :widths: 4 3 7
  232. ========================== ================================== ====================================
  233. role rendered example markup
  234. ========================== ================================== ====================================
  235. :rst:role:`guilabel` :guilabel:`&Cancel` ``:guilabel:`&Cancel```
  236. :rst:role:`kbd` :kbd:`C-x C-f` ``:kbd:`C-x C-f```
  237. :rst:role:`menuselection` :menuselection:`Open --> File` ``:menuselection:`Open --> File```
  238. :rst:role:`download` :download:`this file <reST.rst>` ``:download:`this file <reST.rst>```
  239. :rst:role:`math` :math:`a^2 + b^2 = c^2` ``:math:`a^2 + b^2 = c^2```
  240. :rst:role:`ref` :ref:`svg image example` ``:ref:`svg image example```
  241. :rst:role:`command` :command:`ls -la` ``:command:`ls -la```
  242. :durole:`emphasis` :emphasis:`italic` ``:emphasis:`italic```
  243. :durole:`strong` :strong:`bold` ``:strong:`bold```
  244. :durole:`literal` :literal:`foo()` ``:literal:`foo()```
  245. :durole:`subscript` H\ :sub:`2`\ O ``H\ :sub:`2`\ O``
  246. :durole:`superscript` E = mc\ :sup:`2` ``E = mc\ :sup:`2```
  247. :durole:`title-reference` :title:`Time` ``:title:`Time```
  248. ========================== ================================== ====================================
  249. Figures & Images
  250. ================
  251. .. sidebar:: Image processing
  252. With the directives from :ref:`linuxdoc <linuxdoc:kfigure>` the build process
  253. is flexible. To get best results in the generated output format, install
  254. ImageMagick_ and Graphviz_.
  255. Searx's sphinx setup includes: :ref:`linuxdoc:kfigure`. Scalable here means;
  256. scalable in sense of the build process. Normally in absence of a converter
  257. tool, the build process will break. From the authors POV it’s annoying to care
  258. about the build process when handling with images, especially since he has no
  259. access to the build process. With :ref:`linuxdoc:kfigure` the build process
  260. continues and scales output quality in dependence of installed image processors.
  261. If you want to add an image, you should use the ``kernel-figure`` and
  262. ``kernel-image`` directives. E.g. to insert a figure with a scalable image
  263. format use SVG (:ref:`svg image example`):
  264. .. code:: reST
  265. .. _svg image example:
  266. .. kernel-figure:: svg_image.svg
  267. :alt: SVG image example
  268. simple SVG image
  269. To refer the figure, a caption block is needed: :ref:`svg image example`.
  270. .. _svg image example:
  271. .. kernel-figure:: svg_image.svg
  272. :alt: SVG image example
  273. simple SVG image
  274. To refer the figure, a caption block is needed: :ref:`svg image example`.
  275. DOT files (aka Graphviz)
  276. ------------------------
  277. With :ref:`linuxdoc:kernel-figure` reST support for **DOT** formatted files is
  278. given.
  279. - `Graphviz's dot`_
  280. - DOT_
  281. - Graphviz_
  282. A simple example is shown in :ref:`dot file example`:
  283. .. code:: reST
  284. .. _dot file example:
  285. .. kernel-figure:: hello.dot
  286. :alt: hello world
  287. DOT's hello world example
  288. .. admonition:: hello.dot
  289. :class: rst-example
  290. .. _dot file example:
  291. .. kernel-figure:: hello.dot
  292. :alt: hello world
  293. DOT's hello world example
  294. ``kernel-render`` DOT
  295. ---------------------
  296. Embed *render* markups (or languages) like Graphviz's **DOT** is provided by the
  297. :ref:`linuxdoc:kernel-render` directive. A simple example of embedded DOT_ is
  298. shown in figure :ref:`dot render example`:
  299. .. code:: reST
  300. .. _dot render example:
  301. .. kernel-render:: DOT
  302. :alt: digraph
  303. :caption: Embedded DOT (Graphviz) code
  304. digraph foo {
  305. "bar" -> "baz";
  306. }
  307. Attribute ``caption`` is needed, if you want to refer the figure: :ref:`dot
  308. render example`.
  309. Please note :ref:`build tools <linuxdoc:kfigure_build_tools>`. If Graphviz_ is
  310. installed, you will see an vector image. If not, the raw markup is inserted as
  311. *literal-block*.
  312. .. admonition:: kernel-render DOT
  313. :class: rst-example
  314. .. _dot render example:
  315. .. kernel-render:: DOT
  316. :alt: digraph
  317. :caption: Embedded DOT (Graphviz) code
  318. digraph foo {
  319. "bar" -> "baz";
  320. }
  321. Attribute ``caption`` is needed, if you want to refer the figure: :ref:`dot
  322. render example`.
  323. ``kernel-render`` SVG
  324. ---------------------
  325. A simple example of embedded SVG_ is shown in figure :ref:`svg render example`:
  326. .. code:: reST
  327. .. _svg render example:
  328. .. kernel-render:: SVG
  329. :caption: Embedded **SVG** markup
  330. :alt: so-nw-arrow
  331. ..
  332. .. code:: xml
  333. <?xml version="1.0" encoding="UTF-8"?>
  334. <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
  335. baseProfile="full" width="70px" height="40px"
  336. viewBox="0 0 700 400"
  337. >
  338. <line x1="180" y1="370"
  339. x2="500" y2="50"
  340. stroke="black" stroke-width="15px"
  341. />
  342. <polygon points="585 0 525 25 585 50"
  343. transform="rotate(135 525 25)"
  344. />
  345. </svg>
  346. .. admonition:: kernel-render SVG
  347. :class: rst-example
  348. .. _svg render example:
  349. .. kernel-render:: SVG
  350. :caption: Embedded **SVG** markup
  351. :alt: so-nw-arrow
  352. <?xml version="1.0" encoding="UTF-8"?>
  353. <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
  354. baseProfile="full" width="70px" height="40px"
  355. viewBox="0 0 700 400"
  356. >
  357. <line x1="180" y1="370"
  358. x2="500" y2="50"
  359. stroke="black" stroke-width="15px"
  360. />
  361. <polygon points="585 0 525 25 585 50"
  362. transform="rotate(135 525 25)"
  363. />
  364. </svg>
  365. .. _reST lists:
  366. List markups
  367. ============
  368. Bullet list
  369. -----------
  370. List markup (:duref:`ref <bullet-lists>`) is simple:
  371. .. code:: reST
  372. - This is a bulleted list.
  373. 1. Nested lists are possible, but be aware that they must be separated from
  374. the parent list items by blank line
  375. 2. Second item of nested list
  376. - It has two items, the second
  377. item uses two lines.
  378. #. This is a numbered list.
  379. #. It has two items too.
  380. .. admonition:: bullet list
  381. :class: rst-example
  382. - This is a bulleted list.
  383. 1. Nested lists are possible, but be aware that they must be separated from
  384. the parent list items by blank line
  385. 2. Second item of nested list
  386. - It has two items, the second
  387. item uses two lines.
  388. #. This is a numbered list.
  389. #. It has two items too.
  390. Definition list
  391. ---------------
  392. .. sidebar:: definition term
  393. Note that the term cannot have more than one line of text.
  394. Definition lists (:duref:`ref <definition-lists>`) are created as follows:
  395. .. code:: reST
  396. term (up to a line of text)
  397. Definition of the term, which must be indented
  398. and can even consist of multiple paragraphs
  399. next term
  400. Description.
  401. .. admonition:: definition list
  402. :class: rst-example
  403. term (up to a line of text)
  404. Definition of the term, which must be indented
  405. and can even consist of multiple paragraphs
  406. next term
  407. Description.
  408. Quoted paragraphs
  409. -----------------
  410. Quoted paragraphs (:duref:`ref <block-quotes>`) are created by just indenting
  411. them more than the surrounding paragraphs. Line blocks (:duref:`ref
  412. <line-blocks>`) are a way of preserving line breaks:
  413. .. code:: reST
  414. normal paragraph ...
  415. lorem ipsum.
  416. Quoted paragraph ...
  417. lorem ipsum.
  418. | These lines are
  419. | broken exactly like in
  420. | the source file.
  421. .. admonition:: Quoted paragraph and line block
  422. :class: rst-example
  423. normal paragraph ...
  424. lorem ipsum.
  425. Quoted paragraph ...
  426. lorem ipsum.
  427. | These lines are
  428. | broken exactly like in
  429. | the source file.
  430. .. _reST field list:
  431. Field Lists
  432. -----------
  433. .. _Sphinx Field Lists:
  434. https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html
  435. .. sidebar:: bibliographic fields
  436. First lines fields are bibliographic fields, see `Sphinx Field Lists`_.
  437. Field lists are used as part of an extension syntax, such as options for
  438. directives, or database-like records meant for further processing. Field lists
  439. are mappings from field names to field bodies. They marked up like this:
  440. .. code:: reST
  441. :fieldname: Field content
  442. :foo: first paragraph in field foo
  443. second paragraph in field foo
  444. :bar: Field content
  445. .. admonition:: Field List
  446. :class: rst-example
  447. :fieldname: Field content
  448. :foo: first paragraph in field foo
  449. second paragraph in field foo
  450. :bar: Field content
  451. They are commonly used in Python documentation:
  452. .. code:: python
  453. def my_function(my_arg, my_other_arg):
  454. """A function just for me.
  455. :param my_arg: The first of my arguments.
  456. :param my_other_arg: The second of my arguments.
  457. :returns: A message (just for me, of course).
  458. """
  459. Further list blocks
  460. -------------------
  461. - field lists (:duref:`ref <field-lists>`, with caveats noted in
  462. :ref:`reST field list`)
  463. - option lists (:duref:`ref <option-lists>`)
  464. - quoted literal blocks (:duref:`ref <quoted-literal-blocks>`)
  465. - doctest blocks (:duref:`ref <doctest-blocks>`)
  466. Admonitions
  467. ===========
  468. Sidebar
  469. -------
  470. Sidebar is an eye catcher, often used for admonitions pointing further stuff or
  471. site effects. Here is the source of the sidebar :ref:`on top of this page <reST
  472. primer>`.
  473. .. code:: reST
  474. .. sidebar:: KISS_ and readability_
  475. Instead of defining more and more roles, we at searx encourage our
  476. contributors to follow principles like KISS_ and readability_.
  477. Generic admonition
  478. ------------------
  479. The generic :dudir:`admonition <admonitions>` needs a title:
  480. .. code:: reST
  481. .. admonition:: generic admonition title
  482. lorem ipsum ..
  483. .. admonition:: generic admonition title
  484. lorem ipsum ..
  485. Specific admonitions
  486. --------------------
  487. Specific admonitions: :dudir:`hint`, :dudir:`note`, :dudir:`tip` :dudir:`attention`,
  488. :dudir:`caution`, :dudir:`danger`, :dudir:`error`, , :dudir:`important`, and
  489. :dudir:`warning` .
  490. .. code:: reST
  491. .. hint::
  492. lorem ipsum ..
  493. .. note::
  494. lorem ipsum ..
  495. .. warning::
  496. lorem ipsum ..
  497. .. hint::
  498. lorem ipsum ..
  499. .. note::
  500. lorem ipsum ..
  501. .. tip::
  502. lorem ipsum ..
  503. .. attention::
  504. lorem ipsum ..
  505. .. caution::
  506. lorem ipsum ..
  507. .. danger::
  508. lorem ipsum ..
  509. .. important::
  510. lorem ipsum ..
  511. .. error::
  512. lorem ipsum ..
  513. .. warning::
  514. lorem ipsum ..
  515. Tables
  516. ======
  517. .. sidebar:: Nested tables
  518. Nested tables are ugly! Not all builder support nested tables, don't use
  519. them!
  520. ASCII-art tables like :ref:`reST simple table` and :ref:`reST grid table` might
  521. be comfortable for readers of the text-files, but they have huge disadvantages
  522. in the creation and modifying. First, they are hard to edit. Think about
  523. adding a row or a column to a ASCII-art table or adding a paragraph in a cell,
  524. it is a nightmare on big tables.
  525. .. sidebar:: List tables
  526. For meaningful patch and diff use :ref:`reST flat table`.
  527. Second the diff of modifying ASCII-art tables is not meaningful, e.g. widening a
  528. cell generates a diff in which also changes are included, which are only
  529. ascribable to the ASCII-art. Anyway, if you prefer ASCII-art for any reason,
  530. here are some helpers:
  531. * `Emacs Table Mode`_
  532. * `Online Tables Generator`_
  533. .. _reST simple table:
  534. Simple tables
  535. -------------
  536. :duref:`Simple tables <simple-tables>` allow *colspan* but not *rowspan*. If
  537. your table need some metadata (e.g. a title) you need to add the ``.. table::
  538. directive`` :dudir:`(ref) <table>` in front and place the table in its body:
  539. .. code:: reST
  540. .. table:: foo gate truth table
  541. :widths: grid
  542. :align: left
  543. ====== ====== ======
  544. Inputs Output
  545. ------------- ------
  546. A B A or B
  547. ====== ====== ======
  548. False
  549. --------------------
  550. True
  551. --------------------
  552. True False True
  553. (foo)
  554. ------ ------ ------
  555. False True
  556. (foo)
  557. ====== =============
  558. .. admonition:: Simple ASCII table
  559. :class: rst-example
  560. .. table:: foo gate truth table
  561. :widths: grid
  562. :align: left
  563. ====== ====== ======
  564. Inputs Output
  565. ------------- ------
  566. A B A or B
  567. ====== ====== ======
  568. False
  569. --------------------
  570. True
  571. --------------------
  572. True False True
  573. (foo)
  574. ------ ------ ------
  575. False True
  576. (foo)
  577. ====== =============
  578. .. _reST grid table:
  579. Grid tables
  580. -----------
  581. :duref:`Grid tables <grid-tables>` allow colspan *colspan* and *rowspan*:
  582. .. code:: reST
  583. .. table:: grid table example
  584. :widths: 1 1 5
  585. +------------+------------+-----------+
  586. | Header 1 | Header 2 | Header 3 |
  587. +============+============+===========+
  588. | body row 1 | column 2 | column 3 |
  589. +------------+------------+-----------+
  590. | body row 2 | Cells may span columns.|
  591. +------------+------------+-----------+
  592. | body row 3 | Cells may | - Cells |
  593. +------------+ span rows. | - contain |
  594. | body row 4 | | - blocks. |
  595. +------------+------------+-----------+
  596. .. admonition:: ASCII grid table
  597. :class: rst-example
  598. .. table:: grid table example
  599. :widths: 1 1 5
  600. +------------+------------+-----------+
  601. | Header 1 | Header 2 | Header 3 |
  602. +============+============+===========+
  603. | body row 1 | column 2 | column 3 |
  604. +------------+------------+-----------+
  605. | body row 2 | Cells may span columns.|
  606. +------------+------------+-----------+
  607. | body row 3 | Cells may | - Cells |
  608. +------------+ span rows. | - contain |
  609. | body row 4 | | - blocks. |
  610. +------------+------------+-----------+
  611. .. _reST flat table:
  612. flat-table
  613. ----------
  614. The ``flat-table`` is a further developed variant of the :ref:`list tables
  615. <linuxdoc:list-table-directives>`. It is a double-stage list similar to the
  616. :dudir:`list-table` with some additional features:
  617. column-span: ``cspan``
  618. with the role ``cspan`` a cell can be extended through additional columns
  619. row-span: ``rspan``
  620. with the role ``rspan`` a cell can be extended through additional rows
  621. auto-span:
  622. spans rightmost cell of a table row over the missing cells on the right side
  623. of that table-row. With Option ``:fill-cells:`` this behavior can changed
  624. from *auto span* to *auto fill*, which automatically inserts (empty) cells
  625. instead of spanning the last cell.
  626. options:
  627. :header-rows: [int] count of header rows
  628. :stub-columns: [int] count of stub columns
  629. :widths: [[int] [int] ... ] widths of columns
  630. :fill-cells: instead of auto-span missing cells, insert missing cells
  631. roles:
  632. :cspan: [int] additional columns (*morecols*)
  633. :rspan: [int] additional rows (*morerows*)
  634. The example below shows how to use this markup. The first level of the staged
  635. list is the *table-row*. In the *table-row* there is only one markup allowed,
  636. the list of the cells in this *table-row*. Exception are *comments* ( ``..`` )
  637. and *targets* (e.g. a ref to :ref:`row 2 of table's body <row body 2>`).
  638. .. code:: reST
  639. .. flat-table:: ``flat-table`` example
  640. :header-rows: 2
  641. :stub-columns: 1
  642. :widths: 1 1 1 1 2
  643. * - :rspan:`1` head / stub
  644. - :cspan:`3` head 1.1-4
  645. * - head 2.1
  646. - head 2.2
  647. - head 2.3
  648. - head 2.4
  649. * .. row body 1 / this is a comment
  650. - row 1
  651. - :rspan:`2` cell 1-3.1
  652. - cell 1.2
  653. - cell 1.3
  654. - cell 1.4
  655. * .. Comments and targets are allowed on *table-row* stage.
  656. .. _`row body 2`:
  657. - row 2
  658. - cell 2.2
  659. - :rspan:`1` :cspan:`1`
  660. cell 2.3 with a span over
  661. * col 3-4 &
  662. * row 2-3
  663. * - row 3
  664. - cell 3.2
  665. * - row 4
  666. - cell 4.1
  667. - cell 4.2
  668. - cell 4.3
  669. - cell 4.4
  670. * - row 5
  671. - cell 5.1 with automatic span to rigth end
  672. * - row 6
  673. - cell 6.1
  674. - ..
  675. .. admonition:: List table
  676. :class: rst-example
  677. .. flat-table:: ``flat-table`` example
  678. :header-rows: 2
  679. :stub-columns: 1
  680. :widths: 1 1 1 1 2
  681. * - :rspan:`1` head / stub
  682. - :cspan:`3` head 1.1-4
  683. * - head 2.1
  684. - head 2.2
  685. - head 2.3
  686. - head 2.4
  687. * .. row body 1 / this is a comment
  688. - row 1
  689. - :rspan:`2` cell 1-3.1
  690. - cell 1.2
  691. - cell 1.3
  692. - cell 1.4
  693. * .. Comments and targets are allowed on *table-row* stage.
  694. .. _`row body 2`:
  695. - row 2
  696. - cell 2.2
  697. - :rspan:`1` :cspan:`1`
  698. cell 2.3 with a span over
  699. * col 3-4 &
  700. * row 2-3
  701. * - row 3
  702. - cell 3.2
  703. * - row 4
  704. - cell 4.1
  705. - cell 4.2
  706. - cell 4.3
  707. - cell 4.4
  708. * - row 5
  709. - cell 5.1 with automatic span to rigth end
  710. * - row 6
  711. - cell 6.1
  712. - ..
  713. CSV table
  714. ---------
  715. CSV table might be the choice if you want to include CSV-data from a outstanding
  716. (build) process into your documentation.
  717. .. code:: reST
  718. .. csv-table:: CSV table example
  719. :header: .. , Column 1, Column 2
  720. :widths: 2 5 5
  721. :stub-columns: 1
  722. :file: csv_table.txt
  723. Content of file ``csv_table.txt``:
  724. .. literalinclude:: csv_table.txt
  725. .. admonition:: CSV table
  726. :class: rst-example
  727. .. csv-table:: CSV table example
  728. :header: .. , Column 1, Column 2
  729. :widths: 3 5 5
  730. :stub-columns: 1
  731. :file: csv_table.txt
  732. Templating
  733. ==========
  734. .. sidebar:: Build environment
  735. All *generic-doc* tasks are running in the :ref:`build environment <make
  736. pyenv>`.
  737. Templating is suitable for documentation which is created generic at the build
  738. time. The sphinx-jinja_ extension evaluates jinja_ templates in the :ref:`build
  739. environment <make pyenv>` with installed searx modules. We use this e.g. to
  740. build chapter: :ref:`engines generic`.
  741. Here is the content of the :origin:`docs/admin/engines.rst`:
  742. .. literalinclude:: ../admin/engines.rst
  743. :language: reST
  744. :start-after: .. _configured engines:
  745. The context for the template is selected in the line ``.. jinja:: webapp``. In
  746. sphinx's build configuration (:origin:`docs/conf.py`) the ``webapp`` context
  747. points to the name space of the python module: ``webapp``.
  748. .. code:: py
  749. from searx import webapp
  750. jinja_contexts = {
  751. 'webapp': dict(**webapp.__dict__)
  752. }
  753. .. _KISS: https://en.wikipedia.org/wiki/KISS_principle
  754. .. _readability: https://docs.python-guide.org/writing/style/
  755. .. _Sphinx-Primer:
  756. http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
  757. .. _reST: https://docutils.sourceforge.io/rst.html
  758. .. _Sphinx Roles:
  759. https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html
  760. .. _Sphinx: http://www.sphinx-doc.org
  761. .. _`sphinx-doc FAQ`: http://www.sphinx-doc.org/en/stable/faq.html
  762. .. _Sphinx markup constructs:
  763. http://www.sphinx-doc.org/en/stable/markup/index.html
  764. .. _`sphinx cross references`:
  765. http://www.sphinx-doc.org/en/stable/markup/inline.html#cross-referencing-arbitrary-locations
  766. .. _sphinx.ext.extlinks:
  767. https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
  768. .. _intersphinx: http://www.sphinx-doc.org/en/stable/ext/intersphinx.html
  769. .. _sphinx config: http://www.sphinx-doc.org/en/stable/config.html
  770. .. _Sphinx's autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html
  771. .. _Sphinx's Python domain:
  772. http://www.sphinx-doc.org/en/stable/domains.html#the-python-domain
  773. .. _Sphinx's C domain:
  774. http://www.sphinx-doc.org/en/stable/domains.html#cross-referencing-c-constructs
  775. .. _doctree:
  776. http://www.sphinx-doc.org/en/master/extdev/tutorial.html?highlight=doctree#build-phases
  777. .. _docutils: http://docutils.sourceforge.net/docs/index.html
  778. .. _docutils FAQ: http://docutils.sourceforge.net/FAQ.html
  779. .. _linuxdoc: https://return42.github.io/linuxdoc
  780. .. _jinja: https://jinja.palletsprojects.com/
  781. .. _sphinx-jinja: https://github.com/tardyp/sphinx-jinja
  782. .. _SVG: https://www.w3.org/TR/SVG11/expanded-toc.html
  783. .. _DOT: https://graphviz.gitlab.io/_pages/doc/info/lang.html
  784. .. _`Graphviz's dot`: https://graphviz.gitlab.io/_pages/pdf/dotguide.pdf
  785. .. _Graphviz: https://graphviz.gitlab.io
  786. .. _ImageMagick: https://www.imagemagick.org
  787. .. _`Emacs Table Mode`: https://www.emacswiki.org/emacs/TableMode
  788. .. _`Online Tables Generator`: http://www.tablesgenerator.com/text_tables
  789. .. _`OASIS XML Exchange Table Model`: https://www.oasis-open.org/specs/tm9901.html