gpt4 book ai didi

javascript - 对于具有嵌套列表和段落的列表项,标记返回错误的 html

转载 作者:行者123 更新时间:2023-11-27 22:36:42 24 4
gpt4 key购买 nike

当尝试将这个简单的 markdown 转换为 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)

最佳答案

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

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

假设您正在创建一个仅包含第一个(外部)列表项的内容的文档。当您设置列表格式后,它看起来像这样:

section one
* item one
* item two

This is the first section

哪些大多数 Markdown 实现 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 也错了。绝对是一个错误。

关于javascript - 对于具有嵌套列表和段落的列表项,标记返回错误的 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39059626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com