Last active
December 28, 2015 15:59
-
-
Save MartinSvarrer/7525846 to your computer and use it in GitHub Desktop.
Escape text. And make sure whitespace and line breaks are preserved. This should output the same result as a user input in a textarea.
This will work in IE7 and newer, unlike whitespace: pre-wrap.
Snippet is using the underscore libs escape method.
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
var escapeText = _.escape(insertText), | |
preserveWhiteSpace = escapeText.replace(/ /g, '\u00a0'), | |
preserveWhiteSpaceAndLineBreaks = preserveWhiteSpace.replace(/\n/g, '<br />'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment