Skip to content

Commit e86a8b2

Browse files
committed
fix(stringify): Ignore comments in textContent
1 parent 7c60fc1 commit e86a8b2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/stringify.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { isTag, isCDATA, isText, hasChildren, Node } from "domhandler";
1+
import {
2+
isTag,
3+
isCDATA,
4+
isText,
5+
hasChildren,
6+
Node,
7+
isComment,
8+
} from "domhandler";
29
import renderHTML, { DomSerializerOptions } from "dom-serializer";
310
import { ElementType } from "domelementtype";
411

@@ -54,7 +61,9 @@ export function getText(node: Node | Node[]): string {
5461
*/
5562
export function textContent(node: Node | Node[]): string {
5663
if (Array.isArray(node)) return node.map(textContent).join("");
57-
if (hasChildren(node)) return textContent(node.children);
64+
if (hasChildren(node) && !isComment(node)) {
65+
return textContent(node.children);
66+
}
5867
if (isText(node)) return node.data;
5968
return "";
6069
}

0 commit comments

Comments
 (0)