0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

Fix cleanup of white space

This commit is contained in:
Neil Jenkins 2016-03-28 10:14:55 +11:00
parent bac7c5d2cc
commit 230520645b
3 changed files with 11 additions and 19 deletions

View file

@ -1840,7 +1840,7 @@ var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () {
and whitespace nodes.
2. Convert inline tags into our preferred format.
*/
var cleanTree = function cleanTree ( node ) {
var cleanTree = function cleanTree ( node, preserveWS ) {
var children = node.childNodes,
nonInlineParent, i, l, child, nodeName, nodeType, rewriter, childLength,
startsWithWS, endsWithWS, data, sibling;
@ -1872,14 +1872,14 @@ var cleanTree = function cleanTree ( node ) {
continue;
}
if ( childLength ) {
cleanTree( child );
cleanTree( child, preserveWS || ( nodeName === 'PRE' ) );
}
} else {
if ( nodeType === TEXT_NODE ) {
data = child.data;
startsWithWS = !notWS.test( data.charAt( 0 ) );
endsWithWS = !notWS.test( data.charAt( data.length - 1 ) );
if ( !startsWithWS && !endsWithWS ) {
if ( preserveWS || ( !startsWithWS && !endsWithWS ) ) {
continue;
}
// Iterate through the nodes; if we hit some other content
@ -1898,9 +1898,7 @@ var cleanTree = function cleanTree ( node ) {
break;
}
}
if ( !sibling ) {
data = data.replace( /^\s+/g, '' );
}
data = data.replace( /^\s+/g, sibling ? ' ' : '' );
}
if ( endsWithWS ) {
walker.currentNode = child;
@ -1915,9 +1913,7 @@ var cleanTree = function cleanTree ( node ) {
break;
}
}
if ( !sibling ) {
data = data.replace( /^\s+/g, '' );
}
data = data.replace( /\s+$/g, sibling ? ' ' : '' );
}
if ( data ) {
child.data = data;

File diff suppressed because one or more lines are too long

View file

@ -178,7 +178,7 @@ var walker = new TreeWalker( null, SHOW_TEXT|SHOW_ELEMENT, function () {
and whitespace nodes.
2. Convert inline tags into our preferred format.
*/
var cleanTree = function cleanTree ( node ) {
var cleanTree = function cleanTree ( node, preserveWS ) {
var children = node.childNodes,
nonInlineParent, i, l, child, nodeName, nodeType, rewriter, childLength,
startsWithWS, endsWithWS, data, sibling;
@ -210,14 +210,14 @@ var cleanTree = function cleanTree ( node ) {
continue;
}
if ( childLength ) {
cleanTree( child );
cleanTree( child, preserveWS || ( nodeName === 'PRE' ) );
}
} else {
if ( nodeType === TEXT_NODE ) {
data = child.data;
startsWithWS = !notWS.test( data.charAt( 0 ) );
endsWithWS = !notWS.test( data.charAt( data.length - 1 ) );
if ( !startsWithWS && !endsWithWS ) {
if ( preserveWS || ( !startsWithWS && !endsWithWS ) ) {
continue;
}
// Iterate through the nodes; if we hit some other content
@ -236,9 +236,7 @@ var cleanTree = function cleanTree ( node ) {
break;
}
}
if ( !sibling ) {
data = data.replace( /^\s+/g, '' );
}
data = data.replace( /^\s+/g, sibling ? ' ' : '' );
}
if ( endsWithWS ) {
walker.currentNode = child;
@ -253,9 +251,7 @@ var cleanTree = function cleanTree ( node ) {
break;
}
}
if ( !sibling ) {
data = data.replace( /^\s+/g, '' );
}
data = data.replace( /\s+$/g, sibling ? ' ' : '' );
}
if ( data ) {
child.data = data;