diff --git a/src/core/autotests/utilstest.cpp b/src/core/autotests/utilstest.cpp --- a/src/core/autotests/utilstest.cpp +++ b/src/core/autotests/utilstest.cpp @@ -56,6 +56,8 @@ QTest::newRow("empty") << QString() << QString(); QTest::newRow("testurl") << QStringLiteral("http://www.kde.org http://www.kde.org") << QStringLiteral("http://www.kde.org http://www.kde.org"); + QTest::newRow("named-url") << QStringLiteral("[example.com](http://example.com)") + << QStringLiteral("example.com"); QTest::newRow("bold") << QStringLiteral("*bla*") << QStringLiteral("bla"); QTest::newRow("multi star") << QStringLiteral("**bla**") diff --git a/src/core/room.cpp b/src/core/room.cpp --- a/src/core/room.cpp +++ b/src/core/room.cpp @@ -443,7 +443,7 @@ QString Room::topic() const { - return Utils::convertTextWithUrl(mTopic); + return Utils::markdownToRichText(mTopic); } void Room::setTopic(const QString &topic) @@ -482,7 +482,7 @@ QString Room::markdownAnnouncement() const { - return Utils::convertTextWithUrl(Utils::markdownToRichText(mAnnouncement)); + return Utils::markdownToRichText(mAnnouncement); } QString Room::announcement() const diff --git a/src/core/utils.h b/src/core/utils.h --- a/src/core/utils.h +++ b/src/core/utils.h @@ -36,6 +36,16 @@ Q_REQUIRED_RESULT LIBRUQOLACORE_TESTS_EXPORT qint64 parseDate(const QString &key, const QJsonObject &o); Q_REQUIRED_RESULT LIBRUQOLACORE_TESTS_EXPORT qint64 parseIsoDate(const QString &key, const QJsonObject &o); Q_REQUIRED_RESULT LIBRUQOLACORE_TESTS_EXPORT QString iconFromStatus(const QString &status); + +/** + * @brief Convert []() style Markdown URLS with proper HTML tags + * + * Also supports strings that already contain HTML links. + * + * Examples: + * "[NAME](...)" => "NAME" + * "[NAME](LINK)" => "NAME" + */ Q_REQUIRED_RESULT LIBRUQOLACORE_TESTS_EXPORT QString convertTextWithUrl(const QString &str); } diff --git a/src/core/utils.cpp b/src/core/utils.cpp --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -57,6 +57,10 @@ //TODO remove replaceSmileys when we will use unicode emoticons const KTextToHTML::Options convertFlags = KTextToHTML::PreserveSpaces | KTextToHTML::HighlightText | KTextToHTML::ReplaceSmileys | KTextToHTML::ConvertPhoneNumbers; str = KTextToHTML::convertToHtml(str, convertFlags); + + // substitute "[example.com](...)" style urls + str = Utils::convertTextWithUrl(str); + //Bug 391520 I don't remember why I removed
need to investigate //str.remove(QStringLiteral("
")); //qCDebug(RUQOLA_LOG) << "markdownToRichText "<(.*)")); + QString newStr; bool isRef = false; bool isUrl = false; @@ -203,7 +207,12 @@ isUrl = true; } else if (str.at(i) == QLatin1Char(')') && !references.isEmpty()) { isUrl = false; - newStr += QStringLiteral("%2").arg(url, references); + // detect whether the string already contains HTML tags + if (url.startsWith(QLatin1Char('<'))) { + newStr += url.replace(regularExpressionAHref, QStringLiteral("%1").arg(references)); + } else { + newStr += QStringLiteral("%2").arg(url, references); + } references.clear(); url.clear(); } else {