+
+ var inner = $(documentDescription.HTMLTree);
+ var toret = $('<div></div>');
+ toret.append(inner);
+
+ toret.find('div, span').replaceWith(function() {
+ var div = $(this);
+ var tagName = div.attr('wlxml-tag');
+ var toret = $('<'+tagName+'>');
+ if(div.attr('wlxml-class'))
+ toret.attr('class', div.attr('wlxml-class').replace(/-/g, '.'))
+ toret.append(div.contents());
+ return toret;
+ });
+
+ var meta = $('<metadata></metadata>\n');
+ _.each(_.keys(documentDescription.metadata), function(key) {
+ meta.append('\n\t<dc:'+key+'>' + documentDescription.metadata[key] + '</dc:'+key+'>');
+ });
+ meta.append('\n');
+
+ toret.find('metadata').replaceWith(meta);
+
+ return toret.html();
+