如何在reStructuredText(使用Spinx)中使用文字块时修复列表缩进?

时间:2013-07-26 11:23:27

标签: python python-sphinx restructuredtext docutils

对于文档项目,我想将代码示例作为项目符号列表。我使用Sphinx将.rst文件转换为HTML。这工作正常,直到我开始在列表项中使用文字块。在下面的示例中,我想在与“给定XML文件...”相同的级别上显示句子“执行以下代码之后”。但它会自动缩进。

Example
--------

-   Given an XML-file note.xml, which contains:

    ::

        <note>
            <to>Tove</to>
            <from>Jani</from>
            <heading>Reminder</heading>
            <body>Don't forget me this weekend!</body>
        </note>

    After executing the following code:

    ::

        xml = loadxml ("<your path to file>/note.xml");
        parent = xpath(xml, "//note"); //get main node
        addsubnode (parent, "<comment>Comments are welcome.</comment>");

PS:别介意代码,它是一种特殊的语言。

1 个答案:

答案 0 :(得分:3)

意外地找到了解决方案。事实证明这很简单,只需将子弹标记后面的行留空:

Examples
--------

-   

    Given an XML-file note.xml, which contains:

    ::

        <note>
            <to>Tove</to>
            <from>Jani</from>
            <heading>Reminder</heading>
            <body>Don't forget me this weekend!</body>
        </note>

    After executing the following code:

    ::

        xml = loadxml ("<your path to file>/note.xml");
        parent = xpath(xml, "//note"); //get main node
        addsubnode (parent, "<comment>Comments are welcome.</comment>");