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
73 var name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule, handler = handlers[node.type];
78 isEmpty = node.shortEnded;
79 attrs = node.attributes;
81 if (validate && attrs && attrs.length > 1) {
84 elementRule = schema.getElementRule(node.name);
86 for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
87 attrName = elementRule.attributesOrder[i];
88 if (attrName in attrs.map) {
89 attrValue = attrs.map[attrName];
90 sortedAttrs.map[attrName] = attrValue;
97 for (i = 0, l = attrs.length; i < l; i++) {
98 attrName = attrs[i].name;
99 if (!(attrName in sortedAttrs.map)) {
100 attrValue = attrs.map[attrName];
101 sortedAttrs.map[attrName] = attrValue;
111 writer.start(node.name, attrs, isEmpty);
113 if (node = node.firstChild) {
116 } while (node = node.next);
122 // Serialize element and treat all non elements as fragments
123 1 != node.type || settings.inner ? handlers[11](node) : walk(node);
124 return writer.getContent();