removed use of content_type strings in the highlighting tag
This commit is contained in:
parent
315f4c9222
commit
84b26a31da
|
@ -26,10 +26,16 @@ module Jekyll
|
||||||
@priority || :normal
|
@priority || :normal
|
||||||
end
|
end
|
||||||
|
|
||||||
# priority order of this converter
|
# prefix for highlighting
|
||||||
def content_type(content_type = nil)
|
def pygments_prefix(pygments_prefix = nil)
|
||||||
@content_type = content_type if content_type
|
@pygments_prefix = pygments_prefix if pygments_prefix
|
||||||
@content_type || self.name.downcase.gsub(/^.*::/, '').gsub(/converter$/, '')
|
@pygments_prefix
|
||||||
|
end
|
||||||
|
|
||||||
|
# suffix for highlighting
|
||||||
|
def pygments_suffix(pygments_suffix = nil)
|
||||||
|
@pygments_suffix = pygments_suffix if pygments_suffix
|
||||||
|
@pygments_suffix
|
||||||
end
|
end
|
||||||
|
|
||||||
# Spaceship is priority [higher -> lower]
|
# Spaceship is priority [higher -> lower]
|
||||||
|
@ -41,8 +47,14 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type
|
# prefix for highlighting
|
||||||
self.class.content_type
|
def pygments_prefix
|
||||||
|
self.class.pygments_prefix
|
||||||
|
end
|
||||||
|
|
||||||
|
# suffix for highlighting
|
||||||
|
def pygments_suffix
|
||||||
|
self.class.pygments_suffix
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class MarkdownConverter < Converter
|
class MarkdownConverter < Converter
|
||||||
|
pygments_prefix '\n'
|
||||||
|
pygments_suffix '\n'
|
||||||
|
|
||||||
def initialize(config = {})
|
def initialize(config = {})
|
||||||
# Set the Markdown interpreter (and Maruku self.config, if necessary)
|
# Set the Markdown interpreter (and Maruku self.config, if necessary)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class TextileConverter < Converter
|
class TextileConverter < Converter
|
||||||
|
pygments_prefix '<notextile>'
|
||||||
|
pygments_suffix '</notextile>'
|
||||||
|
|
||||||
def initialize(config = {})
|
def initialize(config = {})
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,8 @@ module Jekyll
|
||||||
converter.output_ext(self.ext)
|
converter.output_ext(self.ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Determine which formatting engine to use based on this convertible's
|
# Determine which converter to use based on this convertible's
|
||||||
# extension
|
# extension
|
||||||
#
|
|
||||||
# Returns one of :textile, :markdown or :unknown
|
|
||||||
def content_type
|
|
||||||
converter.content_type
|
|
||||||
end
|
|
||||||
|
|
||||||
def converter
|
def converter
|
||||||
@converter ||= self.site.converters.find { |c| c.matches(self.ext) }
|
@converter ||= self.site.converters.find { |c| c.matches(self.ext) }
|
||||||
end
|
end
|
||||||
|
@ -67,7 +61,8 @@ module Jekyll
|
||||||
info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } }
|
info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } }
|
||||||
|
|
||||||
# render and transform content (this becomes the final content of the object)
|
# 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.content = Liquid::Template.parse(self.content).render(payload, info)
|
||||||
self.transform
|
self.transform
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,9 @@ module Jekyll
|
||||||
|
|
||||||
def render_pygments(context, code)
|
def render_pygments(context, code)
|
||||||
output = add_code_tags(Albino.new(code, @lang).to_s(@options), @lang)
|
output = add_code_tags(Albino.new(code, @lang).to_s(@options), @lang)
|
||||||
case context["content_type"]
|
output = context["pygments_prefix"] + output if context["pygments_prefix"]
|
||||||
when "markdown" then "\n" + output + "\n"
|
output = output + context["pygments_suffix"] if context["pygments_suffix"]
|
||||||
when "textile" then "<notextile>" + output + "</notextile>"
|
output
|
||||||
else output
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_codehighlighter(context, code)
|
def render_codehighlighter(context, code)
|
||||||
|
|
|
@ -2,14 +2,15 @@ require File.dirname(__FILE__) + '/helper'
|
||||||
|
|
||||||
class TestTags < Test::Unit::TestCase
|
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
|
stub(Jekyll).configuration do
|
||||||
Jekyll::DEFAULTS.merge({'pygments' => true}).merge(override)
|
Jekyll::DEFAULTS.merge({'pygments' => true}).merge(override)
|
||||||
end
|
end
|
||||||
site = Site.new(Jekyll.configuration)
|
site = Site.new(Jekyll.configuration)
|
||||||
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
||||||
payload = {"content_type" => content_type}
|
@converter = site.converters.find { |c| c.class == converter_class }
|
||||||
@converter = site.converters.find { |c| c.content_type == content_type }
|
payload = { "pygments_prefix" => @converter.pygments_prefix,
|
||||||
|
"pygments_suffix" => @converter.pygments_suffix }
|
||||||
|
|
||||||
@result = Liquid::Template.parse(content).render(payload, info)
|
@result = Liquid::Template.parse(content).render(payload, info)
|
||||||
@result = @converter.convert(@result)
|
@result = @converter.convert(@result)
|
||||||
|
@ -73,7 +74,7 @@ CONTENT
|
||||||
|
|
||||||
context "using Textile" do
|
context "using Textile" do
|
||||||
setup do
|
setup do
|
||||||
create_post(@content, {}, "textile")
|
create_post(@content, {}, Jekyll::TextileConverter)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Broken in RedCloth 4.1.9
|
# Broken in RedCloth 4.1.9
|
||||||
|
|
Loading…
Reference in New Issue