- :underline - :highlight - :disable_indented_code_blocks Fix support for - :link_attributes - :filter_html separate Redcarpet extensions from renderer options, add specs for missing renderer options add specs for the missing/new redcarpet extensions, [ :lax_spacing, :underline, :highlight, :quote, :disable_indented_code_blocks, :footnotes ] fix link_attributes option for Redcarpet patch Tilt's reverse option aliases (they were there for RC1) adjust test data for Redcarpet toc_data to match the current way it renders in 3.0 revert tests that aren't in redcarpet 3.0.0 add a cucumber exempt tag for mri-1.8.x move redcarpet 3 specific extensions to a separate scenario filtered by the no18 tag
88 lines
2.5 KiB
Ruby
88 lines
2.5 KiB
Ruby
require "redcarpet"
|
|
|
|
module Middleman
|
|
module Renderers
|
|
|
|
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
|
|
|
# because tilt has decided to convert these
|
|
# in the wrong direction
|
|
ALIASES = {
|
|
:escape_html => :filter_html
|
|
}
|
|
|
|
# Overwrite built-in Tilt version.
|
|
# Don't overload :renderer option with smartypants
|
|
# Support renderer-level options
|
|
def generate_renderer
|
|
return options.delete(:renderer) if options.has_key?(:renderer)
|
|
|
|
covert_options_to_aliases!
|
|
|
|
# Pick a renderer
|
|
renderer = MiddlemanRedcarpetHTML
|
|
|
|
# Support SmartyPants
|
|
if options.delete(:smartypants)
|
|
renderer = Class.new(renderer) do
|
|
include ::Redcarpet::Render::SmartyPants
|
|
end
|
|
end
|
|
|
|
# Renderer Options
|
|
possible_render_opts = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :xhtml, :prettify, :link_attributes]
|
|
|
|
render_options = possible_render_opts.inject({}) do |sum, opt|
|
|
sum[opt] = options.delete(opt) if options.has_key?(opt)
|
|
sum
|
|
end
|
|
|
|
renderer.new(render_options)
|
|
end
|
|
|
|
private
|
|
|
|
def covert_options_to_aliases!
|
|
ALIASES.each do |aka, actual|
|
|
options[actual] = options.delete(aka) if options.has_key? aka
|
|
end
|
|
end
|
|
end
|
|
|
|
# Custom Redcarpet renderer that uses our helpers for images and links
|
|
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
|
cattr_accessor :middleman_app
|
|
|
|
def initialize(options={})
|
|
@local_options = options.dup
|
|
|
|
super
|
|
end
|
|
|
|
def image(link, title, alt_text)
|
|
if !@local_options[:no_images]
|
|
middleman_app.image_tag(link, :title => title, :alt => alt_text)
|
|
else
|
|
link_string = link.dup
|
|
link_string << %Q{"#{title}"} if title && title.length > 0 && title != alt_text
|
|
%Q{}
|
|
end
|
|
end
|
|
|
|
def link(link, title, content)
|
|
if !@local_options[:no_links]
|
|
attributes = { :title => title }
|
|
attributes.merge!( @local_options[:link_attributes] ) if @local_options[:link_attributes]
|
|
|
|
middleman_app.link_to(content, link, attributes )
|
|
else
|
|
link_string = link.dup
|
|
link_string << %Q{"#{title}"} if title && title.length > 0 && title != alt_text
|
|
%Q{[#{content}](#{link_string})}
|
|
end
|
|
end
|
|
end
|
|
|
|
::Tilt.register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
|
end
|
|
end
|