问题
What's the proper way to do a continued list inside of a list in GFM?
Goal:
- One
- one
- two
- Two
- three
- four
I've looked at common posts regarding continued number lists and relevant issues but haven't seen anyone ask this question yet.
回答1:
Technically you can't. Markdown is a subset of HTML and HTML does not offer such a feature. However, you can fake it in HTML with something like <ol start="3">
which essentially tells a list to start numbering with 3
rather than the default 1
.
Of course, you could always fall back to raw HTML, but lets proceed with the goal of accomplishing this in Markdown only. Whether you can do this in Markdown depends on which Markdown implementation you are using.
The traditional Markdown rules state:
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.
From that, it is clear that the desired behavior is currently not possible. However, if the hinted change were to happen, things might be different...
As it turns out, Commonmark, which Github extends, does support starting ordered lists at an arbitrary number. As the spec states:
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.
Given the above, It might seem that the following would produce the desired output:
1. One
1. one
2. two
2. Two
3. three
4. four
But, as Babelmark demonstrates, that only works for a few implementations (notice the implementations which include <ol start="3">
in the output).
Part of the problem is that the parent list contains a paragraph (with content Two
) ont he line immediately before the nested list. So if you add a blank line between the different block level elements, like this:
1. One
1. one
2. two
2. Two
3. three
4. four
Then more implementations properly see the nested list. Specifically, as Babelmark demonstrates, this causes Commonmark to parse the list as you desire. In fact, you get this output (note the <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>
And, in fact, I checked and this works correctly in GitHub.
来源:https://stackoverflow.com/questions/54101316/markdown-whats-the-proper-way-to-do-a-continued-list-inside-of-a-list