Skip to content

Commit

Permalink
New solution for passing restrictions to RedCloth - all tests pass wi…
Browse files Browse the repository at this point in the history
…th ruby 1.8 (just invoking rake)
  • Loading branch information
Thomas Laumann committed Nov 28, 2011
1 parent ab39274 commit d80c773
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/jekyll/converters/textile.rb
Expand Up @@ -27,15 +27,23 @@ def output_ext(ext)

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

Expand Down
29 changes: 29 additions & 0 deletions test/test_redcloth.rb
Expand Up @@ -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

0 comments on commit d80c773

Please sign in to comment.