Skip to content

Instantly share code, notes, and snippets.

@toekneestuck
Created February 21, 2012 20:29
Show Gist options
  • Save toekneestuck/1878713 to your computer and use it in GitHub Desktop.
Save toekneestuck/1878713 to your computer and use it in GitHub Desktop.
A port of nl2br to Underscore
_.mixin({
nl2br : function(str, is_xhtml){
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (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