Search code examples
restructuredtext

How do I nest a code block in a bulleted list?


I have a bulleted list that I'm trying to nest a json code block under, but this is not working:

* sldkfjlskdjflsdn
    * sldkfjlskdfjlksdfj:
        * my code block::

            .. code-block:: json
                ...
                "my.config": {
                    "sldkjflskdjfklsj": "slkdjflksdjfskdf"
                },
                ...

This also is not working:

- sldkfjlskdjflsdn
    - sldkfjlskdfjlksdfj:
        - my code block
          ::
            .. code-block:: json
                ...
                "my.config": {
                    "sldkjflskdjfklsj": "slkdjflksdjfskdf"
                },
                ...

Edit

Per the answer to this post I had a few issues with my line breaks and invalid json, etc.

Also, just want to add, my editor led me astray (not sure why snooty doesn't like it even though it builds):

enter image description here

So that just added to my confusion.


Solution

  • :: is a shortcut for .. code-block:: but uses the default language of your documentation. Do not use both. I prefer to use the latter with a language specification to be explicit.

    Also you need proper indentation, white space, line feeds between nested lists, and correct syntax within your code block (do not use ... unless that is valid syntax in the language).

    * sldkfjlskdjflsdn
    
        * sldkfjlskdfjlksdfj:
    
            * my code block:
    
                .. code-block:: json
    
                    "my.config": {
                        "sldkjflskdjfklsj": "slkdjflksdjfskdf"
                    }