Abe
Abe

Reputation: 23928

RST codeblock with internal indentation

I'm using Sphinx to document methods that return dictionaries.

def do_stuff(foo, bar):
    """Do some stuff

    :param foo: I'm an argument
    :param bar: So am I

    :return: dict::

        {
          "success": (Boolean) True if stuff was done
          "meta": {
              "aaa": A nested return value
              "bbb": Another nested return value
          }
        }
    """

The formatting for the dictionary object looks off:

enter image description here

As best I can tell, the problem is that string literals in RST are expected to be indented at the same level.

Is there a workaround for this?

Upvotes: 2

Views: 752

Answers (1)

e.s.
e.s.

Reputation: 1371

Indenting the :: and then further indenting the dictionary, got it recognized as a codeblock. This was using .. autofunction:: do_stuff and sphinx 1.5.2.

def do_stuff(foo, bar):
    """Do some stuff

    :param foo: I'm an argument
    :param bar: So am I

    :return: dict
        ::
            {
              "success": (Boolean) True if stuff was done
              "meta": {
                  "aaa": A nested return value
                  "bbb": Another nested return value
              }
            }
    """

When I separated out the dict part, I had to format like so.

def do_stuff(foo, bar):
    """Do some stuff

    :param foo: I'm an argument
    :param bar: So am I
    :rtype: dict
    :return:
        ::

            {
              "success": (Boolean) True if stuff was done
              "meta": {
                  "aaa": A nested return value
                  "bbb": Another nested return value
              }
            }
    """

enter image description here

Upvotes: 3

Related Questions