From 543885a30e2917783fe20eafe42c8e6623596a17 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Sat, 6 Apr 2024 10:15:18 +0300 Subject: [PATCH] convert entire words as urls or do nothing --- src/js/filters.js | 34 ++++++++++++++++++++++------------ test/unit/filters.js | 8 ++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/js/filters.js b/src/js/filters.js index 6274c78..d7ebf66 100644 --- a/src/js/filters.js +++ b/src/js/filters.js @@ -68,20 +68,30 @@ weechat.filter('conditionalLinkify', ['$filter', function($filter) { return text; } - return linkifyStr(text, { - className: '', - attributes: { - rel: 'noopener noreferrer' - }, - target: { - url: '_blank' - }, - validate: { - email: function () { - return false; //Do not linkify emails + + return text.replaceAll(/\S+/g, function (match, p2) { + const result = linkifyStr(match, { + className: '', + attributes: { + rel: 'noopener noreferrer' + }, + target: { + url: '_blank' + }, + validate: { + email: function () { + return false; //Do not linkify emails + } } + }); + + if (result.endsWith("")) { + return result; + } else { + return match } - }); + + }); }; }]); diff --git a/test/unit/filters.js b/test/unit/filters.js index 6c09c77..8439f2f 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -30,6 +30,14 @@ describe('Filters', function() { result = $filter('conditionalLinkify')(url); expect(result).toEqual(link); })); + + it('convert the entire words to links', angular.mock.inject(function($filter) { + var text = 'weechat.network.connection_timeout', + link = 'weechat.network.connection_timeout', + result = $filter('conditionalLinkify')(text); + expect(result).toEqual(link); + })); + }); describe('irclinky', function() {