Skip to content

Commit

Permalink
Don't keep stripping BR's
Browse files Browse the repository at this point in the history
  • Loading branch information
djmaze committed Oct 27, 2024
1 parent 66d9fa9 commit 7312d96
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions source/Clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,16 @@ const cleanupBRs = (
const brs: NodeListOf<HTMLBRElement> = node.querySelectorAll('BR:last-child');
let l = brs.length;
while (l--) {
const br = brs[l];
const br = brs[l], parent = br.parentElement;
// TODO: if there are more BR at the end of a block, it creates empty lines
// Example: <br></div> does nothing, <br><br></div> does create empty line
// const prev = br.previousSibling; // br.previousElementSibling;
// (prev && br.parentNode?.lastChild === br && prev.nodeName !== 'BR')
// If it doesn't break a line, just remove it; it's not doing
// anything useful. We'll add it back later if required by the
// browser.
if (!isLineBreak(br)) {
// if (!isLineBreak(br)) {
if (!br.nextSibling && 1 === parent.children.length && parent.textContent.trim().length) {
br.remove();
}
}
Expand Down

0 comments on commit 7312d96

Please sign in to comment.