gomarkdown / markdown

markdown parser and HTML renderer for Go
Other
1.36k stars 171 forks source link

RemoveFromTree panics on Leaf nodes #262

Closed cleborys closed 1 year ago

cleborys commented 1 year ago

RemoveFromTree will panic when called on Leaf nodes, since it sets the children of the passed node to nil, but setting children on Leaf nodes panics.

Is there a reason for that behavior or could this be adapted to allow removing leaf nodes, too? For example, this problem may arise when traversing the tree after parsing and selectively removing nodes, e.g. all headlines matching a certain expression.

I am happy to create a PR if wanted.

kjk commented 1 year ago

Yes, please do a PR.

The code was only tested for the use case used in a parser so it's plausible I missed other use cases.

cleborys commented 1 year ago

Thanks for the quick response. I will mark this resolved.