From bdbf1b9383a0800b907d8cf8385d89a80ce8389e Mon Sep 17 00:00:00 2001 From: Zachary Pinter Date: Sun, 11 Jan 2009 11:41:30 -0700 Subject: [PATCH 1/2] Created a test to expose a bug with markdown and pygments The error seems to stem from how markdown expects certain blocks to begin and end with a newline. --- test/test_tags.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/test_tags.rb diff --git a/test/test_tags.rb b/test/test_tags.rb new file mode 100644 index 00000000..bdf6b858 --- /dev/null +++ b/test/test_tags.rb @@ -0,0 +1,30 @@ +require File.dirname(__FILE__) + '/helper' + +class TestTags < Test::Unit::TestCase + + def setup + @content = < Date: Sun, 11 Jan 2009 12:03:46 -0700 Subject: [PATCH 2/2] Fixed an issue with pygments, markdown, and newlines. --- lib/jekyll.rb | 2 +- lib/jekyll/convertible.rb | 17 ++++++++++++++--- lib/jekyll/tags/highlight.rb | 8 ++++++-- test/test_tags.rb | 1 + 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 829d1d4b..45ec5c2d 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -46,7 +46,7 @@ module Jekyll VERSION = '0.3.0' class << self - attr_accessor :source, :dest, :lsi, :pygments, :markdown_proc + attr_accessor :source, :dest, :lsi, :pygments, :markdown_proc, :content_type end Jekyll.lsi = false diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index d68d6039..62463209 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -24,16 +24,26 @@ module Jekyll # # Returns nothing def transform - case self.ext[1..-1] - when /textile/i + case Jekyll.content_type + when :textile self.ext = ".html" self.content = RedCloth.new(self.content).to_html - when /markdown/i, /mkdn/i, /md/i + when :markdown self.ext = ".html" self.content = Jekyll.markdown_proc.call(self.content) end end + def determine_content_type + case self.ext[1..-1] + when /textile/i + return :textile + when /markdown/i, /mkdn/i, /md/i + return :markdown + end + return :unknown + end + # Add any necessary layouts to this convertible document # +layouts+ is a Hash of {"name" => "layout"} # +site_payload+ is the site payload hash @@ -41,6 +51,7 @@ module Jekyll # Returns nothing def do_layout(payload, layouts) # render and transform content (this becomes the final content of the object) + Jekyll.content_type = self.determine_content_type self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters]) self.transform diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index cd4121ae..685fba3f 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -17,7 +17,11 @@ module Jekyll end def render_pygments(context, code) - "" + Albino.new(code, @lang).to_s + "" + if Jekyll.content_type == :markdown + return "\n" + Albino.new(code, @lang).to_s + "\n" + else + "" + Albino.new(code, @lang).to_s + "" + end end def render_codehighlighter(context, code) @@ -34,4 +38,4 @@ module Jekyll end -Liquid::Template.register_tag('highlight', Jekyll::HighlightBlock) \ No newline at end of file +Liquid::Template.register_tag('highlight', Jekyll::HighlightBlock) diff --git a/test/test_tags.rb b/test/test_tags.rb index bdf6b858..4e6ad795 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -21,6 +21,7 @@ CONTENT def test_markdown_with_pygments_line_handling Jekyll.pygments = true + Jekyll.content_type = :markdown result = Liquid::Template.parse(@content).render({}, [Jekyll::Filters]) result = Jekyll.markdown_proc.call(result)