Permalink
Browse files

removed use of content_type strings in the highlighting tag

  • Loading branch information...
1 parent 315f4c9 commit 84b26a31dabcd3ae3a0b1043e1e959aedc0cdc8c @krisb krisb committed Feb 28, 2010
View
24 lib/jekyll/converter.rb
@@ -26,10 +26,16 @@ def priority(priority = nil)
@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 @@ def <=>(other)
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
View
2 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)
View
2 lib/jekyll/converters/textile.rb
@@ -1,5 +1,7 @@
module Jekyll
class TextileConverter < Converter
+ pygments_prefix '<notextile>'
+ pygments_suffix '</notextile>'
def initialize(config = {})
View
11 lib/jekyll/convertible.rb
@@ -46,14 +46,8 @@ def output_ext
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 @@ def do_layout(payload, layouts)
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
View
8 lib/jekyll/tags/highlight.rb
@@ -31,11 +31,9 @@ def render(context)
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 "<notextile>" + output + "</notextile>"
- 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)
View
9 test/test_tags.rb
@@ -2,14 +2,15 @@
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 @@ def fill_post(code, override = {})
context "using Textile" do
setup do
- create_post(@content, {}, "textile")
+ create_post(@content, {}, Jekyll::TextileConverter)
end
# Broken in RedCloth 4.1.9

0 comments on commit 84b26a3

Please sign in to comment.