diff --git a/src/html2json.js b/src/html2json.js index f35adbc..85579e6 100644 --- a/src/html2json.js +++ b/src/html2json.js @@ -65,7 +65,7 @@ // if this tag dosen't have end tag // like // add to parents - var parent = bufArray[0]; + var parent = bufArray[0] || results; if (parent.child === undefined) { parent.child = []; } diff --git a/test/test.js b/test/test.js index 5bb02f5..eff1f16 100644 --- a/test/test.js +++ b/test/test.js @@ -22,6 +22,20 @@ describe('html2json', function() { assert.deepEqual(html, json2html(json)); }); + it('should parse hr', function() { + var json = { + node: 'root', + child: [ + { node: 'element', tag : 'hr' } + ] + }; + var html = '
foo' + '
goo' + '' - + ''; + + '' + + '