From: Alexander Ebert
Date: Tue, 27 Sep 2016 12:02:22 +0000 (+0200)
Subject: Added source formatting
X-Git-Tag: 3.0.0_Beta_2~104
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=12c322aa6bdd2f2f48af264c67f0fee912b49eb0;p=GitHub%2FWoltLab%2FWCF.git
Added source formatting
---
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js
index 1ef9e05462..4a091d419f 100644
--- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js
+++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js
@@ -31,6 +31,8 @@ $.Redactor.prototype.WoltLabSource = function() {
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);
@@ -44,6 +46,26 @@ $.Redactor.prototype.WoltLabSource = function() {
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*/g, '\n');
+ html = html.replace(/<\/li>\s*/g, '\n');
+ html = html.replace(/([\s\S]*?)<\/li>/g, function(match, content) {
+ var parts = content.trim().split('\n');
+ return '\n\t' + parts.join('\n\t') + '\n';
+ });
+
+ html = html.replace(/\s*<\/p>\s*/g, '\n
\n');
+ html = html.replace(/\s*
\s*<\/p>/g, '
');
+
+ return html.replace(/^\s+/, '');
}
};
};