Method transform has wrong current index
Closed this issue · 5 comments
sx-motive commented
Hi, I probably misunderstood something, but I didn't find any answers or related problems, so please help to make this clear
Expected Behavior
parse('<p>first</p><span>second</span><div>third</div>', {
transform: (reactNode, domNode, index) => {
console.log(index);
return reactNode as string;
},
})output: 0, 1, 2
Actual Behavior
output: 0, 1, 0, 2
Steps to Reproduce
code in Expected Behavior
Environment
- Version: 5.0.11
remarkablemark commented
@sx-motive can you add domNode to your log and provide your output here?
remarkablemark commented
This may not fix your issue, but I released a version that passed index as the 2nd argument in replace:
sx-motive commented
@remarkablemark sure, here is output with domNode
remarkablemark commented
Thanks @sx-motive. So it looks like the node index is correctly resetting itself when the parser is traversing the nested children:
<p><!-- 0 -->
first<!-- 0 -->
</p>
<span><!-- 1 -->
second<!-- 0 -->
</span>
<div><!-- 2 -->
third<!-- 0 -->
</div>Let me know if that makes sense.
sx-motive commented
@remarkablemark yes, now I see how this works, thanks for answers.
