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

implement pre-order traversal of node #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

remodietlicher
Copy link

Hello! I'm playing around with your nice library to learn a bit of Rust. I found myself filtering and mapping the AST, for example to extract only a specific type of Node. After implementing my own filter function I noticed that the Iterator trait actually provides just that, all that's needed is the next function.

So here I implement a pre-order traversal of the Node-tree to create an Iterator over the AST. I show how it can be used on the to_string implementation.

Since I'm new to Rust, I was wondering if this sounds useful to you and if there is anything I could improve.

@wooorm
Copy link
Owner

wooorm commented Feb 10, 2023

Hey! Thanks for your patience, cool work!

This seems a bit similar to my preorder traversel utility here: https://github.com/wooorm/mdxjs-rs/blob/8cba71bcf926057ae4bdc5b67de69010a5621301/src/mdast_util_to_hast.rs#L1198-L1222. (I also had a mutable version there as well: wooorm/mdxjs-rs@f6b705f#diff-d1bf57e8534841c5ee7eda0ab2bcf89b943719c21ea89a48bf96e25a114e2f3f)

I’ve been meaning to turn the nodes into traits (see #27 (comment)). That way, we can have such utilities working on mdast and hast.
Perhaps that’s something you might be interested in working on? :)

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 this pull request may close these issues.

None yet

2 participants