2016-08-20 62 views
1

当尝试这个简单的降价转换为HTML:标记返回与嵌套列表列表项和段落错误的HTML

* section one 
    * item one 
    * item two 

    This is the first section 

* section two 
    * item one 
    * item two 

    This is the second section 

的HTML我得到的回复是:

<ul> 
    <li> 
     <p>section one</p> 
     <ul> 
      <li>item one</li> 
      <li> 
       <p>item two</p> 
       <p>This is the first section</p> 
      </li> 
     </ul> 
    </li> 
    <li> 
     <p>section two</p> 
     <ul> 
      <li>item one</li> 
      <li> 
       <p>item two</p> 
       <p>This is the second section</p> 
      </li> 
     </ul> 
    </li> 
</ul> 

段落第一级列表内部是嵌套列表的第二个列表项的一部分。
我希望这个段落是嵌套列表的兄弟,我甚至在不同的在线编辑器中测试它,并且它们按照我的预期呈现它,并且不喜欢marked的结果。

我做错了什么或者是marked的错误?
我试着玩的选项,但没有任何帮助。

下面的代码:

const marked = require("marked"); 
let str = "* section one\n\t* item one\n\t* item two\n\n\tThis is the first section"; 
str += "\n\n* section two\n\t* item one\n\t* item two\n\n\tThis is the second section"; 

marked(str) 

回答

1

这绝对是一个错误。正如您注意到的那样,other implementations按照您的预期渲染。

但是,您可能会认为文档中存在轻微错误。您应该在(外部)列表项目的第一行和嵌套列表之间添加一行。

假设您创建的文档只包含第一个(外部)列表项的内容。正如你所列表格式,这将是这样的:

section one 
* item one 
* item two 

This is the first section 

最减价实现interpret在其中一个:

<p>section one * item one * item two</p> 
<p>This is the first section</p> 

<p>section one <em> item one </em> item two</p> 
<p>This is the first section</p> 

当然,你需要一个第一行和列表之间的空行。就像这样:

section one 

* item one 
* item two 

This is the first section 

一贯地renders为:

<p>section one</p> 
<ul> 
    <li>item one</li> 
    <li>item two</li> 
</ul> 
<p>This is the first section</p> 

应用,为您的整个文件,就像这样:

* section one 

    * item one 
    * item two 

    This is the first section 

* section two 

    * item one 
    * item two 

    This is the second section 

,你会得到良好的,一致的results

嗯,好吧,事实证明Marked也有错。绝对是一个错误。

+0

谢谢。我打开了一个[新问题](https://github.com/chjj/marked/issues/789),让我们看看他们说了些什么。 –