🐛 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>&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
This commit is contained in:
Kevin Ansfield 2018-08-13 10:37:45 +01:00
parent 61ad09cbc4
commit e082d40d56

View File

@ -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();
}
}
});