Skip to content

Instantly share code, notes, and snippets.

@coryschires
Created June 21, 2010 05:29
Show Gist options
  • Save coryschires/446444 to your computer and use it in GitHub Desktop.
Save coryschires/446444 to your computer and use it in GitHub Desktop.
preserve line breaks javascript
var perserve_linebreaks = function(text) {
var html = text.replace(/\r\n\r\n/g, "</p><p>"),
html = html.replace(/\r\n/g, "<br />"),
html = html.replace(/\n\n/g, "</p><p>"),
html = html.replace(/\n/g, "<br />"),
html = "<p>"+html+"</p>";
return html
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment