expect(children[1]).to.be.instanceOf(documentElement.DocumentNodeElement);
expect(children[1].sameNode(added)).to.be.true;
});
+ it('can put new DocumentNodeElement before DocumentTextElement', function() {
+ var c = canvas.fromXML('<section>Alice</section>'),
+ text = c.doc().children()[0],
+ added = text.before({tag: 'p'}),
+ children = c.doc().children();
+
+ expect(children.length).to.equal(2);
+ expect(children[0]).to.be.instanceOf(documentElement.DocumentNodeElement);
+ expect(children[0].sameNode(added)).to.be.true;
+ expect(children[1]).to.be.instanceOf(documentElement.DocumentTextElement);
+ expect(children[1].getText()).to.equal('Alice');
+ });
});
describe('Splitting text', function() {
this.$element.unwrap();
return documentElementFromHTMLElement(dom[0]);
},
+ before: function(params) {
+ if(params instanceof DocumentTextElement || params.text)
+ return false;
+ var dom;
+ if(params instanceof DocumentNodeElement) {
+ dom = params.dom();
+ } else {
+ dom = DocumentNodeElement.createDOM(params);
+ }
+ this.$element.wrap('<div>');
+ this.$element.parent().before(dom[0]);
+ this.$element.unwrap();
+ return documentElementFromHTMLElement(dom[0]);
+ },
wrapWithNodeElement: function(wlxmlNode) {
if(wlxmlNode.start && wlxmlNode.end) {
return this.canvas.wrapText({