Closed 4l1fe closed 6 months ago
Hi @4l1fe, in mistletoe, deleting tree nodes before rendering should be easy - you just need to update the children
attribute (possibly a property soon - see #206) of the token you want to modify, see e.g. here for inspiration. Mistletoe currently doesn't have any API for handling operations like these explicitly.
Do you think deleting nodes while traversing a tree with utils.traverse is safe?
Well, I think that if you manage to modify the children
of a yielded TraverseResult.node
, nothing bad will happen - the newly assigned child nodes will just be iterated thereafter by the traverse()
function. Right?
I think that if you manage to modify the
children
of a yieldedTraverseResult.node
I'm doing exactly this way, all is ok at the moment,but it is somewhat like modifing a list while iterating it that is unsafe in general.
Anyway, thx for your opinion.
Sadly, after searching the subject i didn't find a way of how i could drop a few nodes while modifying
Document
for further rendering it back to markdown.Pls suggest an idea. I see the example of editing node content, but deleting tree nodes is somewhat more complex and i'm not sure that it can be done by mistletoe