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,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("</a>")) {
return result;
} else {
return match
}
});
});
};
}]);

View File

@ -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() {