var is_short = empty ? Roo.htmleditor.TidyWriter.shortend_elements.indexOf(name) > -1 : false;
- var e_inline = name == 'BR' ? false : this.in_inline;
- var indentstr = e_inline || this.in_pre ? '' : this.indentstr;
+ var add_lb = name == 'BR' ? false : in_inline;
+
+ if (!add_lb && !this.in_pre && this.lastElementEndsWS()) {
+ i_inline = false;
+ }
+
+ var indentstr = this.indentstr;
// e_inline = elements that can be inline, but still allow \n before and after?
// only 'BR' ??? any others?
-
- // 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());
},
+
+ 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>.
*
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 = text.replace(/^\s+/g,'');
+ }
+
+ }
this.html[this.html.length] = text;
return;
}