Skip to content

Commit

Permalink
Replace rdiscount filter with config-aware markdownify.
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed May 31, 2011
1 parent cae0eaf commit 851172b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions lib/jekyll/filters.rb
Expand Up @@ -9,16 +9,20 @@ module Filters
#
# 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".
Expand Down
13 changes: 13 additions & 0 deletions lib/jekyll/site.rb
Expand Up @@ -314,5 +314,18 @@ def filter_entries(entries)
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
1 change: 0 additions & 1 deletion test/helper.rb
Expand Up @@ -12,7 +12,6 @@
require 'shoulda'
require 'rr'


include Jekyll

# Send STDERR into the void to suppress program output messages
Expand Down
9 changes: 7 additions & 2 deletions test/test_filters.rb
Expand Up @@ -3,6 +3,11 @@
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
Expand All @@ -14,8 +19,8 @@ class JekyllFilter
assert_equal "<p>something <strong>really</strong> simple</p>", @filter.textilize("something *really* simple")
end

should "rdiscount with simple string" do
assert_equal "<p>something <strong>really</strong> simple</p>\n", @filter.rdiscount("something **really** simple")
should "markdownify with simple string" do
assert_equal "<p>something <strong>really</strong> simple</p>", @filter.markdownify("something **really** simple")
end

should "convert array to sentence string with no args" do
Expand Down

0 comments on commit 851172b

Please sign in to comment.