From 543885a30e2917783fe20eafe42c8e6623596a17 Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Sat, 6 Apr 2024 10:15:18 +0300 Subject: [PATCH 1/3] 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() { From af2d12134d23ef262d36be27b959309908cf329c Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Sat, 6 Apr 2024 10:26:52 +0300 Subject: [PATCH 2/3] test if ) at the end of the link is also taken into url --- test/unit/filters.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/filters.js b/test/unit/filters.js index 8439f2f..946f44d 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -38,6 +38,13 @@ describe('Filters', function() { expect(result).toEqual(link); })); + it('convert the entire words to links', angular.mock.inject(function($filter) { + var text = 'http://test.com/(test)', + link = 'http://test.com/(test)', + result = $filter('conditionalLinkify')(text); + expect(result).toEqual(link); + })); + }); describe('irclinky', function() { From bfa893fde9f11334197af6ebc9d693e40c702ffb Mon Sep 17 00:00:00 2001 From: Andrius Bentkus Date: Sat, 6 Apr 2024 10:27:52 +0300 Subject: [PATCH 3/3] fix test description --- test/unit/filters.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/filters.js b/test/unit/filters.js index 946f44d..d7820e8 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -21,14 +21,14 @@ describe('Filters', function() { var url = 'asdf https://a.example.com/wiki/asdf_qwer_(rivi%C3%A8re) Some text.', link = 'asdf https://a.example.com/wiki/asdf_qwer_(rivi%C3%A8re) Some text.', result = $filter('conditionalLinkify')(url); - expect(result).toEqual(link); + expect(result).toEqual(link); })); it('should not make emails into links', angular.mock.inject(function($filter) { var url = 'asdf@gmail.com', link = 'asdf@gmail.com', result = $filter('conditionalLinkify')(url); - expect(result).toEqual(link); + expect(result).toEqual(link); })); it('convert the entire words to links', angular.mock.inject(function($filter) { @@ -38,7 +38,7 @@ describe('Filters', function() { expect(result).toEqual(link); })); - it('convert the entire words to links', angular.mock.inject(function($filter) { + it('linkify parenthesis at the end of an url', angular.mock.inject(function($filter) { var text = 'http://test.com/(test)', link = 'http://test.com/(test)', result = $filter('conditionalLinkify')(text); @@ -168,6 +168,6 @@ describe('Filters', function() { expect(codifyFilter('Weird`ness`')).toEqual('Weird`ness`'); })); - + }); });