textarea.style.setProperty('height', Math.ceil(height) + 'px', '');
textarea.style.setProperty('display', 'block', '');
+ textarea.value = this.WoltLabSource.format(textarea.value);
+
textarea.selectionStart = textarea.selectionEnd = textarea.value.length;
}).bind(this);
isActive: function () {
return (this.$editor[0].style.getPropertyValue('display') === 'none');
+ },
+
+ format: function (html) {
+ var blockTags = this.block.tags.join('|').toLowerCase();
+ blockTags += '|ul|ol|li';
+
+ html = html.replace(new RegExp('<(' + blockTags + ')([^>]*)>\s*', 'g'), '<$1$2>\n\t');
+ html = html.replace(new RegExp('\s*</(' + blockTags + ')>', 'g'), '\n</$1>');
+
+ html = html.replace(/\s*<li>/g, '\n<li>');
+ html = html.replace(/<\/li>\s*/g, '</li>\n');
+ html = html.replace(/<li>([\s\S]*?)<\/li>/g, function(match, content) {
+ var parts = content.trim().split('\n');
+ return '<li>\n\t' + parts.join('\n\t') + '\n</li>';
+ });
+
+ html = html.replace(/\s*<\/p>\s*/g, '\n</p>\n');
+ html = html.replace(/<p>\s*<br>\s*<\/p>/g, '<p><br></p>');
+
+ return html.replace(/^\s+/, '');
}
};
};