Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit c345019

Browse files
committed
šŸ› Koenig - Fixed rich-text captions sometimes losing spaces
refs TryGhost/Ghost#9724 - `clean-basic-html` was being overzealous with it's empty element removal, often contenteditable (especially when pasting) will result in HTML such as `<span>&nbsp;</span>` which was being completely removed - if an empty element has any spaces in it, replace the element with a textNode containing a single space
1 parent 46129ac commit c345019

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ā€Žlib/koenig-editor/addon/helpers/clean-basic-html.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export function cleanBasicHtml(html = '') {
1919

2020
doc.body.querySelectorAll('*').forEach((element) => {
2121
if (!element.textContent.trim()) {
22-
element.remove();
22+
if (element.textContent.length > 0) {
23+
// keep a single space to avoid collapsing spaces
24+
let space = document.createTextNode(' ');
25+
element.replaceWith(space);
26+
} else {
27+
element.remove();
28+
}
2329
}
2430
});
2531

0 commit comments

Comments
Ā (0)