Created
March 20, 2013 11:33
-
-
Save adamcbrewer/5204001 to your computer and use it in GitHub Desktop.
JS: Newline to <br>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts newline characters to HTML <br /> elements | |
* | |
* @author Adam Brewer - @adamcbrewer - adamcbrewer.com | |
* | |
* Usage: "String goes\n\rhere".nl2br(); | |
* | |
*/ | |
String.prototype.nl2br = function () { | |
return this.replace(/(\r\n|\n|\r)/gm, "<br />"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment