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

# = MANIFEST =
s.files = %w[
Expand Down
24 changes: 22 additions & 2 deletions lib/jekyll/converters/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,26 @@ def setup
when 'redcarpet'
begin
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
STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install redcarpet'
Expand Down Expand Up @@ -88,7 +107,8 @@ def convert(content)
setup
case @config['markdown']
when 'redcarpet'
Redcarpet.new(content, *@redcarpet_extensions).to_html
# Redcarpet 2.x, converter can be instantiated
@converter.render(content)
when 'kramdown'
# Check for use of coderay
if @config['kramdown']['use_coderay']
Expand Down
15 changes: 13 additions & 2 deletions test/test_redcarpet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class TestRedcarpet < Test::Unit::TestCase
context "redcarpet" do
setup do
config = {
'redcarpet' => { 'extensions' => ['smart'] },
'redcarpet' => {
'extensions' => ['strikethrough', 'smart'],
'render_options' => ['filter_html']
},
'markdown' => 'redcarpet'
}
@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
end

should "pass redcarpet extensions" do
should "pass redcarpet SmartyPants option" do
assert_equal "<p>&ldquo;smart&rdquo;</p>", @markdown.convert('"smart"').strip
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