【问题标题】:Correctly marking up multiple nested lists within the same list item在同一个列表项中正确标记多个嵌套列表
【发布时间】:2026-01-21 14:10:01
【问题描述】:

在 GitHub .md 文件中,我正在尝试编写相当于:

<ul>
  <li>This is a list item</li>
  
  <li>This is also a list item
  
    <ul>
      <li>...containing a sublist</li>
      <li>with two items.</li>
    </ul>
    
    and then...
    
    <ul>
      <li>another sublist</li>
      <li>which also has two items</li>
    </ul>
  </li>
  
  <li>This is a third list item</li>
</ul>

我尝试了很多变化:

 - This is a list item
 - This is also a list item
   - ...containing a sublist
   - with two items.
 
   and then...
 
   - another sublist
   - which also has two items
  - This is a third list item

但我还没有找到如何在单个无序列表项中成功嵌套多个单独的无序列表。

我应该如何标记and then... 行,以便它(以及之后的每一行)在 GitHub 风格的 Markdown 中正确呈现?

【问题讨论】:

  • 一般情况下,使用 Markdown 的逃生舱口:写你想要的 HTML 就行了。但是您已经发布的内容似乎适用于例如gist.github.com,所以不清楚是什么问题。
  • 谢谢,@jonrsharpe。你的建议听起来像是一个完美的漏洞,所以我试了一下。不幸的是,GitHub Markdown 的 HTML 解析器无法识别 Markdown 反引号(它假定它们是文字反引号)并且(不知何故)缩进也丢失了。
  • 什么反引号?一旦你开始 HTML,你必须继续 HTML - 你不能来回切换,所以你会使用例如&lt;code&gt;inline code。再说一次,你发布的作品
  • @jonrsharpe - 啊。我没有尝试&lt;code&gt;,因为我认为我需要手动添加style 属性并查找background-colorfont-family 等(这似乎已经是错误的方法)-但是在我没有的事件:我看到&lt;code&gt; 是反引号的直接替代品。不确定降价中的缩进是怎么回事(它肯定不起作用,但如果它对您有用,则错误必须在 sn-p 之外)。无论如何,HTML 标记中的缩进行为都符合预期。非常感谢您将我指向逃生舱口
  • Rounin 你似乎误解了@jonrsharpe。您发布的 Markdown 作品。无需使用原始 HTML 或任何其他技巧。那是除非我们误解了你的问题。也许您可以发布呈现的 HTML 并解释其中的问题。

标签: github markdown github-flavored-markdown


【解决方案1】:

您可以使用虚假的项目符号列表来实现此目的。您可以使用不间断空格和⦁(Z NOTATION SPOT)字符来构建它们。

 - This is a list item
 - This is also a list item&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;...containing a sublist&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;with two items.
 
   and then...
 
&nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;another sublist&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;⦁&nbsp;&nbsp;which also has two items
 - This is a third list item

结果:

  • 这是一个列表项

  • 这也是一个列表项
    ⦁ ...包含一个子列表
    ⦁ 有两个项目。

    然后……

    ⦁ 另一个子列表
    ⦁ 其中也有两个项目

  • 这是第三个列表项

【讨论】:

  • 谢谢,@TamásSengel - 非常感谢。
最近更新 更多