Describing internal HTML represenation of a sample document
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 10 Jul 2013 09:50:05 +0000 (11:50 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 10 Jul 2013 09:50:05 +0000 (11:50 +0200)
modules/documentCanvas/canvas/canvas.js
modules/documentCanvas/canvas/canvas.test3.js

index 6131e4e..9bf47e8 100644 (file)
@@ -23,7 +23,7 @@ $.extend(Canvas.prototype, {
                 if(currentTag.attr('wlxml-tag'))
                     return;
                 var toret = $('<div>').attr('wlxml-tag', currentTag.prop('tagName').toLowerCase());
-                toret.attr('id', 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}));
+                //toret.attr('id', 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}));
                 for(var i = 0; i < this.attributes.length; i++) {
                     var attr = this.attributes.item(i);
                     var value = attr.name === 'class' ? attr.value.replace(/\./g, '-') : attr.value;
@@ -55,8 +55,10 @@ $.extend(Canvas.prototype, {
                     } else {
                         var oldLength = this.data.length;
                         this.data = $.trim(this.data);
-                        if(this.data.length === 0 && oldLength > 0)
+                        if(this.data.length === 0 && oldLength > 0 && el.parent().contents().length === 1)
                             this.data = ' ';
+                        if(this.data.length === 0)
+                            $(this).remove();
                     }
                 });
             
index 77b3b19..e122a1a 100644 (file)
@@ -11,6 +11,30 @@ var expect = chai.expect;
 
 describe('Canvas', function() {
 
+    describe('Internal HTML representation of a sample document', function() {
+        it('works', function() {
+            var c = canvas.fromXML('\
+                <section>\
+                    This is some text without its own wrapping tag.\
+                    <div class="p.subclass">\
+                        This is a paragraph.\
+                    </div>\
+                    <div>\
+                        This is text in a div <span>with some inline text</span>.\
+                    </div>\
+                    This is some text without its own wrapping tag.\
+                </section>\
+            ');
+            var expected = '<div wlxml-tag="section">'
+                            + 'This is some text without its own wrapping tag.'
+                            + '<div wlxml-tag="div" wlxml-class="p-subclass">This is a paragraph.</div>'
+                            + '<div wlxml-tag="div">This is text in a div <div wlxml-tag="span">with some inline text</div>.</div>'
+                            + 'This is some text without its own wrapping tag.'
+                            + '</div>';
+            expect(c.doc().dom()[0].isEqualNode($(expected)[0])).to.be.true;
+        });
+    });
+
     describe('Internal HTML representation of a DocumentNodeElement', function() {
         it('is always a div tag', function() {
             ['section', 'header', 'span', 'aside', 'figure'].forEach(function(tagName) {