diff --git a/lib/util/parse.js b/lib/util/parse.js index b9b2fc8..a7f84d6 100644 --- a/lib/util/parse.js +++ b/lib/util/parse.js @@ -8,6 +8,8 @@ var SVG_START = '' + svg + ''; + unwrap = true; + } + + var parsed = parseDocument(svg); + + if (!unwrap) { + return parsed; + } + + var fragment = document.createDocumentFragment(); + + var parent = parsed.firstChild; + + while (parent.firstChild) { + fragment.appendChild(parent.firstChild); } - return parseDocument(svg); + return fragment; } function parseDocument(svg) { diff --git a/test/spec/create.js b/test/spec/create.js index 6bc6fbf..c17536d 100644 --- a/test/spec/create.js +++ b/test/spec/create.js @@ -34,7 +34,7 @@ describe('create', function() { }); - it('should create element from SVG markup', function() { + it('should create from markup', function() { // given var container = createContainer(); @@ -50,4 +50,22 @@ describe('create', function() { expect(svg.childNodes[0].nodeName).to.eql('g'); }); + + it('should create from markup', function() { + + // given + var container = createContainer(); + + // when + var g = create(''); + + append(container, g); + + // then + expect(g.nodeName).to.eql('g'); + expect(g.id).to.eql('G'); + expect(g.childNodes.length).to.eql(1); + expect(g.childNodes[0].nodeName).to.eql('circle'); + }); + }); \ No newline at end of file diff --git a/test/spec/util/parse.js b/test/spec/util/parse.js index ef4f128..6fded8b 100644 --- a/test/spec/util/parse.js +++ b/test/spec/util/parse.js @@ -4,6 +4,7 @@ import { import parse from '../../../lib/util/parse'; + describe('parse', function() { it('should parse / CDATA', function() { @@ -16,13 +17,26 @@ describe('parse', function() { ']]>' + ''; + // when + var fragment = parse(text); + var svg = innerSVG(fragment); + + // then + expect(svg).to.eql(text); + }); + + + it('should parse ', function() { + + // given + var text = ''; // when var doc = parse(text); - var svg = innerSVG(doc.documentElement); + var svg = innerSVG(doc); // then - expect(svg).to.eql(text); + expect(svg).to.eql(''); }); });