First naive implementation of transformations.toXML.getXML
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 15 Apr 2013 13:39:15 +0000 (15:39 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 15 Apr 2013 13:39:15 +0000 (15:39 +0200)
modules/visualEditor.transformations.js

index 9d21f5d..22deba5 100644 (file)
@@ -52,7 +52,26 @@ if(typeof module !== 'undefined' && module.exports) {
 
     transformations.toXML = {
         getXML: function(documentDescription) {
-            return documentDescription.HTMLTree;
+            
+            var inner = $(documentDescription.HTMLTree);
+            var toret = $('<div></div>');
+            toret.append(inner);
+            
+            toret.find('div, span').replaceWith(function() {
+                var div = $(this);
+                var tagName = div.attr('class').split('rng-')[1];
+                return $('<'+tagName+'>').append(div.contents());
+            });
+            
+            var meta = $('<metadata>');
+            _.each(_.keys(documentDescription.metadata), function(key) {
+                meta.append($('<dc:'+key+'>' + documentDescription.metadata[key] + '</dc:'+key+'>'));
+            });
+            
+            toret.find('document').prepend(meta);
+            
+            return toret.html();
+            
         }
     }