ext/rdiscount.c in rtomayko-rdiscount-1.3.1.2 vs ext/rdiscount.c in rtomayko-rdiscount-1.3.4

- old
+ new

@@ -29,33 +29,39 @@ mkd_cleanup(doc); return buf; } -#if 0 static VALUE rb_rdiscount_toc_content(int argc, VALUE *argv, VALUE self) { + char *res; + int szres; + int flags = rb_rdiscount__get_flags(self); /* grab char pointer to markdown input text */ VALUE text = rb_funcall(self, rb_intern("text"), 0); Check_Type(text, T_STRING); /* allocate a ruby string buffer and wrap it in a stream */ VALUE buf = rb_str_buf_new(4096); - FILE *stream = rb_str_io_new(buf); MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags); - mkd_compile(doc, flags); - mkd_generatetoc(doc, stream); - fclose(stream); + if ( mkd_compile(doc, flags) ) { + szres = mkd_toc(doc, &res); + if ( szres != EOF ) { + rb_str_cat(buf, res, szres); + rb_str_cat(buf, "\n", 1); + } + } + mkd_cleanup(doc); + return buf; } -#endif int rb_rdiscount__get_flags(VALUE ruby_obj) { /* compile flags */ int flags = MKD_TABSTOP | MKD_NOHEADER; @@ -78,11 +84,9 @@ void Init_rdiscount() { rb_cRDiscount = rb_define_class("RDiscount", rb_cObject); rb_define_method(rb_cRDiscount, "to_html", rb_rdiscount_to_html, -1); -#if 0 rb_define_method(rb_cRDiscount, "toc_content", rb_rdiscount_toc_content, -1); -#endif } /* vim: set ts=4 sw=4: */