gpt4 book ai didi

javascript - Pagedown Markdown 转换器无法正常工作

转载 作者:行者123 更新时间:2023-11-29 23:21:35 25 4
gpt4 key购买 nike

我正在尝试使用 pagedown - Markdown Converter 将 markdown 文本转换为 HTML。它的格式不正确。

这是 JsFiddle URL,它似乎适用于某些标签 - https://jsfiddle.net/oeraroks/

这是堆栈溢出片段 -

var converter = Markdown.getSanitizingConverter();
jQuery('.mdl-card__markdown-content').each(function() {
text = jQuery(this).text();
vhtml = converter.makeHtml(text);
vhtml = vhtml.replace(/(?:\r\n|\r|\n)/g, '<br>');
jQuery(this).html(vhtml);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Sanitizer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.min.js"></script>

<div class="mdl-card__markdown-content">
**DISCLAIMER** He is also known for playing Hal in Malcom in the Middle. Bryan Cranston played the role of Walter in Breaking Bad.
* He is also known for playing Hal in Malcom in the Middle.
* Bryan Cranston played the role of Walter in Breaking Bad.
* He is also known for playing Hal in Malcom in the Middle. Bryan Cranston played the role of Walter in Breaking Bad.
* He is also known for playing Hal in Malcom in the Middle.
* Bryan Cranston played the role of Walter in Breaking Bad. He is also known for playing Hal in Malcom in the Middle.
</div>

如果您可以在 JSFiddle 中看到,您只会看到 Disclaimer 文本变粗了。其余所有预期列表的地方保持不变,没有变化。

常见问题

  1. 我正在使用 SimpleMDE 编辑器 - https://github.com/sparksuite/simplemde-markdown-editor

因为它没有将其更改为 HTML 的选项,所以我不得不查看 pagedown 转换器,将 markdown 文本 转换为 html 文本.

寻求将上述文本转换为 html 的帮助。

最佳答案

您的代码有几个问题。

我对 markdown 本身不是很好,但我注意到的一件事是我需要在段落和列表之间休息一下,以意识到列表在那里。

<div class="mdl-card__markdown-content">
**DISCLAIMER** He is also known for playing Hal in Malcom in the Middle.
Bryan Cranston played the role of Walter in Breaking Bad.

* He is also known for playing Hal in Malcom in the Middle.
* Bryan Cranston played the role of Walter in Breaking Bad.
* He is also known for playing Hal in Malcom in the Middle. Bryan Cranston
played the role of Walter in Breaking Bad.
* He is also known for playing Hal in Malcom in the Middle.
* Bryan Cranston played the role of Walter in Breaking Bad. He is also known
for playing Hal in Malcom in the Middle.
</div>

甚至在此站点(您的版本)上也能看到差异:

免责声明 他还因在中间的 Malcom 中扮演哈尔而闻名。 布莱恩·克兰斯顿在《绝命毒师》中饰演沃尔特。* 他还因在中间的 Malcom 中扮演哈尔而闻名。* 布莱恩·克兰斯顿在《绝命毒师》中饰演沃尔特。* 他还因在中间的 Malcom 中扮演哈尔而闻名。布莱恩克兰斯顿在《绝命毒师》中饰演沃尔特。* 他还因在中间的 Malcom 中扮演哈尔而闻名。* 布莱恩·克兰斯顿在《绝命毒师》中饰演沃尔特。他也是众所周知的 在中间的马尔科姆扮演哈尔。


ws(带中断的版本):

免责声明 他还因在中间的 Malcom 中扮演哈尔而闻名。 布莱恩·科兰斯顿在《绝命毒师》中饰演沃尔特。

  • 他还因在中间的 Malcom 中扮演哈尔而闻名。
  • 布莱恩·克兰斯顿在《绝命毒师》中饰演沃尔特。
  • 他还因在中间的 Malcom 中扮演 Hal 而闻名。布莱恩克兰斯顿在《绝命毒师》中饰演沃尔特。
  • 他还因在中间的 Malcom 中扮演哈尔而闻名。
  • 布莱恩·克兰斯顿在《绝命毒师》中扮演沃尔特一 Angular 。他也是众所周知的在中间的马尔科姆扮演哈尔。

那么你可能想删除

vhtml = vhtml.replace(/(?:\r\n|\r|\n)/g, '<br>');

让它看起来更漂亮

关于javascript - Pagedown Markdown 转换器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50422795/

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