Fixed \u200B handling
authorAlexander Ebert <ebert@woltlab.com>
Thu, 6 Oct 2016 08:03:55 +0000 (10:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 6 Oct 2016 08:04:01 +0000 (10:04 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 4f287512bf181f581f13d03d343419dca8d484fd..c997ede8d2279a6053c9708e98465d5a9d1c5728 100644 (file)
@@ -33,20 +33,33 @@ $.Redactor.prototype.WoltLabClean = function() {
                        var mpOnSync = this.clean.onSync;
                        this.clean.onSync = (function (html) {
                                var div = elCreate('div');
+                               div.innerHTML = html;
                                var replacements = {};
                                
-                               if (html.indexOf('<pre') !== -1) {
-                                       div.innerHTML = html;
-                                       
-                                       elBySelAll('pre', div, function (pre) {
-                                               var uuid = WCF.getUUID();
-                                               
-                                               replacements[uuid] = pre.textContent;
-                                               pre.textContent = uuid;
-                                       });
+                               elBySelAll('pre', div, function (pre) {
+                                       var uuid = WCF.getUUID();
                                        
-                                       html = div.innerHTML;
-                               }
+                                       replacements[uuid] = pre.textContent;
+                                       pre.textContent = uuid;
+                               });
+                               
+                               // handle <p> with trailing `<br>\u200B`
+                               elBySelAll('p', div, function (p) {
+                                       var br = p.lastElementChild;
+                                       if (br && br.nodeName === 'BR') {
+                                               // check if there is only whitespace afterwards
+                                               if (br.nextSibling && br.nextSibling.textContent.match(/^[\s\u200B]+$/)) {
+                                                       var newP = elCreate('p');
+                                                       newP.innerHTML = '<br>';
+                                                       p.parentNode.insertBefore(newP, p.nextSibling);
+                                                       
+                                                       p.removeChild(br.nextSibling);
+                                                       p.removeChild(br);
+                                               }
+                                       }
+                               });
+                               
+                               html = div.innerHTML;
                                
                                html = html.replace(/<p>\u200B<\/p>/g, '<p><br></p>');