From 15a5d39692f088f0225cb2d7e7930f540f422105 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 10 Jan 2022 14:59:52 +0100 Subject: [PATCH] Replace legacy HTML tags during paste See https://www.woltlab.com/community/thread/293870-artikel-beim-ersten-abspeichern-b-statt-strong/ --- .../js/3rdParty/redactor2/plugins/WoltLabPaste.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js index 79dc16c815..ddc29199ef 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js @@ -374,6 +374,20 @@ $.Redactor.prototype.WoltLabPaste = function() { parent.removeChild(br); }); }); + + // Convert legacy HTML tags into their consistent equivalent. + Object.keys(this.opts.replaceTags).forEach((tagName) => { + const newTagName = this.opts.replaceTags[tagName].toLowerCase(); + + div.querySelectorAll(tagName.toLowerCase()).forEach((legacyElement) => { + const newElement = document.createElement(newTagName); + while (legacyElement.childNodes.length > 0) { + newElement.appendChild(legacyElement.childNodes[0]); + } + legacyElement.insertAdjacentElement("beforebegin", newElement); + legacyElement.remove(); + }); + }); mpInsert.call(this, div.innerHTML, data); -- 2.20.1