我正在尝试使用pagedown
- Markdown Converter将markdown文本转换为HTML。它格式不正确。
这是JsFiddle网址,它似乎适用于某些标记 - 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
文字变得粗体。在预期列表的所有位置保持不变且没有变化。
常见问题
由于它无法将其更改为HTML,因此我必须向下看pagedown
转换器,以便将markdown text
转换为html text
。
寻求将上述文本转换为html的帮助。
答案 0 :(得分:0)
您的代码存在一些问题。
我对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中扮演Hal而闻名。 布莱恩克兰斯顿扮演沃尔特在破坏中的角色。 *他也因在中间的Malcom中扮演Hal而闻名。 *布莱恩·克兰斯顿扮演沃尔特的角色。 *他也因在中间的Malcom中扮演Hal而闻名。布莱恩克兰斯顿 扮演沃尔特在打破坏人的角色。 *他也因在中间的Malcom中扮演Hal而闻名。 *布莱恩·克兰斯顿扮演沃尔特的角色。他也是众所周知的 在中间的Malcom玩Hal。
免责声明他也因在中间的Malcom中扮演Hal而闻名。 布莱恩·克兰斯顿(Bryan Cranston)扮演沃尔特(Walter)的角色。
然后你可能想删除
vhtml = vhtml.replace(/(?:\r\n|\r|\n)/g, '<br>');
让它看起来更漂亮