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;
} 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();
}
});
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) {