Roo/htmleditor/TidyWriter.js
[roojs1] / Roo / htmleditor / TidyWriter.js
index f4c8c9b..4d23dcd 100644 (file)
@@ -93,7 +93,6 @@ Roo.htmleditor.TidyWriter.prototype = {
                     this.addLine();
                 } else{
                     // otherwise - no new line. (and dont indent.)
-                    
                     indentstr = '';
                 }
                 
@@ -147,7 +146,7 @@ Roo.htmleditor.TidyWriter.prototype = {
         
         
         this.pushState({
-            indentstr : in_pre || in_inline ? '' : (this.indentstr + this.indent),
+            indentstr : in_pre   ? '' : (this.indentstr + this.indent),
             in_pre : in_pre,
             in_inline :  in_inline
         });
@@ -210,6 +209,34 @@ 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,'');
+                }
+                // repace long lines
+                text = this.indentstr + text.replace(
+                    /(?![^\n]{1,64}$)([^\n]{1,64})\s/g, '$1\n' + this.indentstr
+                );
+                // remoeve the last whitespace / line break.
+                text = text.replace(/\s+$/,''); 
+                
+                
+                
+            }
             this.html[this.html.length] =  text;
             return;   
         }