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

Method transform has wrong current index #1259

Closed
sx-motive opened this issue Jan 10, 2024 · 5 comments
Closed

Method transform has wrong current index #1259

sx-motive opened this issue Jan 10, 2024 · 5 comments
Assignees
Labels
question Further information is requested wontfix This will not be worked on

Comments

@sx-motive
Copy link

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
@sx-motive sx-motive added the bug Something isn't working label Jan 10, 2024
@sx-motive sx-motive changed the title Method Transform has wrong index Method Transform has wrong current index Jan 10, 2024
@sx-motive sx-motive changed the title Method Transform has wrong current index Method transform has wrong current index Jan 10, 2024
@remarkablemark
Copy link
Owner

@sx-motive can you add domNode to your log and provide your output here?

@remarkablemark
Copy link
Owner

This may not fix your issue, but I released a version that passed index as the 2nd argument in replace:

@sx-motive
Copy link
Author

@remarkablemark sure, here is output with domNode

Screenshot 2024-01-12 132554

@remarkablemark
Copy link
Owner

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.

@remarkablemark remarkablemark added question Further information is requested wontfix This will not be worked on and removed bug Something isn't working labels Jan 12, 2024
@sx-motive
Copy link
Author

@remarkablemark yes, now I see how this works, thanks for answers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants