Created
September 15, 2010 09:45
-
-
Save xarg/580485 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Linkify(inputText) { | |
//URLs starting with http://, https://, or ftp:// | |
var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim; | |
var replacedText = inputText.replace(replacePattern1, '<a href="$1">$1</a>'); | |
//URLs starting with www. (without // before it, or it'd re-link the ones done above) | |
var replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim; | |
var replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2">$2</a>'); | |
//Change email addresses to mailto:: links | |
var replacePattern3 = /(^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-\.]+?\.[a-zA-Z]{2,6}$)/gim; | |
var replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>'); | |
return replacedText | |
} | |
$(document).ready(function(){ | |
$('.stringWidget span').each(function(){ | |
$(this).html(Linkify($(this).html())); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment