From 9d1641f163e6b20507436872336414cf6df931c7 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Sat, 31 Oct 2015 23:58:49 +0000 Subject: [PATCH 1/2] Fix #3371 - kramdown:syntax_highlighter should automatically take value of highlighter --- features/collections.feature | 4 ++-- lib/jekyll/converters/markdown/kramdown_parser.rb | 1 + test/test_kramdown.rb | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/features/collections.feature b/features/collections.feature index dc4ea311..d97918bd 100644 --- a/features/collections.feature +++ b/features/collections.feature @@ -9,7 +9,7 @@ Feature: Collections And I have a configuration file with "collections" set to "['methods']" When I run jekyll build Then the _site directory should exist - And I should see "Collections:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

\n

Signs are nice

\n

Jekyll.sanitized_path is used to make sure your path is in your source.

\n

Run your generators! default

\n

Page without title.

\n

Run your generators! default

" in "_site/index.html" + And I should see "Collections:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

\n

Signs are nice

\n

Jekyll.sanitized_path is used to make sure your path is in your source.

\n

Run your generators! default

\n

Page without title.

\n

Run your generators! default

" in "_site/index.html" And the "_site/methods/configuration.html" file should not exist Scenario: Rendered collection @@ -108,7 +108,7 @@ Feature: Collections """ When I run jekyll build Then the _site directory should exist - And I should see "First document's output:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

" in "_site/index.html" + And I should see "First document's output:

Use Jekyll.configuration to build a full configuration for use w/Jekyll.

\n\n

Whatever: foo.bar

" in "_site/index.html" Scenario: Filter documents by where Given I have an "index.html" page that contains "{% assign items = site.methods | where: 'whatever','foo.bar' %}Item count: {{ items.size }}" diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index a9dbec96..c9d290df 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -5,6 +5,7 @@ module Jekyll def initialize(config) require 'kramdown' @config = config + @config['kramdown']['syntax_highlighter'] ||= @config['highlighter'] rescue LoadError STDERR.puts 'You are missing a library required for Markdown. Please run:' STDERR.puts ' $ [sudo] gem install kramdown' diff --git a/test/test_kramdown.rb b/test/test_kramdown.rb index 7101baaa..b7f44925 100644 --- a/test/test_kramdown.rb +++ b/test/test_kramdown.rb @@ -39,6 +39,16 @@ class TestKramdown < JekyllUnitTest assert_match /

(«|«)Pit(›|›)hy(»|»)<\/p>/, markdown.convert(%{"Pit'hy"}).strip end + should "render fenced code blocks with syntax highlighting" do + assert_equal "

puts \"Hello world\"\n
\n
", @markdown.convert( + <<-EOS +~~~ruby +puts "Hello world" +~~~ + EOS + ).strip + end + context "moving up nested coderay options" do setup do @markdown.convert('some markup') From e5279d47733d25f88519025ee1ece33bc725d660 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Sun, 1 Nov 2015 23:04:59 +0000 Subject: [PATCH 2/2] Santize @config['highlighter'] to only allow highlighters supported by kramdown --- lib/jekyll/converters/markdown/kramdown_parser.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index c9d290df..40dfa87e 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -5,7 +5,11 @@ module Jekyll def initialize(config) require 'kramdown' @config = config - @config['kramdown']['syntax_highlighter'] ||= @config['highlighter'] + # If kramdown supported highlighter enabled, use that + highlighter = @config['highlighter'] + if highlighter == 'rouge' || highlighter == 'coderay' + @config['kramdown']['syntax_highlighter'] ||= highlighter + end rescue LoadError STDERR.puts 'You are missing a library required for Markdown. Please run:' STDERR.puts ' $ [sudo] gem install kramdown'