Open luccasmaso opened 9 years ago
Want to submit a PR?
Actually I realize a simpler solution for my case, and created own directive. The regex is kind of different and more like the facebook one's
appDirectives.directive('linkify', ['$timeout', function($timeout){
return {
restrict: 'A',
replace: true,
link: function(scope, element, attrs){
var linkify = function(text){
if (text) {
text = text.replace(
/((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
function(url){
var full_url = url;
if (!full_url.match('^https?:\/\/')) {
full_url = 'http://' + full_url;
}
return '<a target="_blank" href="' + full_url + '">' + url + '</a>';
}
);
}
return text;
};
$timeout(function() {
element.html(linkify(element.text()));
});
}
};
}])
Would this be useful in this directive? Should we use that regex?
Given the url to linkify:
https://www.site.com/someimage.jpg?var=1&option=1
The
href
attribute for the<a>
tag has some characters (&) escaped to html entities.https://www.site.com/someimage.jpg?var=1&option=1
This way the url cannot be achieved. I suggest unescaping it back when adding the attribute do the tag.