Support tables in the code formatter
authorAlexander Ebert <ebert@woltlab.com>
Thu, 31 Jan 2019 11:14:30 +0000 (12:14 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 31 Jan 2019 11:14:30 +0000 (12:14 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js

index a56e5294fa86c4d1846a349d42200861a625c3bc..ac5ed4e824c51f2c2da7da17bd91bc6c17adebbc 100644 (file)
@@ -125,7 +125,7 @@ $.Redactor.prototype.WoltLabSource = function() {
                },
                
                format: function (html) {
-                       var blockTags = ['ul', 'ol', 'li'];
+                       var blockTags = ['ul', 'ol', 'li', 'table', 'tbody', 'thead', 'tr', 'td', 'th'];
                        this.block.tags.forEach(function(tag) {
                                blockTags.push(tag);
                        });
@@ -134,7 +134,7 @@ $.Redactor.prototype.WoltLabSource = function() {
                        
                        // block tags that are recognized as block tags, but both
                        // newline and indentation matches inline elements
-                       var blocksAsInline = ['p', 'li'];
+                       var blocksAsInline = ['p', 'li', 'td', 'th'];
                        
                        var patternTagAttributes = '[^\'">]*(?:(?:"[^"]*"|\'[^\']*\')[^\'">]*)*';
                        
@@ -154,6 +154,9 @@ $.Redactor.prototype.WoltLabSource = function() {
                                return '\n<' + tag + attributes + '>' + (blocksAsInline.indexOf(tag) === -1 ? '\n' : '');
                        });
                        
+                       // Remove empty lines between two adjacent block elements.
+                       html = html.replace(new RegExp('(<(?:' + blockTags + ')(?:' + patternTagAttributes + ')>\n)\n+(?=<(?:' + blockTags + ')(?:' + patternTagAttributes + ')>)', 'g'), '$1');
+                       
                        // avoid empty newline at quote start
                        html = html.replace(/<woltlab-quote([^>]*)>\n\t*\n(\t*)<p/, '<woltlab-quote$1>\n$2<p');