Merge pull request #1279 from txdv/entire-words-as-links

convert entire words as urls or do nothing
This commit is contained in:
Lorenz Hübschle 2024-04-26 18:16:22 +02:00 committed by GitHub
commit f39fe804b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 15 deletions

View File

@ -68,7 +68,9 @@ weechat.filter('conditionalLinkify', ['$filter', function($filter) {
return text;
}
return linkifyStr(text, {
return text.replaceAll(/\S+/g, function (match, p2) {
const result = linkifyStr(match, {
className: '',
attributes: {
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,21 @@ 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);
}));
it('linkify parenthesis at the end of an url', angular.mock.inject(function($filter) {
var text = 'http://test.com/(test)',
link = '<a href="http://test.com/(test)" target="_blank" rel="noopener noreferrer">http://test.com/(test)</a>',
result = $filter('conditionalLinkify')(text);
expect(result).toEqual(link);
}));
});
describe('irclinky', function() {