comrak icon indicating copy to clipboard operation
comrak copied to clipboard

Allow `c_char` options to be NULL

Open gjtorikian opened this issue 3 years ago • 0 comments

What the title says!

ComrakOptions::default() sets the header_ids option of extensions to ""; this means that, by default, headers are always given anchor tags (with an ID matching the text content of the header).

In C, there's currently no way of implementing the removal of the header_ids option. This won't work:

comrak_set_extension_option_header_ids(comrak_options, "", 0);

Because it reads just as default does: add the header IDs, but don't add any prefix.

This PR introduces (and tests) a different possibility:

comrak_set_extension_option_header_ids(comrak_options, NULL, 0);

Passing this ☝️ will effectively "turn off" header ID generation by checking to see if the incoming value is NULL. (Some kind of NULL check is necessary here, with or without this change. I was able to segfault the FFI.)

I'm happy to expose a different function to configure this if it doesn't look good!

gjtorikian avatar Jul 27 '22 23:07 gjtorikian