This commit is contained in:
2026-01-17 02:23:10 +01:00
parent bb8d5475b8
commit 5f085a23a8

View File

@@ -33,17 +33,14 @@
const frag = document.createDocumentFragment(); const frag = document.createDocumentFragment();
if (addBreak) { if (addBreak) {
const prev = el.previousSibling; const prev = el.previousSibling;
const needsLeadBreak = !!(prev && (prev.nodeType === 3 ? prev.textContent.trim() : (prev.tagName && prev.tagName !== 'BR'))); const hasPrevContent = !!(prev && (prev.nodeType === 3 ? prev.textContent.trim() : (prev.tagName && prev.tagName !== 'BR')));
if (needsLeadBreak) { if (hasPrevContent) {
frag.appendChild(document.createElement('br')); frag.appendChild(document.createElement('br'));
} }
} }
while (el.firstChild) { while (el.firstChild) {
frag.appendChild(el.firstChild); frag.appendChild(el.firstChild);
} }
if (addBreak) {
frag.appendChild(document.createElement('br'));
}
el.replaceWith(frag); el.replaceWith(frag);
}; };