3 * @class Roo.htmleditor.Tidy
5 * @cfg {Roo.HtmlEditorCore} core the editor.
8 * @param {Object} config Configuration options
12 Roo.htmleditor.Tidy = function(cfg) {
15 this.core.doc.body.innerHTML = this.tidy(this.core.doc.body, '');
18 Roo.htmleditor.Tidy.prototype = {
22 return s.replace(/\n/g, " ").replace(/(?![^\n]{1,80}$)([^\n]{1,80})\s/g, '$1\n');
27 tidy : function(node, indent) {
30 //Roo.log(currentElement);
32 var nodeName = node.nodeName;
33 //var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
34 var tagName = node.tagName; /// why encode tagname?
36 if (node.nodeType == 3) {
38 return indent === false ? node.nodeValue :
39 this.wrap(node.nodeValue.trim()).split("\n").join("\n" + indent)
43 if (node.nodeType != 1) {
49 if (node.tagName == 'BODY') {
51 return this.cn(node, '');
54 // Prints the node tagName, such as <A>, <IMG>, etc
55 var ret = (indent === false ? '' : indent ) + "<"+ node.node.tagName + _this.attr(node)
57 // elements with no children..
58 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
63 var cindent = indent + ' ';
64 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
69 this.cn(node, cindent ) +
70 '</' + node.tagName + '>' +
71 (indent === false ? '' : "\n");
74 cn: function(node, indent)
78 var ar = Array.from(node.childNodes);
79 for (var i = 0 ; i < ar.length ; i++) {
80 ret.push(this.tidy(ar[i], indent));
81 if (ar[i].nodeType != 3) { //text
93 for(i = 0; i < node.attributes.length;i++) {
96 if (!node.attributes.item(i).value.length) {
99 attr.push( node.attributes.item(i).name + '="' +
100 Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"'
103 return attr.length ? (' ' + attr.join(' ') ) : '';