【问题标题】:Nested sub-list in reStructuredText with code blocks not workingreStructuredText 中的嵌套子列表,代码块不起作用
【发布时间】:2018-07-09 11:16:02
【问题描述】:

我正在使用 sphinx 尝试从 .rst 文件创建 HTML 文档。我正在尝试创建一个包含编号列表 (1., 2., ...) 的文档,其中包含显示示例代码的嵌套子列表 (a., b, c., ...)。但是我在梳理语法以使嵌套子列表工作时遇到了麻烦。这是我尝试过的.rst 文件示例:

===========
Tester Page
===========

Below are some test paragraphs.

1. This is a paragraph detailing a higher level step, with 3 sub-steps.
 a. This is a sub-bullet, with an example:
::

    ls -l foo.txt

 b. I can't get this line to not display as part of the code block! This is another sub-bullet, with an example:
::

    git add bar.txt

2. This is step 2.

This is the end of the document.

上面给了我一个类似的结果(很难在 Markdown 中完全重现,但希望你明白):

测试页面

以下是一些测试段落。

  1. 这是一些文字。

    一个。这是一个子项目符号,有一个例子:

  ls -l foo.txt

b. This is another sub-bullet, with an example:
  git add bar.txt
  1. 这是第 2 步。

文档到此结束。

我已经调整双冒号、空格和反引号至少一个小时了,但不知道如何让它正确格式化。也许 reStructuredText 只是不够通用,无法处理嵌入代码块的嵌套列表?

【问题讨论】:

    标签: python-sphinx restructuredtext


    【解决方案1】:

    您必须非常小心垂直和水平空白。嵌套列表必须通过空行与父列表项分开。文字块中的代码示例必须正确缩进。

    Below are some test paragraphs.
    
    1. This is a paragraph detailing a higher level step, with 3 sub-steps.
    
       a. This is a sub-bullet, with an example::
    
             ls -l foo.txt
    
       b. I can get this line to display as part of the code block!
          This is another sub-bullet, with an example::
    
             git add bar.txt
    
    2. This is step 2.
    

    【讨论】:

    • 好的,这让我找到了我需要的解决方案!总之:空行应该是 empty 空行(注意像 TextPad 和 Eclipse 这样的自动缩进和留空格的编辑器)!此外,额外缩进 3 个空格似乎是一个神奇的数字。确保所有项目都垂直对齐,如果有疑问,请缩进更多!这对我有用。
    • @OgrePsalm33 3 个空格不是必需的,可能会妨碍您的编辑器。见stackoverflow.com/a/48313531/2214933 和我的Bonus Tip
    • 我想知道这是否同样适用于引用中的code-block?我在this one 上非常努力,但我无法弄清楚规则是什么。
    • 如果问题不同,我可能应该提出一个新问题。
    • 啊,没关系,我发现了问题,我有一个不可见的字符弄乱了我的代码。 Fixed it
    猜你喜欢
    • 1970-01-01
    • 2011-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多