JuliaDocs / MarkdownAST.jl

Abstract syntax tree representation of Markdown documents in Julia
https://juliadocs.github.io/MarkdownAST.jl
Other
13 stars 3 forks source link

Whole tree iteration #1

Open mortenpi opened 2 years ago

mortenpi commented 2 years ago

CommonMark iterates over the whole tree if you do for node in tree, which is currently not implemented here (we only have children).

I would argue, however, that it is not intuitively clear which type of iteration (over direct children? over whole tree? over direct and indirect children, but not parents?) should be the default. Hence I would advocate that for each iterator there should be a function (like children) that returns the iterator. For the whole-tree iteration it could be called tree(node).

MichaelHatherly commented 2 years ago

Perhaps make use of AbstractTrees.jl for this?

Any particular use cases you have in mind where different iteration schemes are preferable?

mortenpi commented 2 years ago

AbstractTrees crossed my radar as well, but it wasn't clear from the docs how useful it would be. However, it seems to be undergoing an overhaul (https://github.com/JuliaCollections/AbstractTrees.jl/pull/96, https://github.com/JuliaCollections/AbstractTrees.jl/pull/99, dev docs), so it might make sense to wait until that is done for final decision.

I guess one question is whether we want to add a dependency for this. If the goal is to upstream the Markdown handing to core Julia eventually, then I think we'd have to drop the dependency again. But I guess maybe we can still keep this package around to provide bells and whistles on top of a minimal implementation in a standard library.

As for different iteration schemes, I don't have very specific use cases in mind, but my main gripe is that it is not obvious that for node in node should iterate over the whole tree.

In all cases it simply seems to me that being explicit would be better.

ExpandingMan commented 2 years ago

I recommend waiting for v0.4 of AbstractTrees to be tagged, which should be coming soon. There will be much more extensive documentation.