From dd73a4b2786a0b934f338fbf9d07032a13ac6a94 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Wed, 12 Sep 2018 14:20:12 +0300 Subject: Trim whitespace from text messages --- src/Utils.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 84978bae..5a0558f4 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -337,10 +337,12 @@ utils::linkifyMessage(const QString &body) return textString; } -std::string -utils::markdownToHtml(const std::string &text) +QString +utils::markdownToHtml(const QString &text) { - const char *tmp_buf = cmark_markdown_to_html(text.c_str(), text.size(), CMARK_OPT_DEFAULT); + const auto str = text.toUtf8(); + const char *tmp_buf = + cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_DEFAULT); // Copy the null terminated output buffer. std::string html(tmp_buf); @@ -348,17 +350,11 @@ utils::markdownToHtml(const std::string &text) // The buffer is no longer needed. free((char *)tmp_buf); - return html; -} - -std::string -utils::markdownToHtml(const QString &text) -{ - return utils::markdownToHtml(text.toStdString()); + return QString::fromStdString(html).trimmed(); } std::string -utils::stripHtml(const std::string &text) +utils::stripHtml(const QString &text) { - return QString::fromStdString(text).remove(QRegExp("<[^>]*>")).toStdString(); + return text.trimmed().remove(QRegExp("<[^>]*>")).toStdString(); } -- cgit 1.5.1