static VALUE rb_redcarpet_md__new(int argc, VALUE *argv, VALUE klass)
{
VALUE rb_markdown, rb_rndr, hash, rndr_options;
unsigned int extensions = 0;
struct rb_redcarpet_rndr *rndr;
struct sd_markdown *markdown;
if (rb_scan_args(argc, argv, "11", &rb_rndr, &hash) == 2)
rb_redcarpet_md_flags(hash, &extensions);
if (rb_obj_is_kind_of(rb_rndr, rb_cClass))
rb_rndr = rb_funcall(rb_rndr, rb_intern("new"), 0);
if (!rb_obj_is_kind_of(rb_rndr, rb_cRenderBase))
rb_raise(rb_eTypeError, "Invalid Renderer instance given");
/**
* Automatically enable the `fenced_code_blocks` option if
* given a kind of `HTML_TOC` object since many languages
* like Ruby use the sharp to comment code so these comments
* would be processed as titles.
*/
if (rb_obj_is_kind_of(rb_rndr, rb_cRenderHTML_TOC))
extensions |= MKDEXT_FENCED_CODE;
rndr = rb_redcarpet_rndr_unwrap(rb_rndr);
/* Merge the current options in the @options hash */
if (hash != Qnil) {
rndr_options = rb_funcall(rb_iv_get(rb_rndr, "@options"), rb_intern("merge"), 1, hash);
rb_iv_set(rb_rndr, "@options", rndr_options);
}
markdown = sd_markdown_new(extensions, 16, &rndr->callbacks, &rndr->options);
if (!markdown)
rb_raise(rb_eRuntimeError, "Failed to create new Renderer class");
rb_markdown = TypedData_Wrap_Struct(klass, &rb_redcarpet_md__type, markdown);
rb_iv_set(rb_markdown, "@renderer", rb_rndr);
return rb_markdown;
}