Skip to content

Instantly share code, notes, and snippets.

@mrchess
Created November 27, 2013 15:59
Show Gist options
  • Save mrchess/7678104 to your computer and use it in GitHub Desktop.
Save mrchess/7678104 to your computer and use it in GitHub Desktop.
nl2br coffee plugin
$.extend
nl2br: (str, is_xhtml = false) ->
breakTag = (if (is_xhtml or typeof is_xhtml is "undefined") then "" else "<br>")
(str + "").replace /([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1" + breakTag + "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment