reST.rst 38 KB

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