Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

filter_html/filter_styles support; extension/class renaming

The markdown extension has been renamed peg_markdown. The
class has been renamed PEGMarkdown. You can still just:
require 'markdown' -- the ::Markdown constant will be set
to PEGMarkdown if it's not already defined. IOW, this should
be a mostly backward compatible change.
  • Loading branch information...
commit d49de5c225420b99389e5232fb84af16c42d49b3 1 parent 532ae5e
@rtomayko authored
View
11 Rakefile
@@ -11,7 +11,7 @@ spec =
Gem::Specification.new do |s|
s.name = "rpeg-markdown"
s.version = VERS
- s.summary = "Ruby extension library for peg-markdown"
+ s.summary = "Fast and correct Markdown implementation"
s.files = FileList[
'README','LICENSE','Rakefile',
'{lib,ext,test}/**.rb','ext/*.{c,h}',
@@ -78,17 +78,18 @@ file 'ext/Makefile' => FileList['ext/{extconf.rb,*.c,*.h,*.rb}'] do
end
CLEAN.include 'ext/Makefile'
-file "ext/markdown.#{DLEXT}" => FileList['ext/Makefile', 'ext/*.{c,h,rb}'] do |f|
+file "ext/peg_markdown.#{DLEXT}" => FileList['ext/Makefile', 'ext/*.{c,h,rb}'] do |f|
sh 'cd ext && make'
end
CLEAN.include 'ext/*.{o,bundle,so}'
-file "lib/markdown.#{DLEXT}" => "ext/markdown.#{DLEXT}" do |f|
+file "lib/peg_markdown.#{DLEXT}" => "ext/peg_markdown.#{DLEXT}" do |f|
cp f.prerequisites, "lib/", :preserve => true
end
+CLEAN.include "lib/*.{so,bundle}"
-desc 'Build the peg-markdown extension'
-task :build => "lib/markdown.#{DLEXT}"
+desc 'Build the peg_markdown extension'
+task :build => "lib/peg_markdown.#{DLEXT}"
desc 'Run unit and conformance tests'
task :test => [ 'test:unit', 'test:conformance' ]
View
6 ext/extconf.rb
@@ -1,8 +1,6 @@
require 'mkmf'
-dir_config('markdown')
-
-require 'pp'
+dir_config('peg_markdown')
$objs = %w[markdown.o markdown_lib.o markdown_output.o markdown_parser.o]
@@ -14,4 +12,4 @@
end
create_header
-create_makefile('markdown')
+create_makefile('peg_markdown')
View
26 ext/markdown.c
@@ -3,27 +3,24 @@
static VALUE rb_cMarkdown;
-static ID id_text;
-static ID id_smart;
-static ID id_notes;
-
-#define TABSTOP 4
-#define INCREMENT 4096 /* size of chunks in which to allocate memory */
-
static VALUE
rb_markdown_to_html(int argc, VALUE *argv, VALUE self)
{
/* grab char pointer to markdown input text */
- VALUE text = rb_funcall(self, id_text, 0);
+ VALUE text = rb_funcall(self, rb_intern("text"), 0);
Check_Type(text, T_STRING);
char * ptext = StringValuePtr(text);
/* flip extension bits */
int extensions = 0;
- if ( rb_funcall(self, id_smart, 0) == Qtrue )
+ if ( rb_funcall(self, rb_intern("smart"), 0) == Qtrue )
extensions = extensions | EXT_SMART ;
- if ( rb_funcall(self, id_notes, 0) == Qtrue )
+ if ( rb_funcall(self, rb_intern("notes"), 0) == Qtrue )
extensions = extensions | EXT_NOTES ;
+ if ( rb_funcall(self, rb_intern("filter_html"), 0) == Qtrue )
+ extensions = extensions | EXT_FILTER_HTML ;
+ if ( rb_funcall(self, rb_intern("filter_styles"), 0) == Qtrue )
+ extensions = extensions | EXT_FILTER_STYLES ;
char *html = markdown_to_string(ptext, extensions, HTML_FORMAT);
VALUE result = rb_str_new2(html);
@@ -32,14 +29,9 @@ rb_markdown_to_html(int argc, VALUE *argv, VALUE self)
return result;
}
-void Init_markdown()
+void Init_peg_markdown()
{
- /* Initialize frequently used Symbols */
- id_text = rb_intern("text");
- id_smart = rb_intern("smart");
- id_notes = rb_intern("notes");
-
- rb_cMarkdown = rb_define_class("Markdown", rb_cObject);
+ rb_cMarkdown = rb_define_class("PEGMarkdown", rb_cObject);
rb_define_method(rb_cMarkdown, "to_html", rb_markdown_to_html, -1);
}
View
42 lib/markdown.rb
@@ -1,41 +1 @@
-require 'markdown.so'
-
-class Markdown
-
- # Original Markdown formatted text.
- attr_reader :text
-
- # Set true to have smarty-like quote translation performed.
- attr_accessor :smart
-
- # Set true to have footnotes processed.
- attr_accessor :notes
-
- # BlueCloth compatible output filtering.
- attr_accessor :filter_styles, :filter_html
-
- # RedCloth compatible line folding -- not used for Markdown but
- # included for compatibility.
- attr_accessor :fold_lines
-
- # Create a new 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>:notes</tt> - Enable footnotes.
- # * <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).
- #
- # NOTE: The <tt>:filter_styles</tt> and <tt>:filter_html</tt> extensions
- # are not yet implemented.
- def initialize(text, *extensions)
- @smart = false
- @notes = false
- @text = text
- extensions.each { |e| send("#{e}=", true) }
- end
-
-end
+require 'peg_markdown'
View
57 lib/peg_markdown.rb
@@ -0,0 +1,57 @@
+require 'peg_markdown.so'
+
+# Front-end to jgm's peg-markdown implementation of Markdown, the humane
+# text markup language.
+#
+# A simple processor:
+# >>> puts Markdown.new("Hello, World.").to_html
+# <p>Hello, World.</p>
+#
+# With other stuff:
+# >>> puts Markdown.new("_Hello -- World!_", :smart, :filter_html).to_html
+# <p><em>Hello World!</em></p>
+#
+class PEGMarkdown
+
+ # Original Markdown formatted text.
+ attr_reader :text
+
+ # Set true to have smarty-like quote translation performed.
+ attr_accessor :smart
+
+ # Set true to have footnotes processed.
+ attr_accessor :notes
+
+ # Do not output <style> 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
+
+ # Included for compatibility with RedCloth's interface.
+ attr_accessor :fold_lines
+
+ # Create a new Markdown processor. The +text+ argument is a string
+ # containing Markdown text. Variable other arguments may be supplied to
+ # set various processing options:
+ #
+ # * <tt>:smart</tt> - Enable SmartyPants processing.
+ # * <tt>:notes</tt> - Enable footnotes.
+ # * <tt>:filter_styles</tt> - Do not output <style> tags included in the
+ # source text.
+ # * <tt>:filter_html</tt> - Do not output raw HTML included in the
+ # source text.
+ # * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
+ #
+ def initialize(text, *extensions)
+ @text = text
+ @smart = false
+ @notes = false
+ @filter_styles = false
+ @filter_html = false
+ extensions.each { |e| send("#{e}=", true) }
+ end
+
+end
+
+Markdown = PEGMarkdown unless defined? Markdown
View
2  test/markdown_test.rb
@@ -53,6 +53,8 @@ def test_that_redcloth_to_html_with_single_arg_is_supported
assert_nothing_raised(ArgumentError) { markdown.to_html(true) }
end
+
+
# Build tests for each file in the MarkdownTest test suite
Dir["#{MARKDOWN_TEST_DIR}/Tests/*.text"].each do |text_file|
Please sign in to comment.
Something went wrong with that request. Please try again.