Pagedown Markdown 转换器无法正常工作

Pagedown Markdown Converter not working properly

我正在尝试使用 pagedown - Markdown 转换器将 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 text 转换为 html text

寻求帮助将以上文本转换为 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 中扮演哈尔而闻名。 * 布莱恩·克兰斯顿在《绝命毒师》中饰演沃尔特。他也是众所周知的 因为在中间的马尔科姆玩哈尔。


ws(带中断的版本):

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

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

那么您可能想要删除

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

让它看起来更漂亮