Use middleman's image_tag and link_to helpers from within Redcarpet markdown
This commit is contained in:
parent
6dad42bc77
commit
7be0590acf
2 changed files with 25 additions and 6 deletions
|
@ -10,7 +10,6 @@ module Middleman
|
||||||
# Once registered
|
# Once registered
|
||||||
def registered(app)
|
def registered(app)
|
||||||
# Set our preference for a markdown engine
|
# Set our preference for a markdown engine
|
||||||
# TODO: Find a JRuby-compatible version
|
|
||||||
app.set :markdown_engine, :maruku
|
app.set :markdown_engine, :maruku
|
||||||
app.set :markdown_engine_prefix, ::Tilt
|
app.set :markdown_engine_prefix, ::Tilt
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ module Middleman
|
||||||
|
|
||||||
# Overwrite built-in Tilt version.
|
# Overwrite built-in Tilt version.
|
||||||
# Don't overload :renderer option with smartypants
|
# Don't overload :renderer option with smartypants
|
||||||
# Supper renderer-level options
|
# Support renderer-level options
|
||||||
def generate_renderer
|
def generate_renderer
|
||||||
return options.delete(:renderer) if options.has_key?(:renderer)
|
return options.delete(:renderer) if options.has_key?(:renderer)
|
||||||
|
|
||||||
# Pick a renderer
|
# Pick a renderer
|
||||||
renderer = ::Redcarpet::Render::HTML
|
renderer = MiddlemanRedcarpetHTML
|
||||||
|
|
||||||
# Support SmartyPants
|
# Support SmartyPants
|
||||||
if options.delete(:smartypants)
|
if options.delete(:smartypants)
|
||||||
|
@ -31,6 +31,26 @@ module Middleman
|
||||||
|
|
||||||
renderer.new(render_options)
|
renderer.new(render_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def evaluate(scope, locals, &block)
|
||||||
|
if @engine.renderer.respond_to? :middleman_app=
|
||||||
|
@engine.renderer.middleman_app = scope
|
||||||
|
end
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Custom Redcarpet renderer that uses our helpers for images and links
|
||||||
|
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
||||||
|
attr_accessor :middleman_app
|
||||||
|
|
||||||
|
def image(link, title, alt_text)
|
||||||
|
middleman_app.image_tag(link, :title => title, :alt => alt_text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def link(link, title, content)
|
||||||
|
middleman_app.link_to(content, link, :title => title)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::Tilt.register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
::Tilt.register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
||||||
|
|
Loading…
Reference in a new issue