524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
|
# File 'ext/redcarpet/rc_render.c', line 524
static VALUE rb_redcarpet_htmltoc_init(int argc, VALUE *argv, VALUE self)
{
struct rb_redcarpet_rndr *rndr;
unsigned int render_flags = HTML_TOC;
VALUE hash, nesting_level = Qnil;
TypedData_Get_Struct(self, struct rb_redcarpet_rndr, &rb_redcarpet_rndr_type, rndr);
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
Check_Type(hash, T_HASH);
/* Give access to the passed options through `@options` */
rb_iv_set(self, "@options", hash);
/* escape_html */
if (rb_hash_aref(hash, CSTR2SYM("escape_html")) == Qtrue)
render_flags |= HTML_ESCAPE;
/* Nesting level */
nesting_level = rb_hash_aref(hash, CSTR2SYM("nesting_level"));
}
sdhtml_toc_renderer(&rndr->callbacks, (struct html_renderopt *)&rndr->options.html, render_flags);
rb_redcarpet__overload(self, rb_cRenderHTML_TOC);
/* Check whether we are dealing with a Range object by
checking whether the object responds to min and max */
if (rb_respond_to(nesting_level, rb_intern("min")) &&
rb_respond_to(nesting_level, rb_intern("max"))) {
int min = NUM2INT(rb_funcall(nesting_level, rb_intern("min"), 0));
int max = NUM2INT(rb_funcall(nesting_level, rb_intern("max"), 0));
rndr->options.html.toc_data.nesting_bounds[0] = min;
rndr->options.html.toc_data.nesting_bounds[1] = max;
} else if (FIXNUM_P(nesting_level)) {
rndr->options.html.toc_data.nesting_bounds[0] = 1;
rndr->options.html.toc_data.nesting_bounds[1] = NUM2INT(nesting_level);
} else {
rndr->options.html.toc_data.nesting_bounds[0] = 1;
rndr->options.html.toc_data.nesting_bounds[1] = 6;
}
return Qnil;
}
|