Skip to content

Instantly share code, notes, and snippets.

@igorsgm
Last active December 28, 2016 19:56
Show Gist options
  • Save igorsgm/79ec3db34d8ab1950d572ba2ffbc075b to your computer and use it in GitHub Desktop.
Save igorsgm/79ec3db34d8ab1950d572ba2ffbc075b to your computer and use it in GitHub Desktop.
Filtro para transformar urls em links clicáveis @READ https://devdactic.com/angularjs-filters-html-parsing/
.filter('parseUrl', function ($sce) {
var urls = /(\b(https?|ftp):\/\/[A-Z0-9+&@#\/%?=~_|!:,.;-]*[-A-Z0-9+&@#\/%=~_|])/gim;
var emails = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
return function (text) {
if (text.match(urls)) {
text = text.replace(urls, '<a href="$1">$1</a>');
}
if (text.match(emails)) {
text = text.replace(emails, '<a href=\"mailto:$1\">$1</a>');
}
return $sce.trustAsHtml(text);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment