From 851172b5ef1a7c649296dd00390c067168eebc0f Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 31 May 2011 14:40:21 -0700 Subject: [PATCH] Replace rdiscount filter with config-aware markdownify. --- History.txt | 1 + lib/jekyll/filters.rb | 12 ++++++++---- lib/jekyll/site.rb | 13 +++++++++++++ test/helper.rb | 1 - test/test_filters.rb | 9 +++++++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/History.txt b/History.txt index 042e9074..326affc1 100644 --- a/History.txt +++ b/History.txt @@ -3,6 +3,7 @@ * Add command line importer functionality (#253) * Add Recarpet Markdown support (#318) * Make markdown/textile extensions configurable (#312) + * Add `markdownify` filter * Minor Enhancements * Switch to Albino gem * Bundler support diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 8fd3f4c0..eb61d84a 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -9,16 +9,20 @@ module Jekyll # # Returns the HTML formatted String. def textilize(input) - TextileConverter.new.convert(input) + site = @context.registers[:site] + converter = site.getConverterImpl(Jekyll::TextileConverter) + converter.convert(input) end - # Convert a Markdown string into HTML output using RDiscount. + # Convert a Markdown string into HTML output. # # input - The Markdown String to convert. # # Returns the HTML formatted String. - def rdiscount(input) - RDiscount.new(input).to_html + def markdownify(input) + site = @context.registers[:site] + converter = site.getConverterImpl(Jekyll::MarkdownConverter) + converter.convert(input) end # Format a date in short format e.g. "27 Jan 2011". diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 41905d65..69ea43e7 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -314,5 +314,18 @@ module Jekyll end end + # Get the implementation class for the given Converter. + # + # klass - The Class of the Converter to fetch. + # + # Returns the Converter instance implementing the given Converter. + def getConverterImpl(klass) + matches = self.converters.select { |c| c.class == klass } + if impl = matches.first + impl + else + raise "Converter implementation not found for #{klass}" + end + end end end diff --git a/test/helper.rb b/test/helper.rb index 2d2e9871..c6a8a763 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -12,7 +12,6 @@ require 'redgreen' if RUBY_VERSION < '1.9' require 'shoulda' require 'rr' - include Jekyll # Send STDERR into the void to suppress program output messages diff --git a/test/test_filters.rb b/test/test_filters.rb index 4b554319..205d4bca 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -3,6 +3,11 @@ require 'helper' class TestFilters < Test::Unit::TestCase class JekyllFilter include Jekyll::Filters + + def initialize + site = Jekyll::Site.new(Jekyll.configuration({})) + @context = Liquid::Context.new({}, {}, { :site => site }) + end end context "filters" do @@ -14,8 +19,8 @@ class TestFilters < Test::Unit::TestCase assert_equal "

something really simple

", @filter.textilize("something *really* simple") end - should "rdiscount with simple string" do - assert_equal "

something really simple

\n", @filter.rdiscount("something **really** simple") + should "markdownify with simple string" do + assert_equal "

something really simple

", @filter.markdownify("something **really** simple") end should "convert array to sentence string with no args" do