Skip to content

Instantly share code, notes, and snippets.

@reinh
Created February 10, 2011 16:43
Show Gist options
  • Select an option

  • Save reinh/820855 to your computer and use it in GitHub Desktop.

Select an option

Save reinh/820855 to your computer and use it in GitHub Desktop.
$.fn.autolink = ->
regexps =
'<a href="$1">$1</a>' : /(https?:\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g
'<a href="http://twitter.com/user/$1">@$1</a>' : /@([\w\d_]+)/g
@.each ->
for template, regexp of regexps
$(@).html( $(@).html().replace(regexp,template) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment