🐛 Koenig - Fixed rich-text captions sometimes losing spaces
refs https://github.com/TryGhost/Ghost/issues/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> </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
This commit is contained in:
parent
46129aca55
commit
c345019b92
|
@ -19,8 +19,14 @@ export function cleanBasicHtml(html = '') {
|
||||||
|
|
||||||
doc.body.querySelectorAll('*').forEach((element) => {
|
doc.body.querySelectorAll('*').forEach((element) => {
|
||||||
if (!element.textContent.trim()) {
|
if (!element.textContent.trim()) {
|
||||||
|
if (element.textContent.length > 0) {
|
||||||
|
// keep a single space to avoid collapsing spaces
|
||||||
|
let space = document.createTextNode(' ');
|
||||||
|
element.replaceWith(space);
|
||||||
|
} else {
|
||||||
element.remove();
|
element.remove();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cleanHtml = doc.body.innerHTML;
|
cleanHtml = doc.body.innerHTML;
|
||||||
|
|
Loading…
Reference in New Issue