1 if(typeof module !== 'undefined' && module.exports) {
2 var $ = require('jquery');
7 var transformations = {};
9 transformations.fromXML = {
10 getHTMLTree: function(xml) {
11 var inner = $(xml).clone();
12 var toret = $('<div></div>');
14 toret.find('metadata').remove();
16 var toBlock = ['div', 'document', 'section', 'header'];
17 var toInline = ['aside'];
19 toBlock.forEach(function(tagName) {
20 tagName = tagName.toLowerCase();
21 console.log('running ' + tagName);
22 toret.find(tagName).replaceWith(function() {
23 var suffix = tagName !== 'div' ? tagName : 'block';
24 return $('<div></div>').addClass('rng-' + suffix).append($(this).contents());
28 toInline.forEach(function(tagName) {
29 tagName = tagName.toLowerCase();
30 toret.find(tagName).replaceWith(function() {
32 return $('<span></span>').addClass('rng-' + tagName).append($(this).contents());
35 return toret.children();
37 getMetaData: function(xml) {
39 $(xml).find('metadata').children().each(function() {
41 toret[this.nodeName.split(':')[1].toLowerCase()] = node.text();
45 getDocumentDescription: function(xml) {
47 HTMLTree: this.getHTMLTree(xml),
48 metadata: this.getMetaData(xml)
53 transformations.toXML = {
54 getXML: function(documentDescription) {
55 return documentDescription.HTMLTree;
60 if(typeof module !== 'undefined' && module.exports) {
61 module.exports = transformations;
63 rng.modules.visualEditor.transformations = transformations;