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
|
||||
require "middleman-core/renderers/redcarpet"
|
||||
::Tilt.prefer(::Middleman::Renderers::RedcarpetTemplate)
|
||||
MiddlemanRedcarpetHTML.middleman_app = self
|
||||
elsif !config[:markdown_engine].nil?
|
||||
# Map symbols to classes
|
||||
markdown_engine_klass = if config[:markdown_engine].is_a? Symbol
|
||||
|
|
|
@ -4,15 +4,6 @@ module Middleman
|
|||
module Renderers
|
||||
|
||||
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.
|
||||
# Don't overload :renderer option with smartypants
|
||||
# Support renderer-level options
|
||||
|
@ -39,27 +30,31 @@ module Middleman
|
|||
|
||||
renderer.new(render_options)
|
||||
end
|
||||
|
||||
def evaluate(context, locals, &block)
|
||||
@context ||= context
|
||||
|
||||
if @engine.renderer.respond_to? :middleman_app=
|
||||
@engine.renderer.middleman_app = @context
|
||||
end
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# Custom Redcarpet renderer that uses our helpers for images and links
|
||||
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
||||
attr_accessor :middleman_app
|
||||
cattr_accessor :middleman_app
|
||||
|
||||
def image(link, title, 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
|
||||
|
||||
def link(link, title, content)
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue