Improved pasting of <p> formatted content
authorAlexander Ebert <ebert@woltlab.com>
Sun, 18 Jan 2015 14:08:03 +0000 (15:08 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 18 Jan 2015 14:08:03 +0000 (15:08 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index abb0e8b16437bd6023e69706c9062553b8658010..b92346a338c3800f48981f41275f3669fbe53f06 100644 (file)
@@ -1305,17 +1305,24 @@ RedactorPlugins.wbbcode = function() {
                 * @return      string
                 */
                _pasteCallback: function(html) {
-                       // reduce successive <br> by one
-                       //html = html.replace(/<br[^>]*>(<br[^>]*>)+/g, '$1');
+                       var $uuid = WCF.getUUID();
                        
-                       // replace <p>...</p> with <p>...</p><p><br></p>
-                       /*html = html.replace(/<p>([\s\S]*?)<\/p>/g, function(match, content) {
-                               if (content.match(/<br( \/)?>$/)) {
+                       // replace <p>...</p> with <p>...</p><p><br></p> unless there is already a newline
+                       html = html.replace(/<p>([\s\S]*?)<\/p>/gi, function(match, content) {
+                               if (content.match(/^<br( \/)?>$/)) {
                                        return match;
                                }
                                
-                               return '<p>' + content + '</p><p><br></p>';
-                       });*/
+                               return match + '@@@' + $uuid + '@@@';
+                       });
+                       
+                       html = html.replace(new RegExp('@@@' + $uuid + '@@@(<p><br(?: /)?></p>)?', 'g'), function(match, next) {
+                               if (next) {
+                                       return next;
+                               }
+                               
+                               return '<p><br></p>';
+                       });
                        
                        // restore font size
                        html = html.replace(/\[size=(\d+)\]/g, '<p><span style="font-size: $1pt">');