From 3468f0a2c3643c0417d52feb895da7ef2d7a47d2 Mon Sep 17 00:00:00 2001 From: laumann Date: Wed, 9 Feb 2011 01:37:30 +0100 Subject: [PATCH 1/8] expanded config yaml to allow setting hard_breaks=false on RedCloth, modified textile converter to take this option into account --- lib/jekyll.rb | 3 +++ lib/jekyll/converters/textile.rb | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 7928850c..59cd1dec 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -90,6 +90,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 072e393a..21e1ab49 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -26,7 +26,11 @@ module Jekyll def convert(content) setup - RedCloth.new(content).to_html + r = RedCloth.new(content) + if !@config['redcloth']['hard_breaks'] + r.hard_breaks = false + end + r.to_html end end From 3f889ef077b9157666664205bb484de3efcea4ca Mon Sep 17 00:00:00 2001 From: Thomas Laumann Date: Wed, 23 Mar 2011 18:17:14 +0100 Subject: [PATCH 2/8] added test case to hard_breaks (disable/enable in _config.yml) --- lib/jekyll/converters/textile.rb | 8 +++++--- test/test_redcloth.rb | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/test_redcloth.rb diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index 21e1ab49..347ab197 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -27,9 +27,11 @@ module Jekyll def convert(content) setup r = RedCloth.new(content) - if !@config['redcloth']['hard_breaks'] - r.hard_breaks = false - end + r.hard_breaks = @config['redcloth']['hard_breaks'] + # if @config['redcloth']['hard_breaks'] == false + # STDERR.puts 'hards_breaks disabled' + # r.hard_breaks = false + # end r.to_html end end diff --git a/test/test_redcloth.rb b/test/test_redcloth.rb new file mode 100644 index 00000000..9fd32be1 --- /dev/null +++ b/test/test_redcloth.rb @@ -0,0 +1,33 @@ +require File.dirname(__FILE__) + '/helper' + +class TestRedCloth < Test::Unit::TestCase + context "RedCloth with hard_breaks enabled" do + setup do + config = { + 'redcloth' => { + 'hard_breaks' => true # default + } + } + @textile = TextileConverter.new config + end + + should "preserve single line breaks in HTML output" do + assert_equal "

line1
\nline2

", @textile.convert("p. line1\nline2").strip + end + end + + context "RedCloth with hard_breaks disabled" do + setup do + config = { + 'redcloth' => { + 'hard_breaks' => false + } + } + @textile = TextileConverter.new config + end + + should "not generate break tags in HTML output" do + assert_equal "

line1\nline2

", @textile.convert("p. line1\nline2").strip + end + end +end From ef7b4aa57aac400f3a9132ea3b3da7e2b98fec30 Mon Sep 17 00:00:00 2001 From: Thomas Laumann Date: Wed, 6 Apr 2011 14:18:55 +0200 Subject: [PATCH 3/8] added test_redcloth to gemspec --- jekyll.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/jekyll.gemspec b/jekyll.gemspec index bf9bb663..444605ad 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -133,6 +133,7 @@ Gem::Specification.new do |s| test/test_rdiscount.rb test/test_site.rb test/test_tags.rb + test/test_redcloth.rb ] # = MANIFEST = From ed7f914459bc8710005535214c48803442524794 Mon Sep 17 00:00:00 2001 From: Thomas Laumann Date: Thu, 7 Jul 2011 11:29:40 +0200 Subject: [PATCH 4/8] removed unused code --- lib/jekyll/converters/textile.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index 6433dbb5..4b507996 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -29,10 +29,6 @@ module Jekyll setup r = RedCloth.new(content) r.hard_breaks = @config['redcloth']['hard_breaks'] - # if @config['redcloth']['hard_breaks'] == false - # STDERR.puts 'hards_breaks disabled' - # r.hard_breaks = false - # end r.to_html end end From 69e7f4abef6343538c6e566706bc3be24b7e0983 Mon Sep 17 00:00:00 2001 From: Carl Groner Date: Thu, 3 Nov 2011 11:54:49 -0700 Subject: [PATCH 5/8] Add test cases for default values with no explicit config. for `hard_breaks`. --- lib/jekyll/converters/textile.rb | 6 +++++- test/test_redcloth.rb | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index 4b507996..814b2080 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -28,7 +28,11 @@ module Jekyll def convert(content) setup r = RedCloth.new(content) - r.hard_breaks = @config['redcloth']['hard_breaks'] + + if !@config['redcloth'].nil? and !@config['redcloth']['hard_breaks'].nil? + r.hard_breaks = @config['redcloth']['hard_breaks'] + end + r.to_html end end diff --git a/test/test_redcloth.rb b/test/test_redcloth.rb index 9fd32be1..2b43fe24 100644 --- a/test/test_redcloth.rb +++ b/test/test_redcloth.rb @@ -1,6 +1,30 @@ 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

", @textile.convert("p. line1\nline2").strip + end + end + + context "Default hard_breaks enabled w/ redcloth section, no hard_breaks value" do + setup do + config = { + 'redcloth' => {} + } + @textile = TextileConverter.new config + end + + should "preserve single line breaks in HTML output" do + assert_equal "

line1
\nline2

", @textile.convert("p. line1\nline2").strip + end + end + context "RedCloth with hard_breaks enabled" do setup do config = { From 8c4edb655e44defd2f0c1199440cf4775f0f4277 Mon Sep 17 00:00:00 2001 From: Thomas Laumann Date: Fri, 4 Nov 2011 17:33:53 +0100 Subject: [PATCH 6/8] Have TextileConverter pass any arguments set to true in config's redcloth section to RedCloth constructor as an array of symbols. This means explicitly setting (for example): redcloth: hard_breaks: false lite_mode: true no_span_caps: true will cause RedCloth to be invoked thusly: RedCloth.new(content, [:lite_mode, :no_span_caps]) (Notice that hard_breaks is ignored.) This means, however, anything set to true in the redcloth section in _config.yml _will_ be passed to RedCloth. Mayhem may ensue. --- lib/jekyll/converters/textile.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index 814b2080..838c96a7 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -27,13 +27,18 @@ module Jekyll def convert(content) setup - r = RedCloth.new(content) - if !@config['redcloth'].nil? and !@config['redcloth']['hard_breaks'].nil? - r.hard_breaks = @config['redcloth']['hard_breaks'] + restrictions = Array.new + if !@config['redcloth'].nil? + @config['redcloth'].each do |key, value| + restrictions << key.to_sym if value + end + require 'ap' + ap restrictions end - r.to_html + + RedCloth.new(content, restrictions).to_html end end From ab3927499fc4b96ad3c0540836be4df18c6b3f94 Mon Sep 17 00:00:00 2001 From: Thomas Laumann Date: Fri, 4 Nov 2011 17:41:47 +0100 Subject: [PATCH 7/8] Forgot to remove debugging code :-/ --- lib/jekyll/converters/textile.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/jekyll/converters/textile.rb b/lib/jekyll/converters/textile.rb index 838c96a7..aa7201cd 100644 --- a/lib/jekyll/converters/textile.rb +++ b/lib/jekyll/converters/textile.rb @@ -33,11 +33,8 @@ module Jekyll @config['redcloth'].each do |key, value| restrictions << key.to_sym if value end - require 'ap' - ap restrictions end - RedCloth.new(content, restrictions).to_html end end From d80c773b0194dec9400f97c29b48fc8e63a58f3c Mon Sep 17 00:00:00 2001 From: Thomas Laumann Date: Mon, 28 Nov 2011 14:05:34 +0100 Subject: [PATCH 8/8] 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