From 730d12ee48c6966f7c96aca4f6917bf67261b5b0 Mon Sep 17 00:00:00 2001 From: "Suraj N. Kurapati" Date: Tue, 12 Jul 2011 14:31:03 -0700 Subject: [PATCH 1/3] extconf: assume long is doubleword & short is word --- ext/extconf.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ext/extconf.rb b/ext/extconf.rb index 1bbfe49..f9a9b5d 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -7,13 +7,8 @@ HAVE_RAND = have_func('rand') HAVE_SRAND = have_func('srand') -def sized_int(size, types) - types.find { |type| check_sizeof(type) == 4 } || - abort("no int with size #{size}") -end - -DWORD = sized_int(4, ["unsigned long", "unsigned int"]) -WORD = sized_int(2, ["unsigned int", "unsigned short"]) +DWORD = "unsigned long" +WORD = "unsigned short" BYTE = "unsigned char" $defs.push("-DDWORD='#{DWORD}'") From b03f0172270a3b4b2429fdb7739acf37a10e0495 Mon Sep 17 00:00:00 2001 From: "Suraj N. Kurapati" Date: Wed, 13 Jul 2011 09:56:54 -0700 Subject: [PATCH 2/3] use Discount flags instead of custom attributes --- ext/rdiscount.c | 69 ++++++++++++----------------------- lib/rdiscount.rb | 83 +++++++++++++++++++----------------------- test/markdown_test.rb | 51 +++++++++++++------------- test/rdiscount_test.rb | 36 +++++++++--------- 4 files changed, 104 insertions(+), 135 deletions(-) diff --git a/ext/rdiscount.c b/ext/rdiscount.c index 86167ff..dd38f2d 100644 --- a/ext/rdiscount.c +++ b/ext/rdiscount.c @@ -71,57 +71,34 @@ rb_rdiscount_toc_content(int argc, VALUE *argv, VALUE self) int rb_rdiscount__get_flags(VALUE ruby_obj) { - /* compile flags */ - int flags = MKD_TABSTOP | MKD_NOHEADER; - - /* smart */ - if ( rb_funcall(ruby_obj, rb_intern("smart"), 0) != Qtrue ) - flags = flags | MKD_NOPANTS; - - /* filter_html */ - if ( rb_funcall(ruby_obj, rb_intern("filter_html"), 0) == Qtrue ) - flags = flags | MKD_NOHTML; - - /* generate_toc */ - if ( rb_funcall(ruby_obj, rb_intern("generate_toc"), 0) == Qtrue) - flags = flags | MKD_TOC; - - /* no_image */ - if ( rb_funcall(ruby_obj, rb_intern("no_image"), 0) == Qtrue) - flags = flags | MKD_NOIMAGE; - - /* no_links */ - if ( rb_funcall(ruby_obj, rb_intern("no_links"), 0) == Qtrue) - flags = flags | MKD_NOLINKS; - - /* no_tables */ - if ( rb_funcall(ruby_obj, rb_intern("no_tables"), 0) == Qtrue) - flags = flags | MKD_NOTABLES; - - /* strict */ - if ( rb_funcall(ruby_obj, rb_intern("strict"), 0) == Qtrue) - flags = flags | MKD_STRICT; - - /* autolink */ - if ( rb_funcall(ruby_obj, rb_intern("autolink"), 0) == Qtrue) - flags = flags | MKD_AUTOLINK; - - /* safelink */ - if ( rb_funcall(ruby_obj, rb_intern("safelink"), 0) == Qtrue) - flags = flags | MKD_SAFELINK; - - /* no_pseudo_protocols */ - if ( rb_funcall(ruby_obj, rb_intern("no_pseudo_protocols"), 0) == Qtrue) - flags = flags | MKD_NO_EXT; - - - return flags; + VALUE flags = rb_funcall(ruby_obj, rb_intern("flags"), 0); + return NUM2INT(rb_funcall(flags, rb_intern("to_i"), 0)); } - void Init_rdiscount() { rb_cRDiscount = rb_define_class("RDiscount", rb_cObject); + rb_define_const(rb_cRDiscount, "MKD_NOLINKS", INT2NUM(MKD_NOLINKS)); + rb_define_const(rb_cRDiscount, "MKD_NOIMAGE", INT2NUM(MKD_NOIMAGE)); + rb_define_const(rb_cRDiscount, "MKD_NOPANTS", INT2NUM(MKD_NOPANTS)); + rb_define_const(rb_cRDiscount, "MKD_NOHTML", INT2NUM(MKD_NOHTML)); + rb_define_const(rb_cRDiscount, "MKD_STRICT", INT2NUM(MKD_STRICT)); + rb_define_const(rb_cRDiscount, "MKD_TAGTEXT", INT2NUM(MKD_TAGTEXT)); + rb_define_const(rb_cRDiscount, "MKD_NO_EXT", INT2NUM(MKD_NO_EXT)); + rb_define_const(rb_cRDiscount, "MKD_CDATA", INT2NUM(MKD_CDATA)); + rb_define_const(rb_cRDiscount, "MKD_NOSUPERSCRIPT", INT2NUM(MKD_NOSUPERSCRIPT)); + rb_define_const(rb_cRDiscount, "MKD_NORELAXED", INT2NUM(MKD_NORELAXED)); + rb_define_const(rb_cRDiscount, "MKD_NOTABLES", INT2NUM(MKD_NOTABLES)); + rb_define_const(rb_cRDiscount, "MKD_NOSTRIKETHROUGH", INT2NUM(MKD_NOSTRIKETHROUGH)); + rb_define_const(rb_cRDiscount, "MKD_TOC", INT2NUM(MKD_TOC)); + rb_define_const(rb_cRDiscount, "MKD_1_COMPAT", INT2NUM(MKD_1_COMPAT)); + rb_define_const(rb_cRDiscount, "MKD_AUTOLINK", INT2NUM(MKD_AUTOLINK)); + rb_define_const(rb_cRDiscount, "MKD_SAFELINK", INT2NUM(MKD_SAFELINK)); + rb_define_const(rb_cRDiscount, "MKD_NOHEADER", INT2NUM(MKD_NOHEADER)); + rb_define_const(rb_cRDiscount, "MKD_TABSTOP", INT2NUM(MKD_TABSTOP)); + rb_define_const(rb_cRDiscount, "MKD_NODIVQUOTE", INT2NUM(MKD_NODIVQUOTE)); + rb_define_const(rb_cRDiscount, "MKD_NOALPHALIST", INT2NUM(MKD_NOALPHALIST)); + rb_define_const(rb_cRDiscount, "MKD_NODLIST", INT2NUM(MKD_NODLIST)); rb_define_method(rb_cRDiscount, "to_html", rb_rdiscount_to_html, -1); rb_define_method(rb_cRDiscount, "toc_content", rb_rdiscount_toc_content, -1); } diff --git a/lib/rdiscount.rb b/lib/rdiscount.rb index c732704..d9ac4db 100644 --- a/lib/rdiscount.rb +++ b/lib/rdiscount.rb @@ -29,64 +29,55 @@ class RDiscount # Original Markdown formatted text. attr_reader :text - # Set true to have smarty-like quote translation performed. - attr_accessor :smart + # Integer containing bit flags for the underlying Discount library. + attr_accessor :flags # Do not output