gjtorikian / commonmarker

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

Add support for rendering XML from cmark-gfm #144

Closed digitalmoksha closed 2 years ago

digitalmoksha commented 2 years ago

cmark-gfm supports rending to the XML format and exports the correct functions. So I've added support to the Node class so you can now do doc.to_xml.

Also added support for a new command line option, —to=FORMAT (which mirrors the option in cmark-gfm) that allows you to specify the output format. Since to_plaintext and to_commonmark were already supported internally, possible output formats is html, xml, plaintext, and CommonMark. For example commonmarker --to=xml

Currently man and latex are not supported output formats.

digitalmoksha commented 2 years ago

@gjtorikian I think this is ready for your consideration if you have time.

The reason I added this is that we would like to be able to output as XML, particularly since that's currently the only format that supports inline source mapping.

gjtorikian commented 2 years ago

I think this looks great. Thank you for your contribution.

I tend to lean extra hard on the side of caution/paranoia when working with FFI. Could you add a few more "malicious" test cases, such as:

Those are a few I can think of off the top of my head. Obviously it looks like the code would be able to handle such situations but better safe than sorry! At least the first one, in any event, should be test.

The README should also be updated, probably a quick blurb under the OPTIONS header to let people know.

digitalmoksha commented 2 years ago

Thanks @gjtorikian and @kivikakk for taking a look!

I've added some additional specs, and made unrecognized formats abort like the other options.

I also took a stab at updating the README.

gjtorikian commented 2 years ago

Nice nice nice. Thank you!