Skip to content

Commit

Permalink
Expose linkifyUrls() into library API for future use
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal committed Mar 24, 2019
1 parent e2dea5a commit adcea58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion lib/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit adcea58

Please sign in to comment.