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, {
25 * Serializes the specified node into a string.
28 * new tinymce.html.Serializer().serialize(new tinymce.html.DomParser().parse('<p>text</p>'));
30 * @param {DomElement} node Node instance to serialize.
31 * @return {String} String with HTML based on DOM tree.
33 serialize : function(node) {
35 // = settings.validate;
36 var writer = this.writer;
40 writer.text(node.value, node.raw);
44 writer.comment(node.value);
46 // Processing instruction
48 writer.pi(node.name, node.value);
52 writer.doctype(node.value);
56 writer.cdata(node.value);
60 node = node.firstChild;
66 node = node.nextSibling
71 1 != node.nodeType || this.inner ? handlers[11](node) : walk(node);
72 return writer.getContent();
75 var name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule, handler = handlers[node.type];
80 isEmpty = node.shortEnded;
81 attrs = node.attributes;
83 if (validate && attrs && attrs.length > 1) {
86 elementRule = schema.getElementRule(node.name);
88 for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
89 attrName = elementRule.attributesOrder[i];
90 if (attrName in attrs.map) {
91 attrValue = attrs.map[attrName];
92 sortedAttrs.map[attrName] = attrValue;
99 for (i = 0, l = attrs.length; i < l; i++) {
100 attrName = attrs[i].name;
101 if (!(attrName in sortedAttrs.map)) {
102 attrValue = attrs.map[attrName];
103 sortedAttrs.map[attrName] = attrValue;
113 writer.start(node.name, attrs, isEmpty);
115 if (node = node.firstChild) {
118 } while (node = node.next);
124 // Serialize element and treat all non elements as fragments