diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-02-26 13:12:01 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-02-26 13:12:01 +0900 |
commit | 17c7afaa4339e7e2259718f19a80ffbf960b1a8d (patch) | |
tree | 67ae9831a8d9b45ea8ca8eb1357b6e4bcef0c9de /lib | |
parent | c411bd00d9a4574ee858003493b523811c50d024 (diff) | |
download | libquotient-17c7afaa4339e7e2259718f19a80ffbf960b1a8d.tar.gz libquotient-17c7afaa4339e7e2259718f19a80ffbf960b1a8d.zip |
Linkify Matrix identifiers
This is a crude interim implementation until we get new fancy Matrix
URIs.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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"(<a href="mailto:\2">\1\2</a>)")); htmlEscapedText.replace(FullUrlRegExp, QStringLiteral(R"(<a href="\1">\1</a>)")); + htmlEscapedText.replace(MxIdRegExp, + QStringLiteral(R"(\1<a href="https://matrix.to/#/\2">\2</a>)")); } QString QMatrixClient::prettyPrint(const QString& plainText) |