html - CommonMark 规范是否允许列表标记前有前导空格?

标签 html list markdown commonmark

这是 CommonMark 中的有效列表吗?

  1. Foo
     - Bar
     - Baz
  2. Qux

我担心每个列表标记前两个前导空格的有效性,即 1.2. 等。在列表标记?

我无法在规范中找到任何明确提到在 http://spec.commonmark.org/0.27/ 的 CommonMark 规范中每个列表标记之前可以有前导空格的内容。 .

但是有很多例子似乎显示了在列表标记之前使用的前导空格。例如,参见

但我希望规范清楚地说明在列表标记之前放置空格是有效的。您能否在规范中找到任何明确说明或至少暗示这一点的内容?

最佳答案

具体规则是list items规则4部分(在 example 246 之后开始):

  1. Indentation. If a sequence of lines Ls constitutes a list item according to rule #1, #2, or #3, then the result of indenting each line of Ls by 1-3 spaces (the same for each line) also constitutes a list item with the same contents and attributes. If a line is empty, then it need not be indented.

示例 247 , 248249然后分别显示一个、两个和三个空格,所有这些都被解释为列表项。最后,example 250显示四个空格的缩进导致一个代码块。

当然是 indented blocks 的规则状态(添加了强调):

An indented code block is composed of one or more indented chunks separated by blank lines. An indented chunk is a sequence of non-blank lines, each indented four or more spaces. The contents of the code block are the literal contents of the lines, including trailing line endings, minus four spaces of indentation.

因此,任何缩进少于四个空格的都不是代码块。几段之后我们发现以下内容:

If there is any ambiguity between an interpretation of indentation as a code block and as indicating that material belongs to a list item, the list item interpretation takes precedence:

给出的示例显示了一个嵌套列表项,它缩进了四个或更多空格。但是,同一个示例也将父列表项缩进了两个空格,因此该规则适用于两者。

为了比较,原始 Markdown rules明确说明:

List markers typically start at the left margin, but may be indented by up to three spaces.

这个概念在 Markdown 中已经存在多年。

关于html - CommonMark 规范是否允许列表标记前有前导空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43276145/

相关文章:

javascript - 使用 jQuery 延迟关闭 Bootstrap 模式

javascript - 向下滑动div上的关闭按钮 - jQuery

html - 如何在具有灵活高度的html css中嵌入Google Form iframe(响应式)

python - 将列表中的每三个项目组合在一起 - Python

latex - Pandoc 不使用 latex 在 Markdown 中生成新行

documentation - Markdown 或其他简单标记语言中的条件逻辑?

html - 如何将水平线放在两个兄弟 <p> 标签下

java - 循环遍历列表 - 当索引到达末尾时,从 0 开始

java - 从大到小排序列表

syntax-highlighting - doxygen markdown 防止在围栏代码块中突出显示语法