Skip to content

Instantly share code, notes, and snippets.

@Atlas48
Last active April 13, 2018 16:08
Show Gist options
  • Save Atlas48/4454a48dcce5b2bffb697285e2bab1a4 to your computer and use it in GitHub Desktop.
Save Atlas48/4454a48dcce5b2bffb697285e2bab1a4 to your computer and use it in GitHub Desktop.
small little coffescript function to turn links into html hyperlinks
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