Output formatting wip: keeping excessive white space at the end of text intact
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 18 Jul 2013 14:05:55 +0000 (16:05 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 18 Jul 2013 14:05:55 +0000 (16:05 +0200)
modules/documentCanvas/canvas/canvas.js
modules/documentCanvas/canvas/canvas.test3.js

index 079c229..b11432f 100644 (file)
@@ -65,11 +65,11 @@ $.extend(Canvas.prototype, {
                         idx = parentContents.index(this),
                         next = idx < parentContents.length - 1 ? parentContents[idx+1] : null;
 
-                    var addInfo = function() {
+                    var addInfo = function(toAdd) {
                         if(next) {
-                            $(next).data('orig-before', oldText);
+                            $(next).data('orig-before', toAdd);
                         } else {
-                            parent.data('orig-append', oldText);
+                            parent.data('orig-append', toAdd);
                         }
                     }
 
@@ -82,7 +82,12 @@ $.extend(Canvas.prototype, {
                                     + (endSpace && (spanParent || spanAfter) ? ' ' : '');
                         if(newText !== oldText) {
                             this.data = newText;
-                            addInfo();
+                            if(endSpace) {
+                                var toAdd = oldText.match(/\s+$/g)[0];
+                                if(newText[newText.length - 1] === ' ' && toAdd[0] === ' ')
+                                    toAdd = toAdd.substr(1);
+                                addInfo(toAdd);
+                            }
                         }
                     } else {
 
@@ -90,7 +95,7 @@ $.extend(Canvas.prototype, {
                         if(this.data.length === 0 && oldLength > 0 && el.parent().contents().length === 1)
                             this.data = ' ';
                         if(this.data.length === 0) {
-                            addInfo();
+                            addInfo(oldText);
                             el.remove();
 
                             return true; // continue
index 2017a8a..e17c758 100644 (file)
@@ -1173,6 +1173,21 @@ describe('Canvas', function() {
                 expect(xmlOut).to.equal('<section><span></span></section>');
             });
 
+            it('keeps original white space at the end of text', function() {
+                
+                var xmlIn = '<header>Some text ended with white space \
+                \
+                <span class="uri">Some text</span> some text\
+            \
+            </header>',
+                    c = canvas.fromXML(xmlIn);
+
+            var xmlOut = c.toXML();
+            console.log(xmlOut);
+            expect(xmlOut).to.equal(xmlIn);
+
+            });
+
         })
     })
 });