Question

I'm using Sphinx to manage my project's documentation.

I have an unordered list, and I want the first line of every item to be a code segment. (Not inline, a paragraph.)

How can I do that?

Was it helpful?

Solution

Looking at my own documentation I found a similar scenario, however I can't guarantee that it will work with the documentation as the first text in the list:

#.  **Defining the Model Class**

    All models must inherit from |LrbBaseModel| either directly or
    indirectly and have the |LrbModelInit| decorator above their
    constructor (a.k.a. ``__init__``)::

        class foo(LrbBaseModel):
            @LrbModelInit()
            def __init__(self):
                ...

This produces:

alt text

I think you can get away with a code block without pre-amble text like the following:

#.  ::
        def fooDeFaFa():
            pass

Notice that my code block is indented twice. The :: indicates the empty textual paragraph block, and then my code is a child of this :: syntax via indenting a second time.

Alternatively, this may work:

#.
    ::
        def fooDeFaFa():
            pass
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top