gjtorikian / commonmarker

Ruby wrapper for the comrak (CommonMark parser) Rust crate
MIT License
416 stars 80 forks source link

Reintroduce AST parse/walk #276

Closed gjtorikian closed 2 months ago

gjtorikian commented 5 months ago

This PR reintroduces a feature which I had intentionally ripped out in the Rust write: the ability to parse text and manipulate the resulting node(s).

To accomplish this, I had to do some truly awkward " serializing " as I couldn't get magnus to play very nicely with comrak's use of typed_arena (and more specifically, lifetimes). I end up having to get the node data, unpack it, iterate over it, and then turn the raw comrak data into Commonmarker Ruby-ish data. It's kind of a beautiful mess.

I only implemented a few AST methods for now, as I only needed a few for the project I'm working on.

xref https://github.com/gjtorikian/commonmarker/issues/199

robaiken commented 1 month ago

Thanks @gjtorikian for getting this over the line! 🎉