diff --git a/lib/jekyll/converter.rb b/lib/jekyll/converter.rb index 50965be1..faacfb7d 100644 --- a/lib/jekyll/converter.rb +++ b/lib/jekyll/converter.rb @@ -26,10 +26,16 @@ module Jekyll @priority || :normal end - # priority order of this converter - def content_type(content_type = nil) - @content_type = content_type if content_type - @content_type || self.name.downcase.gsub(/^.*::/, '').gsub(/converter$/, '') + # prefix for highlighting + def pygments_prefix(pygments_prefix = nil) + @pygments_prefix = pygments_prefix if pygments_prefix + @pygments_prefix + end + + # suffix for highlighting + def pygments_suffix(pygments_suffix = nil) + @pygments_suffix = pygments_suffix if pygments_suffix + @pygments_suffix end # Spaceship is priority [higher -> lower] @@ -41,8 +47,14 @@ module Jekyll end end - def content_type - self.class.content_type + # prefix for highlighting + def pygments_prefix + self.class.pygments_prefix + end + + # suffix for highlighting + def pygments_suffix + self.class.pygments_suffix end end diff --git a/lib/jekyll/converters/markdown.rb b/lib/jekyll/converters/markdown.rb index c7cdbbd5..a9056c7d 100644 --- a/lib/jekyll/converters/markdown.rb +++ b/lib/jekyll/converters/markdown.rb @@ -1,5 +1,7 @@ module Jekyll class MarkdownConverter < Converter + pygments_prefix '\n' + pygments_suffix '\n' def initialize(config = {}) # Set the Markdown interpreter (and Maruku self.config, if necessary) diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index 79eb5476..5a4d68cd 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -1,5 +1,7 @@ module Jekyll class TextileConverter < Converter + pygments_prefix '' + pygments_suffix '' def initialize(config = {}) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 96e18523..b76157ec 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -46,14 +46,8 @@ module Jekyll converter.output_ext(self.ext) end - # Determine which formatting engine to use based on this convertible's + # Determine which converter to use based on this convertible's # extension - # - # Returns one of :textile, :markdown or :unknown - def content_type - converter.content_type - end - def converter @converter ||= self.site.converters.find { |c| c.matches(self.ext) } end @@ -67,7 +61,8 @@ module Jekyll info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } } # render and transform content (this becomes the final content of the object) - payload["content_type"] = self.content_type + payload["pygments_prefix"] = converter.pygments_prefix + payload["pygments_suffix"] = converter.pygments_suffix self.content = Liquid::Template.parse(self.content).render(payload, info) self.transform diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 046cf290..84cd1a41 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -31,11 +31,9 @@ module Jekyll def render_pygments(context, code) output = add_code_tags(Albino.new(code, @lang).to_s(@options), @lang) - case context["content_type"] - when "markdown" then "\n" + output + "\n" - when "textile" then "" + output + "" - else output - end + output = context["pygments_prefix"] + output if context["pygments_prefix"] + output = output + context["pygments_suffix"] if context["pygments_suffix"] + output end def render_codehighlighter(context, code) diff --git a/test/test_tags.rb b/test/test_tags.rb index 8659ffd7..ac92deda 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -2,14 +2,15 @@ require File.dirname(__FILE__) + '/helper' class TestTags < Test::Unit::TestCase - def create_post(content, override = {}, content_type = "markdown") + def create_post(content, override = {}, converter_class = Jekyll::MarkdownConverter) stub(Jekyll).configuration do Jekyll::DEFAULTS.merge({'pygments' => true}).merge(override) end site = Site.new(Jekyll.configuration) info = { :filters => [Jekyll::Filters], :registers => { :site => site } } - payload = {"content_type" => content_type} - @converter = site.converters.find { |c| c.content_type == content_type } + @converter = site.converters.find { |c| c.class == converter_class } + payload = { "pygments_prefix" => @converter.pygments_prefix, + "pygments_suffix" => @converter.pygments_suffix } @result = Liquid::Template.parse(content).render(payload, info) @result = @converter.convert(@result) @@ -73,7 +74,7 @@ CONTENT context "using Textile" do setup do - create_post(@content, {}, "textile") + create_post(@content, {}, Jekyll::TextileConverter) end # Broken in RedCloth 4.1.9