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

Introduce a mechanism to duplicate/clone a node and all it's children? #560

Open
ioquatix opened this issue Aug 19, 2024 · 4 comments
Open

Comments

@ioquatix
Copy link
Contributor

When manipulating ASTs using nodes, sometimes you need to copy parts of the AST to a different place or part of the document.

The most naive approach I can think of is converting a document to a markdown string and parsing it again, but I'm sure there are subtle differences. It might be good for an initial implementation.

It might be nice to introduce a clone function which takes a node and returns a copy, including all children.

@jgm
Copy link
Member

jgm commented Aug 22, 2024

This seems reasonable to me. @nwellnhof what do you think?

@nwellnhof
Copy link
Contributor

The most naive approach I can think of is converting a document to a markdown string and parsing it again, but I'm sure there are subtle differences.

This should result in a perfect copy (except for source positions), but it's inefficient. A clone function certainly seems useful.

@ioquatix
Copy link
Contributor Author

Okay can I submit a PR?

@jgm
Copy link
Member

jgm commented Aug 28, 2024

Yes!

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

No branches or pull requests

3 participants