convert entire words as urls or do nothing

This commit is contained in:
Andrius Bentkus 2024-04-06 10:15:18 +03:00
parent 5a494a007f
commit 543885a30e
2 changed files with 30 additions and 12 deletions

View File

@ -68,7 +68,9 @@ weechat.filter('conditionalLinkify', ['$filter', function($filter) {
return text; return text;
} }
return linkifyStr(text, {
return text.replaceAll(/\S+/g, function (match, p2) {
const result = linkifyStr(match, {
className: '', className: '',
attributes: { attributes: {
rel: 'noopener noreferrer' rel: 'noopener noreferrer'
@ -82,6 +84,14 @@ weechat.filter('conditionalLinkify', ['$filter', function($filter) {
} }
} }
}); });
if (result.endsWith("</a>")) {
return result;
} else {
return match
}
});
}; };
}]); }]);

View File

@ -30,6 +30,14 @@ describe('Filters', function() {
result = $filter('conditionalLinkify')(url); result = $filter('conditionalLinkify')(url);
expect(result).toEqual(link); 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() { describe('irclinky', function() {