When intercepting a paste event and cleaning HTML off of the content using textNodes, I am faced with an issue where all white space is reduced to a single space and new lines are disregarded. For example, pasting:
"hello world
!"
ends up being "hello world !". Is there a way to preserve white space and new lines? Any suggestions using JavaScript, jQuery, or CSS would be appreciated. Below is the current code snippet:
iframe.contentWindow.focus()
var sel, range;
if (iframe.contentWindow.getSelection) {
sel = iframe.contentWindow.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();}
text = window.clipboardData.getData("Text");
frag = iframe.contentDocument.createTextNode(text);
range.insertNode(frag);