Improved pasting of content during WYSIWYG mode
authorAlexander Ebert <ebert@woltlab.com>
Tue, 23 Dec 2014 19:58:54 +0000 (20:58 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 23 Dec 2014 19:58:54 +0000 (20:58 +0100)
This of course fails if a page has a completely messed up markup e.g. Spiegel Online, but I cannot fix the view for them without messing up the other. The current approach deals best with the average content encountered, if it encounters messy markup it follows the simple rule: Garbage in, Garbage out.

wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 412098ec9465b3c2a65f0cc7e6a04567dd4c194a..edf53ac67d553c51634e0a81689ccf98569a73bf 100644 (file)
@@ -1125,7 +1125,7 @@ RedactorPlugins.wbbcode = function() {
                        // replace nested elements e.g. <div><p>...</p></div>
                        html = html.replace(/<(div|p)([^>]+)?><(div|p)([^>]+)?>/g, '<p>');
                        html = html.replace(/<\/(div|p)><\/(div|p)>/g, '</p>');
-                       html = html.replace(/<(div|p)><br><\/(div|p)>/g, '<p>');
+                       //html = html.replace(/<(div|p)><br><\/(div|p)>/g, '<p>');
                        
                        WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'beforePaste', { html: html });
                        
@@ -1140,7 +1140,7 @@ RedactorPlugins.wbbcode = function() {
                 */
                _pasteCallback: function(html) {
                        // reduce successive <br> by one
-                       html = html.replace(/<br[^>]*>(<br[^>]*>)+/g, '$1');
+                       //html = html.replace(/<br[^>]*>(<br[^>]*>)+/g, '$1');
                        
                        // replace <p>...</p> with <p>...</p><p><br></p>
                        /*html = html.replace(/<p>([\s\S]*?)<\/p>/g, function(match, content) {
index fafd67b5d4e5c2abcb1a7ad607f0f0fa97b1e4c8..110bee2f5e6cca8ae71b56c3257c47158cf52115 100644 (file)
@@ -242,6 +242,11 @@ RedactorPlugins.wmonkeypatch = function() {
                                return $restoreSpecialCharacters(html);
                        }).bind(this);
                        
+                       // clean.onPasteRemoveEmpty
+                       this.clean.onPasteRemoveEmpty = function(html) {
+                               return html.replace(/<br\s?\/?>$/i, '');
+                       };
+                       
                        // clean.onSet
                        var $mpOnSet = this.clean.onSet;
                        this.clean.onSet = (function(html) {