带内部缩进的RST代码块

时间:2017-12-09 16:03:54

标签: python python-sphinx restructuredtext

我正在使用Sphinx来记录返回字典的方法。

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
          }
        }
    """

字典对象的格式设置为:

enter image description here

我可以说,问题是RST中的字符串文字预计会缩进到同一级别。

有解决方法吗?

1 个答案:

答案 0 :(得分:2)

缩进::然后进一步缩进字典,将其识别为代码块。这是使用.. autofunction:: do_stuff和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
              }
            }
    """

当我把dict部分分开时,我不得不这样格式化。

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