From d80c773b0194dec9400f97c29b48fc8e63a58f3c Mon Sep 17 00:00:00 2001 From: Thomas Laumann Date: Mon, 28 Nov 2011 14:05:34 +0100 Subject: [PATCH] New solution for passing restrictions to RedCloth - all tests pass with ruby 1.8 (just invoking rake) --- lib/jekyll/converters/textile.rb | 22 +++++++++++++++------- test/test_redcloth.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index aa7201cd..6572b518 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -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 diff --git a/test/test_redcloth.rb b/test/test_redcloth.rb index 2b43fe24..55e52cdf 100644 --- a/test/test_redcloth.rb +++ b/test/test_redcloth.rb @@ -54,4 +54,33 @@ class TestRedCloth < Test::Unit::TestCase assert_equal "

line1\nline2

", @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 "

NSC

", @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 "

NSC

", @textile.convert("NSC").strip + end + end end