Roo/htmleditor/TidyWriter.js
[roojs1] / Roo / htmleditor / TidyWriter.js
index 3fe22f8..4105267 100644 (file)
@@ -42,7 +42,7 @@ Roo.htmleditor.TidyWriter.prototype = {
     indentstr : '',
     in_pre: false,
     in_inline : false,
-    
+    last_inline : false,
     encode : false,
      
     
@@ -139,13 +139,15 @@ Roo.htmleditor.TidyWriter.prototype = {
     end: function(name) {
         var value;
         this.popState();
-        var indentstr = ''; 
-        if (!this.in_pre && !this.in_inline) {
+        var indentstr = '';
+        var in_inline = this.in_inline || Roo.htmleditor.TidyWriter.inline_elements.indexOf(name) > -1;
+        
+        if (!this.in_pre && !in_inline) {
             this.addLine();
             indentstr  = this.indentstr;
         }
         this.html.push(indentstr + '</', name.toLowerCase(), '>');
-       
+        this.last_inline = in_inline;
         
         // pop the indent state..
     },
@@ -159,7 +161,7 @@ Roo.htmleditor.TidyWriter.prototype = {
      * @param {String} text String to write out.
      * @param {Boolean} raw Optional raw state if true the contents wont get encoded.
      */
-    text: function(text )
+    text: function(text, node)
     {
         // if not in whitespace critical
         if (text.length < 1) {
@@ -167,12 +169,15 @@ Roo.htmleditor.TidyWriter.prototype = {
         }
         if (this.in_pre || this.in_inline) {
             this.html[this.html.length] =  text;
-            return;
-            
+            return;   
         }
         // see if last line is a line break
-        
-        this.addLine();
+        var indentstr = this.indentstr;
+        if (node.previousSibling && node.previousSibling.nodeType == 1 && Roo.htmleditor.TidyWriter.inline_elements.indexOf(node.previousSibling.nodeName) > -1) {
+            indentstr = '';
+        } else {
+            this.addLine();
+        }
             
         
         
@@ -184,7 +189,7 @@ Roo.htmleditor.TidyWriter.prototype = {
             return;
         }
         if (!text.match(/\n/)) {
-            this.html.push(this.indentstr + text);
+            this.html.push(indentstr + text);
             return;
         }