kontent-ai / kontent-delivery-node-parser

Rich text element parser for node.js & javascript delivery SDK.
MIT License
0 stars 2 forks source link

Empty text #4

Open noreiller opened 1 year ago

noreiller commented 1 year ago

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

hellomathieuJT commented 1 year ago

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