Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions bin/rdiscount
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env ruby
# Usage: rdiscount [<file>...]
# Convert one or more Markdown files to HTML and write to standard output. With
# no <file> or when <file> is '-', read Markdown source text from standard input.
#
# Usage: [env RDISCOUNT_EXTENSIONS='<extension>,...'] rdiscount [<file>...]
#
# Convert one or more Markdown files to HTML and write to standard output.
# With no <file> or when <file> 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]
Expand All @@ -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)
9 changes: 2 additions & 7 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")
Expand Down
69 changes: 23 additions & 46 deletions ext/rdiscount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
83 changes: 37 additions & 46 deletions lib/rdiscount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt><style></tt> tags included in the source text.
attr_accessor :filter_styles

# Do not output any raw HTML included in the source text.
attr_accessor :filter_html

# RedCloth compatible line folding -- not used for Markdown but
# included for compatibility.
attr_accessor :fold_lines

# Enable Table Of Contents generation
attr_accessor :generate_toc

# Do not process <tt>![]</tt> and remove <tt><img></tt> tags from the output.
attr_accessor :no_image

# Do not process <tt>[]</tt> and remove <tt><a></tt> tags from the output.
attr_accessor :no_links

# Do not process tables
attr_accessor :no_tables

# Disable superscript and relaxed emphasis processing.
attr_accessor :strict

# Convert URL in links, even if they aren't encased in <tt><></tt>
attr_accessor :autolink

# Don't make hyperlinks from <tt>[][]</tt> links that have unknown URL types.
attr_accessor :safelink

# Do not process pseudo-protocols like <tt>[](id:name)</tt>
attr_accessor :no_pseudo_protocols

# Create a RDiscount Markdown processor. The +text+ argument
# should be a string containing Markdown text. Additional arguments may be
# supplied to set various processing options:
# Create a RDiscount Markdown processor. The +text+ argument should be a
# string containing Markdown text. Additional arguments may be supplied to
# set various processing options:
#
# * <tt>:smart</tt> - Enable SmartyPants processing.
# * <tt>:filter_styles</tt> - Do not output <tt><style></tt> tags.
# * <tt>:filter_html</tt> - Do not output any raw HTML tags included in
# the source text.
# * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
# * <tt>:generate_toc</tt> - Enable Table Of Contents generation
# * <tt>:no_image</tt> - Do not output any <tt><img></tt> tags.
# * <tt>:no_links</tt> - Do not output any <tt><a></tt> tags.
# * <tt>:no_tables</tt> - Do not output any tables.
# * <tt>:strict</tt> - Disable superscript and relaxed emphasis processing.
# * <tt>:autolink</tt> - Greedily urlify links.
# * <tt>:safelink</tt> - Do not make links for unknown URL types.
# * <tt>:no_pseudo_protocols</tt> - Do not process pseudo-protocols.
# * <tt>:filter_styles</tt> - Do not output <tt><style></tt> tags.
# * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
# * <tt>:MKD_NOLINKS</tt> - Don't do link processing, block <a> tags
# * <tt>:MKD_NOIMAGE</tt> - Don't do image processing, block <img>
# * <tt>:MKD_NOPANTS</tt> - Don't run smartypants()
# * <tt>:MKD_NOHTML</tt> - Don't allow raw html through AT ALL
# * <tt>:MKD_STRICT</tt> - Disable SUPERSCRIPT, RELAXED_EMPHASIS
# * <tt>:MKD_TAGTEXT</tt> - Process text inside an html tag; no <em>, no <bold>, no html or [] expansion
# * <tt>:MKD_NO_EXT</tt> - Don't allow pseudo-protocols
# * <tt>:MKD_CDATA</tt> - Generate code for xml ![CDATA[...]]
# * <tt>:MKD_NOSUPERSCRIPT</tt> - No A^B
# * <tt>:MKD_NORELAXED</tt> - Emphasis happens everywhere
# * <tt>:MKD_NOTABLES</tt> - Don't process PHP Markdown Extra tables.
# * <tt>:MKD_NOSTRIKETHROUGH</tt> - Forbid ~~strikethrough~~
# * <tt>:MKD_TOC</tt> - Do table-of-contents processing
# * <tt>:MKD_1_COMPAT</tt> - Compatability with MarkdownTest_1.0
# * <tt>:MKD_AUTOLINK</tt> - Make http://foo.com a link even without <>s
# * <tt>:MKD_SAFELINK</tt> - Paranoid check for link protocol
# * <tt>:MKD_NOHEADER</tt> - Don't process document headers
# * <tt>:MKD_TABSTOP</tt> - Expand tabs to 4 spaces
# * <tt>:MKD_NODIVQUOTE</tt> - Forbid >%class% blocks
# * <tt>:MKD_NOALPHALIST</tt> - Forbid alphabetic lists
# * <tt>:MKD_NODLIST</tt> - Forbid definition lists
#
def initialize(text, *extensions)
@text = text
extensions.each { |e| send("#{e}=", true) }
@flags = 0
extensions.each do |ext|
writer = "#{ext}="
if respond_to? writer
send writer, true
else
@flags |= RDiscount.const_get(ext)
end
end
end

