New solution for passing restrictions to RedCloth - all tests pass with ruby 1.8 (just invoking rake)

This commit is contained in:
Thomas Laumann 2011-11-28 14:05:34 +01:00
parent ab3927499f
commit d80c773b01
2 changed files with 44 additions and 7 deletions

View File

@ -27,15 +27,23 @@ module Jekyll
def convert(content)
setup
restrictions = Array.new
if !@config['redcloth'].nil?
@config['redcloth'].each do |key, value|
restrictions << key.to_sym if value
end
# Shortcut if config doesn't contain RedCloth section
return RedCloth.new(content).to_html if @config['redcloth'].nil?
# List of attributes defined on RedCloth
# (from http://redcloth.rubyforge.org/classes/RedCloth/TextileDoc.html)
attrs = ['filter_classes', 'filter_html', 'filter_ids', 'filter_styles',
'hard_breaks', 'lite_mode', 'no_span_caps', 'sanitize_html']
r = RedCloth.new(content)
# Set attributes in r if they are NOT nil in the config
attrs.each do |attr|
r.instance_variable_set("@#{attr}".to_sym, @config['redcloth'][attr]) unless @config['redcloth'][attr].nil?
end
RedCloth.new(content, restrictions).to_html
r.to_html
end
end

View File

@ -54,4 +54,33 @@ class TestRedCloth < Test::Unit::TestCase
assert_equal "<p>line1\nline2</p>", @textile.convert("p. line1\nline2").strip
end
end
context "RedCloth w/no_span_caps set to false" do
setup do
config = {
'redcloth' => {
'no_span_caps' => false
}
}
@textile = TextileConverter.new config
end
should "generate span tags around capitalized words" do
assert_equal "<p><span class=\"caps\">NSC</span></p>", @textile.convert("NSC").strip
end
end
context "RedCloth w/no_span_caps set to true" do
setup do
config = {
'redcloth' => {
'no_span_caps' => true
}
}
@textile = TextileConverter.new config
end
should "not generate span tags around capitalized words" do
assert_equal "<p>NSC</p>", @textile.convert("NSC").strip
end
end
end