Roo/htmleditor/TidyWriter.js
[roojs1] / Roo / htmleditor / TidyWriter.js
index e2ccd4b..a42e6db 100644 (file)
@@ -82,19 +82,17 @@ Roo.htmleditor.TidyWriter.prototype = {
         
         // e_inline = elements that can be inline, but still allow \n before and after?
         // only 'BR' ??? any others?
-        var e_inline = name == 'BR' ? false : this.in_inline;
         
         // ADD LINE BEFORE tage
         if (!this.in_pre) {
             if (in_inline) {
                 //code
-                if (is_br) {
+                if (name == 'BR') {
                     this.addLine();
                 } else if (this.lastElementEndsWS()) {
                     this.addLine();
                 } else{
                     // otherwise - no new line. (and dont indent.)
-                    
                     indentstr = '';
                 }
                 
@@ -211,6 +209,26 @@ Roo.htmleditor.TidyWriter.prototype = {
             return;
         }
         if (this.in_pre || this.in_inline) {
+            
+            if (this.in_inline) {
+                text = text.replace(/\s/g,' ') // all line breaks to ' '
+                    .replace(/\s+/,' ')  // all white space to single white space
+                // if next tag is '<BR>', then we can trim right..
+                if (node.nextSibling &&
+                    node.nextSibling.nodeType == 1 &&
+                    node.nextSibling.nodeName == 'BR' )
+                {
+                    text = text.replace(/\s+$/g,'');
+                }
+                // if previous tag was a BR, we can also trim..
+                if (node.previousSibling &&
+                    node.previousSibling.nodeType == 1 &&
+                    node.previousSibling.nodeName == 'BR' )
+                {
+                    text = this.indentstr +  text.replace(/^\s+/g,'');
+                }
+                
+            }
             this.html[this.html.length] =  text;
             return;   
         }