Fixed nested formating
authorAlexander Ebert <ebert@woltlab.com>
Mon, 19 Dec 2016 12:53:01 +0000 (13:53 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 19 Dec 2016 12:53:01 +0000 (13:53 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 26cf5ccc883b0cae9754a36c025efa6760328d1d..8747166532cff912e13925a79b8588b1b2993547 100644 (file)
@@ -152,6 +152,10 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        else if (p.className.match(/\btext-(left|right|center|justify)\b/)) {
                                                p.insertBefore(document.createTextNode('@@@WOLTLAB-P-ALIGN-' + RegExp.$1 + '@@@'), p.firstChild);
                                        }
+                                       
+                                       // discard classes and styles, they're stripped later on anyway
+                                       p.className = '';
+                                       p.removeAttribute('style');
                                });
                                
                                elBySelAll('br', div, function (br) {
@@ -237,7 +241,17 @@ $.Redactor.prototype.WoltLabClean = function() {
                                });
                                
                                storage.forEach(function (item, i) {
-                                       item.element.outerHTML = '###custom' + i + '###' + item.element.innerHTML + '###/custom' + i + '###';
+                                       var element = item.element;
+                                       var parent = element.parentNode;
+                                       
+                                       parent.insertBefore(document.createTextNode('###custom' + i + '###'), element);
+                                       parent.insertBefore(document.createTextNode('###/custom' + i + '###'), element.nextSibling);
+                                       
+                                       while (element.childNodes.length) {
+                                               parent.insertBefore(element.childNodes[0], element);
+                                       }
+                                       
+                                       parent.removeChild(element);
                                });
                                
                                var hadLinks = false;