Replace `<br>` inside dynamically converted code elements
authorAlexander Ebert <ebert@woltlab.com>
Mon, 4 Nov 2019 14:36:38 +0000 (15:36 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 4 Nov 2019 14:36:38 +0000 (15:36 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js

index ffa6ea6d5007f8155ab9aa7f3214cc9070a7e5aa..b1335864797815ed8537d6522da0a80aef4497e5 100644 (file)
@@ -96,6 +96,16 @@ $.Redactor.prototype.WoltLabBlock = function() {
                                
                                var replaced = mpFormatUncollapsed.call(this, tag, attr, value, type);
                                
+                               // Convert any `<br>` inside `<pre>` with a plain newline character.
+                               if (tag === 'pre') {
+                                       replaced.forEach(function(pre) {
+                                               elBySelAll('br', pre[0], function(br) {
+                                                       br.parentNode.insertBefore(document.createTextNode('\n'), br);
+                                                       elRemove(br);
+                                               });
+                                       });
+                               }
+                               
                                var block, firstBlock = null;
                                for (var i = 0, length = replaced.length; i < length; i++) {
                                        block = replaced[i][0];