reST.rst 38 KB

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