Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Redcarpet 2.0 #450

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion jekyll.gemspec
Expand Up @@ -37,7 +37,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('cucumber', "= 1.1") s.add_development_dependency('cucumber', "= 1.1")
s.add_development_dependency('RedCloth', "~> 4.2") s.add_development_dependency('RedCloth', "~> 4.2")
s.add_development_dependency('rdiscount', "~> 1.6") s.add_development_dependency('rdiscount', "~> 1.6")
s.add_development_dependency('redcarpet', "~> 1.9") s.add_development_dependency('redcarpet', "~> 2.0")


# = MANIFEST = # = MANIFEST =
s.files = %w[ s.files = %w[
Expand Down
24 changes: 22 additions & 2 deletions lib/jekyll/converters/markdown.rb
Expand Up @@ -13,7 +13,26 @@ def setup
when 'redcarpet' when 'redcarpet'
begin begin
require 'redcarpet' require 'redcarpet'
@redcarpet_extensions = @config['redcarpet']['extensions'].map { |e| e.to_sym } # Redcarpet 2.x, converter can be instantiated,
# and the format of renderer options is in hash, not in array

# convert extensions array to hash form
# [ 'ext_a', 'ext_b', 'ext_c' ]
# => { :ext_a => true, :ext_b => true, :ext_c => true }
redcarpet_extensions = Hash[@config['redcarpet']['extensions'].map { |e| [e.to_sym, true] }]
redcarpet_render_options = Hash[@config['redcarpet']['render_options'].map { |e| [e.to_sym, true] }] rescue {}

custom_redcarpet_class = Class.new(Redcarpet::Render::HTML)

# add SmartyPants module into the class if 'smart' is specified
if redcarpet_extensions[:smart] == true
custom_redcarpet_class.class_eval do
include Redcarpet::Render::SmartyPants
end
end

# TODO: support Renderer options
@converter = Redcarpet::Markdown.new(custom_redcarpet_class.new(redcarpet_render_options), redcarpet_extensions)
rescue LoadError rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:' STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install redcarpet' STDERR.puts ' $ [sudo] gem install redcarpet'
Expand Down Expand Up @@ -88,7 +107,8 @@ def convert(content)
setup setup
case @config['markdown'] case @config['markdown']
when 'redcarpet' when 'redcarpet'
Redcarpet.new(content, *@redcarpet_extensions).to_html # Redcarpet 2.x, converter can be instantiated
@converter.render(content)
when 'kramdown' when 'kramdown'
# Check for use of coderay # Check for use of coderay
if @config['kramdown']['use_coderay'] if @config['kramdown']['use_coderay']
Expand Down
15 changes: 13 additions & 2 deletions test/test_redcarpet.rb
Expand Up @@ -4,7 +4,10 @@ class TestRedcarpet < Test::Unit::TestCase
context "redcarpet" do context "redcarpet" do
setup do setup do
config = { config = {
'redcarpet' => { 'extensions' => ['smart'] }, 'redcarpet' => {
'extensions' => ['strikethrough', 'smart'],
'render_options' => ['filter_html']
},
'markdown' => 'redcarpet' 'markdown' => 'redcarpet'
} }
@markdown = MarkdownConverter.new config @markdown = MarkdownConverter.new config
Expand All @@ -14,8 +17,16 @@ class TestRedcarpet < Test::Unit::TestCase
assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip
end end


should "pass redcarpet extensions" do should "pass redcarpet SmartyPants option" do
assert_equal "<p>&ldquo;smart&rdquo;</p>", @markdown.convert('"smart"').strip assert_equal "<p>&ldquo;smart&rdquo;</p>", @markdown.convert('"smart"').strip
end end

should "pass redcarpet extensions" do
assert_equal "<p><del>deleted</del></p>", @markdown.convert('~~deleted~~').strip
end

should "pass redcarpet render options" do
assert_equal "<p><strong>bad code not here</strong>: i am bad</p>", @markdown.convert('**bad code not here**: <script>i am bad</script>').strip
end
end end
end end