Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty text #4

Open
noreiller opened this issue Apr 21, 2023 · 1 comment · May be fixed by #5
Open

Empty text #4

noreiller opened this issue Apr 21, 2023 · 1 comment · May be fixed by #5

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
@noreiller noreiller linked a pull request May 2, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants