Skip to content

Instantly share code, notes, and snippets.

@Yaffle
Created March 16, 2012 09:34
Show Gist options
  • Select an option

  • Save Yaffle/2049292 to your computer and use it in GitHub Desktop.

Select an option

Save Yaffle/2049292 to your computer and use it in GitHub Desktop.
function urlify(text) { // urlify + escapeHTML
return text.replace(/([\s\S]*?)(\bhttps?:\/\/\S+|$)/g, function (p, a, b) {
b = escapeHTML(b);
return escapeHTML(a) + (b ? ('<a href="' + b + '">' + truncate(b, 48) + '</a>') : '');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment