Markdown子列表位于项目符号点的中间而不是结尾

flu*_*ffy 3 markdown

以下HTML的Markdown等同于什么?

    <ul><li>Here is a bullet point</li>
    <li>Here is another bullet point; it has sub-points:
        <ul><li>subpoint 1</li>
        <li>subpoint 2</li>
        <li>subpoint 3</li></ul>
    but then continues with the original bullet point</li>
    <li>and here's one more point just to drive it home</li>
    </ul>
Run Code Online (Sandbox Code Playgroud)

我似乎无法让“ ...但是然后继续...”位保留在封装子列表的同一项目符号中。我已经尝试了几种方法:

* Here is a bullet point
* Here is another bullet point; it has sub-points:
    * subpoint 1
    * subpoint 2
    * subpoint 3
  but then continues with the original bullet point
* and here's one more point just to drive it home
Run Code Online (Sandbox Code Playgroud)

带有不同的缩进级别的“” but then,但无论它与“ subpoint 3” 连接什么,或者它只是在项目符号点下变成另一个子缩进。特定行为也会因我使用的Markdown风格而异。

这是否太复杂而无法封装在Markdown中,是我应该只使用内联HTML的情况?

Way*_*lan 5

您需要添加一些空行来告诉Markdown何时启动列表,何时终止列表,何时启动段落(不在列表中)等等。

* Here is a bullet point
* Here is another bullet point; it has sub-points:

    * subpoint 1
    * subpoint 2
    * subpoint 3

    but then continues with the original bullet point

* and here's one more point just to drive it home
Run Code Online (Sandbox Code Playgroud)

呈现为:

<ul>
    <li>Here is a bullet point</li>
    <li>
        <p>Here is another bullet point; it has sub-points:</p>
        <ul>
            <li>subpoint 1</li>
            <li>subpoint 2</li>
            <li>subpoint 3</li>
        </ul>
        <p>but then continues with the original bullet point</p>
    </li>
    <li>
        <p>and here's one more point just to drive it home</p>
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

关键在于将嵌套在列表项中的所有内容视为其自己的独立Markdown文档,该文档在文档的其余部分缩进了四个空格。在这种情况下,您将需要在最后一个列表项和后面的段落之间添加一个空白行,因此您也要在此处进行。

需要注意的一件事是,此生成的输出包括您现在具有“惰性列表”的副作用。即,列表项的内容现在被包装在<p>标签中。这在规则中严格执行:

如果列表项用空行分隔,则Markdown会将这些项目包装<p>在HTML输出中的标记中。

如果您不想使用额外的<p>标签,则列表项内不能嵌套多个块级元素。

最后,我会注意到在上面的示例中,第一个列表项没有获得<p>标签。尽管没有在规则中以一种或另一种方式对其进行记录,但这是原始参考实现的行为(仅列出与空白行接壤的项目(空白行之前和之后的项目)会获得<p>标记)。虽然某些实现已复制了此行为,但并非所有实现都具有,并且各种边缘情况之间存在差异。为了实现不同实施之间的一致性,如果需要在列表中的任何位置使用空白行,则在每个列表项之间包含空白行是一种很好的做法。因此,我会这样做:

* Here is a bullet point

* Here is another bullet point; it has sub-points:

    * subpoint 1
    * subpoint 2
    * subpoint 3

    but then continues with the original bullet point

* and here's one more point just to drive it home
Run Code Online (Sandbox Code Playgroud)

应该更一致地呈现为:

<ul>
    <li>
        <p>Here is a bullet point</p>
    </li>
    <li>
        <p>Here is another bullet point; it has sub-points:</p>
        <ul>
            <li>subpoint 1</li>
            <li>subpoint 2</li>
            <li>subpoint 3</li>
        </ul>
        <p>but then continues with the original bullet point</p>
    </li>
    <li>
        <p>and here's one more point just to drive it home</p>
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)