From 17c7afaa4339e7e2259718f19a80ffbf960b1a8d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 26 Feb 2019 13:12:01 +0900 Subject: Linkify Matrix identifiers This is a crude interim implementation until we get new fancy Matrix URIs. --- lib/util.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/util.cpp b/lib/util.cpp index fc90ea76..d042aa34 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -38,6 +38,7 @@ static void linkifyUrls(QString& htmlEscapedText) // comma or dot // Note: outer parentheses are a part of C++ raw string delimiters, not of // the regex (see http://en.cppreference.com/w/cpp/language/string_literal). + // Note2: yet another pair of outer parentheses are \1 in the replacement. static const QRegularExpression FullUrlRegExp(QStringLiteral( R"(((www\.(?!\.)|(https?|ftp|magnet)://)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))" ), RegExpOptions); @@ -46,6 +47,11 @@ static void linkifyUrls(QString& htmlEscapedText) static const QRegularExpression EmailAddressRegExp(QStringLiteral( R"((mailto:)?(\b(\w|\.|-)+@(\w|\.|-)+\.\w+\b))" ), RegExpOptions); + // An interim liberal implementation of + // https://matrix.org/docs/spec/appendices.html#identifier-grammar + static const QRegularExpression MxIdRegExp(QStringLiteral( + R"((^|[^<>/])([!#@][-a-z0-9_=/.]{1,252}:[-.a-z0-9]+))" + ), RegExpOptions); // NOTE: htmlEscapedText is already HTML-escaped! No literal <,>,& @@ -53,6 +59,8 @@ static void linkifyUrls(QString& htmlEscapedText) QStringLiteral(R"(\1\2)")); htmlEscapedText.replace(FullUrlRegExp, QStringLiteral(R"(\1)")); + htmlEscapedText.replace(MxIdRegExp, + QStringLiteral(R"(\1\2)")); } QString QMatrixClient::prettyPrint(const QString& plainText) -- cgit v1.2.3