end
Expand Down
107 changes: 102 additions & 5 deletions man/rdiscount.1
Original file line number Diff line number Diff line change
@@ -1,22 +1,119 @@
.\" generated with Ronn/v0.6.8
.\" http://github.com/rtomayko/ronn/
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "RDISCOUNT" "1" "April 2010" "" "RUBY"
.TH "RDISCOUNT" "1" "July 2011" "" "RUBY"
.
.SH "NAME"
\fBrdiscount\fR \- humane markup to HTML conversion tool
.
.SH "SYNOPSIS"
\fBrdiscount\fR [\fIfile\fR\.\.\.]
[\fBenv\fR RDISCOUNT_EXTENSIONS=\'\fIextension\fR,\.\.\.\'] \fBrdiscount\fR [\fIfile\fR\.\.\.]
.
.SH "DESCRIPTION"
The \fBrdiscount\fR utility reads one or more markdown(7)\-formatted text \fIfile\fRs and writes HTML to standard output\. With no \fIfile\fR, or when \fIfile\fR is \'\-\', \fBrdiscount\fR reads source text from standard input\.
.
.P
The \fBRDISCOUNT_EXTENSIONS\fR environment variable can specify a comma\-separated list of Markdown processing \fIextension\fRs to enable (see \fBEXTENSIONS\fR below)\.
.
.SH "EXTENSIONS"
.
.TP
\fBfilter_styles\fR
Do not output \fB<style>\fR tags\.
.
.TP
\fBfold_lines\fR
RedCloth compatible line folding (not used)\.
.
.TP
\fBMKD_NOLINKS\fR
Don\'t do link processing, block \fB<a>\fR tags
.
.TP
\fBMKD_NOIMAGE\fR
Don\'t do image processing, block \fB<img>\fR
.
.TP
\fBMKD_NOPANTS\fR
Don\'t run smartypants()
.
.TP
\fBMKD_NOHTML\fR
Don\'t allow raw html through AT ALL
.
.TP
\fBMKD_STRICT\fR
Disable SUPERSCRIPT, RELAXED_EMPHASIS
.
.TP
\fBMKD_TAGTEXT\fR
Process text inside an html tag; no \fB<em>\fR, no \fB<bold>\fR, no html or [] expansion
.
.TP
\fBMKD_NO_EXT\fR
Don\'t allow pseudo\-protocols
.
.TP
\fBMKD_CDATA\fR
Generate code for xml ![CDATA[\.\.\.]]
.
.TP
\fBMKD_NOSUPERSCRIPT\fR
No A
.
.TP
\fBMKD_NORELAXED\fR
Emphasis happens everywhere
.
.TP
\fBMKD_NOTABLES\fR
Don\'t process PHP Markdown Extra tables\.
.
.TP
\fBMKD_NOSTRIKETHROUGH\fR
Forbid
.
.TP
\fBMKD_TOC\fR
Do table\-of\-contents processing
.
.TP
\fBMKD_1_COMPAT\fR
Compatability with MarkdownTest_1\.0
.
.TP
\fBMKD_AUTOLINK\fR
Make http://foo\.com a link even without \fB<>\fRs
.
.TP
\fBMKD_SAFELINK\fR
Paranoid check for link protocol
.
.TP
\fBMKD_NOHEADER\fR
Don\'t process document headers
.
.TP
\fBMKD_TABSTOP\fR
Expand tabs to 4 spaces
.
.TP
\fBMKD_NODIVQUOTE\fR
Forbid >%class% blocks
.
.TP
\fBMKD_NOALPHALIST\fR
Forbid alphabetic lists
.
.TP
\fBMKD_NODLIST\fR
Forbid definition lists
.
.SH "RETURN VALUES"
The \fBrdiscount\fR utility exits 0 on success, and > 0 if an error occurs\.
.
.SH "SEE ALSO"
markdown(7)
markdown(7), env(1)
.
.SH "AUTHOR"
Ryan Tomayko \fIhttp://tomayko\.com/about\fR
Loading