Merge branch 'redcarpet-update' of https://github.com/tombell/jekyll into tombell-redcarpet-update

This commit is contained in:
Tom Preston-Werner 2012-12-15 14:09:55 -08:00
commit 098da3d3fa
3 changed files with 44 additions and 9 deletions

View File

@ -28,7 +28,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('directory_watcher', "~> 1.1")
s.add_runtime_dependency('maruku', "~> 0.5")
s.add_runtime_dependency('kramdown', "~> 0.13.4")
s.add_runtime_dependency('pygments.rb', "~> 0.2.12")
s.add_runtime_dependency('pygments.rb', "~> 0.3.2")
s.add_development_dependency('rake', "~> 0.9")
s.add_development_dependency('rdoc', "~> 3.11")
@ -38,7 +38,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.1.1")
# = MANIFEST =
s.files = %w[

View File

@ -8,12 +8,28 @@ module Jekyll
def setup
return if @setup
# Set the Markdown interpreter (and Maruku self.config, if necessary)
case @config['markdown']
when 'redcarpet'
begin
require 'redcarpet'
@redcarpet_extensions = @config['redcarpet']['extensions'].map { |e| e.to_sym }
@renderer ||= Class.new(Redcarpet::Render::HTML) do
def block_code(code, lang)
lang = lang && lang.split.first || "text"
output = add_code_tags(
Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }),
lang
)
end
def add_code_tags(code, lang)
code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
code = code.sub(/<\/pre>/,"</code></pre>")
end
end
@redcarpet_extensions = {}
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install redcarpet'
@ -30,8 +46,6 @@ module Jekyll
when 'rdiscount'
begin
require 'rdiscount'
# Load rdiscount extensions
@rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:'
@ -88,7 +102,10 @@ module Jekyll
setup
case @config['markdown']
when 'redcarpet'
Redcarpet.new(content, *@redcarpet_extensions).to_html
@redcarpet_extensions[:fenced_code_blocks] = !@redcarpet_extensions[:no_fenced_code_blocks]
@renderer.send :include, Redcarpet::Render::SmartyPants if @redcarpet_extensions[:smart]
markdown = Redcarpet::Markdown.new(@renderer.new(@redcarpet_extensions), @redcarpet_extensions)
markdown.render(content)
when 'kramdown'
# Check for use of coderay
if @config['kramdown']['use_coderay']

View File

@ -4,7 +4,7 @@ class TestRedcarpet < Test::Unit::TestCase
context "redcarpet" do
setup do
config = {
'redcarpet' => { 'extensions' => ['smart'] },
'redcarpet' => { 'extensions' => ['smart', 'strikethrough', 'filter_html'] },
'markdown' => 'redcarpet'
}
@markdown = MarkdownConverter.new config
@ -14,8 +14,26 @@ 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 options" 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
should "render fenced code blocks" do
assert_equal "<div class=\"highlight\"><pre><code class=\"ruby\"><span class=\"nb\">puts</span> <span class=\"s2\">&quot;Hello world&quot;</span>\n</code></pre>\n</div>", @markdown.convert(
<<-EOS
```ruby
puts "Hello world"
```
EOS
).strip
end
end
end