Skip to content

[Documentation] mention the existence of the RST .. code:: directiveΒ #12322

@jakkdl

Description

@jakkdl

Is your feature request related to a problem? Please describe.
I just spent way too long being confused by what the difference between .. code:: and .. code-block:: were, which in large part was caused by .. code:: not being mentioned at all in the sphinx documentation. I'd expect some, if not all, of these sections to mention it:
https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#rst-directives
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#showing-code-examples
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-code-block

It is only indirectly documented by https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directives saying

As previously discussed, a directive is a generic block of explicit markup. While Docutils provides a number of directives, Sphinx provides many more and uses directives as one of the primary extension mechanisms.

and that making the reader independently hunt down a link to the docutils documentation for directives - where it can finally be found: https://docutils.sourceforge.io/docs/ref/rst/directives.html#code

Soooo... what is the difference in terms of sphinx docs? As far as I can tell it's solely that .. code:: does not support options such as :linenos:

Describe the solution you'd like
Mention it existing, but that it is strictly inferior and in general not recommended.

Describe alternatives you've considered
Make .. code:: also support options, and elevate it to being a proper alias for .. code-block:: as with .. sourcecode::. But maybe that is problematic because it breaks the RST spec or something?

Additional context
Encountered while working on python-trio/trio#2968

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions