From b79d5fbbeac712b332f3c893311340a69a53c8d2 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 4 Dec 2016 16:23:26 +0100 Subject: [PATCH] Compressing HTML source in editor --- .../redactor2/plugins/WoltLabSource.js | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js index b829cf912d..1471a0c6f4 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js @@ -78,8 +78,16 @@ $.Redactor.prototype.WoltLabSource = function() { }, format: function (html) { - var blockTags = this.block.tags.join('|').toLowerCase(); - blockTags += '|ul|ol|li'; + var blockTags = ['ul', 'ol', 'li']; + this.block.tags.forEach(function(tag) { + blockTags.push(tag); + }); + + blockTags = blockTags.join('|').toLowerCase(); + + // block tags that are recognized as block tags, but both + // newline and indentation matches inline elements + var blocksAsInline = ['p', 'li']; var patternTagAttributes = '[^\'">]*(?:(?:"[^"]*"|\'[^\']*\')[^\'">]*)*'; @@ -92,8 +100,12 @@ $.Redactor.prototype.WoltLabSource = function() { }); // normalize whitespace before and after block tags - html = html.replace(new RegExp('\\s*\\s*', 'g'), '\n'); - html = html.replace(new RegExp('\\s*<(' + blockTags + ')(' + patternTagAttributes + ')>\\s*', 'g'), '\n<$1$2>\n'); + html = html.replace(new RegExp('\\s*\\s*', 'g'), function(match, tag) { + return (blocksAsInline.indexOf(tag) === -1 ? '\n' : '') + ''; + }); + html = html.replace(new RegExp('\\s*<(' + blockTags + ')(' + patternTagAttributes + ')>\\s*', 'g'), function(match, tag, attributes) { + return '\n<' + tag + attributes + '>' + (blocksAsInline.indexOf(tag) === -1 ? '\n' : ''); + }); // avoid empty newline at quote start html = html.replace(/]*)>\n\t*\n(\t*)

\n$2$'); var increaseDepth = false; for (i = 0, length = parts.length; i < length; i++) { @@ -113,7 +125,9 @@ $.Redactor.prototype.WoltLabSource = function() { increaseDepth = false; if (line.match(reIsBlockStart)) { - increaseDepth = true; + if (blocksAsInline.indexOf(RegExp.$1) === -1) { + increaseDepth = true; + } } else if (line.match(reIsBlockEnd)) { depth--; -- 2.20.1