Created
June 5, 2018 10:08
-
-
Save Aymkdn/4bfe85186f5dcf14b058048b23ae2e1e to your computer and use it in GitHub Desktop.
Parse URL in a string and convert in a link
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
var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; | |
function linkify(text, safeText) { | |
safeText = (safeText===false? false : true); | |
if (safeText) text=escapeHtml(text); | |
return text.replace(urlRegex, function(url) { | |
return '<a href="' + url + '">' + url + '</a>'; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment