From d273c3c42753d639705b38b239d7e558dbd37ed7 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 20 Oct 2016 13:11:44 +0200 Subject: [PATCH] Improved pasting --- .../redactor2/plugins/WoltLabClean.js | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js index 38346dcc00..6d30544dad 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js @@ -133,7 +133,41 @@ $.Redactor.prototype.WoltLabClean = function() { } }); - return mpOnPaste.call(this, div.innerHTML, data, insert); + elBySelAll('br', div, function (br) { + br.parentNode.insertBefore(document.createTextNode('@@@WOLTLAB-BR-MARKER@@@'), br); + }); + + html = mpOnPaste.call(this, div.innerHTML, data, insert); + + html = html.replace(/@@@WOLTLAB-BR-MARKER@@@/g, ''); + + div.innerHTML = html; + + elBySelAll('woltlab-br-marker', div, function (marker) { + var parent = marker.parentNode; + + if (parent.nodeName === 'P') { + var p = elCreate('p'); + while (marker.nextSibling) { + p.appendChild(marker.nextSibling); + } + p.appendChild(elCreate('br')); + + parent.parentNode.insertBefore(p, parent.nextSibling); + + var previous = marker.previousElementSibling; + if (previous && previous.nodeName === 'BR') { + elRemove(previous); + } + } + else { + parent.insertBefore(elCreate('br'), marker); + } + + elRemove(marker); + }); + + return div.innerHTML; }).bind(this); var storage = []; -- 2.20.1