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.
31 * Serializes the specified node into a string.
34 * new tinymce.html.Serializer().serialize(new tinymce.html.DomParser().parse('<p>text</p>'));
36 * @param {DomElement} node Node instance to serialize.
37 * @return {String} String with HTML based on DOM tree.
39 serialize : function(node) {
41 // = settings.validate;
42 var writer = this.writer;
46 writer.text(node.value, node.raw);
50 writer.comment(node.value);
52 // Processing instruction
54 writer.pi(node.name, node.value);
58 writer.doctype(node.value);
62 writer.cdata(node.value);
66 node = node.firstChild;
72 node = node.nextSibling
77 1 != node.nodeType || this.inner ? handlers[11](node) : walk(node);
78 return writer.getContent();
81 var name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule, handler = handlers[node.type];
86 isEmpty = node.shortEnded;
87 attrs = node.attributes;
89 if (validate && attrs && attrs.length > 1) {
92 elementRule = schema.getElementRule(node.name);
94 for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
95 attrName = elementRule.attributesOrder[i];
96 if (attrName in attrs.map) {
97 attrValue = attrs.map[attrName];
98 sortedAttrs.map[attrName] = attrValue;
105 for (i = 0, l = attrs.length; i < l; i++) {
106 attrName = attrs[i].name;
107 if (!(attrName in sortedAttrs.map)) {
108 attrValue = attrs.map[attrName];
109 sortedAttrs.map[attrName] = attrValue;
119 writer.start(node.name, attrs, isEmpty);
121 if (node = node.firstChild) {
124 } while (node = node.next);
130 // Serialize element and treat all non elements as fragments