Skip to content

Commit cbf947d

Browse files
committed
Remove empty text nodes
1 parent f918a06 commit cbf947d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33

44
module.exports = function (ast) {
55
ast.children = ast.children.filter(function (node) {
6-
return !(node.type == 'paragraph' && !node.children.length);
6+
if (node.type == 'paragraph') {
7+
// Remove empty text nodes.
8+
node.children = node.children.filter(function (node) {
9+
return node.type != 'text' || !/^\s*$/.test(node.value);
10+
});
11+
12+
return node.children.length;
13+
}
14+
15+
return true;
716
});
817

918
return ast;

test/input.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
},
2121
{
2222
"type": "paragraph",
23-
"children": []
23+
"children": [
24+
{
25+
"type": "text",
26+
"value": "\n"
27+
}
28+
]
2429
},
2530
{
2631
"type": "paragraph",

0 commit comments

Comments
 (0)