0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Treat nbsp as content when cleaning DOM tree.

Fixes #240.
This commit is contained in:
Neil Jenkins 2016-09-28 12:02:29 +10:00
parent 0fa4a9b587
commit 5f8bd2d935
3 changed files with 10 additions and 10 deletions

View file

@ -1983,7 +1983,7 @@ var cleanTree = function cleanTree ( node, preserveWS ) {
nodeName = sibling.nodeName; nodeName = sibling.nodeName;
if ( nodeName === 'IMG' || if ( nodeName === 'IMG' ||
( nodeName === '#text' && ( nodeName === '#text' &&
/\S/.test( sibling.data ) ) ) { notWS.test( sibling.data ) ) ) {
break; break;
} }
if ( !isInline( sibling ) ) { if ( !isInline( sibling ) ) {
@ -1991,14 +1991,14 @@ var cleanTree = function cleanTree ( node, preserveWS ) {
break; break;
} }
} }
data = data.replace( /^\s+/g, sibling ? ' ' : '' ); data = data.replace( /^[ \t\r\n]+/g, sibling ? ' ' : '' );
} }
if ( endsWithWS ) { if ( endsWithWS ) {
walker.currentNode = child; walker.currentNode = child;
while ( sibling = walker.nextNode() ) { while ( sibling = walker.nextNode() ) {
if ( nodeName === 'IMG' || if ( nodeName === 'IMG' ||
( nodeName === '#text' && ( nodeName === '#text' &&
/\S/.test( sibling.data ) ) ) { notWS.test( sibling.data ) ) ) {
break; break;
} }
if ( !isInline( sibling ) ) { if ( !isInline( sibling ) ) {
@ -2006,7 +2006,7 @@ var cleanTree = function cleanTree ( node, preserveWS ) {
break; break;
} }
} }
data = data.replace( /\s+$/g, sibling ? ' ' : '' ); data = data.replace( /[ \t\r\n]+$/g, sibling ? ' ' : '' );
} }
if ( data ) { if ( data ) {
child.data = data; child.data = data;

File diff suppressed because one or more lines are too long

View file

@ -243,7 +243,7 @@ var cleanTree = function cleanTree ( node, preserveWS ) {
nodeName = sibling.nodeName; nodeName = sibling.nodeName;
if ( nodeName === 'IMG' || if ( nodeName === 'IMG' ||
( nodeName === '#text' && ( nodeName === '#text' &&
/\S/.test( sibling.data ) ) ) { notWS.test( sibling.data ) ) ) {
break; break;
} }
if ( !isInline( sibling ) ) { if ( !isInline( sibling ) ) {
@ -251,14 +251,14 @@ var cleanTree = function cleanTree ( node, preserveWS ) {
break; break;
} }
} }
data = data.replace( /^\s+/g, sibling ? ' ' : '' ); data = data.replace( /^[ \t\r\n]+/g, sibling ? ' ' : '' );
} }
if ( endsWithWS ) { if ( endsWithWS ) {
walker.currentNode = child; walker.currentNode = child;
while ( sibling = walker.nextNode() ) { while ( sibling = walker.nextNode() ) {
if ( nodeName === 'IMG' || if ( nodeName === 'IMG' ||
( nodeName === '#text' && ( nodeName === '#text' &&
/\S/.test( sibling.data ) ) ) { notWS.test( sibling.data ) ) ) {
break; break;
} }
if ( !isInline( sibling ) ) { if ( !isInline( sibling ) ) {
@ -266,7 +266,7 @@ var cleanTree = function cleanTree ( node, preserveWS ) {
break; break;
} }
} }
data = data.replace( /\s+$/g, sibling ? ' ' : '' ); data = data.replace( /[ \t\r\n]+$/g, sibling ? ' ' : '' );
} }
if ( data ) { if ( data ) {
child.data = data; child.data = data;