Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
fix parsing alone unary inline tag fixing #14
Browse files Browse the repository at this point in the history
  • Loading branch information
Jxck committed Apr 21, 2016
1 parent 1522b90 commit 3885c92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/html2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
// if this tag dosen't have end tag
// like <img src="hoge.png"/>
// add to parents
var parent = bufArray[0];
var parent = bufArray[0] || results;
if (parent.child === undefined) {
parent.child = [];
}
Expand Down
21 changes: 20 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<hr/>';

assert.deepEqual(json, html2json(html));
assert.deepEqual(html, json2html(json));
});


it('should parse multi div', function() {
var json = {
node: 'root',
Expand Down Expand Up @@ -385,6 +399,10 @@ describe('html2json', function() {
attr: { id: 'execute', type: 'button', value: 'execute' }
}
]
},
{
node: 'element',
tag: 'hr',
}
]
};
Expand All @@ -394,7 +412,8 @@ describe('html2json', function() {
+ '<pre id="demo" class="foo bar">foo</pre>'
+ '<pre id="output" class="goo">goo</pre>'
+ '<input id="execute" type="button" value="execute"/>'
+ '</div>';
+ '</div>'
+ '<hr/>';

assert.deepEqual(json, html2json(html));
assert.deepEqual(html, json2html(json));
Expand Down

0 comments on commit 3885c92

Please sign in to comment.