Roo/htmleditor/TidyWriter.js
[roojs1] / Roo / htmleditor / TidyWriter.js
index 575efdc..f4c8c9b 100644 (file)
@@ -72,17 +72,36 @@ Roo.htmleditor.TidyWriter.prototype = {
         
         var is_short   = empty ? Roo.htmleditor.TidyWriter.shortend_elements.indexOf(name) > -1 : false;
         
-        var i_inline = name == 'BR' ? false : in_inline;
+        var add_lb = name == 'BR' ? false : in_inline;
+        
+        if (!add_lb && !this.in_pre && this.lastElementEndsWS()) {
+            i_inline = false;
+        }
 
-        var indentstr = in_inli_inlineine || this.in_pre ? '' : this.indentstr;
+        var indentstr =  this.indentstr;
         
         // 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;
         
-        // if this element is inline - then don't add stuff beforehand..
-        if (!e_inline && !this.in_pre) {
-            this.addLine();
+        // ADD LINE BEFORE tage
+        if (!this.in_pre) {
+            if (in_inline) {
+                //code
+                if (name == 'BR') {
+                    this.addLine();
+                } else if (this.lastElementEndsWS()) {
+                    this.addLine();
+                } else{
+                    // otherwise - no new line. (and dont indent.)
+                    
+                    indentstr = '';
+                }
+                
+            } else {
+                this.addLine();
+            }
+        } else {
+            indentstr = '';
         }
         
         this.html.push(indentstr + '<', name.toLowerCase());
@@ -142,6 +161,17 @@ Roo.htmleditor.TidyWriter.prototype = {
          
         
     },
+    
+    lastElementEndsWS : function()
+    {
+        var value = this.html.length > 0 ? this.html[this.html.length-1] : false;
+        if (value === false) {
+            return true;
+        }
+        return value.match(/\s+$/);
+        
+    },
+    
     /**
      * Writes the a end element such as </p>.
      *