- if(this.data('orig-before') && this.data('orig-before').length) {
- this.data('orig-before').forEach(function(toAdd) {
- if(toAdd)
- toret.prepend(document.createTextNode(toAdd));
- });
- } else if(level && this.getWlxmlTag() !== 'span') {
- toret.append('\n' + (new Array(level * 2 + 1)).join(' '));
- }
- if(this.data('orig-append') && this.data('orig-append').length) {
- this.data('orig-append').forEach(function(toAdd) {
- if(toAdd)
- node.prepend(toAdd);
- });
- //toret = toret.prepend(document.createTextNode(this.data('orig-prepend')));
- } else if(this.getWlxmlTag() !== 'span'){
- node.append('\n' + (new Array(level * 2 + 1)).join(' '));
+ var addFormatting = function() {
+ var toret = $('<div>');
+
+ if(this.data('orig-before') && this.data('orig-before').length) {
+ this.data('orig-before').forEach(function(toAdd) {
+ if(toAdd)
+ toret.prepend(document.createTextNode(toAdd));
+ });
+ } else if(level && this.getWlxmlTag() !== 'span') {
+ toret.append('\n' + (new Array(level * 2 + 1)).join(' '));
+ }
+ if(this.data('orig-append') && this.data('orig-append').length) {
+ this.data('orig-append').forEach(function(toAdd) {
+ if(toAdd)
+ node.prepend(toAdd);
+ });
+ } else if(this.getWlxmlTag() !== 'span'){
+ node.append('\n' + (new Array(level * 2 + 1)).join(' '));
+ }
+ toret.append(node);
+ return toret.contents();
+ }.bind(this);
+
+ var parts = addFormatting(node);
+
+ var children = this.children();
+ for(var i = children.length - 1; i >= 0; i--) {
+ children[i].toXML(node, level + 1);