Fixes https://www.woltlab.com/community/thread/300657-quoting-pre-6-0-posts-does-not-normalize-the-old-paragraph-behavior/
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";
}
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);
}
}
-export function normalizeLegacyMessage(element: HTMLElement): void {
- if (!(element instanceof HTMLTextAreaElement)) {
- throw new TypeError("Expected the element to be a <textarea>.");
- }
-
+export function normalizeLegacyHtml(html: string): string {
const div = document.createElement("div");
- div.innerHTML = element.value;
+ div.innerHTML = html;
normalizeBr(div);
const paragraphs = getPossibleSpacerParagraphs(div);
reduceSpacerParagraphs(paragraphs);
convertFloatingImages(div);
- element.value = div.innerHTML;
+ return div.innerHTML;
+}
+
+export function normalizeLegacyMessage(element: HTMLElement): void {
+ if (!(element instanceof HTMLTextAreaElement)) {
+ throw new TypeError("Expected the element to be a <textarea>.");
+ }
+
+ element.value = normalizeLegacyHtml(element.value);
}
return this.#editor.data.get();
}
insertHtml(html) {
+ html = (0, Normalizer_1.normalizeLegacyHtml)(html);
this.#editor.model.change((writer) => {
const viewFragment = this.#editor.data.processor.toView(html);
const modelFragment = this.#editor.data.toModel(viewFragment);
define(["require", "exports", "tslib", "../../Dom/Util"], function (require, exports, tslib_1, Util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
- exports.normalizeLegacyMessage = void 0;
+ exports.normalizeLegacyMessage = exports.normalizeLegacyHtml = void 0;
Util_1 = tslib_1.__importDefault(Util_1);
function normalizeBr(div) {
div.querySelectorAll("br").forEach((br) => {
paragraph.remove();
}
}
- function normalizeLegacyMessage(element) {
- if (!(element instanceof HTMLTextAreaElement)) {
- throw new TypeError("Expected the element to be a <textarea>.");
- }
+ function normalizeLegacyHtml(html) {
const div = document.createElement("div");
- div.innerHTML = element.value;
+ div.innerHTML = html;
normalizeBr(div);
const paragraphs = getPossibleSpacerParagraphs(div);
reduceSpacerParagraphs(paragraphs);
convertFloatingImages(div);
- element.value = div.innerHTML;
+ return div.innerHTML;
+ }
+ exports.normalizeLegacyHtml = normalizeLegacyHtml;
+ function normalizeLegacyMessage(element) {
+ if (!(element instanceof HTMLTextAreaElement)) {
+ throw new TypeError("Expected the element to be a <textarea>.");
+ }
+ element.value = normalizeLegacyHtml(element.value);
}
exports.normalizeLegacyMessage = normalizeLegacyMessage;
});