From 54944b2d07be03a99e94f12d2630abd43b1a8f04 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 5 Dec 2017 11:53:57 +0100 Subject: [PATCH] Improved handling of empty `
` blocks

---
 .../files/js/3rdParty/redactor2/plugins/WoltLabClean.js    | 7 +++++++
 .../files/js/3rdParty/redactor2/plugins/WoltLabSource.js   | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js
index 044a18d734..2830384941 100644
--- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js
+++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js
@@ -42,6 +42,13 @@ $.Redactor.prototype.WoltLabClean = function() {
 					}
 				});
 				
+				// enforce at least a single whitespace inside certain block elements
+				elBySelAll('pre, woltlab-quote, woltlab-spoiler', div, function (element) {
+					if (element.childElementCount === 0 && (element.textContent.length === 0 || element.textContent.match(/^\r?\n$/))) {
+						element.textContent = '\u200B';
+					}
+				});
+				
 				html = div.innerHTML;
 				
 				return html;
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js
index bfbe6b51dc..0b38ce076f 100644
--- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js
+++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js
@@ -67,6 +67,7 @@ $.Redactor.prototype.WoltLabSource = function() {
 				// use jQuery to parse, its parser is much more graceful
 				var div = $('
').html(this.source.$textarea.val()); stripIcons(div[0]); + this.source.$textarea.val(div[0].innerHTML); mpHide.call(this); @@ -198,6 +199,9 @@ $.Redactor.prototype.WoltLabSource = function() { html = html.replace('@@@WCF_PRE_BACKUP_' + i + '@@@', backup[i]); } + // remove the trailing newline in front of
+			html = html.replace(/\r?\n<\/pre>/g, '
'); + return html.trim(); } }; -- 2.20.1