Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Empty text #4

Open
noreiller opened this issue Apr 21, 2023 · 1 comment
Open

Empty text #4

noreiller opened this issue Apr 21, 2023 · 1 comment

Comments

@noreiller
Copy link

Brief bug description

When I want to parse an HTML string like this one <p>one <strong>two</strong></p>, the first TextNode child (#text) of the P tag does not contain the value one .

The issue comes from the text node which is serialized with parse5 while parse5 computes the text value from the childNodes, which a TextNode has not.

If you replace the parentNode instead of adding it to the childNodes, it works better:
https://github.com/kontent-ai/kontent-delivery-node-parser/blob/master/lib/parser/implementation/shared.ts#L160

-        text: striptags(serialize(node)),
+        text:  tagName === "#text" ? node.value : striptags(serialize(node)),

Test environment

  • Node
@hellomathieuJT
Copy link

Thank you @noreiller , I also have the same issue!

noreiller added a commit to noreiller/kontent-delivery-node-parser that referenced this issue May 2, 2023
A text node serialized with parse5 has no child so no value is returned.
With these changes, we check the type and avoid the serialization.

FIXES kontent-ai#4
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants