reST.rst 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  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 default. 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 manually :ref:`foo
  154. bar <reST anchor>`.
  155. .. admonition:: ``:ref:`` role
  156. :class: rst-example
  157. Visist chapter :ref:`reST anchor`. Or set hyperlink text manually :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. ...
  220. $ python -m sphinx.ext.intersphinx https://searx.github.io/searx/objects.inv
  221. ...
  222. Literal blocks
  223. ==============
  224. The simplest form of :duref:`literal-blocks` is a indented block introduced by
  225. two colons (``::``). For highlighting use :dudir:`highlight` or :ref:`reST
  226. code` directive. To include literals from external files use
  227. :rst:dir:`literalinclude` or :ref:`kernel-include <kernel-include-directive>`
  228. directive (latter one expands environment variables in the path name).
  229. .. _reST literal:
  230. ``::``
  231. ------
  232. .. code:: reST
  233. ::
  234. Literal block
  235. Lorem ipsum dolor::
  236. Literal block
  237. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  238. eirmod tempor invidunt ut labore ::
  239. Literal block
  240. .. admonition:: Literal block
  241. :class: rst-example
  242. ::
  243. Literal block
  244. Lorem ipsum dolor::
  245. Literal block
  246. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  247. eirmod tempor invidunt ut labore ::
  248. Literal block
  249. .. _reST code:
  250. ``code-block``
  251. --------------
  252. .. _pygments: https://pygments.org/languages/
  253. .. sidebar:: Syntax highlighting
  254. is handled by pygments_.
  255. The :rst:dir:`code-block` directive is a variant of the :dudir:`code` directive
  256. with additional options. To learn more about code literals visit
  257. :ref:`sphinx:code-examples`.
  258. .. code-block:: reST
  259. The URL ``/stats`` handle is shown in :ref:`stats-handle`
  260. .. code-block:: Python
  261. :caption: python code block
  262. :name: stats-handle
  263. @app.route('/stats', methods=['GET'])
  264. def stats():
  265. """Render engine statistics page."""
  266. stats = get_engines_stats()
  267. return render(
  268. 'stats.html'
  269. , stats = stats )
  270. .. code-block:: reST
  271. .. admonition:: Code block
  272. :class: rst-example
  273. The URL ``/stats`` handle is shown in :ref:`stats-handle`
  274. .. code-block:: Python
  275. :caption: python code block
  276. :name: stats-handle
  277. @app.route('/stats', methods=['GET'])
  278. def stats():
  279. """Render engine statistics page."""
  280. stats = get_engines_stats()
  281. return render(
  282. 'stats.html'
  283. , stats = stats )
  284. Unicode substitution
  285. ====================
  286. The :dudir:`unicode directive <unicode-character-codes>` converts Unicode
  287. character codes (numerical values) to characters. This directive can only be
  288. used within a substitution definition.
  289. .. code-block:: reST
  290. .. |copy| unicode:: 0xA9 .. copyright sign
  291. .. |(TM)| unicode:: U+2122
  292. Trademark |(TM)| and copyright |copy| glyphs.
  293. .. admonition:: Unicode
  294. :class: rst-example
  295. .. |copy| unicode:: 0xA9 .. copyright sign
  296. .. |(TM)| unicode:: U+2122
  297. Trademark |(TM)| and copyright |copy| glyphs.
  298. .. _reST roles:
  299. Roles
  300. =====
  301. .. sidebar:: Further reading
  302. - `Sphinx Roles`_
  303. - :doc:`sphinx:usage/restructuredtext/domains`
  304. A *custom interpreted text role* (:duref:`ref <roles>`) is an inline piece of
  305. explicit markup. It signifies that that the enclosed text should be interpreted
  306. in a specific way.
  307. The general markup is one of:
  308. .. code:: reST
  309. :rolename:`ref-name`
  310. :rolename:`ref text <ref-name>`
  311. .. table:: smart refs with sphinx.ext.extlinks_ and intersphinx_
  312. :widths: 4 3 7
  313. ========================== ================================== ====================================
  314. role rendered example markup
  315. ========================== ================================== ====================================
  316. :rst:role:`guilabel` :guilabel:`&Cancel` ``:guilabel:`&Cancel```
  317. :rst:role:`kbd` :kbd:`C-x C-f` ``:kbd:`C-x C-f```
  318. :rst:role:`menuselection` :menuselection:`Open --> File` ``:menuselection:`Open --> File```
  319. :rst:role:`download` :download:`this file <reST.rst>` ``:download:`this file <reST.rst>```
  320. math_ :math:`a^2 + b^2 = c^2` ``:math:`a^2 + b^2 = c^2```
  321. :rst:role:`ref` :ref:`svg image example` ``:ref:`svg image example```
  322. :rst:role:`command` :command:`ls -la` ``:command:`ls -la```
  323. :durole:`emphasis` :emphasis:`italic` ``:emphasis:`italic```
  324. :durole:`strong` :strong:`bold` ``:strong:`bold```
  325. :durole:`literal` :literal:`foo()` ``:literal:`foo()```
  326. :durole:`subscript` H\ :sub:`2`\ O ``H\ :sub:`2`\ O``
  327. :durole:`superscript` E = mc\ :sup:`2` ``E = mc\ :sup:`2```
  328. :durole:`title-reference` :title:`Time` ``:title:`Time```
  329. ========================== ================================== ====================================
  330. Figures & Images
  331. ================
  332. .. sidebar:: Image processing
  333. With the directives from :ref:`linuxdoc <linuxdoc:kfigure>` the build process
  334. is flexible. To get best results in the generated output format, install
  335. ImageMagick_ and Graphviz_.
  336. Searx's sphinx setup includes: :ref:`linuxdoc:kfigure`. Scalable here means;
  337. scalable in sense of the build process. Normally in absence of a converter
  338. tool, the build process will break. From the authors POV it’s annoying to care
  339. about the build process when handling with images, especially since he has no
  340. access to the build process. With :ref:`linuxdoc:kfigure` the build process
  341. continues and scales output quality in dependence of installed image processors.
  342. If you want to add an image, you should use the ``kernel-figure`` (inheritance
  343. of :dudir:`figure`) and ``kernel-image`` (inheritance of :dudir:`image`)
  344. directives. E.g. to insert a figure with a scalable image format use SVG
  345. (:ref:`svg image example`):
  346. .. code:: reST
  347. .. _svg image example:
  348. .. kernel-figure:: svg_image.svg
  349. :alt: SVG image example
  350. Simple SVG image
  351. To refer the figure, a caption block is needed: :ref:`svg image example`.
  352. .. _svg image example:
  353. .. kernel-figure:: svg_image.svg
  354. :alt: SVG image example
  355. Simple SVG image.
  356. To refer the figure, a caption block is needed: :ref:`svg image example`.
  357. DOT files (aka Graphviz)
  358. ------------------------
  359. With :ref:`linuxdoc:kernel-figure` reST support for **DOT** formatted files is
  360. given.
  361. - `Graphviz's dot`_
  362. - DOT_
  363. - Graphviz_
  364. A simple example is shown in :ref:`dot file example`:
  365. .. code:: reST
  366. .. _dot file example:
  367. .. kernel-figure:: hello.dot
  368. :alt: hello world
  369. DOT's hello world example
  370. .. admonition:: hello.dot
  371. :class: rst-example
  372. .. _dot file example:
  373. .. kernel-figure:: hello.dot
  374. :alt: hello world
  375. DOT's hello world example
  376. ``kernel-render`` DOT
  377. ---------------------
  378. Embed *render* markups (or languages) like Graphviz's **DOT** is provided by the
  379. :ref:`linuxdoc:kernel-render` directive. A simple example of embedded DOT_ is
  380. shown in figure :ref:`dot render example`:
  381. .. code:: reST
  382. .. _dot render example:
  383. .. kernel-render:: DOT
  384. :alt: digraph
  385. :caption: Embedded DOT (Graphviz) code
  386. digraph foo {
  387. "bar" -> "baz";
  388. }
  389. Attribute ``caption`` is needed, if you want to refer the figure: :ref:`dot
  390. render example`.
  391. Please note :ref:`build tools <linuxdoc:kfigure_build_tools>`. If Graphviz_ is
  392. installed, you will see an vector image. If not, the raw markup is inserted as
  393. *literal-block*.
  394. .. admonition:: kernel-render DOT
  395. :class: rst-example
  396. .. _dot render example:
  397. .. kernel-render:: DOT
  398. :alt: digraph
  399. :caption: Embedded DOT (Graphviz) code
  400. digraph foo {
  401. "bar" -> "baz";
  402. }
  403. Attribute ``caption`` is needed, if you want to refer the figure: :ref:`dot
  404. render example`.
  405. ``kernel-render`` SVG
  406. ---------------------
  407. A simple example of embedded SVG_ is shown in figure :ref:`svg render example`:
  408. .. code:: reST
  409. .. _svg render example:
  410. .. kernel-render:: SVG
  411. :caption: Embedded **SVG** markup
  412. :alt: so-nw-arrow
  413. ..
  414. .. code:: xml
  415. <?xml version="1.0" encoding="UTF-8"?>
  416. <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
  417. baseProfile="full" width="70px" height="40px"
  418. viewBox="0 0 700 400"
  419. >
  420. <line x1="180" y1="370"
  421. x2="500" y2="50"
  422. stroke="black" stroke-width="15px"
  423. />
  424. <polygon points="585 0 525 25 585 50"
  425. transform="rotate(135 525 25)"
  426. />
  427. </svg>
  428. .. admonition:: kernel-render SVG
  429. :class: rst-example
  430. .. _svg render example:
  431. .. kernel-render:: SVG
  432. :caption: Embedded **SVG** markup
  433. :alt: so-nw-arrow
  434. <?xml version="1.0" encoding="UTF-8"?>
  435. <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
  436. baseProfile="full" width="70px" height="40px"
  437. viewBox="0 0 700 400"
  438. >
  439. <line x1="180" y1="370"
  440. x2="500" y2="50"
  441. stroke="black" stroke-width="15px"
  442. />
  443. <polygon points="585 0 525 25 585 50"
  444. transform="rotate(135 525 25)"
  445. />
  446. </svg>
  447. .. _reST lists:
  448. List markups
  449. ============
  450. Bullet list
  451. -----------
  452. List markup (:duref:`ref <bullet-lists>`) is simple:
  453. .. code:: reST
  454. - This is a bulleted list.
  455. 1. Nested lists are possible, but be aware that they must be separated from
  456. the parent list items by blank line
  457. 2. Second item of nested list
  458. - It has two items, the second
  459. item uses two lines.
  460. #. This is a numbered list.
  461. #. It has two items too.
  462. .. admonition:: bullet list
  463. :class: rst-example
  464. - This is a bulleted list.
  465. 1. Nested lists are possible, but be aware that they must be separated from
  466. the parent list items by blank line
  467. 2. Second item of nested list
  468. - It has two items, the second
  469. item uses two lines.
  470. #. This is a numbered list.
  471. #. It has two items too.
  472. Horizontal list
  473. ---------------
  474. The :rst:dir:`.. hlist:: <hlist>` transforms a bullet list into a more compact
  475. list.
  476. .. code:: reST
  477. .. hlist::
  478. - first list item
  479. - second list item
  480. - third list item
  481. ...
  482. .. admonition:: hlist
  483. :class: rst-example
  484. .. hlist::
  485. - first list item
  486. - second list item
  487. - third list item
  488. - next list item
  489. - next list item xxxx
  490. - next list item yyyy
  491. - next list item zzzz
  492. Definition list
  493. ---------------
  494. .. sidebar:: Note ..
  495. - the term cannot have more than one line of text
  496. - there is **no blank line between term and definition block** // this
  497. distinguishes definition lists (:duref:`ref <definition-lists>`) from block
  498. quotes (:duref:`ref <block-quotes>`).
  499. Each definition list (:duref:`ref <definition-lists>`) item contains a term,
  500. optional classifiers and a definition. A term is a simple one-line word or
  501. phrase. Optional classifiers may follow the term on the same line, each after
  502. an inline ' : ' (**space, colon, space**). A definition is a block indented
  503. relative to the term, and may contain multiple paragraphs and other body
  504. elements. There may be no blank line between a term line and a definition block
  505. (*this distinguishes definition lists from block quotes*). Blank lines are
  506. required before the first and after the last definition list item, but are
  507. optional in-between.
  508. Definition lists are created as follows:
  509. .. code:: reST
  510. term 1 (up to a line of text)
  511. Definition 1.
  512. See the typo : this line is not a term!
  513. And this is not term's definition. **There is a blank line** in between
  514. the line above and this paragraph. That's why this paragraph is taken as
  515. **block quote** (:duref:`ref <block-quotes>`) and not as term's definition!
  516. term 2
  517. Definition 2, paragraph 1.
  518. Definition 2, paragraph 2.
  519. term 3 : classifier
  520. Definition 3.
  521. term 4 : classifier one : classifier two
  522. Definition 4.
  523. .. admonition:: definition list
  524. :class: rst-example
  525. term 1 (up to a line of text)
  526. Definition 1.
  527. See the typo : this line is not a term!
  528. And this is not term's definition. **There is a blank line** in between
  529. the line above and this paragraph. That's why this paragraph is taken as
  530. **block quote** (:duref:`ref <block-quotes>`) and not as term's definition!
  531. term 2
  532. Definition 2, paragraph 1.
  533. Definition 2, paragraph 2.
  534. term 3 : classifier
  535. Definition 3.
  536. term 4 : classifier one : classifier two
  537. Quoted paragraphs
  538. -----------------
  539. Quoted paragraphs (:duref:`ref <block-quotes>`) are created by just indenting
  540. them more than the surrounding paragraphs. Line blocks (:duref:`ref
  541. <line-blocks>`) are a way of preserving line breaks:
  542. .. code:: reST
  543. normal paragraph ...
  544. lorem ipsum.
  545. Quoted paragraph ...
  546. lorem ipsum.
  547. | These lines are
  548. | broken exactly like in
  549. | the source file.
  550. .. admonition:: Quoted paragraph and line block
  551. :class: rst-example
  552. normal paragraph ...
  553. lorem ipsum.
  554. Quoted paragraph ...
  555. lorem ipsum.
  556. | These lines are
  557. | broken exactly like in
  558. | the source file.
  559. .. _reST field list:
  560. Field Lists
  561. -----------
  562. .. _Sphinx Field Lists:
  563. https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html
  564. .. sidebar:: bibliographic fields
  565. First lines fields are bibliographic fields, see `Sphinx Field Lists`_.
  566. Field lists are used as part of an extension syntax, such as options for
  567. directives, or database-like records meant for further processing. Field lists
  568. are mappings from field names to field bodies. They marked up like this:
  569. .. code:: reST
  570. :fieldname: Field content
  571. :foo: first paragraph in field foo
  572. second paragraph in field foo
  573. :bar: Field content
  574. .. admonition:: Field List
  575. :class: rst-example
  576. :fieldname: Field content
  577. :foo: first paragraph in field foo
  578. second paragraph in field foo
  579. :bar: Field content
  580. They are commonly used in Python documentation:
  581. .. code:: python
  582. def my_function(my_arg, my_other_arg):
  583. """A function just for me.
  584. :param my_arg: The first of my arguments.
  585. :param my_other_arg: The second of my arguments.
  586. :returns: A message (just for me, of course).
  587. """
  588. Further list blocks
  589. -------------------
  590. - field lists (:duref:`ref <field-lists>`, with caveats noted in
  591. :ref:`reST field list`)
  592. - option lists (:duref:`ref <option-lists>`)
  593. - quoted literal blocks (:duref:`ref <quoted-literal-blocks>`)
  594. - doctest blocks (:duref:`ref <doctest-blocks>`)
  595. Admonitions
  596. ===========
  597. Sidebar
  598. -------
  599. Sidebar is an eye catcher, often used for admonitions pointing further stuff or
  600. site effects. Here is the source of the sidebar :ref:`on top of this page <reST
  601. primer>`.
  602. .. code:: reST
  603. .. sidebar:: KISS_ and readability_
  604. Instead of defining more and more roles, we at searx encourage our
  605. contributors to follow principles like KISS_ and readability_.
  606. Generic admonition
  607. ------------------
  608. The generic :dudir:`admonition <admonitions>` needs a title:
  609. .. code:: reST
  610. .. admonition:: generic admonition title
  611. lorem ipsum ..
  612. .. admonition:: generic admonition title
  613. lorem ipsum ..
  614. Specific admonitions
  615. --------------------
  616. Specific admonitions: :dudir:`hint`, :dudir:`note`, :dudir:`tip` :dudir:`attention`,
  617. :dudir:`caution`, :dudir:`danger`, :dudir:`error`, , :dudir:`important`, and
  618. :dudir:`warning` .
  619. .. code:: reST
  620. .. hint::
  621. lorem ipsum ..
  622. .. note::
  623. lorem ipsum ..
  624. .. warning::
  625. lorem ipsum ..
  626. .. hint::
  627. lorem ipsum ..
  628. .. note::
  629. lorem ipsum ..
  630. .. tip::
  631. lorem ipsum ..
  632. .. attention::
  633. lorem ipsum ..
  634. .. caution::
  635. lorem ipsum ..
  636. .. danger::
  637. lorem ipsum ..
  638. .. important::
  639. lorem ipsum ..
  640. .. error::
  641. lorem ipsum ..
  642. .. warning::
  643. lorem ipsum ..
  644. Tables
  645. ======
  646. .. sidebar:: Nested tables
  647. Nested tables are ugly! Not all builder support nested tables, don't use
  648. them!
  649. ASCII-art tables like :ref:`reST simple table` and :ref:`reST grid table` might
  650. be comfortable for readers of the text-files, but they have huge disadvantages
  651. in the creation and modifying. First, they are hard to edit. Think about
  652. adding a row or a column to a ASCII-art table or adding a paragraph in a cell,
  653. it is a nightmare on big tables.
  654. .. sidebar:: List tables
  655. For meaningful patch and diff use :ref:`reST flat table`.
  656. Second the diff of modifying ASCII-art tables is not meaningful, e.g. widening a
  657. cell generates a diff in which also changes are included, which are only
  658. ascribable to the ASCII-art. Anyway, if you prefer ASCII-art for any reason,
  659. here are some helpers:
  660. * `Emacs Table Mode`_
  661. * `Online Tables Generator`_
  662. .. _reST simple table:
  663. Simple tables
  664. -------------
  665. :duref:`Simple tables <simple-tables>` allow *colspan* but not *rowspan*. If
  666. your table need some metadata (e.g. a title) you need to add the ``.. table::
  667. directive`` :dudir:`(ref) <table>` in front and place the table in its body:
  668. .. code:: reST
  669. .. table:: foo gate truth table
  670. :widths: grid
  671. :align: left
  672. ====== ====== ======
  673. Inputs Output
  674. ------------- ------
  675. A B A or B
  676. ====== ====== ======
  677. False
  678. --------------------
  679. True
  680. --------------------
  681. True False True
  682. (foo)
  683. ------ ------ ------
  684. False True
  685. (foo)
  686. ====== =============
  687. .. admonition:: Simple ASCII table
  688. :class: rst-example
  689. .. table:: foo gate truth table
  690. :widths: grid
  691. :align: left
  692. ====== ====== ======
  693. Inputs Output
  694. ------------- ------
  695. A B A or B
  696. ====== ====== ======
  697. False
  698. --------------------
  699. True
  700. --------------------
  701. True False True
  702. (foo)
  703. ------ ------ ------
  704. False True
  705. (foo)
  706. ====== =============
  707. .. _reST grid table:
  708. Grid tables
  709. -----------
  710. :duref:`Grid tables <grid-tables>` allow colspan *colspan* and *rowspan*:
  711. .. code:: reST
  712. .. table:: grid table example
  713. :widths: 1 1 5
  714. +------------+------------+-----------+
  715. | Header 1 | Header 2 | Header 3 |
  716. +============+============+===========+
  717. | body row 1 | column 2 | column 3 |
  718. +------------+------------+-----------+
  719. | body row 2 | Cells may span columns.|
  720. +------------+------------+-----------+
  721. | body row 3 | Cells may | - Cells |
  722. +------------+ span rows. | - contain |
  723. | body row 4 | | - blocks. |
  724. +------------+------------+-----------+
  725. .. admonition:: ASCII grid table
  726. :class: rst-example
  727. .. table:: grid table example
  728. :widths: 1 1 5
  729. +------------+------------+-----------+
  730. | Header 1 | Header 2 | Header 3 |
  731. +============+============+===========+
  732. | body row 1 | column 2 | column 3 |
  733. +------------+------------+-----------+
  734. | body row 2 | Cells may span columns.|
  735. +------------+------------+-----------+
  736. | body row 3 | Cells may | - Cells |
  737. +------------+ span rows. | - contain |
  738. | body row 4 | | - blocks. |
  739. +------------+------------+-----------+
  740. .. _reST flat table:
  741. flat-table
  742. ----------
  743. The ``flat-table`` is a further developed variant of the :ref:`list tables
  744. <linuxdoc:list-table-directives>`. It is a double-stage list similar to the
  745. :dudir:`list-table` with some additional features:
  746. column-span: ``cspan``
  747. with the role ``cspan`` a cell can be extended through additional columns
  748. row-span: ``rspan``
  749. with the role ``rspan`` a cell can be extended through additional rows
  750. auto-span:
  751. spans rightmost cell of a table row over the missing cells on the right side
  752. of that table-row. With Option ``:fill-cells:`` this behavior can changed
  753. from *auto span* to *auto fill*, which automatically inserts (empty) cells
  754. instead of spanning the last cell.
  755. options:
  756. :header-rows: [int] count of header rows
  757. :stub-columns: [int] count of stub columns
  758. :widths: [[int] [int] ... ] widths of columns
  759. :fill-cells: instead of auto-span missing cells, insert missing cells
  760. roles:
  761. :cspan: [int] additional columns (*morecols*)
  762. :rspan: [int] additional rows (*morerows*)
  763. The example below shows how to use this markup. The first level of the staged
  764. list is the *table-row*. In the *table-row* there is only one markup allowed,
  765. the list of the cells in this *table-row*. Exception are *comments* ( ``..`` )
  766. and *targets* (e.g. a ref to :ref:`row 2 of table's body <row body 2>`).
  767. .. code:: reST
  768. .. flat-table:: ``flat-table`` example
  769. :header-rows: 2
  770. :stub-columns: 1
  771. :widths: 1 1 1 1 2
  772. * - :rspan:`1` head / stub
  773. - :cspan:`3` head 1.1-4
  774. * - head 2.1
  775. - head 2.2
  776. - head 2.3
  777. - head 2.4
  778. * .. row body 1 / this is a comment
  779. - row 1
  780. - :rspan:`2` cell 1-3.1
  781. - cell 1.2
  782. - cell 1.3
  783. - cell 1.4
  784. * .. Comments and targets are allowed on *table-row* stage.
  785. .. _`row body 2`:
  786. - row 2
  787. - cell 2.2
  788. - :rspan:`1` :cspan:`1`
  789. cell 2.3 with a span over
  790. * col 3-4 &
  791. * row 2-3
  792. * - row 3
  793. - cell 3.2
  794. * - row 4
  795. - cell 4.1
  796. - cell 4.2
  797. - cell 4.3
  798. - cell 4.4
  799. * - row 5
  800. - cell 5.1 with automatic span to right end
  801. * - row 6
  802. - cell 6.1
  803. - ..
  804. .. admonition:: List table
  805. :class: rst-example
  806. .. flat-table:: ``flat-table`` example
  807. :header-rows: 2
  808. :stub-columns: 1
  809. :widths: 1 1 1 1 2
  810. * - :rspan:`1` head / stub
  811. - :cspan:`3` head 1.1-4
  812. * - head 2.1
  813. - head 2.2
  814. - head 2.3
  815. - head 2.4
  816. * .. row body 1 / this is a comment
  817. - row 1
  818. - :rspan:`2` cell 1-3.1
  819. - cell 1.2
  820. - cell 1.3
  821. - cell 1.4
  822. * .. Comments and targets are allowed on *table-row* stage.
  823. .. _`row body 2`:
  824. - row 2
  825. - cell 2.2
  826. - :rspan:`1` :cspan:`1`
  827. cell 2.3 with a span over
  828. * col 3-4 &
  829. * row 2-3
  830. * - row 3
  831. - cell 3.2
  832. * - row 4
  833. - cell 4.1
  834. - cell 4.2
  835. - cell 4.3
  836. - cell 4.4
  837. * - row 5
  838. - cell 5.1 with automatic span to right end
  839. * - row 6
  840. - cell 6.1
  841. - ..
  842. CSV table
  843. ---------
  844. CSV table might be the choice if you want to include CSV-data from a outstanding
  845. (build) process into your documentation.
  846. .. code:: reST
  847. .. csv-table:: CSV table example
  848. :header: .. , Column 1, Column 2
  849. :widths: 2 5 5
  850. :stub-columns: 1
  851. :file: csv_table.txt
  852. Content of file ``csv_table.txt``:
  853. .. literalinclude:: csv_table.txt
  854. .. admonition:: CSV table
  855. :class: rst-example
  856. .. csv-table:: CSV table example
  857. :header: .. , Column 1, Column 2
  858. :widths: 3 5 5
  859. :stub-columns: 1
  860. :file: csv_table.txt
  861. Templating
  862. ==========
  863. .. sidebar:: Build environment
  864. All *generic-doc* tasks are running in the :ref:`make install`.
  865. Templating is suitable for documentation which is created generic at the build
  866. time. The sphinx-jinja_ extension evaluates jinja_ templates in the :ref:`make
  867. install` (with searx modules installed). We use this e.g. to build chapter:
  868. :ref:`engines generic`. Below the jinja directive from the
  869. :origin:`docs/admin/engines.rst` is shown:
  870. .. literalinclude:: ../admin/engines.rst
  871. :language: reST
  872. :start-after: .. _configured engines:
  873. The context for the template is selected in the line ``.. jinja:: searx``. In
  874. sphinx's build configuration (:origin:`docs/conf.py`) the ``searx`` context
  875. contains the ``engines`` and ``plugins``.
  876. .. code:: py
  877. import searx.search
  878. import searx.engines
  879. import searx.plugins
  880. searx.search.initialize()
  881. jinja_contexts = {
  882. 'searx': {
  883. 'engines': searx.engines.engines,
  884. 'plugins': searx.plugins.plugins
  885. },
  886. }
  887. Tabbed views
  888. ============
  889. .. _sphinx-tabs: https://github.com/djungelorm/sphinx-tabs
  890. .. _basic-tabs: https://github.com/djungelorm/sphinx-tabs#basic-tabs
  891. .. _group-tabs: https://github.com/djungelorm/sphinx-tabs#group-tabs
  892. .. _code-tabs: https://github.com/djungelorm/sphinx-tabs#code-tabs
  893. With `sphinx-tabs`_ extension we have *tabbed views*. To provide installation
  894. instructions with one tab per distribution we use the `group-tabs`_ directive,
  895. others are basic-tabs_ and code-tabs_. Below a *group-tab* example from
  896. :ref:`docs build` is shown:
  897. .. literalinclude:: ../admin/buildhosts.rst
  898. :language: reST
  899. :start-after: .. SNIP sh lint requirements
  900. :end-before: .. SNAP sh lint requirements
  901. .. _math:
  902. Math equations
  903. ==============
  904. .. _Mathematics: https://en.wikibooks.org/wiki/LaTeX/Mathematics
  905. .. _amsmath user guide:
  906. http://vesta.informatik.rwth-aachen.de/ftp/pub/mirror/ctan/macros/latex/required/amsmath/amsldoc.pdf
  907. .. sidebar:: About LaTeX
  908. - `amsmath user guide`_
  909. - Mathematics_
  910. - :ref:`docs build`
  911. The input language for mathematics is LaTeX markup using the :ctan:`amsmath`
  912. package.
  913. To embed LaTeX markup in reST documents, use role :rst:role:`:math: <math>` for
  914. inline and directive :rst:dir:`.. math:: <math>` for block markup.
  915. .. code:: reST
  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. .. admonition:: LaTeX math equation
  923. :class: rst-example
  924. In :math:numref:`schroedinger general` the time-dependent Schrödinger equation
  925. is shown.
  926. .. math::
  927. :label: schroedinger general
  928. \mathrm{i}\hbar\dfrac{\partial}{\partial t} |\,\psi (t) \rangle =
  929. \hat{H} |\,\psi (t) \rangle.
  930. The next example shows the difference of ``\tfrac`` (*textstyle*) and ``\dfrac``
  931. (*displaystyle*) used in a inline markup or another fraction.
  932. .. code:: reST
  933. ``\tfrac`` **inline example** :math:`\tfrac{\tfrac{1}{x}+\tfrac{1}{y}}{y-z}`
  934. ``\dfrac`` **inline example** :math:`\dfrac{\dfrac{1}{x}+\dfrac{1}{y}}{y-z}`
  935. .. admonition:: Line spacing
  936. :class: rst-example
  937. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  938. eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
  939. voluptua. ...
  940. ``\tfrac`` **inline example** :math:`\tfrac{\tfrac{1}{x}+\tfrac{1}{y}}{y-z}`
  941. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
  942. gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  943. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  944. eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
  945. voluptua. ...
  946. ``\tfrac`` **inline example** :math:`\dfrac{\dfrac{1}{x}+\dfrac{1}{y}}{y-z}`
  947. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
  948. gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  949. .. _KISS: https://en.wikipedia.org/wiki/KISS_principle
  950. .. _readability: https://docs.python-guide.org/writing/style/
  951. .. _Sphinx-Primer:
  952. https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
  953. .. _reST: https://docutils.sourceforge.io/rst.html
  954. .. _Sphinx Roles:
  955. https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html
  956. .. _Sphinx: https://www.sphinx-doc.org
  957. .. _`sphinx-doc FAQ`: https://www.sphinx-doc.org/en/stable/faq.html
  958. .. _Sphinx markup constructs:
  959. https://www.sphinx-doc.org/en/stable/markup/index.html
  960. .. _`sphinx cross references`:
  961. https://www.sphinx-doc.org/en/stable/markup/inline.html#cross-referencing-arbitrary-locations
  962. .. _sphinx.ext.extlinks:
  963. https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
  964. .. _intersphinx: https://www.sphinx-doc.org/en/stable/ext/intersphinx.html
  965. .. _sphinx config: https://www.sphinx-doc.org/en/stable/config.html
  966. .. _Sphinx's autodoc: https://www.sphinx-doc.org/en/stable/ext/autodoc.html
  967. .. _Sphinx's Python domain:
  968. https://www.sphinx-doc.org/en/stable/domains.html#the-python-domain
  969. .. _Sphinx's C domain:
  970. https://www.sphinx-doc.org/en/stable/domains.html#cross-referencing-c-constructs
  971. .. _doctree:
  972. https://www.sphinx-doc.org/en/master/extdev/tutorial.html?highlight=doctree#build-phases
  973. .. _docutils: http://docutils.sourceforge.net/docs/index.html
  974. .. _docutils FAQ: http://docutils.sourceforge.net/FAQ.html
  975. .. _linuxdoc: https://return42.github.io/linuxdoc
  976. .. _jinja: https://jinja.palletsprojects.com/
  977. .. _sphinx-jinja: https://github.com/tardyp/sphinx-jinja
  978. .. _SVG: https://www.w3.org/TR/SVG11/expanded-toc.html
  979. .. _DOT: https://graphviz.gitlab.io/_pages/doc/info/lang.html
  980. .. _`Graphviz's dot`: https://graphviz.gitlab.io/_pages/pdf/dotguide.pdf
  981. .. _Graphviz: https://graphviz.gitlab.io
  982. .. _ImageMagick: https://www.imagemagick.org
  983. .. _`Emacs Table Mode`: https://www.emacswiki.org/emacs/TableMode
  984. .. _`Online Tables Generator`: https://www.tablesgenerator.com/text_tables
  985. .. _`OASIS XML Exchange Table Model`: https://www.oasis-open.org/specs/tm9901.html