list - Markdown:列表转换不好

标签 list markdown pandoc

我正在尝试在 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
    

“问题”是 Atom 编辑器使用 CommonMark 解析器,默认情况下,Pandoc 使用老式的 Markdown 解析器,它主要遵循 these rules和引用实现(markdown.pl)。事实上,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.

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

关于list - Markdown:列表转换不好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54524349/

相关文章:

markdown - pandoc 输出到 markdown,用 _ 表示斜体而不是 *

cmake - gnu 使 : use wildcard twice in rule dependency

tomcat - Markdown 服务器和网络服务器有什么区别?

ruby-on-rails - 在 Ruby 中将换行符解释为 markdown(Github Markdown 样式)中的 <br>s

python - 递归修改不规则形状的列表

c# - 按引用对列表进行排序 C#

github - 在 GitHub Flavored Markdown 中的 Markdown 代码块中显示突出显示的代码块

r - 无法在 rstudio 中启动 pandoc

R:如何通过单列聚合数据帧列表,一次聚合所有列

c# - linq查询中的自动编号