X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2Fhtmleditor%2FTidyWriter.js;h=575efdc3625914d4347b2bc132345cbfe46345bc;hb=b85f624217edf58108ae121a01b6d0e9a7d613b5;hp=bfcb7cfb2a28ffc144b204fa3c73d04e540eaca7;hpb=f1dad0a9a5e162577fad08e7358f988fd6f5a2d2;p=roojs1 diff --git a/Roo/htmleditor/TidyWriter.js b/Roo/htmleditor/TidyWriter.js index bfcb7cfb2a..575efdc362 100644 --- a/Roo/htmleditor/TidyWriter.js +++ b/Roo/htmleditor/TidyWriter.js @@ -2,6 +2,12 @@ * This is based loosely on tinymce * @class Roo.htmleditor.TidyWriter * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js + * + * Known issues? + * - not tested much with 'PRE' formated elements. + * - long text inside of inline can be wrapped and clened? + * + * */ Roo.htmleditor.TidyWriter = function(settings) @@ -42,7 +48,7 @@ Roo.htmleditor.TidyWriter.prototype = { indentstr : '', in_pre: false, in_inline : false, - + last_inline : false, encode : false, @@ -66,10 +72,16 @@ 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 indentstr = this.in_inline || this.in_pre ? '' : this.indentstr; + var indentstr = in_inli_inlineine || this.in_pre ? '' : 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 (!in_inline && !this.in_pre) { + // if this element is inline - then don't add stuff beforehand.. + if (!e_inline && !this.in_pre) { this.addLine(); } @@ -88,8 +100,9 @@ Roo.htmleditor.TidyWriter.prototype = { } else { this.html[this.html.length] = '>'; } + var e_inline = name == 'BR' ? false : this.in_inline; - if (!this.in_inline && !this.in_pre) { + if (!e_inline && !this.in_pre) { this.addLine(); } return; @@ -138,13 +151,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 + ''); - + this.last_inline = in_inline; // pop the indent state.. }, @@ -158,20 +173,26 @@ 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) { return; } - if (this.in_pre || this.is_inline) { + if (this.in_pre || this.in_inline) { this.html[this.html.length] = text; - return; - + return; + } + // see if last element was a inline element. + 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(); } - // see if last line is a line break - - this.addLine(); @@ -183,7 +204,7 @@ Roo.htmleditor.TidyWriter.prototype = { return; } if (!text.match(/\n/)) { - this.html.push(this.indentstr + text); + this.html.push(indentstr + text); return; }