Fix/autofix empty div (#2066)

* Remove empty divs in rich text input

* Refactor inline content detection

* Fix formatting
This commit is contained in:
Henrik Giesel 2022-09-13 06:11:47 +02:00 committed by GitHub
parent 497b246b66
commit 892c9f6da8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,7 @@ function adjustInputHTML(html: string): string {
function adjustInputFragment(fragment: DocumentFragment): void {
if (nodeContainsInlineContent(fragment)) {
fragment.appendChild(document.createElement("br"));
fragment.append(document.createElement("br"));
}
}
@ -35,12 +35,16 @@ export function storedToFragment(storedHTML: string): DocumentFragment {
function adjustOutputFragment(fragment: DocumentFragment): void {
if (
fragment.hasChildNodes() &&
nodeIsElement(fragment.lastChild!) &&
nodeContainsInlineContent(fragment) &&
fragment.lastChild!.tagName === "BR"
fragment.lastChild &&
nodeIsElement(fragment.lastChild) &&
fragment.lastChild.tagName === "BR"
) {
fragment.lastChild!.remove();
fragment.lastChild.remove();
}
for (const divElement of fragment.querySelectorAll("div:empty")) {
divElement.remove();
}
}