From: Alexander Ebert Date: Wed, 10 May 2023 13:43:18 +0000 (+0200) Subject: Convert floating images in CKEditor into `
` X-Git-Tag: 6.0.0_Alpha_1~115 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7fe18d91a7c1361d9e20d518e526308e48cb3582;p=GitHub%2FWoltLab%2FWCF.git Convert floating images in CKEditor into `
` See WoltLab/editor#51 --- diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts index 9b6447c646..7b576552a4 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts @@ -123,6 +123,27 @@ function reduceSpacerParagraphs(paragraphs: HTMLParagraphElement[]): void { } } +function convertFloatingImages(div: HTMLElement): void { + div.querySelectorAll("img").forEach((img) => { + if (img.classList.contains("messageFloatObjectRight")) { + const paragraph = img.closest("p"); + if (paragraph === null) { + return; + } + + const figure = document.createElement("figure"); + figure.classList.add("image", "image-style-side"); + figure.append(img); + + paragraph.insertAdjacentElement("beforebegin", figure); + + if (paragraph.innerHTML === "") { + paragraph.remove(); + } + } + }); +} + export function normalizeLegacyMessage(element: HTMLElement): void { if (!(element instanceof HTMLTextAreaElement)) { throw new TypeError("Expected the element to be a