Last active
December 28, 2016 19:56
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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