3 * This is based loosely on tinymce
4 * @class Roo.htmleditor.TidySerializer
5 * https://github.com/thorn0/tinymce.html/blob/master/tinymce.html.js
8 * @param {Object} settings Name/value settings object.
9 * @param {tinymce.html.Schema} schema Schema instance to use.
13 Roo.htmleditor.TidySerializer = function(settings)
15 Roo.apply(this.settings);
17 this.writer = new Roo.htmleditor.TidyWriter(settings);
19 //settings.validate = !('validate' in settings) || settings.validate;
20 // self.schema = schema = schema || new Schema();
23 Roo.apply(Roo.htmleditor.TidySerializer.prototype, {
26 * @param {boolean} inner do the inner of the node.
33 * Serializes the specified node into a string.
36 * new tinymce.html.Serializer().serialize(new tinymce.html.DomParser().parse('<p>text</p>'));
38 * @param {DomElement} node Node instance to serialize.
39 * @return {String} String with HTML based on DOM tree.
41 serialize : function(node) {
43 // = settings.validate;
44 var writer = this.writer;
49 writer.text(node.value, node.raw);
53 writer.comment(node.value);
55 // Processing instruction
57 writer.pi(node.name, node.value);
61 writer.doctype(node.value);
65 writer.cdata(node.value);
69 node = node.firstChild;
75 node = node.nextSibling
80 1 != node.nodeType || this.inner ? handlers[11](node) : walk(node);
81 return writer.getContent();
86 var attrName, attrValue, sortedAttrs, i, l, elementRule,
87 handler = this.handlers[node.type];
94 var name = node.nodeName;
95 var isEmpty = node.childNodes.length < 1;
96 var writer = this.writer;
97 var attrs = node.attributes;
100 if (validate && attrs && attrs.length > 1) {
102 sortedAttrs.map = {};
103 elementRule = schema.getElementRule(node.name);
105 for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
106 attrName = elementRule.attributesOrder[i];
107 if (attrName in attrs.map) {
108 attrValue = attrs.map[attrName];
109 sortedAttrs.map[attrName] = attrValue;
116 for (i = 0, l = attrs.length; i < l; i++) {
117 attrName = attrs[i].name;
118 if (!(attrName in sortedAttrs.map)) {
119 attrValue = attrs.map[attrName];
120 sortedAttrs.map[attrName] = attrValue;
131 writer.start(node.name, attrs, isEmpty);
135 node = node.firstChild;
143 } while (node = node.next);
149 // Serialize element and treat all non elements as fragments