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