Add support/tests for Redcarpet 3.0.0 features
- :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
This commit is contained in:
parent
abfe5e673f
commit
ee7c9e6a6e
|
@ -19,6 +19,7 @@ require 'cucumber/rake/task'
|
||||||
Cucumber::Rake::Task.new do |t|
|
Cucumber::Rake::Task.new do |t|
|
||||||
exempt_tags = ["--tags ~@wip"]
|
exempt_tags = ["--tags ~@wip"]
|
||||||
exempt_tags << "--tags ~@nojava" if RUBY_PLATFORM == "java"
|
exempt_tags << "--tags ~@nojava" if RUBY_PLATFORM == "java"
|
||||||
|
exempt_tags << "--tags ~@no18" if RUBY_VERSION < "1.9"
|
||||||
exempt_tags << "--tags ~@encoding" unless Object.const_defined?(:Encoding)
|
exempt_tags << "--tags ~@encoding" unless Object.const_defined?(:Encoding)
|
||||||
exempt_tags << "--tags ~@travishatesme" if ENV["TRAVIS"] == "true"
|
exempt_tags << "--tags ~@travishatesme" if ENV["TRAVIS"] == "true"
|
||||||
|
|
||||||
|
|
|
@ -12,17 +12,12 @@ Feature: Markdown support
|
||||||
:fenced_code_blocks => true,
|
:fenced_code_blocks => true,
|
||||||
:autolink => true,
|
:autolink => true,
|
||||||
:strikethrough => true,
|
:strikethrough => true,
|
||||||
:lax_html_blocks => true,
|
|
||||||
:space_after_headers => true,
|
:space_after_headers => true,
|
||||||
:with_toc_data => true,
|
|
||||||
:superscript => true,
|
:superscript => true,
|
||||||
:smartypants => true,
|
:lax_spacing => true
|
||||||
:hard_wrap => true
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Given the Server is running at "markdown-app"
|
Given the Server is running at "markdown-app"
|
||||||
When I go to "/smarty_pants.html"
|
|
||||||
Then I should see "“"
|
|
||||||
When I go to "/no_intra_emphasis.html"
|
When I go to "/no_intra_emphasis.html"
|
||||||
Then I should not see "<em>"
|
Then I should not see "<em>"
|
||||||
When I go to "/tables.html"
|
When I go to "/tables.html"
|
||||||
|
@ -37,36 +32,97 @@ Feature: Markdown support
|
||||||
Then I should not see "<h1>"
|
Then I should not see "<h1>"
|
||||||
When I go to "/superscript.html"
|
When I go to "/superscript.html"
|
||||||
Then I should see "<sup>"
|
Then I should see "<sup>"
|
||||||
When I go to "/with_toc_data.html"
|
When I go to "/lax_spacing.html"
|
||||||
Then I should see "toc_0"
|
Then I should see "<p>hello</p>"
|
||||||
When I go to "/hard_wrap.html"
|
|
||||||
Then I should see "br"
|
|
||||||
|
|
||||||
Scenario: Redcarpet 2 no_images extension (with overrides)
|
@no18
|
||||||
|
Scenario: Redcarpet 3 extensions
|
||||||
Given a fixture app "markdown-app"
|
Given a fixture app "markdown-app"
|
||||||
And a file named "config.rb" with:
|
And a file named "config.rb" with:
|
||||||
"""
|
"""
|
||||||
set :markdown_engine, :redcarpet
|
set :markdown_engine, :redcarpet
|
||||||
set :markdown, :no_images => true
|
set :markdown, :underline => true,
|
||||||
|
:highlight => true,
|
||||||
|
:disable_indented_code_blocks => true
|
||||||
"""
|
"""
|
||||||
Given the Server is running at "markdown-app"
|
Given the Server is running at "markdown-app"
|
||||||
|
When I go to "/underline.html"
|
||||||
|
Then I should see "<u>underlined</u>"
|
||||||
|
When I go to "/highlighted.html"
|
||||||
|
Then I should see "<mark>highlighted</mark>"
|
||||||
|
When I go to "/indented_code_blocks.html"
|
||||||
|
Then I should not see "<code>"
|
||||||
|
|
||||||
|
Scenario: Redcarpet smartypants extension
|
||||||
|
Given a fixture app "markdown-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
set :markdown_engine, :redcarpet
|
||||||
|
set :markdown, :smartypants => true
|
||||||
|
"""
|
||||||
|
Given the Server is running at "markdown-app"
|
||||||
|
When I go to "/smarty_pants.html"
|
||||||
|
Then I should see "“"
|
||||||
|
|
||||||
|
Scenario: Redcarpet::Render::HTML options
|
||||||
|
Given a fixture app "markdown-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
set :markdown_engine, :redcarpet
|
||||||
|
set :markdown, :filter_html => true,
|
||||||
|
:no_images => true,
|
||||||
|
:no_links => true,
|
||||||
|
:with_toc_data => true,
|
||||||
|
:hard_wrap => true,
|
||||||
|
:safe_links_only => true,
|
||||||
|
:prettify => true
|
||||||
|
|
||||||
|
"""
|
||||||
|
Given the Server is running at "markdown-app"
|
||||||
|
When I go to "/filter_html.html"
|
||||||
|
Then I should not see "<em>"
|
||||||
When I go to "/img.html"
|
When I go to "/img.html"
|
||||||
Then I should see "![dust mite](http://dust.mite/image.png)"
|
Then I should see "![dust mite](http://dust.mite/image.png)"
|
||||||
And I should not see "<img"
|
And I should not see "<img"
|
||||||
|
When I go to "/with_toc_data.html"
|
||||||
|
Then I should see 'id="toc_0"'
|
||||||
|
And I should see 'id="toc_1"'
|
||||||
|
When I go to "/hard_wrap.html"
|
||||||
|
Then I should see "br"
|
||||||
|
When I go to "/link.html"
|
||||||
|
Then I should see "[This link](http://example.net/) links"
|
||||||
|
And I should not see "<a"
|
||||||
|
When I go to "/safe_links.html"
|
||||||
|
Then I should see "[IRC](irc://chat.freenode.org/#freenode)"
|
||||||
|
When I go to "/prettify.html"
|
||||||
|
Then I should see '<code class="prettyprint">'
|
||||||
|
|
||||||
Scenario: Redcarpet 2 no_links extension (with overrides)
|
Scenario: Redcarpet link_attributes option
|
||||||
Given a fixture app "markdown-app"
|
Given a fixture app "markdown-app"
|
||||||
And a file named "config.rb" with:
|
And a file named "config.rb" with:
|
||||||
"""
|
"""
|
||||||
set :markdown_engine, :redcarpet
|
set :markdown_engine, :redcarpet
|
||||||
set :markdown, :no_links => true
|
set :markdown, :link_attributes => { :target => "_blank" }
|
||||||
|
"""
|
||||||
|
And a file named "source/link.html.markdown" with:
|
||||||
|
"""
|
||||||
|
[A link](/foo.html)
|
||||||
"""
|
"""
|
||||||
Given the Server is running at "markdown-app"
|
Given the Server is running at "markdown-app"
|
||||||
When I go to "/link.html"
|
When I go to "/link.html"
|
||||||
Then I should see "[This link](http://example.net/) links"
|
Then I should see 'target="_blank"'
|
||||||
And I should not see "<a"
|
|
||||||
|
Scenario: Redcarpet xhtml option
|
||||||
|
Given a fixture app "markdown-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
set :markdown_engine, :redcarpet
|
||||||
|
set :markdown, :xhtml => true,
|
||||||
|
:hard_wrap => true
|
||||||
|
"""
|
||||||
|
Given the Server is running at "markdown-app"
|
||||||
|
When I go to "/hard_wrap.html"
|
||||||
|
Then I should see "<br/>"
|
||||||
|
|
||||||
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"
|
||||||
|
@ -109,4 +165,3 @@ Feature: Markdown support
|
||||||
Then I should see 'width="1"'
|
Then I should see 'width="1"'
|
||||||
And I should see 'height="1"'
|
And I should see 'height="1"'
|
||||||
And I should see 'src="/images/blank.gif"'
|
And I should see 'src="/images/blank.gif"'
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
I <em>shouldn't</em> be emphasised
|
|
@ -0,0 +1,3 @@
|
||||||
|
This is a footnote.[^1]
|
||||||
|
|
||||||
|
[^1]: It provides additional information.
|
|
@ -0,0 +1 @@
|
||||||
|
this is ==highlighted==
|
|
@ -0,0 +1,5 @@
|
||||||
|
Hello
|
||||||
|
|
||||||
|
Something that would be flagged as code
|
||||||
|
|
||||||
|
World
|
|
@ -0,0 +1,3 @@
|
||||||
|
hello
|
||||||
|
<div>world</div>
|
||||||
|
again
|
|
@ -0,0 +1,3 @@
|
||||||
|
```
|
||||||
|
code block
|
||||||
|
```
|
|
@ -0,0 +1 @@
|
||||||
|
this is "quote"
|
|
@ -0,0 +1 @@
|
||||||
|
[IRC](irc://chat.freenode.org/#freenode)
|
|
@ -0,0 +1 @@
|
||||||
|
hello _underlined_ text
|
|
@ -1,3 +1,3 @@
|
||||||
# Header 1
|
# First Header
|
||||||
|
|
||||||
## Header 2
|
## Second Header
|
|
@ -4,12 +4,21 @@ module Middleman
|
||||||
module Renderers
|
module Renderers
|
||||||
|
|
||||||
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
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.
|
# 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
|
||||||
def generate_renderer
|
def generate_renderer
|
||||||
return options.delete(:renderer) if options.has_key?(:renderer)
|
return options.delete(:renderer) if options.has_key?(:renderer)
|
||||||
|
|
||||||
|
covert_options_to_aliases!
|
||||||
|
|
||||||
# Pick a renderer
|
# Pick a renderer
|
||||||
renderer = MiddlemanRedcarpetHTML
|
renderer = MiddlemanRedcarpetHTML
|
||||||
|
|
||||||
|
@ -30,6 +39,14 @@ module Middleman
|
||||||
|
|
||||||
renderer.new(render_options)
|
renderer.new(render_options)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# Custom Redcarpet renderer that uses our helpers for images and links
|
# Custom Redcarpet renderer that uses our helpers for images and links
|
||||||
|
@ -54,7 +71,10 @@ module Middleman
|
||||||
|
|
||||||
def link(link, title, content)
|
def link(link, title, content)
|
||||||
if !@local_options[:no_links]
|
if !@local_options[:no_links]
|
||||||
middleman_app.link_to(content, link, :title => title)
|
attributes = { :title => title }
|
||||||
|
attributes.merge!( @local_options[:link_attributes] ) if @local_options[:link_attributes]
|
||||||
|
|
||||||
|
middleman_app.link_to(content, link, attributes )
|
||||||
else
|
else
|
||||||
link_string = link.dup
|
link_string = link.dup
|
||||||
link_string << %Q{"#{title}"} if title && title.length > 0 && title != alt_text
|
link_string << %Q{"#{title}"} if title && title.length > 0 && title != alt_text
|
||||||
|
|
Loading…
Reference in a new issue