Skip to content

Commit 0b09ab2

Browse files
committed
We ought to drop text nodes that are nothing but whitespace since not useful in HTML.
1 parent 73e94a8 commit 0b09ab2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/parse.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@ module.exports = function parse(html, options) {
7070
// calculate correct end of the content slice in case there's
7171
// no tag after the text node.
7272
var end = html.indexOf('<', start);
73-
end = end === -1 ? undefined : end;
74-
parent.push({
75-
type: 'text',
76-
content: html.slice(start, end)
77-
});
73+
var content = html.slice(start, end === -1 ? undefined : end);
74+
// if a node is nothing but whitespace, no need to add it.
75+
if (!/^\s*$/.test(content)) {
76+
parent.push({
77+
type: 'text',
78+
content: content
79+
});
80+
}
7881
}
7982
}
8083
});

0 commit comments

Comments
 (0)