Markdown:列表转换不好

Markdown: lists are not well converted

我正在尝试在 Markdown 中创建一个列表。正如我在一些文档中读到的,如果我写这个 Markdown 代码:

My list
* first item
* second item
* third item

Not in the list

我得到的结果与我在 HTML 中写的结果相同:

<p>My list</p>
<li>
   <ul>first item</ul>
   <ul>second item</ul>
   <ul>third item</ul>
</li>
<p>Not in the list</p>

我使用 Atom 作为编辑器及其 Markdown 预览器,一切正常,但是当我使用 pandoc 转换我的 Markdown 文件时,如下所示:

pandoc test.md -o test.odt

我得到的是这样的:

My list * first item * second item * third item
Not in the list

我哪里做错了?

您的问题有两种可能的解决方案:

  1. 在段落和列表之间添加一个空行(如评论中提到的@melpomene)。

    My list
    
    * first item
    * second item
    * third item
    
    Not in the list
    
  2. 省略空行并告诉 Pandoc 使用 commonmark 作为 input format 而不是默认的 markdown.

    pandoc -f commonmark -o test.odt test.md
    

"problem" 是 Atom 编辑器使用 CommonMark 解析器,默认情况下,Pandoc 使用老式的 Markdown 解析器,主要遵循 these rules and the reference implementation (markdown.pl). In fact, the Commonmark spec 特别承认这种差异:

In CommonMark, a list can interrupt a paragraph. That is, no blank line is needed to separate a paragraph from a following list:

Foo
- bar
- baz

<p>Foo</p>
<ul>
<li>bar</li>
<li>baz</li>
</ul>

Markdown.pl does not allow this, through fear of triggering a list via a numeral in a hard-wrapped line:

The number of windows in my house is
14.  The number of doors is 6.

如果您希望您的工具具有共同的行为,那么您只需要使用遵循相同行为的工具。