From: Aleksander Ɓukasz Date: Wed, 10 Jul 2013 09:50:05 +0000 (+0200) Subject: Describing internal HTML represenation of a sample document X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/d67ed5177c7b434beb026aab16a91333e295a914 Describing internal HTML represenation of a sample document --- diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index 6131e4e..9bf47e8 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -23,7 +23,7 @@ $.extend(Canvas.prototype, { if(currentTag.attr('wlxml-tag')) return; var toret = $('
').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(); } }); diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 77b3b19..e122a1a 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -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('\ +
\ + This is some text without its own wrapping tag.\ +
\ + This is a paragraph.\ +
\ +
\ + This is text in a div with some inline text.\ +
\ + This is some text without its own wrapping tag.\ +
\ + '); + var expected = '
' + + 'This is some text without its own wrapping tag.' + + '
This is a paragraph.
' + + '
This is text in a div
with some inline text
.
' + + 'This is some text without its own wrapping tag.' + + '
'; + 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) {