diff --git a/Rakefile b/Rakefile index c4a670a..9a30ac7 100644 --- a/Rakefile +++ b/Rakefile @@ -63,7 +63,7 @@ task 'test:conformance' => [:build] do |t| test_version = ENV['MARKDOWN_TEST_VER'] || '1.0.3' lib_dir = "#{pwd}/lib" chdir("test/MarkdownTest_#{test_version}") do - sh "RUBYLIB=#{lib_dir} ./MarkdownTest.pl --script='#{script}' --tidy" + sh "env RDISCOUNT_EXTENSIONS='MKD_NOPANTS' RUBYLIB=#{lib_dir} ./MarkdownTest.pl --script='#{script}' --tidy" end end diff --git a/bin/rdiscount b/bin/rdiscount index 3e3a638..636de30 100755 --- a/bin/rdiscount +++ b/bin/rdiscount @@ -1,7 +1,12 @@ #!/usr/bin/env ruby -# Usage: rdiscount [...] -# Convert one or more Markdown files to HTML and write to standard output. With -# no or when is '-', read Markdown source text from standard input. +# +# Usage: [env RDISCOUNT_EXTENSIONS=',...'] rdiscount [...] +# +# Convert one or more Markdown files to HTML and write to standard output. +# With no or when is '-', read Markdown source text from +# standard input. Optionally, the RDISCOUNT_EXTENSIONS environment variable +# can specify a comma-separated list of extensions to enable in RDiscount. +# if ARGV.include?('--help') File.read(__FILE__).split("\n").grep(/^# /).each do |line| puts line[2..-1] @@ -10,4 +15,5 @@ if ARGV.include?('--help') end require 'rdiscount' -STDOUT.write(RDiscount.new(ARGF.read).to_html) +extensions = ENV['RDISCOUNT_EXTENSIONS'].to_s.split(',') +STDOUT.write(RDiscount.new(ARGF.read, *extensions).to_html) 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}'") 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