diff --git a/markdownhighlighter.cpp b/markdownhighlighter.cpp index 5a24ed0..4da1c5e 100644 --- a/markdownhighlighter.cpp +++ b/markdownhighlighter.cpp @@ -149,13 +149,20 @@ void MarkdownHighlighter::initHighlightingRules() { { HighlightingRule rule(HighlighterState::Link); - // highlight urls without any other markup + // highlight urls without any other markup like http://www.github.com rule.pattern = QRegularExpression(QStringLiteral(R"(\b\w+?:\/\/[^\s>]+)")); rule.capturingGroup = 0; rule.shouldContain = QStringLiteral("://"); _highlightingRules.append(rule); + // highlight urls without any other markup like www.github.com + rule.pattern = + QRegularExpression(QStringLiteral(R"(\bwww\.[^\s]+\.[^\s]+\b)")); + rule.capturingGroup = 0; + rule.shouldContain = QStringLiteral("www."); + _highlightingRules.append(rule); + // highlight urls with <> but without any . in it rule.pattern = QRegularExpression(QStringLiteral(R"(<(\w+?:\/\/[^\s]+)>)")); diff --git a/qmarkdowntextedit.cpp b/qmarkdowntextedit.cpp index 5ec395f..fcfbf01 100644 --- a/qmarkdowntextedit.cpp +++ b/qmarkdowntextedit.cpp @@ -1238,6 +1238,15 @@ QMap QMarkdownTextEdit::parseMarkdownUrlsFromText( urlMap[url] = url; } + // match urls like this: www.github.com + regex = QRegularExpression(R"(\bwww\.[^\s]+\.[^\s]+\b)"); + iterator = regex.globalMatch(text); + while (iterator.hasNext()) { + QRegularExpressionMatch match = iterator.next(); + QString url = match.captured(0); + urlMap[url] = QStringLiteral("http://") + url; + } + // match reference urls like this: [this url][1] with this later: // [1]: http://domain regex = QRegularExpression(R"(\[(.*?)\]\[(.+?)\])");