Created
September 26, 2014 11:37
-
-
Save morgondag/5e5696e3a1e9d949afe1 to your computer and use it in GitHub Desktop.
Linkify
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
linkify: function(inputText) { | |
var replacedText, replacePattern1, replacePattern2, replacePattern3; | |
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim; | |
replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>'); | |
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim; | |
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>'); | |
replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim; | |
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>'); | |
replacedText = replacedText.replace(/\B@([\w-]+)/gm, '<a href="http://twitter.com/$1" target="_blank">@$1</a>'); | |
return replacedText; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment