Skip to content

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? :)

@wooorm
Copy link
Owner

wooorm commented Apr 23, 2025

Closing; I think I would be open to a a unist_util_visit fork as a subcrate here!

@wooorm wooorm closed this Apr 23, 2025
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.

2 participants