Last active
April 13, 2018 16:08
-
-
Save Atlas48/4454a48dcce5b2bffb697285e2bab1a4 to your computer and use it in GitHub Desktop.
small little coffescript function to turn links into html hyperlinks
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 = -> (x) | |
url = /^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$/ | |
email = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/ | |
"<a href=\"#{x}\">#{x}</a>" if url.test x else x | |
"<a href=\"mailto:#{x}\">" if email.test x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment