From d979d7689b391771f6ea6f8dff57a1a9a655f9ac Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 8 Jul 2015 11:11:42 +0200 Subject: [PATCH] Fixed handling of [align]-BBCode --- .../files/js/WoltLab/WCF/BBCode/FromHtml.js | 4 ++-- .../files/js/WoltLab/WCF/BBCode/ToHtml.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLab/WCF/BBCode/FromHtml.js b/wcfsetup/install/files/js/WoltLab/WCF/BBCode/FromHtml.js index 34c7ecbd94..9745f1862e 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/BBCode/FromHtml.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/BBCode/FromHtml.js @@ -466,8 +466,8 @@ define(['EventHandler', 'StringUtil', 'DOM/Traverse'], function(EventHandler, St * @param {Element} element target element */ _convertInlineTextAlign: function(element, value) { - if (value === 'left' || value === 'right' || value === 'justify') { - element.innerHTML = '[align=' + value + ']' + innerHTML + '[/align]'; + if (['center', 'justify', 'left', 'right'].indexOf(value) !== -1) { + element.innerHTML = '[align=' + value + ']' + element.innerHTML + '[/align]'; } }, diff --git a/wcfsetup/install/files/js/WoltLab/WCF/BBCode/ToHtml.js b/wcfsetup/install/files/js/WoltLab/WCF/BBCode/ToHtml.js index b77d9308bf..399d2eb5b4 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/BBCode/ToHtml.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/BBCode/ToHtml.js @@ -135,6 +135,7 @@ define(['Core', 'EventHandler', 'Language', 'StringUtil', 'WoltLab/WCF/BBCode/Pa tt: 'kbd', // callback replacement + align: this._convertAlignment.bind(this), attach: this._convertAttachment.bind(this), color: this._convertColor.bind(this), code: this._convertCode.bind(this), @@ -212,6 +213,23 @@ define(['Core', 'EventHandler', 'Language', 'StringUtil', 'WoltLab/WCF/BBCode/Pa } }, + /** + * Converts [align] into
. + * + * @param {array} stack linear list of BBCode tags and regular strings + * @param {object} item current BBCode tag object + * @param {integer} index current stack index representing `item` + * @returns {array} first item represents the opening tag, the second the closing one + */ + _convertAlignment: function(stack, item, index) { + var align = (item.attributes.length) ? item.attributes[0] : ''; + if (['center', 'justify', 'left', 'right'].indexOf(align) === -1) { + return [null, null]; + } + + return ['
', '
']; + }, + /** * Converts [attach] into an or to plain text if attachment is a non-image. * -- 2.20.1