parent
41fa9cda36
commit
e0758ba550
1
Gemfile
1
Gemfile
|
@ -77,7 +77,6 @@ group :jekyll_optional_dependencies do
|
|||
gem "liquid-c", "~> 3.0"
|
||||
gem "pygments.rb", "~> 1.0"
|
||||
gem "rdiscount", "~> 2.0"
|
||||
gem "redcarpet", "~> 3.2", ">= 3.2.3"
|
||||
gem "yajl-ruby", "~> 1.3"
|
||||
end
|
||||
|
||||
|
|
|
@ -81,14 +81,6 @@ Feature: Site configuration
|
|||
And the _site directory should exist
|
||||
And I should see "<a href=\"https://www.google.com\">Google</a>" in "_site/index.html"
|
||||
|
||||
Scenario: Use Redcarpet for markup
|
||||
Given I have an "index.markdown" page that contains "[Google](https://www.google.com)"
|
||||
And I have a configuration file with "markdown" set to "redcarpet"
|
||||
When I run jekyll build
|
||||
Then I should get a zero exit status
|
||||
And the _site directory should exist
|
||||
And I should see "<a href=\"https://www.google.com\">Google</a>" in "_site/index.html"
|
||||
|
||||
Scenario: Highlight code with pygments
|
||||
Given I have an "index.html" page that contains "{% highlight ruby %} puts 'Hello world!' {% endhighlight %}"
|
||||
When I run jekyll build
|
||||
|
|
|
@ -70,10 +70,6 @@ module Jekyll
|
|||
"extensions" => [],
|
||||
},
|
||||
|
||||
"redcarpet" => {
|
||||
"extensions" => [],
|
||||
},
|
||||
|
||||
"kramdown" => {
|
||||
"auto_ids" => true,
|
||||
"toc_levels" => "1..6",
|
||||
|
|
|
@ -30,7 +30,6 @@ module Jekyll
|
|||
# rubocop:disable Naming/AccessorMethodName
|
||||
def get_processor
|
||||
case @config["markdown"].downcase
|
||||
when "redcarpet" then return RedcarpetParser.new(@config)
|
||||
when "kramdown" then return KramdownParser.new(@config)
|
||||
when "rdiscount" then return RDiscountParser.new(@config)
|
||||
else
|
||||
|
@ -44,7 +43,7 @@ module Jekyll
|
|||
# are not in safe mode.)
|
||||
|
||||
def valid_processors
|
||||
%w(rdiscount kramdown redcarpet) + third_party_processors
|
||||
%w(rdiscount kramdown) + third_party_processors
|
||||
end
|
||||
|
||||
# Public: A list of processors that you provide via plugins.
|
||||
|
@ -53,7 +52,7 @@ module Jekyll
|
|||
|
||||
def third_party_processors
|
||||
self.class.constants - \
|
||||
%w(KramdownParser RDiscountParser RedcarpetParser PRIORITIES).map(
|
||||
%w(KramdownParser RDiscountParser PRIORITIES).map(
|
||||
&:to_sym
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,113 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Jekyll::Converters::Markdown::RedcarpetParser
|
||||
module CommonMethods
|
||||
def add_code_tags(code, lang)
|
||||
code = code.to_s
|
||||
code = code.sub(
|
||||
%r!<pre>!,
|
||||
"<pre><code class=\"language-#{lang}\" data-lang=\"#{lang}\">"
|
||||
)
|
||||
code = code.sub(%r!</pre>!, "</code></pre>")
|
||||
code
|
||||
end
|
||||
end
|
||||
|
||||
module WithPygments
|
||||
include CommonMethods
|
||||
def block_code(code, lang)
|
||||
unless defined?(Pygments)
|
||||
Jekyll::External.require_with_graceful_fail("pygments")
|
||||
end
|
||||
lang = lang && lang.split.first || "text"
|
||||
add_code_tags(
|
||||
Pygments.highlight(
|
||||
code,
|
||||
{
|
||||
:lexer => lang,
|
||||
:options => { :encoding => "utf-8" },
|
||||
}
|
||||
),
|
||||
lang
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
module WithoutHighlighting
|
||||
require "cgi"
|
||||
|
||||
include CommonMethods
|
||||
|
||||
def code_wrap(code)
|
||||
"<figure class=\"highlight\"><pre>#{CGI.escapeHTML(code)}</pre></figure>"
|
||||
end
|
||||
|
||||
def block_code(code, lang)
|
||||
lang = lang && lang.split.first || "text"
|
||||
add_code_tags(code_wrap(code), lang)
|
||||
end
|
||||
end
|
||||
|
||||
module WithRouge
|
||||
def block_code(_code, lang)
|
||||
code = "<pre>#{super}</pre>"
|
||||
|
||||
"<div class=\"highlight\">#{add_code_tags(code, lang)}</div>"
|
||||
end
|
||||
|
||||
protected
|
||||
def rouge_formatter(_lexer)
|
||||
require "rouge"
|
||||
::Rouge::Formatters::HTMLLegacy.new(:wrap => false)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(config)
|
||||
unless defined?(Redcarpet)
|
||||
Jekyll::External.require_with_graceful_fail("redcarpet")
|
||||
end
|
||||
@config = config
|
||||
@redcarpet_extensions = {}
|
||||
@config["redcarpet"]["extensions"].each do |e|
|
||||
@redcarpet_extensions[e.to_sym] = true
|
||||
end
|
||||
|
||||
@renderer ||= class_with_proper_highlighter(@config["highlighter"])
|
||||
end
|
||||
|
||||
def class_with_proper_highlighter(highlighter)
|
||||
Class.new(Redcarpet::Render::HTML) do
|
||||
case highlighter
|
||||
when "pygments"
|
||||
include WithPygments
|
||||
when "rouge"
|
||||
Jekyll::External.require_with_graceful_fail(%w(
|
||||
rouge rouge/plugins/redcarpet
|
||||
))
|
||||
|
||||
unless Gem::Version.new(Rouge.version) > Gem::Version.new("1.3.0")
|
||||
abort "Please install Rouge 1.3.0 or greater and try running Jekyll again."
|
||||
end
|
||||
|
||||
include Rouge::Plugins::Redcarpet
|
||||
include CommonMethods
|
||||
include WithRouge
|
||||
else
|
||||
include WithoutHighlighting
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def convert(content)
|
||||
@redcarpet_extensions[:fenced_code_blocks] = \
|
||||
!@redcarpet_extensions[:no_fenced_code_blocks]
|
||||
if @redcarpet_extensions[:smart]
|
||||
@renderer.send :include, Redcarpet::Render::SmartyPants
|
||||
end
|
||||
markdown = Redcarpet::Markdown.new(
|
||||
@renderer.new(@redcarpet_extensions),
|
||||
@redcarpet_extensions
|
||||
)
|
||||
markdown.render(content)
|
||||
end
|
||||
end
|
|
@ -36,7 +36,6 @@ Jekyll.logger = Logger.new(StringIO.new, :error)
|
|||
|
||||
unless jruby?
|
||||
require "rdiscount"
|
||||
require "redcarpet"
|
||||
end
|
||||
|
||||
require "kramdown"
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "helper"
|
||||
|
||||
class TestRedcarpet < JekyllUnitTest
|
||||
context "redcarpet" do
|
||||
setup do
|
||||
if jruby?
|
||||
then skip(
|
||||
"JRuby does not perform well with CExt, test disabled."
|
||||
)
|
||||
end
|
||||
|
||||
@config = {
|
||||
"markdown" => "redcarpet",
|
||||
"redcarpet" => {
|
||||
"extensions" => %w(smart strikethrough filter_html),
|
||||
},
|
||||
}
|
||||
|
||||
@markdown = Converters::Markdown.new @config
|
||||
|
||||
@sample = Jekyll::Utils.strip_heredoc(<<-EOS
|
||||
```ruby
|
||||
puts "Hello world"
|
||||
```
|
||||
EOS
|
||||
)
|
||||
end
|
||||
|
||||
should "pass redcarpet options" do
|
||||
assert_equal "<h1>Some Header</h1>", @markdown.convert("# Some Header #").strip
|
||||
end
|
||||
|
||||
should "pass redcarpet SmartyPants options" do
|
||||
assert_equal "<p>“smart”</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
|
||||
|
||||
context "with pygments enabled" do
|
||||
setup do
|
||||
@markdown = Converters::Markdown.new @config.merge(
|
||||
{ "highlighter" => "pygments" }
|
||||
)
|
||||
end
|
||||
|
||||
should "render fenced code blocks with syntax highlighting" do
|
||||
assert_equal(
|
||||
%(<div class="highlight"><pre><code class="language-ruby" ) +
|
||||
%(data-lang="ruby"><span></span><span class="nb">puts</span> <span ) +
|
||||
%(class="s2">"Hello world"</span>\n</code></pre></div>),
|
||||
@markdown.convert(@sample).strip
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "with rouge enabled" do
|
||||
setup do
|
||||
@markdown = Converters::Markdown.new @config.merge({ "highlighter" => "rouge" })
|
||||
end
|
||||
|
||||
should "render fenced code blocks with syntax highlighting" do
|
||||
assert_equal(
|
||||
%(<div class="highlight"><pre><code class="language-ruby" ) +
|
||||
%(data-lang="ruby"><span class="nb">puts</span> <span ) +
|
||||
%(class="s2">"Hello world"</span>\n</code></pre></div>),
|
||||
@markdown.convert(@sample).strip
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "without any highlighter" do
|
||||
setup do
|
||||
@markdown = Converters::Markdown.new @config.merge({ "highlighter" => nil })
|
||||
end
|
||||
|
||||
should "render fenced code blocks without syntax highlighting" do
|
||||
assert_equal(
|
||||
%(<figure class="highlight"><pre><code class="language-ruby" ) +
|
||||
%(data-lang="ruby">puts "Hello world"\n</code></pre></figure>),
|
||||
@markdown.convert(@sample).strip
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -494,7 +494,7 @@ EOS
|
|||
setup do
|
||||
@content = <<CONTENT
|
||||
---
|
||||
title: Kramdown vs. RDiscount vs. Redcarpet
|
||||
title: Kramdown vs. RDiscount
|
||||
---
|
||||
|
||||
_FIGHT!_
|
||||
|
@ -536,25 +536,6 @@ CONTENT
|
|||
assert_match %r!<em>FINISH HIM</em>!, @result
|
||||
end
|
||||
end
|
||||
|
||||
context "using Redcarpet" do
|
||||
setup do
|
||||
if jruby?
|
||||
skip(
|
||||
"JRuby does not perform well with CExt, test disabled."
|
||||
)
|
||||
end
|
||||
|
||||
create_post(@content, {
|
||||
"markdown" => "redcarpet",
|
||||
})
|
||||
end
|
||||
|
||||
should "parse correctly" do
|
||||
assert_match %r{<em>FIGHT!</em>}, @result
|
||||
assert_match %r!<em>FINISH HIM</em>!, @result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "simple page with post linking" do
|
||||
|
|
Loading…
Reference in New Issue