From: Alexander Ebert Date: Fri, 4 Aug 2023 10:23:43 +0000 (+0200) Subject: Normalize HTML before inserting it into CKEditor X-Git-Tag: 6.0.0_Alpha_8~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=be579c61302712c056fe62d7a7662ea5f6b2f99e;p=GitHub%2FWoltLab%2FWCF.git Normalize HTML before inserting it into CKEditor Fixes https://www.woltlab.com/community/thread/300657-quoting-pre-6-0-posts-does-not-normalize-the-old-paragraph-behavior/ --- diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor.ts b/ts/WoltLabSuite/Core/Component/Ckeditor.ts index 54dbf90a61..c8eb2853db 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor.ts @@ -21,7 +21,7 @@ import { deleteDraft, initializeAutosave, setupRestoreDraft } from "./Ckeditor/A import { createConfigurationFor, Features } from "./Ckeditor/Configuration"; import { dispatchToCkeditor } from "./Ckeditor/Event"; import { setup as setupSubmitOnEnter } from "./Ckeditor/SubmitOnEnter"; -import { normalizeLegacyMessage } from "./Ckeditor/Normalizer"; +import { normalizeLegacyHtml, normalizeLegacyMessage } from "./Ckeditor/Normalizer"; import { element as scrollToElement } from "../Ui/Scroll"; import Devtools from "../Devtools"; import { ClassicEditor, CodeBlockConfig, EditorConfig, Element as CkeElement } from "./Ckeditor/Types"; @@ -78,6 +78,8 @@ class Ckeditor { } insertHtml(html: string): void { + html = normalizeLegacyHtml(html); + this.#editor.model.change((writer) => { const viewFragment = this.#editor.data.processor.toView(html); const modelFragment = this.#editor.data.toModel(viewFragment); diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts index 0ad32f1db0..6bb2cfc914 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts @@ -151,18 +151,22 @@ function imageToFigure(img: HTMLImageElement, alignmentClass: string): void { } } -export function normalizeLegacyMessage(element: HTMLElement): void { - if (!(element instanceof HTMLTextAreaElement)) { - throw new TypeError("Expected the element to be a