我正在尝试在 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
我哪里做错了?
最佳答案
您的问题有两种可能的解决方案:
在段落和列表之间添加一个空行(如评论中提到的@melpomene)。
My list * first item * second item * third item Not in the list
省略空行并告诉 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/