Skip to content

Commit

Permalink
feat(dom-to-react): add option trim that skips whitespace nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 5, 2020
1 parent 4ef89af commit 413eaa0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/dom-to-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function domToReact(nodes, options) {
var replaceElement;
var props;
var children;
var data;
var trim = options.trim;

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

if (node.type === 'text') {
result.push(node.data);
// if trim option is enabled, skip whitespace text nodes
if (trim) {
data = node.data.trim();
if (data) {
result.push(node.data);
}
} else {
result.push(node.data);
}
continue;
}

Expand Down

0 comments on commit 413eaa0

Please sign in to comment.