Skip to content

Instantly share code, notes, and snippets.

@westonwatson
Created February 1, 2013 13:29
Show Gist options
  • Save westonwatson/4691315 to your computer and use it in GitHub Desktop.
Save westonwatson/4691315 to your computer and use it in GitHub Desktop.
# Pure Javascript Linkify Solution ======================== > pure-linkify.js
function linkify(textBlock){
return textBlock.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g, '$1<a href="http://$2">$2</a>$3')
.replace(/(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g, '$1<a href="$2">$2</a>$5');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment