Skip to content

Instantly share code, notes, and snippets.

@arbales
Created August 2, 2011 23:28
Show Gist options
  • Save arbales/1121495 to your computer and use it in GitHub Desktop.
Save arbales/1121495 to your computer and use it in GitHub Desktop.
Endor.Utils.formatLinks = (content) ->
safeContent = Handlebars.Utils.escapeExpression(content)
safeContent = safeContent.replace LINK_DETECTION_REGEX, (url) ->
address = if /[a-z]+:\/\//.test url then url else "http://#{url}"
"<a href='#{address}' target='_blank'>#{url}</a>"
new Handlebars.SafeString(safeContent) # Mark our string as safe, since it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment