Skip to content

Instantly share code, notes, and snippets.

@andershaig
Created November 14, 2011 20:44
Show Gist options
  • Save andershaig/1365095 to your computer and use it in GitHub Desktop.
Save andershaig/1365095 to your computer and use it in GitHub Desktop.
Turn URL Titles into Links
<script type="text/javascript">
var to_parse = '{{ media_item.title | strip_newlines }}';
var URL_RE = /(?:(?=[\s`!()\[\]{};:'".,<>?«»“”‘’])|\b)((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/|[a-z0-9.\-]+[.](?:com|org|net))(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))*(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]|\b))/gi;
var parsed_url = to_parse.match(URL_RE);
document.write('<a id="magic_button" href="' + parsed_url + '" target="_blank">View Blog Post &raquo;</a>');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment