mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05: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
1 changed files with 7 additions and 1 deletions
|
@ -19,8 +19,14 @@ export function cleanBasicHtml(html = '') {
|
|||
|
||||
doc.body.querySelectorAll('*').forEach((element) => {
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cleanHtml = doc.body.innerHTML;
|
||||
|
|
Loading…
Add table
Reference in a new issue