Fixed handling of lists inside quotes
authorAlexander Ebert <ebert@woltlab.com>
Mon, 4 Apr 2016 11:23:36 +0000 (13:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 4 Apr 2016 11:23:41 +0000 (13:23 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index fe6091189b68926d2dbf549b0239bfee9342a1b2..fc68b1fbe331666f88a017285085101bf836607b 100644 (file)
@@ -1315,6 +1315,19 @@ RedactorPlugins.wbbcode = function() {
                                                var $tmp = '';
                                                
                                                if (innerContent.length) {
+                                                       // remove lists to prevent them being handled by the code above
+                                                       var $cachedLists = [];
+                                                       innerContent = innerContent.replace(/(<(ol|ul)[^>]*>[\s\S]+?<\/\2>)/g, function(match) {
+                                                               var $hash = WCF.getUUID();
+                                                               
+                                                               $cachedLists.push({
+                                                                       hash: $hash,
+                                                                       content: match
+                                                               });
+                                                               
+                                                               return '@@' + $hash + '@@';
+                                                       });
+                                                       
                                                        var $lines = innerContent.split('\n');
                                                        for (var $i = 0; $i < $lines.length; $i++) {
                                                                var $line = $lines[$i];
@@ -1331,6 +1344,20 @@ RedactorPlugins.wbbcode = function() {
                                                                
                                                                $tmp += '<div>' + $line + '</div>';
                                                        }
+                                                       
+                                                       // reinsert lists
+                                                       if ($cachedLists.length) {
+                                                               for (var $i = 0, $length = $cachedLists.length; $i < $length; $i++) {
+                                                                       var $content = $cachedLists[$i].content;
+                                                                       
+                                                                       // line-breaks within list items must be a <br> instead of <p></p>
+                                                                       $content = $content.replace(/(<li>[\s\S]*?<\/li>)/g, function(match) {
+                                                                               return $.trim(match).replace(/\n/g, '<br>');
+                                                                       });
+                                                                       
+                                                                       $tmp = $tmp.replace(new RegExp('@@' + $cachedLists[$i].hash + '@@'), $content);
+                                                               }
+                                                       }
                                                }
                                                else {
                                                        $tmp = '<div>' + self.opts.invisibleSpace + '</div>';
@@ -1576,7 +1603,6 @@ RedactorPlugins.wbbcode = function() {
                        
                        // some fixes for paste from Microsoft Word / OpenOffice / LibreOffice
                        if (/<p class="MsoNormal/.test(html) || /margin-bottom: 0cm/.test(html)) {
-                               console.debug("hit");
                                // fix weird newlines
                                html = html.replace(/([^>\s])\n([^<\s])/g, '$1 $2');