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

Rewrite all <br>s in cleanupBRs fn.

Previously, we were just removing <br>s that didn't have siblings on both sides. A better test is whether the containing block has any non-whitespace text content. If it does, the <br> is a line break and we can just split the block. If it doesn't though, we need to leave the <br> as a placeholder, to ensure the block doesn't collapse to 0 height.
This commit is contained in:
Neil Jenkins 2013-02-22 15:07:25 +11:00
parent ac14985583
commit 0ba91e627d
2 changed files with 17 additions and 17 deletions

File diff suppressed because one or more lines are too long

View file

@ -1217,24 +1217,24 @@
// Cleanup may have removed it
block = br.parentNode;
if ( !block ) { continue; }
if ( br.nextSibling && br.previousSibling ) {
while ( block.isInline() ) {
block = block.parentNode;
}
// If this is not inside a block, replace it by wrapping
// inlines in DIV.
if ( !block.isBlock() ) {
wrapTopLevelInline( block, 'DIV' );
}
// If in a block we can split, split it instead
else if ( tagAfterSplit[ block.nodeName ] ) {
splitBlock( block, br.parentNode, br );
br.detach();
}
// Otherwise leave the br alone.
} else {
while ( block.isInline() ) {
block = block.parentNode;
}
// If this is not inside a block, replace it by wrapping
// inlines in DIV.
if ( !block.isBlock() ) {
wrapTopLevelInline( block, 'DIV' );
}
// If in a block we can split, split it instead, but only if there
// is actual text content in the block. Otherwise, the <br> is a
// placeholder to stop the block from collapsing, so we must leave
// it.
else if ( tagAfterSplit[ block.nodeName ] &&
/\S/.test( block.textContent ) ) {
splitBlock( block, br.parentNode, br );
br.detach();
}
// Otherwise leave the br alone.
}
};