|
| 1 | +Relevent To |
| 2 | +=========== |
| 3 | + |
| 4 | +The ``esbonio.relevant_to`` extension is similar to the `sphinx-panels`_ and `sphinx-tabs`_ extensions, where you can define sections of documentation that is only relevant to a given subject (e.g. Python version) and be able to choose between them. |
| 5 | + |
| 6 | +However, instead of presenting these sections as tabs, this extension uses a dropdown which scales better when you have a large collection of subjects to cover (like text editors!) |
| 7 | + |
| 8 | +Additionally this extension |
| 9 | + |
| 10 | +- Reflects the chosen topic in the page's URL, making subject choices linkable |
| 11 | +- Uses `htmx`_ to swap out the relevant sections. |
| 12 | + |
| 13 | +See the Esbonio language server's :ref:`lsp_getting_started` guide for an example of this extension in action. |
| 14 | + |
| 15 | +.. note:: |
| 16 | + |
| 17 | + This extension currently only supports HTML builders. |
| 18 | + |
| 19 | +.. _htmx: https://htmx.org/ |
| 20 | +.. _sphinx-panels: https://sphinx-panels.readthedocs.io/en/latest/index.html#tabbed-content |
| 21 | +.. _sphinx-tabs: https://sphinx-tabs.readthedocs.io/en/latest/ |
| 22 | + |
| 23 | + |
| 24 | +Getting Started |
| 25 | +--------------- |
| 26 | + |
| 27 | +The ``esbonio.relevant_to`` is available through the ``esbonio-extensions`` Python package. |
| 28 | + |
| 29 | +.. code-block:: console |
| 30 | +
|
| 31 | + $ pip install esbonio-extensions |
| 32 | +
|
| 33 | +Ensure that the extension is enabled by including ``esbonio.relevant_to`` in the ``extensions`` list inside your project's ``conf.py``:: |
| 34 | + |
| 35 | + extensions = [ |
| 36 | + "esbonio.relevant_to" |
| 37 | + ] |
| 38 | + |
| 39 | + |
| 40 | +Then within your documentation, "relevant sections" are defined using the :rst:dir:`relevent-to` directive. |
| 41 | + |
| 42 | +.. rst:directive:: relevent-to |
| 43 | +
|
| 44 | + Define sections that can be swapped out based on the chosen subject. |
| 45 | + Consider the following example. |
| 46 | + |
| 47 | + .. code-block:: rst |
| 48 | +
|
| 49 | + .. relevant-to:: Colour |
| 50 | +
|
| 51 | + Blue |
| 52 | + The chosen colour is blue. |
| 53 | +
|
| 54 | + Green |
| 55 | + The chosen colour is green. |
| 56 | +
|
| 57 | + Red |
| 58 | + The chosen colour is red. |
| 59 | +
|
| 60 | + The argument to the directive defines the category of subject this section is about. The content of the directive must be a valid `definition list <https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#definition-lists>`_ where the term is the name of the subject (``Red``, ``Green`` or ``Blue`` in this case) and the definition is the term's corresponding content. |
| 61 | + |
| 62 | + Here is how the above example is rendered. |
| 63 | + |
| 64 | + .. relevant-to:: Colour |
| 65 | + |
| 66 | + Blue |
| 67 | + The chosen colour is blue. |
| 68 | + |
| 69 | + Green |
| 70 | + The chosen colour is green. |
| 71 | + |
| 72 | + Red |
| 73 | + The chosen colour is red. |
| 74 | + |
| 75 | + The body of a definition can contain most reStructuredText constructs including roles and directives |
| 76 | + |
| 77 | + .. literalinclude:: /lsp/getting-started.rst |
| 78 | + :language: rst |
| 79 | + :start-at: .. relevant-to:: Editor |
| 80 | + :end-before: Emacs |
| 81 | + |
| 82 | + However section titles are not supported. |
0 commit comments