From 34522a8d14cab8d27c73c357cecbaf295cdc3b7d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 23 Feb 2022 19:41:21 +0100 Subject: [PATCH] Improved the detection of pasted redundant styles --- .../redactor2/plugins/WoltLabClean.js | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js index 3bc6ebb64b..a25cc56877 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js @@ -708,11 +708,29 @@ $.Redactor.prototype.WoltLabClean = function() { // Search for span[style] that contain styles that actually do nothing, because their set style // equals the inherited style from its ancestors. - elBySelAll('span[style]', this.$editor[0], function(element) { - ['color', 'font-family', 'font-size'].forEach(function(propertyName) { + const normalizeFontFamily = (value) => value.toLowerCase().replace(/['" ]/g, ''); + + const propertyNames = ["color", "font-family", "font-size"]; + this.$editor[0].querySelectorAll("span[style]").forEach((element) => { + if (element.getAttribute("style").trim() === "") { + removeElements.push(element); + return; + } + + propertyNames.forEach((propertyName) => { var value = element.style.getPropertyValue(propertyName); if (value) { - if (window.getComputedStyle(element.parentNode).getPropertyValue(propertyName) === value) { + let parentStyle = window.getComputedStyle(element.parentNode).getPropertyValue(propertyName); + + // The browser handling of font families with quotes is highly inconsistent + // and causes frequent mismatches. Normalizing these values should improve + // the recognition of redundant styling. + if (propertyName === "font-family") { + parentStyle = normalizeFontFamily(parentStyle); + value = normalizeFontFamily(value); + } + + if (parentStyle === value) { removeElements.push(element); } } -- 2.20.1