Skip to content

Commit

Permalink
fix: Can't get text from TextNode in the browser (fixes #40)
Browse files Browse the repository at this point in the history
  • Loading branch information
nonara committed Oct 26, 2022
1 parent 7d52c92 commit feec660
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,16 @@ export class Visitor {
if (!node.preserve) return;

/* Handle text node */
if (isTextNode(node))
if (isTextNode(node)) {
if ((<any>node).wholeText) {
(<any>node).text ??= (<any>node).wholeText;
(<any>node).trimmedText ??= trimNewLines((<any>node).wholeText);
}

return node.isWhitespace && !metadata?.preserveWhitespace
? (!result.text.length || result.trailingNewlineStats.whitespace > 0) ? void 0 : this.appendResult(' ')
: this.appendResult(this.processText(metadata?.preserveWhitespace ? node.text : node.trimmedText, metadata));
}

if (textOnly || !isElementNode(node)) return;

Expand Down

0 comments on commit feec660

Please sign in to comment.