Markdown:在列表中做连续列表的正确方法是什么?

Markdown: What's the proper way to do a continued list inside of a list?

在 GFM 的列表中做连续列表的正确方法是什么?

目标:

  1. 一个
    1. 一个
    2. 两个
  2. 两个
    1. 三个
    2. 四个

我看过关于 continued number lists and relevant issues 的常见帖子,但还没有看到有人问这个问题。

从技术上讲你不能。 Markdown 是 HTML 的一个子集,HTML 不提供这样的功能。但是,您可以在 HTML 中使用类似 <ol start="3"> 的内容来伪造它,它实际上告诉列表以 3 开始编号,而不是默认的 1.

当然,您总是可以退回到原始 HTML,但让我们继续实现仅在 Markdown 中完成此目标的目标。您是否可以在 Markdown 中执行此操作取决于您使用的是哪种 Markdown 实现。

传统Markdown rules状态:

It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces.

...

If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number.

由此可见,目前无法实现所需的行为。但是,如果暗示的更改发生,情况可能会有所不同...

事实证明,Github 扩展的 Commonmark 确实支持以任意数字开始有序列表。正如 spec 所述:

The start number of an ordered list is determined by the list number of its initial list item. The numbers of subsequent list items are disregarded.

鉴于以上情况,以下内容似乎会产生所需的输出:

1. One
    1. one
    2. two
2. Two
    3. three
    4. four 

但是,正如 Babelmark 所展示的那样,这仅适用于少数实现(请注意输出中包含 <ol start="3"> 的实现)。

部分问题是父列表在嵌套列表之前的行中包含一个段落(内容为 Two)。所以如果你在不同的块级元素之间添加一个空行,像这样:

1. One

    1. one
    2. two

2. Two

    3. three
    4. four

然后更多的实现正确地看到嵌套列表。具体来说,如 Babelmark 所示,这会导致 Commonmark 按照您的需要解析列表。事实上,您得到了这个输出(注意 <ol start="3">):

<ol>
    <li>
        <p>One</p>
        <ol>
            <li>one</li>
            <li>two</li>
        </ol>
    </li>
    <li>
        <p>Two</p>
        <ol start="3">
            <li>three</li>
            <li>four</li>
        </ol>
    </li>
</ol>

而且,事实上,我检查过这在 GitHub 中正常工作。