Improved formatting of nested lists
authorAlexander Ebert <ebert@woltlab.com>
Sat, 28 Oct 2017 13:49:03 +0000 (15:49 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 28 Oct 2017 13:49:03 +0000 (15:49 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js

index 9c750e2ddd119ccfda24665eb8a10899d566a6f4..bfbe6b51dcb99db9308b3f5de926779b06e994ea 100644 (file)
@@ -153,12 +153,15 @@ $.Redactor.prototype.WoltLabSource = function() {
                        // lists have additional whitespace inside
                        html = html.replace(new RegExp('<(ol|ul)(' + patternTagAttributes + ')>\\s*', 'g'), '<$1$2>\n');
                        
+                       // closing lists may have an adjacent closing list item, causing a depth mismatch
+                       html = html.replace(/(<\/[ou]l>)<\/li>/g, '$1\n</li>');
+                       
                        // split by line break
                        var parts = html.split(/\n/);
                        var depth = 0;
                        var i, length, line;
                        var reIsBlockStart = new RegExp('^<(' + blockTags + ')');
-                       var reIsBlockEnd = new RegExp('^</(?:' + blockTags + ')>$');
+                       var reIsBlockEnd = new RegExp('^</(' + blockTags + ')>$');
                        var increaseDepth = false;
                        for (i = 0, length = parts.length; i < length; i++) {
                                line = parts[i];
@@ -170,7 +173,9 @@ $.Redactor.prototype.WoltLabSource = function() {
                                        }
                                }
                                else if (line.match(reIsBlockEnd)) {
-                                       depth--;
+                                       if (blocksAsInline.indexOf(RegExp.$1) === -1) {
+                                               depth--;
+                                       }
                                }
                                
                                if (depth > 0) {