diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-03-24 19:09:48 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-03-24 19:09:48 +0900 |
commit | adcea5868d45610be0539af3e1cfc15f8495815c (patch) | |
tree | 61eac587abf7999ae5e0b40799086364241af185 | |
parent | e2dea5a7e263707c283b63f0c31b4fae8399db3b (diff) | |
download | libquotient-adcea5868d45610be0539af3e1cfc15f8495815c.tar.gz libquotient-adcea5868d45610be0539af3e1cfc15f8495815c.zip |
Expose linkifyUrls() into library API for future use
-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); |