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

Allow comments under root #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/html2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
node: 'comment',
text: text,
};
var parent = bufArray[0];
var parent = bufArray[0] || results;
if (parent.child === undefined) {
parent.child = [];
}
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ describe('html2json', function() {
assert.deepEqual(json, html2json(html));
assert.deepEqual(html, json2html(json));
});

it('should parse top-level comment', function() {
var json = {
node: 'root',
child: [
{
node: 'comment',
text: ' foo '
}
]
};
var html = '<!-- foo -->';

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

it('should parse div with id', function() {
var json = {
Expand Down