Reputation: 19000
I would line to auto number code-blocks in reStructuredText, if auto numbering is not possible then name/number them manually.
.. code-block:: python
:name: super awesome code exaple no 5
a = 1
When in training we can then reference them and tell students on witch example we now work on. We don't need to reference them in the document itself.
Is it possible in any way? Out of box or by extending Sphinx?
Upvotes: 1
Views: 749
Reputation: 2786
It is possible to do that via extending Sphinx.
You have to create your own extension (see how to create an extension and where to put your own extension) which will implement you new custom directive (see how to create a directive).
Directives are usual Python classes, so your NamedCodeBlock directive class should extend the CodeBlock directive class (see sphinx.directives.code.CodeBlock
) and add support for the name
optional argument where you will be able to set names for your code blocks.
Upvotes: 1