More agressively set the context for our custom Markdown renderer, and fall back if we still don't manage to get it right. Fixes #662.
This commit is contained in:
parent
fca4c0330e
commit
f89c815868
|
@ -29,6 +29,7 @@ module Middleman
|
||||||
if config[:markdown_engine] == :redcarpet
|
if config[:markdown_engine] == :redcarpet
|
||||||
require "middleman-core/renderers/redcarpet"
|
require "middleman-core/renderers/redcarpet"
|
||||||
::Tilt.prefer(::Middleman::Renderers::RedcarpetTemplate)
|
::Tilt.prefer(::Middleman::Renderers::RedcarpetTemplate)
|
||||||
|
MiddlemanRedcarpetHTML.middleman_app = self
|
||||||
elsif !config[:markdown_engine].nil?
|
elsif !config[:markdown_engine].nil?
|
||||||
# Map symbols to classes
|
# Map symbols to classes
|
||||||
markdown_engine_klass = if config[:markdown_engine].is_a? Symbol
|
markdown_engine_klass = if config[:markdown_engine].is_a? Symbol
|
||||||
|
|
|
@ -4,15 +4,6 @@ module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
||||||
|
|
||||||
def initialize(*args, &block)
|
|
||||||
super
|
|
||||||
|
|
||||||
if @options.has_key?(:context)
|
|
||||||
@context = @options[:context]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Overwrite built-in Tilt version.
|
# Overwrite built-in Tilt version.
|
||||||
# Don't overload :renderer option with smartypants
|
# Don't overload :renderer option with smartypants
|
||||||
# Support renderer-level options
|
# Support renderer-level options
|
||||||
|
@ -39,27 +30,31 @@ module Middleman
|
||||||
|
|
||||||
renderer.new(render_options)
|
renderer.new(render_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(context, locals, &block)
|
|
||||||
@context ||= context
|
|
||||||
|
|
||||||
if @engine.renderer.respond_to? :middleman_app=
|
|
||||||
@engine.renderer.middleman_app = @context
|
|
||||||
end
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom Redcarpet renderer that uses our helpers for images and links
|
# Custom Redcarpet renderer that uses our helpers for images and links
|
||||||
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
||||||
attr_accessor :middleman_app
|
cattr_accessor :middleman_app
|
||||||
|
|
||||||
def image(link, title, alt_text)
|
def image(link, title, alt_text)
|
||||||
middleman_app.image_tag(link, :title => title, :alt => alt_text)
|
if middleman_app && middleman_app.respond_to?(:image_tag)
|
||||||
|
middleman_app.image_tag(link, :title => title, :alt => alt_text)
|
||||||
|
else
|
||||||
|
img = "<img src=\"#{link}\""
|
||||||
|
img << " title=\"#{title}\"" if title
|
||||||
|
img << " alt=\"#{alt_text}\"" if alt_text
|
||||||
|
img << ">"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def link(link, title, content)
|
def link(link, title, content)
|
||||||
middleman_app.link_to(content, link, :title => title)
|
if middleman_app && middleman_app.respond_to?(:link_to)
|
||||||
|
middleman_app.link_to(content, link, :title => title)
|
||||||
|
else
|
||||||
|
a = "<a href=\"#{link}\""
|
||||||
|
a << " title=\"#{title}\"" if title
|
||||||
|
a << ">#{content}</a>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue