mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03:00
🐛 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
61ad09cbc4
commit
e082d40d56
@ -19,7 +19,13 @@ export function cleanBasicHtml(html = '') {
|
||||
|
||||
doc.body.querySelectorAll('*').forEach((element) => {
|
||||
if (!element.textContent.trim()) {
|
||||
element.remove();
|
||||
if (element.textContent.length > 0) {
|
||||
// keep a single space to avoid collapsing spaces
|
||||
let space = document.createTextNode(' ');
|
||||
element.replaceWith(space);
|
||||
} else {
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user