Improved handling of newlines in list items
authorAlexander Ebert <ebert@woltlab.com>
Tue, 16 Dec 2014 12:38:47 +0000 (13:38 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 16 Dec 2014 12:38:47 +0000 (13:38 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index aad1352697ca60f8be8785c0a0c4a7e144b3060e..2a5e4bf742c7c5f0fac045b1f54bfec11085dd6b 100644 (file)
@@ -874,6 +874,20 @@ RedactorPlugins.wbbcode = function() {
                        // drop trailing line breaks
                        data = data.replace(/\n*$/, '');
                        
+                       // line-breaks within list items must be a <br> instead of <p></p>
+                       var $listItems = [ ];
+                       data = data.replace(/(<li>[\s\S]*?<\/li>)/g, function(match) {
+                               match = $.trim(match).replace(/\n/, '<br>');
+                               
+                               var $key = WCF.getUUID();
+                               $listItems.push({
+                                       key: $key,
+                                       content: match
+                               });
+                               
+                               return $key;
+                       });
+                       
                        // convert line breaks into <p></p> or empty lines to <p><br></p>
                        var $tmp = data.split("\n");
                        
@@ -911,6 +925,13 @@ RedactorPlugins.wbbcode = function() {
                                }
                        }
                        
+                       // insert list items
+                       if ($listItems.length) {
+                               for (var $i = $listItems.length - 1; $i >= 0; $i--) {
+                                       data = data.replace($listItems[$i].key, $listItems[$i].content);
+                               }
+                       }
+                       
                        // insert quotes
                        if ($cachedQuotes.length) {
                                // [quote]