Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
18 lines (13 sloc) 796 Bytes
class Linkify
# replace links in text with HREFs
linkify: (inputText) ->
# URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim
replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>')
# URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>')
# change email addresses to mailto:: links.
replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>')
return replacedText
Something went wrong with that request. Please try again.