agentofuser / rehype-section

Wraps headings and their contents in `<section>` elements.
https://npm.im/@agentofuser/rehype-section
7 stars 1 forks source link

Use visitor pattern #13

Open agentofuser opened 5 years ago

agentofuser commented 5 years ago

It hadn't occurred to me that the visitor pattern could be used here, so I did the stack-based explicit recursion thing, but that only works it all the headings and content are top-level children of the root element. If they are already nested within, for instance, some arbitrary div, it doesn't work.

remark-sectionize does that much more elegantly.

wooorm commented 5 years ago

I just wrote about tree traversing in https://github.com/syntax-tree/unist/pull/23!

agentofuser commented 5 years ago

That is very helpful, thank you!