support redcarpet's no_ flags which need to be re-implemented in our overrides. Fixes #951
This commit is contained in:
parent
5806f2cbf5
commit
8b970f9d92
|
@ -1,3 +1,8 @@
|
||||||
|
master
|
||||||
|
===
|
||||||
|
|
||||||
|
* Support redcarpet's :no_links & :no_images. #951
|
||||||
|
|
||||||
3.1.3
|
3.1.3
|
||||||
===
|
===
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,32 @@ Feature: Markdown support
|
||||||
When I go to "/hard_wrap.html"
|
When I go to "/hard_wrap.html"
|
||||||
Then I should see "br"
|
Then I should see "br"
|
||||||
|
|
||||||
|
Scenario: Redcarpet 2 no_images extension (with overrides)
|
||||||
|
Given a fixture app "markdown-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
set :markdown_engine, :redcarpet
|
||||||
|
set :markdown, :no_images => true
|
||||||
|
|
||||||
|
"""
|
||||||
|
Given the Server is running at "markdown-app"
|
||||||
|
When I go to "/img.html"
|
||||||
|
Then I should see "![dust mite](http://dust.mite/image.png)"
|
||||||
|
And I should not see "<img"
|
||||||
|
|
||||||
|
Scenario: Redcarpet 2 no_links extension (with overrides)
|
||||||
|
Given a fixture app "markdown-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
set :markdown_engine, :redcarpet
|
||||||
|
set :markdown, :no_links => true
|
||||||
|
|
||||||
|
"""
|
||||||
|
Given the Server is running at "markdown-app"
|
||||||
|
When I go to "/link.html"
|
||||||
|
Then I should see "[This link](http://example.net/) links"
|
||||||
|
And I should not see "<a"
|
||||||
|
|
||||||
Scenario: Redcarpet per-page frontmatter options
|
Scenario: Redcarpet per-page frontmatter options
|
||||||
Given a fixture app "markdown-frontmatter-options-app"
|
Given a fixture app "markdown-frontmatter-options-app"
|
||||||
And a file named "config.rb" with:
|
And a file named "config.rb" with:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
![dust mite](http://dust.mite/image.png) <img src="image.png" />
|
|
@ -0,0 +1 @@
|
||||||
|
[This link](http://example.net/) <a href="links.html">links</a>
|
|
@ -21,7 +21,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
# Renderer Options
|
# Renderer Options
|
||||||
possible_render_opts = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :xhtml]
|
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|
|
render_options = possible_render_opts.inject({}) do |sum, opt|
|
||||||
sum[opt] = options.delete(opt) if options.has_key?(opt)
|
sum[opt] = options.delete(opt) if options.has_key?(opt)
|
||||||
|
@ -36,12 +36,30 @@ module Middleman
|
||||||
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
||||||
cattr_accessor :middleman_app
|
cattr_accessor :middleman_app
|
||||||
|
|
||||||
|
def initialize(options={})
|
||||||
|
@local_options = options.dup
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def image(link, title, alt_text)
|
def image(link, title, alt_text)
|
||||||
middleman_app.image_tag(link, :title => title, :alt => 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{![#{alt_text}](#{link_string})}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def link(link, title, content)
|
def link(link, title, content)
|
||||||
middleman_app.link_to(content, link, :title => title)
|
if !@local_options[:no_links]
|
||||||
|
middleman_app.link_to(content, link, :title => title)
|
||||||
|
else
|
||||||
|
link_string = link.dup
|
||||||
|
link_string << %Q{"#{title}"} if title && title.length > 0 && title != alt_text
|
||||||
|
%Q{[#{content}](#{link_string})}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue