Created
March 8, 2016 10:30
-
-
Save eneko89/f9a066cb9762f820055b to your computer and use it in GitHub Desktop.
Looks for URLs in the source text and replaces them with anchor tags. If there are no links in the text, it does nothing.
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
/** | |
* Looks for URLs in the source text and replaces them with anchor | |
* tags. If there are no links in the text, it does nothing. | |
* | |
* @param {String} text Source text. | |
* | |
* @return {String} New string with URLs in the source | |
* text replaced with anchor tags. | |
*/ | |
function anchorify(text) { | |
var urlRegExp = /(https?:\/\/[^\s]+)/g; | |
return text.replace(urlRegExp, function(url) { | |
return anchor(url, url); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment