Improved handling of [tt]...[/tt]
authorAlexander Ebert <ebert@woltlab.com>
Tue, 17 Mar 2015 08:51:11 +0000 (09:51 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 17 Mar 2015 08:51:11 +0000 (09:51 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js

index 23ea557727bd766cad06294aa78f555b5f7b32ec..13f13033d1baea25803122b54abc79079f40d071 100644 (file)
@@ -1303,7 +1303,35 @@ RedactorPlugins.wbbcode = function() {
                                        var $value = $cachedCode.value;
                                        
                                        // [tt]
-                                       //$value = $value.replace(/^\[tt\](.*)\[\/tt\]/, '<span class="inlineCode">$1</span>');
+                                       $value = $value.replace(/^\[tt\]([\s\S]+)\[\/tt\]/, (function(match, content) {
+                                               var $tmp = content.split("\n");
+                                               content = '';
+                                               
+                                               for (var $i = 0, $length = $tmp.length; $i < $length; $i++) {
+                                                       var $line = $tmp[$i];
+                                                       
+                                                       if ($line.length) {
+                                                               if (content.length) content += '</p><p>';
+                                                               
+                                                               content += '[tt]' + $line + '[/tt]';
+                                                       }
+                                                       else {
+                                                               if ($i === 0 || ($i + 1) === $length) {
+                                                                       // ignore the first and last empty element
+                                                                       continue;
+                                                               }
+                                                               
+                                                               if (content.match(/\[\/tt\]$/)) {
+                                                                       content += '</p><p>' + this.opts.invisibleSpace + '';
+                                                               }
+                                                               else {
+                                                                       content += '</p><p><br>';
+                                                               }
+                                                       }
+                                               }
+                                               
+                                               return content;
+                                       }).bind(this));
                                        
                                        // [code]
                                        $value = $value.replace(/^\[code([^\]]*)\]([\S\s]*)\[\/code\]$/, (function(matches, parameters, content) {
index 2485356f5e73b93e2c20f761ab36fb10025027d6..7ea3d5e51191dbd072cb5d40e9f70da2805d8891 100644 (file)
@@ -161,6 +161,7 @@ RedactorPlugins.wbutton = function() {
                        
                        if ($eventData.cancel === false) {
                                var $selectedHtml = this.selection.getHtml();
+                               $selectedHtml = $selectedHtml.replace(/<p>@@@wcf_empty_line@@@<\/p>/g, '<p><br></p>');
                                
                                // TODO: this behaves pretty weird at this time, fix or remove
                                if (false && $bbcode === 'tt') {