列表中代码块的 Markdown 格式

Markdown formatting of code blocks in lists

我正在尝试确定是我做错了什么,还是常见的 Markdown 处理器存在错误。

我有以下降价代码 (source):

1. Verify that your system meets the [system requirements for BLT](../INSTALL.md)
1. [Fork](https://help.github.com/articles/fork-a-repo) the primary GitHub repository
1. Clone your fork to your local machine:

         git clone git@github.com:username/project-repo.git
         git remote add upstream git@github.com:acquia-pso/project-repo.git

1. If your project uses separate `master` and `develop` branches, checkout the `develop` branch: `git checkout develop`
1. Run `composer install` (you must already have Composer installed).
1. Install `blt` alias: `composer blt-alias`

您可以在此处查看其呈现方式:

  1. 验证您的系统是否满足 BLT 的系统要求
  2. Fork 主要 GitHub 存储库
  3. 将您的分支克隆到您的本地机器:

     git clone git@github.com:username/project-repo.git
     git remote add upstream git@github.com:acquia-pso/project-repo.git
    
  4. 如果您的项目使用单独的 masterdevelop 分支,请检查 develop 分支:git checkout develop

  5. 运行 composer install(您必须已经安装了 Composer)。
  6. 安装 blt 别名:composer blt-alias

检查 HTML 并注意列表项 3 和 4 如何包含在段落块中,而其他列表项不是。这可能会导致样式非常不一致,具体取决于所使用的 CSS。

我只是想知道为什么 Markdown 将一些列表项放在段落中而不是其他的?我可以在 Whosebug 上的 Github, and on Readthedocs(看起来最糟糕)上复制此行为。

段落仅在第 3 项和第 4 项上。#3 有一个是因为代码块——我认为没有任何解决方法 [0]。 #4 有一个是因为代码块后多了一行。

这里 a gist 没有关于第 4 项的段落。

[0] 我不是 HTML 专家,但由于代码块需要 <pre>,前面的文本可能需要在 <p> 中。参见 inline vs block-level elements

最接近降价标准的是 CommonMark,它 says:

A list is loose if any of its constituent list items are separated by blank lines, or if any of its constituent list items directly contain two block-level elements with a blank line between them. Otherwise a list is tight. (The difference in HTML output is that paragraphs in a loose list are wrapped in <p> tags, while paragraphs in a tight list are not.)

不同的 markdown 解析器处理这些事情的方式不同,但由于您的第三个项目包含代码块,因此至少该项目将包装在 <p> 标记中。根据 CommonMark,所有列表项都应包含在段落中。

无论哪种方式,您都可以通过用换行符分隔列表项来强制所有 <p> 标记:

1. Verify that your system meets the [system requirements for BLT](../INSTALL.md)

1. [Fork](https://help.github.com/articles/fork-a-repo) the primary GitHub repository

1. Clone your fork to your local machine:

         git clone git@github.com:username/project-repo.git
         git remote add upstream git@github.com:acquia-pso/project-repo.git

1. If your project uses separate `master` and `develop` branches, checkout the `develop` branch: `git checkout develop`

1. Run `composer install` (you must already have Composer installed).

1. Install `blt` alias: `composer blt-alias`