reST.rst 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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:: Note ..
  393. - the term cannot have more than one line of text
  394. - there is **no blank line between term and definition block** // this
  395. distinguishes definition lists (:duref:`ref <definition-lists>`) from block
  396. quotes (:duref:`ref <block-quotes>`).
  397. Each definition list (:duref:`ref <definition-lists>`) item contains a term,
  398. optional classifiers and a definition. A term is a simple one-line word or
  399. phrase. Optional classifiers may follow the term on the same line, each after
  400. an inline ' : ' (**space, colon, space**). A definition is a block indented
  401. relative to the term, and may contain multiple paragraphs and other body
  402. elements. There may be no blank line between a term line and a definition block
  403. (*this distinguishes definition lists from block quotes*). Blank lines are
  404. required before the first and after the last definition list item, but are
  405. optional in-between.
  406. Definition lists are created as follows:
  407. .. code:: reST
  408. term 1 (up to a line of text)
  409. Definition 1.
  410. See the typo : this line is not a term!
  411. And this is not term's definition. **There is a blank line** in between
  412. the line above and this paragraph. That's why this paragraph is taken as
  413. **block quote** (:duref:`ref <block-quotes>`) and not as term's definition!
  414. term 2
  415. Definition 2, paragraph 1.
  416. Definition 2, paragraph 2.
  417. term 3 : classifier
  418. Definition 3.
  419. term 4 : classifier one : classifier two
  420. Definition 4.
  421. .. admonition:: definition list
  422. :class: rst-example
  423. term 1 (up to a line of text)
  424. Definition 1.
  425. See the typo : this line is not a term!
  426. And this is not term's definition. **There is a blank line** in between
  427. the line above and this paragraph. That's why this paragraph is taken as
  428. **block quote** (:duref:`ref <block-quotes>`) and not as term's definition!
  429. term 2
  430. Definition 2, paragraph 1.
  431. Definition 2, paragraph 2.
  432. term 3 : classifier
  433. Definition 3.
  434. term 4 : classifier one : classifier two
  435. Quoted paragraphs
  436. -----------------
  437. Quoted paragraphs (:duref:`ref <block-quotes>`) are created by just indenting
  438. them more than the surrounding paragraphs. Line blocks (:duref:`ref
  439. <line-blocks>`) are a way of preserving line breaks:
  440. .. code:: reST
  441. normal paragraph ...
  442. lorem ipsum.
  443. Quoted paragraph ...
  444. lorem ipsum.
  445. | These lines are
  446. | broken exactly like in
  447. | the source file.
  448. .. admonition:: Quoted paragraph and line block
  449. :class: rst-example
  450. normal paragraph ...
  451. lorem ipsum.
  452. Quoted paragraph ...
  453. lorem ipsum.
  454. | These lines are
  455. | broken exactly like in
  456. | the source file.
  457. .. _reST field list:
  458. Field Lists
  459. -----------
  460. .. _Sphinx Field Lists:
  461. https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html
  462. .. sidebar:: bibliographic fields
  463. First lines fields are bibliographic fields, see `Sphinx Field Lists`_.
  464. Field lists are used as part of an extension syntax, such as options for
  465. directives, or database-like records meant for further processing. Field lists
  466. are mappings from field names to field bodies. They marked up like this:
  467. .. code:: reST
  468. :fieldname: Field content
  469. :foo: first paragraph in field foo
  470. second paragraph in field foo
  471. :bar: Field content
  472. .. admonition:: Field List
  473. :class: rst-example
  474. :fieldname: Field content
  475. :foo: first paragraph in field foo
  476. second paragraph in field foo
  477. :bar: Field content
  478. They are commonly used in Python documentation:
  479. .. code:: python
  480. def my_function(my_arg, my_other_arg):
  481. """A function just for me.
  482. :param my_arg: The first of my arguments.
  483. :param my_other_arg: The second of my arguments.
  484. :returns: A message (just for me, of course).
  485. """
  486. Further list blocks
  487. -------------------
  488. - field lists (:duref:`ref <field-lists>`, with caveats noted in
  489. :ref:`reST field list`)
  490. - option lists (:duref:`ref <option-lists>`)
  491. - quoted literal blocks (:duref:`ref <quoted-literal-blocks>`)
  492. - doctest blocks (:duref:`ref <doctest-blocks>`)
  493. Admonitions
  494. ===========
  495. Sidebar
  496. -------
  497. Sidebar is an eye catcher, often used for admonitions pointing further stuff or
  498. site effects. Here is the source of the sidebar :ref:`on top of this page <reST
  499. primer>`.
  500. .. code:: reST
  501. .. sidebar:: KISS_ and readability_
  502. Instead of defining more and more roles, we at searx encourage our
  503. contributors to follow principles like KISS_ and readability_.
  504. Generic admonition
  505. ------------------
  506. The generic :dudir:`admonition <admonitions>` needs a title:
  507. .. code:: reST
  508. .. admonition:: generic admonition title
  509. lorem ipsum ..
  510. .. admonition:: generic admonition title
  511. lorem ipsum ..
  512. Specific admonitions
  513. --------------------
  514. Specific admonitions: :dudir:`hint`, :dudir:`note`, :dudir:`tip` :dudir:`attention`,
  515. :dudir:`caution`, :dudir:`danger`, :dudir:`error`, , :dudir:`important`, and
  516. :dudir:`warning` .
  517. .. code:: reST
  518. .. hint::
  519. lorem ipsum ..
  520. .. note::
  521. lorem ipsum ..
  522. .. warning::
  523. lorem ipsum ..
  524. .. hint::
  525. lorem ipsum ..
  526. .. note::
  527. lorem ipsum ..
  528. .. tip::
  529. lorem ipsum ..
  530. .. attention::
  531. lorem ipsum ..
  532. .. caution::
  533. lorem ipsum ..
  534. .. danger::
  535. lorem ipsum ..
  536. .. important::
  537. lorem ipsum ..
  538. .. error::
  539. lorem ipsum ..
  540. .. warning::
  541. lorem ipsum ..
  542. Tables
  543. ======
  544. .. sidebar:: Nested tables
  545. Nested tables are ugly! Not all builder support nested tables, don't use
  546. them!
  547. ASCII-art tables like :ref:`reST simple table` and :ref:`reST grid table` might
  548. be comfortable for readers of the text-files, but they have huge disadvantages
  549. in the creation and modifying. First, they are hard to edit. Think about
  550. adding a row or a column to a ASCII-art table or adding a paragraph in a cell,
  551. it is a nightmare on big tables.
  552. .. sidebar:: List tables
  553. For meaningful patch and diff use :ref:`reST flat table`.
  554. Second the diff of modifying ASCII-art tables is not meaningful, e.g. widening a
  555. cell generates a diff in which also changes are included, which are only
  556. ascribable to the ASCII-art. Anyway, if you prefer ASCII-art for any reason,
  557. here are some helpers:
  558. * `Emacs Table Mode`_
  559. * `Online Tables Generator`_
  560. .. _reST simple table:
  561. Simple tables
  562. -------------
  563. :duref:`Simple tables <simple-tables>` allow *colspan* but not *rowspan*. If
  564. your table need some metadata (e.g. a title) you need to add the ``.. table::
  565. directive`` :dudir:`(ref) <table>` in front and place the table in its body:
  566. .. code:: reST
  567. .. table:: foo gate truth table
  568. :widths: grid
  569. :align: left
  570. ====== ====== ======
  571. Inputs Output
  572. ------------- ------
  573. A B A or B
  574. ====== ====== ======
  575. False
  576. --------------------
  577. True
  578. --------------------
  579. True False True
  580. (foo)
  581. ------ ------ ------
  582. False True
  583. (foo)
  584. ====== =============
  585. .. admonition:: Simple ASCII table
  586. :class: rst-example
  587. .. table:: foo gate truth table
  588. :widths: grid
  589. :align: left
  590. ====== ====== ======
  591. Inputs Output
  592. ------------- ------
  593. A B A or B
  594. ====== ====== ======
  595. False
  596. --------------------
  597. True
  598. --------------------
  599. True False True
  600. (foo)
  601. ------ ------ ------
  602. False True
  603. (foo)
  604. ====== =============
  605. .. _reST grid table:
  606. Grid tables
  607. -----------
  608. :duref:`Grid tables <grid-tables>` allow colspan *colspan* and *rowspan*:
  609. .. code:: reST
  610. .. table:: grid table example
  611. :widths: 1 1 5
  612. +------------+------------+-----------+
  613. | Header 1 | Header 2 | Header 3 |
  614. +============+============+===========+
  615. | body row 1 | column 2 | column 3 |
  616. +------------+------------+-----------+
  617. | body row 2 | Cells may span columns.|
  618. +------------+------------+-----------+
  619. | body row 3 | Cells may | - Cells |
  620. +------------+ span rows. | - contain |
  621. | body row 4 | | - blocks. |
  622. +------------+------------+-----------+
  623. .. admonition:: ASCII grid table
  624. :class: rst-example
  625. .. table:: grid table example
  626. :widths: 1 1 5
  627. +------------+------------+-----------+
  628. | Header 1 | Header 2 | Header 3 |
  629. +============+============+===========+
  630. | body row 1 | column 2 | column 3 |
  631. +------------+------------+-----------+
  632. | body row 2 | Cells may span columns.|
  633. +------------+------------+-----------+
  634. | body row 3 | Cells may | - Cells |
  635. +------------+ span rows. | - contain |
  636. | body row 4 | | - blocks. |
  637. +------------+------------+-----------+
  638. .. _reST flat table:
  639. flat-table
  640. ----------
  641. The ``flat-table`` is a further developed variant of the :ref:`list tables
  642. <linuxdoc:list-table-directives>`. It is a double-stage list similar to the
  643. :dudir:`list-table` with some additional features:
  644. column-span: ``cspan``
  645. with the role ``cspan`` a cell can be extended through additional columns
  646. row-span: ``rspan``
  647. with the role ``rspan`` a cell can be extended through additional rows
  648. auto-span:
  649. spans rightmost cell of a table row over the missing cells on the right side
  650. of that table-row. With Option ``:fill-cells:`` this behavior can changed
  651. from *auto span* to *auto fill*, which automatically inserts (empty) cells
  652. instead of spanning the last cell.
  653. options:
  654. :header-rows: [int] count of header rows
  655. :stub-columns: [int] count of stub columns
  656. :widths: [[int] [int] ... ] widths of columns
  657. :fill-cells: instead of auto-span missing cells, insert missing cells
  658. roles:
  659. :cspan: [int] additional columns (*morecols*)
  660. :rspan: [int] additional rows (*morerows*)
  661. The example below shows how to use this markup. The first level of the staged
  662. list is the *table-row*. In the *table-row* there is only one markup allowed,
  663. the list of the cells in this *table-row*. Exception are *comments* ( ``..`` )
  664. and *targets* (e.g. a ref to :ref:`row 2 of table's body <row body 2>`).
  665. .. code:: reST
  666. .. flat-table:: ``flat-table`` example
  667. :header-rows: 2
  668. :stub-columns: 1
  669. :widths: 1 1 1 1 2
  670. * - :rspan:`1` head / stub
  671. - :cspan:`3` head 1.1-4
  672. * - head 2.1
  673. - head 2.2
  674. - head 2.3
  675. - head 2.4
  676. * .. row body 1 / this is a comment
  677. - row 1
  678. - :rspan:`2` cell 1-3.1
  679. - cell 1.2
  680. - cell 1.3
  681. - cell 1.4
  682. * .. Comments and targets are allowed on *table-row* stage.
  683. .. _`row body 2`:
  684. - row 2
  685. - cell 2.2
  686. - :rspan:`1` :cspan:`1`
  687. cell 2.3 with a span over
  688. * col 3-4 &
  689. * row 2-3
  690. * - row 3
  691. - cell 3.2
  692. * - row 4
  693. - cell 4.1
  694. - cell 4.2
  695. - cell 4.3
  696. - cell 4.4
  697. * - row 5
  698. - cell 5.1 with automatic span to rigth end
  699. * - row 6
  700. - cell 6.1
  701. - ..
  702. .. admonition:: List table
  703. :class: rst-example
  704. .. flat-table:: ``flat-table`` example
  705. :header-rows: 2
  706. :stub-columns: 1
  707. :widths: 1 1 1 1 2
  708. * - :rspan:`1` head / stub
  709. - :cspan:`3` head 1.1-4
  710. * - head 2.1
  711. - head 2.2
  712. - head 2.3
  713. - head 2.4
  714. * .. row body 1 / this is a comment
  715. - row 1
  716. - :rspan:`2` cell 1-3.1
  717. - cell 1.2
  718. - cell 1.3
  719. - cell 1.4
  720. * .. Comments and targets are allowed on *table-row* stage.
  721. .. _`row body 2`:
  722. - row 2
  723. - cell 2.2
  724. - :rspan:`1` :cspan:`1`
  725. cell 2.3 with a span over
  726. * col 3-4 &
  727. * row 2-3
  728. * - row 3
  729. - cell 3.2
  730. * - row 4
  731. - cell 4.1
  732. - cell 4.2
  733. - cell 4.3
  734. - cell 4.4
  735. * - row 5
  736. - cell 5.1 with automatic span to rigth end
  737. * - row 6
  738. - cell 6.1
  739. - ..
  740. CSV table
  741. ---------
  742. CSV table might be the choice if you want to include CSV-data from a outstanding
  743. (build) process into your documentation.
  744. .. code:: reST
  745. .. csv-table:: CSV table example
  746. :header: .. , Column 1, Column 2
  747. :widths: 2 5 5
  748. :stub-columns: 1
  749. :file: csv_table.txt
  750. Content of file ``csv_table.txt``:
  751. .. literalinclude:: csv_table.txt
  752. .. admonition:: CSV table
  753. :class: rst-example
  754. .. csv-table:: CSV table example
  755. :header: .. , Column 1, Column 2
  756. :widths: 3 5 5
  757. :stub-columns: 1
  758. :file: csv_table.txt
  759. Templating
  760. ==========
  761. .. sidebar:: Build environment
  762. All *generic-doc* tasks are running in the :ref:`build environment <make
  763. pyenv>`.
  764. Templating is suitable for documentation which is created generic at the build
  765. time. The sphinx-jinja_ extension evaluates jinja_ templates in the :ref:`build
  766. environment <make pyenv>` (with searx modules installed). We use this e.g. to
  767. build chapter: :ref:`engines generic`. Below the jinja directive from the
  768. :origin:`docs/admin/engines.rst` is shown:
  769. .. literalinclude:: ../admin/engines.rst
  770. :language: reST
  771. :start-after: .. _configured engines:
  772. The context for the template is selected in the line ``.. jinja:: webapp``. In
  773. sphinx's build configuration (:origin:`docs/conf.py`) the ``webapp`` context
  774. points to the name space of the python module: ``webapp``.
  775. .. code:: py
  776. from searx import webapp
  777. jinja_contexts = {
  778. 'webapp': dict(**webapp.__dict__)
  779. }
  780. Tabbed views
  781. ============
  782. .. _sphinx-tabs: https://github.com/djungelorm/sphinx-tabs
  783. .. _basic-tabs: https://github.com/djungelorm/sphinx-tabs#basic-tabs
  784. .. _group-tabs: https://github.com/djungelorm/sphinx-tabs#group-tabs
  785. .. _code-tabs: https://github.com/djungelorm/sphinx-tabs#code-tabs
  786. With `sphinx-tabs`_ extension we have *tabbed views*. To provide installation
  787. instructions with one tab per distribution we use the `group-tabs`_ directive,
  788. others are basic-tabs_ and code-tabs_.
  789. .. code:: reST
  790. .. tabs::
  791. .. group-tab:: Linux
  792. Linux Line 1
  793. .. group-tab:: Mac OSX
  794. Mac OSX Line 1
  795. .. group-tab:: Windows
  796. Windows Line 1
  797. .. tabs::
  798. .. group-tab:: Linux
  799. Linux Line 1
  800. .. group-tab:: Mac OSX
  801. Mac OSX Line 1
  802. .. group-tab:: Windows
  803. Windows Line 1
  804. .. admonition:: Tabbed view (grouped)
  805. :class: rst-example
  806. .. tabs::
  807. .. group-tab:: Linux
  808. Linux Line 1
  809. .. group-tab:: Mac OSX
  810. Mac OSX Line 1
  811. .. group-tab:: Windows
  812. Windows Line 1
  813. .. tabs::
  814. .. group-tab:: Linux
  815. Linux Line 1
  816. .. group-tab:: Mac OSX
  817. Mac OSX Line 1
  818. .. group-tab:: Windows
  819. Windows Line 1
  820. .. _KISS: https://en.wikipedia.org/wiki/KISS_principle
  821. .. _readability: https://docs.python-guide.org/writing/style/
  822. .. _Sphinx-Primer:
  823. http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
  824. .. _reST: https://docutils.sourceforge.io/rst.html
  825. .. _Sphinx Roles:
  826. https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html
  827. .. _Sphinx: http://www.sphinx-doc.org
  828. .. _`sphinx-doc FAQ`: http://www.sphinx-doc.org/en/stable/faq.html
  829. .. _Sphinx markup constructs:
  830. http://www.sphinx-doc.org/en/stable/markup/index.html
  831. .. _`sphinx cross references`:
  832. http://www.sphinx-doc.org/en/stable/markup/inline.html#cross-referencing-arbitrary-locations
  833. .. _sphinx.ext.extlinks:
  834. https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
  835. .. _intersphinx: http://www.sphinx-doc.org/en/stable/ext/intersphinx.html
  836. .. _sphinx config: http://www.sphinx-doc.org/en/stable/config.html
  837. .. _Sphinx's autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html
  838. .. _Sphinx's Python domain:
  839. http://www.sphinx-doc.org/en/stable/domains.html#the-python-domain
  840. .. _Sphinx's C domain:
  841. http://www.sphinx-doc.org/en/stable/domains.html#cross-referencing-c-constructs
  842. .. _doctree:
  843. http://www.sphinx-doc.org/en/master/extdev/tutorial.html?highlight=doctree#build-phases
  844. .. _docutils: http://docutils.sourceforge.net/docs/index.html
  845. .. _docutils FAQ: http://docutils.sourceforge.net/FAQ.html
  846. .. _linuxdoc: https://return42.github.io/linuxdoc
  847. .. _jinja: https://jinja.palletsprojects.com/
  848. .. _sphinx-jinja: https://github.com/tardyp/sphinx-jinja
  849. .. _SVG: https://www.w3.org/TR/SVG11/expanded-toc.html
  850. .. _DOT: https://graphviz.gitlab.io/_pages/doc/info/lang.html
  851. .. _`Graphviz's dot`: https://graphviz.gitlab.io/_pages/pdf/dotguide.pdf
  852. .. _Graphviz: https://graphviz.gitlab.io
  853. .. _ImageMagick: https://www.imagemagick.org
  854. .. _`Emacs Table Mode`: https://www.emacswiki.org/emacs/TableMode
  855. .. _`Online Tables Generator`: http://www.tablesgenerator.com/text_tables
  856. .. _`OASIS XML Exchange Table Model`: https://www.oasis-open.org/specs/tm9901.html