From 14418f74ae743237bede319a8aef2196e48ce569 Mon Sep 17 00:00:00 2001 From: Eric Mill Date: Sun, 8 Dec 2013 22:37:46 -0500 Subject: [PATCH 1/5] in-progress patch for maruku and fenced code blocks --- .../converters/markdown/maruku_parser.rb | 6 +++ test/test_tags.rb | 46 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/jekyll/converters/markdown/maruku_parser.rb b/lib/jekyll/converters/markdown/maruku_parser.rb index ad9834cf..e000701c 100644 --- a/lib/jekyll/converters/markdown/maruku_parser.rb +++ b/lib/jekyll/converters/markdown/maruku_parser.rb @@ -8,6 +8,12 @@ module Jekyll @errors = [] load_divs_library if @config['maruku']['use_divs'] load_blahtext_library if @config['maruku']['use_tex'] + + # allow fenced code blocks (new in Maruku 0.7.0) + if @config['maruku']['fenced_code_blocks'] + MaRuKu::Globals[:fenced_code_blocks] = true + end + rescue LoadError STDERR.puts 'You are missing a library required for Markdown. Please run:' STDERR.puts ' $ [sudo] gem install maruku' diff --git a/test/test_tags.rb b/test/test_tags.rb index 0368c6db..ec8f7124 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -451,5 +451,51 @@ CONTENT assert_match "", @result end end + + + context "with maruku and fenced code blocks with backticks" do + + setup do + @config = { + 'markdown' => 'maruku', + 'maruku' => { + 'fenced_code_blocks' => true + } + } + end + +# context "with pygments enabled" do +# setup do +# @markdown = Converters::Markdown.new @config.merge({ 'pygments' => true }) +# end + +# should "render fenced code blocks with syntax highlighting" do +# assert_equal "
puts "Hello world"\n
", @markdown.convert( +# <<-EOS +# ```ruby +# puts "Hello world" +# ``` +# EOS +# ).strip +# end +# end + + context "with pygments disabled" do + setup do + @markdown = Converters::Markdown.new @config.merge({ 'pygments' => false }) + end + + should "render fenced code blocks without syntax highlighting" do + assert_equal "
\nputs "Hello world"\n
", @markdown.convert( + <<-EOS +```ruby +puts "Hello world" +``` + EOS + ).strip + end + end + end + end end From 71e625e02ce4ec02795e11710a3118a674b2e097 Mon Sep 17 00:00:00 2001 From: Eric Mill Date: Sun, 8 Dec 2013 22:56:29 -0500 Subject: [PATCH 2/5] current state --- test/test_tags.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/test_tags.rb b/test/test_tags.rb index ec8f7124..f1fb9c4c 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -464,21 +464,21 @@ CONTENT } end -# context "with pygments enabled" do -# setup do -# @markdown = Converters::Markdown.new @config.merge({ 'pygments' => true }) -# end + context "with pygments enabled" do + setup do + @markdown = Converters::Markdown.new @config.merge({ 'pygments' => true }) + end -# should "render fenced code blocks with syntax highlighting" do -# assert_equal "
puts "Hello world"\n
", @markdown.convert( -# <<-EOS -# ```ruby -# puts "Hello world" -# ``` -# EOS -# ).strip -# end -# end + should "render fenced code blocks with syntax highlighting" do + assert_equal "
puts "Hello world"\n
", @markdown.convert( + <<-EOS +```ruby +puts "Hello world" +``` + EOS + ).strip + end + end context "with pygments disabled" do setup do From 470abf46e274985ae796fbd8b5ab6d2819da71c9 Mon Sep 17 00:00:00 2001 From: Eric Mill Date: Mon, 9 Dec 2013 16:42:51 -0500 Subject: [PATCH 3/5] better, simpler test case... --- test/test_tags.rb | 52 ++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/test/test_tags.rb b/test/test_tags.rb index f1fb9c4c..0f12f7ad 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -452,48 +452,30 @@ CONTENT end end + context "with fenced code blocks with backticks" do - context "with maruku and fenced code blocks with backticks" do - + # setup do + # @config = { + # 'markdown' => 'maruku', + # 'maruku' => { + # 'fenced_code_blocks' => true + # } + # } + # end setup do - @config = { - 'markdown' => 'maruku', - 'maruku' => { - 'fenced_code_blocks' => true - } - } - end - - context "with pygments enabled" do - setup do - @markdown = Converters::Markdown.new @config.merge({ 'pygments' => true }) - end - - should "render fenced code blocks with syntax highlighting" do - assert_equal "
puts "Hello world"\n
", @markdown.convert( - <<-EOS + content = < {'fenced_code_blocks' => true}} + ) end - context "with pygments disabled" do - setup do - @markdown = Converters::Markdown.new @config.merge({ 'pygments' => false }) - end - - should "render fenced code blocks without syntax highlighting" do - assert_equal "
\nputs "Hello world"\n
", @markdown.convert( - <<-EOS -```ruby -puts "Hello world" -``` - EOS - ).strip - end + # todo: if #112 is merged into maruku, update to remove the newlines inside code block + should "render fenced code blocks" do + assert_match %r{
\nputs "Hello world"\n
}, @result.strip end end From 28ca5d71eedbb1d3b644d5f01a7e7a37f8ea6153 Mon Sep 17 00:00:00 2001 From: Eric Mill Date: Mon, 9 Dec 2013 16:47:42 -0500 Subject: [PATCH 4/5] Remove comments --- test/test_tags.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/test_tags.rb b/test/test_tags.rb index 0f12f7ad..b21f4931 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -454,14 +454,6 @@ CONTENT context "with fenced code blocks with backticks" do - # setup do - # @config = { - # 'markdown' => 'maruku', - # 'maruku' => { - # 'fenced_code_blocks' => true - # } - # } - # end setup do content = < Date: Tue, 10 Dec 2013 11:04:04 -0500 Subject: [PATCH 5/5] condensing code slightly --- lib/jekyll/converters/markdown/maruku_parser.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/jekyll/converters/markdown/maruku_parser.rb b/lib/jekyll/converters/markdown/maruku_parser.rb index e000701c..7d14c8a5 100644 --- a/lib/jekyll/converters/markdown/maruku_parser.rb +++ b/lib/jekyll/converters/markdown/maruku_parser.rb @@ -10,9 +10,7 @@ module Jekyll load_blahtext_library if @config['maruku']['use_tex'] # allow fenced code blocks (new in Maruku 0.7.0) - if @config['maruku']['fenced_code_blocks'] - MaRuKu::Globals[:fenced_code_blocks] = true - end + MaRuKu::Globals[:fenced_code_blocks] = !!@config['maruku']['fenced_code_blocks'] rescue LoadError STDERR.puts 'You are missing a library required for Markdown. Please run:'