-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Adding Node.traverse() examples and/or documentation. #369
Comments
Thank you so much, that'd be lovely! This is a really nice example! |
Thanks. I'll do a bit of comment editing and make sure the proper use statements are included. |
And, last night I found an even easier iteration method. 🤨 fn extract_text<'a>(root: &'a AstNode<'a>) -> String {
let mut output_text = String::new();
// Use `traverse` to get an iterator of `NodeEdge` and process each.
for node in root.descendants() {
if let NodeValue::Text(ref text) = node.data.borrow().value {
// If the node is a text node, append its text to `output_text`.
output_text.push_str(text);
}
}
output_text
} I might submit a dockstring PR because |
Happy to tackle any other documentation needs. |
Expand traverse and descendants documentation: Issue #369
I appreciate that so much! How about the usage example in README.md? (Under "Or you can parse the input into an AST yourself, manipulate it, and then use your desired formatter:") It's extremely verbose and you've done a really good job of documenting some much nicer APIs. The |
Sounds good, it might be a few weeks until I get some bandwidth to work on it. |
Yeah, of course, no worries at all :) Life's always like that. Thank you (as always) for your interest and effort! ❤️ |
PR submitted. Comments welcome. |
Really excellent — thank you so much. |
I have the following example of a function using Node.traverse() to extract text as an alternative to the recursive examples from the README. If there's interest, I can clean it up and put in a PR adding it to examples or the generated API documentation.
It should handle nested inline markup to generate a plain text string.
The text was updated successfully, but these errors were encountered: