Skip to content

Commit 413eaa0

Browse files
feat(dom-to-react): add option trim that skips whitespace nodes
1 parent 4ef89af commit 413eaa0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/dom-to-react.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function domToReact(nodes, options) {
2424
var replaceElement;
2525
var props;
2626
var children;
27+
var data;
28+
var trim = options.trim;
2729

2830
for (var i = 0, len = nodes.length; i < len; i++) {
2931
node = nodes[i];
@@ -46,7 +48,15 @@ function domToReact(nodes, options) {
4648
}
4749

4850
if (node.type === 'text') {
49-
result.push(node.data);
51+
// if trim option is enabled, skip whitespace text nodes
52+
if (trim) {
53+
data = node.data.trim();
54+
if (data) {
55+
result.push(node.data);
56+
}
57+
} else {
58+
result.push(node.data);
59+
}
5060
continue;
5161
}
5262

0 commit comments

Comments
 (0)