diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.cpp | 11 | ||||
-rw-r--r-- | lib/util.h | 5 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/util.cpp b/lib/util.cpp index 8d16cfc8..fe6286f3 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -29,16 +29,17 @@ static const auto RegExpOptions = | QRegularExpression::UseUnicodePropertiesOption; // Converts all that looks like a URL into HTML links -static void linkifyUrls(QString& htmlEscapedText) +void QMatrixClient::linkifyUrls(QString& htmlEscapedText) { + // 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: the next-outer parentheses are \N in the replacement. + + // generic url: // regexp is originally taken from Konsole (https://github.com/KDE/konsole) - // full url: // protocolname:// or www. followed by anything other than whitespaces, // <, >, ' or ", and ends before whitespaces, <, >, ', ", ], !, ), :, // 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: the next-outer parentheses are \N in the replacement. static const QRegularExpression FullUrlRegExp(QStringLiteral( R"(\b((www\.(?!\.)(?!(\w|\.|-)+@)|(https?|ftp|magnet)://)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))" ), RegExpOptions); @@ -296,13 +296,16 @@ namespace QMatrixClient return std::make_pair(last, sLast); } + /** Convert what looks like a URL or a Matrix ID to an HTML hyperlink */ + void linkifyUrls(QString& htmlEscapedText); + /** Sanitize the text before showing in HTML * This does toHtmlEscaped() and removes Unicode BiDi marks. */ QString sanitized(const QString& plainText); /** Pretty-print plain text into HTML - * This includes HTML escaping of <,>,",& and URLs linkification. + * This includes HTML escaping of <,>,",& and calling linkifyUrls() */ QString prettyPrint(const QString& plainText); |