wooorm / markdown-rs

CommonMark compliant markdown parser in Rust with ASTs and extensions
https://docs.rs/markdown/1.0.0-alpha.18/markdown/
MIT License
836 stars 41 forks source link

Would `to_mdast()` return variants of `mdast::Node` other than `mdast::Node::Root`? #109

Open lo48576 opened 4 months ago

lo48576 commented 4 months ago

I haven't read the parser thoroughly, but it looks like to_mdast() always returns mdast::Node::Root(_) on success, even if the source document looks like a simple "inline" text. If so, isn't it natural and explicit to return mdast::Root directly instead of wrapping it to mdast::Node enum?

Or if it can return something other than mdast::Node::Root(_) variant, the condition would be worth documented.

I'm wondering my converter over md AST can assume that the returned AST is always mdast::Root.

wooorm commented 4 months ago

Hey! It does indeed always return a root. I don’t have strong opinions on this. The AST can be improved though. That’s one of the main reasons this is still alpha. There are different issues about it.