diff --git a/jekyll.gemspec b/jekyll.gemspec index def6b568..970a8ddc 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -143,6 +143,7 @@ Gem::Specification.new do |s| test/test_redcarpet.rb test/test_site.rb test/test_tags.rb + test/test_redcloth.rb ] # = MANIFEST = diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 9998799c..6d5afd85 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -98,6 +98,9 @@ module Jekyll 'coderay_bold_every' => 10, 'coderay_css' => 'style' } + }, + 'redcloth' => { + 'hard_breaks' => true } } diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index da823d35..6572b518 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -27,7 +27,23 @@ module Jekyll def convert(content) setup - RedCloth.new(content).to_html + + # 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 + + r.to_html end end diff --git a/test/test_redcloth.rb b/test/test_redcloth.rb new file mode 100644 index 00000000..55e52cdf --- /dev/null +++ b/test/test_redcloth.rb @@ -0,0 +1,86 @@ +require File.dirname(__FILE__) + '/helper' + +class TestRedCloth < Test::Unit::TestCase + + context "RedCloth default (no explicit config) hard_breaks enabled" do + setup do + @textile = TextileConverter.new + end + + should "preserve single line breaks in HTML output" do + assert_equal "
line1
\nline2
line1
\nline2
line1
\nline2
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