From 831834f5dfa2321e659247f7cc88b1757c9826a9 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 19 Dec 2016 13:11:45 +0100 Subject: [PATCH] Fixed text alignment not preserved on paste --- .../redactor2/plugins/WoltLabClean.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js index 687ecbc4fb..26cf5ccc88 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js @@ -111,7 +111,7 @@ $.Redactor.prototype.WoltLabClean = function() { } var div = elCreate('div'); - div.innerHTML = html; + div.innerHTML = html.replace(/@@@WOLTLAB-P-ALIGN-(?:left|right|center|justify)@@@/g, ''); var element, elements = elBySelAll('[style]', div), property, removeStyles; for (var i = 0, length = elements.length; i < length; i++) { @@ -142,10 +142,15 @@ $.Redactor.prototype.WoltLabClean = function() { } }); - // Empty lines in Microsoft Word are represented with   - elBySelAll('p.MsoNormal', div, function (p) { - if (p.childElementCount === 1 && p.children[0].nodeName === 'O:P' && p.textContent === '\u00A0') { - p.innerHTML = '
'; + elBySelAll('p', div, function (p) { + if (p.classList.contains('MsoNormal')) { + // Empty lines in Microsoft Word are represented with   + if (p.childElementCount === 1 && p.children[0].nodeName === 'O:P' && p.textContent === '\u00A0') { + p.innerHTML = '
'; + } + } + else if (p.className.match(/\btext-(left|right|center|justify)\b/)) { + p.insertBefore(document.createTextNode('@@@WOLTLAB-P-ALIGN-' + RegExp.$1 + '@@@'), p.firstChild); } }); @@ -156,6 +161,13 @@ $.Redactor.prototype.WoltLabClean = function() { html = mpOnPaste.call(this, div.innerHTML, data, insert); html = html.replace(/@@@WOLTLAB-BR-MARKER@@@/g, ''); + html = html.replace(/(

)?\s*@@@WOLTLAB-P-ALIGN-(left|right|center|justify)@@@/g, function (match, p, alignment) { + if (p) { + return '

'; + } + + return ''; + }); div.innerHTML = html; -- 2.20.1