reST.rst 38 KB

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