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;
47 writer.text(node.value, node.raw);
51 writer.comment(node.value);
53 // Processing instruction
55 writer.pi(node.name, node.value);
59 writer.doctype(node.value);
63 writer.cdata(node.value);
67 node = node.firstChild;
73 node = node.nextSibling
78 1 != node.nodeType || this.inner ? handlers[11](node) : walk(node);
79 return writer.getContent();
83 var name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule, handler = handlers[node.type];
88 isEmpty = node.shortEnded;
89 attrs = node.attributes;
91 if (validate && attrs && attrs.length > 1) {
94 elementRule = schema.getElementRule(node.name);
96 for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
97 attrName = elementRule.attributesOrder[i];
98 if (attrName in attrs.map) {
99 attrValue = attrs.map[attrName];
100 sortedAttrs.map[attrName] = attrValue;
107 for (i = 0, l = attrs.length; i < l; i++) {
108 attrName = attrs[i].name;
109 if (!(attrName in sortedAttrs.map)) {
110 attrValue = attrs.map[attrName];
111 sortedAttrs.map[attrName] = attrValue;
121 writer.start(node.name, attrs, isEmpty);
123 if (node = node.firstChild) {
126 } while (node = node.next);
132 // Serialize element and treat all non elements as fragments