Removing all \n is incorrect as these are used to show linebreaks in the html formatted body. Instead use the CMARK_OPT_HARDBREAKS options so these softbreaks in the markdown string are converted to hard breaks <br/> in the html.

Also remove 2 step process to replace <!-- raw HTML omitted --> and straight replace with "" to ensure no real breaks are removed
This commit is contained in:
James Graham
2022-07-10 11:21:54 +01:00
committed by Tobias Fella
parent a07537367f
commit 4337d0d5d8

View File

@@ -633,7 +633,7 @@ void NeoChatRoom::removeLocalAlias(const QString &alias)
QString NeoChatRoom::markdownToHTML(const QString &markdown)
{
const auto str = markdown.toUtf8();
char *tmp_buf = cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_DEFAULT);
char *tmp_buf = cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_HARDBREAKS);
const std::string html(tmp_buf);
@@ -641,11 +641,9 @@ QString NeoChatRoom::markdownToHTML(const QString &markdown)
auto result = QString::fromStdString(html).trimmed();
result.replace("<!-- raw HTML omitted -->", "<br />");
result.replace(QRegularExpression("(<br />)*$"), "");
result.replace("<!-- raw HTML omitted -->", "");
result.replace("<p>", "");
result.replace("</p>", "");
result.replace("\n", "<br>");
return result;
}