Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/laumann/jekyll

  • Loading branch information...
commit d0d143452ae3b1c38ba354b5c5257c0f551de0dc 2 parents c14eb34 + d80c773
@mojombo mojombo authored
View
1  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 =
View
3  lib/jekyll.rb
@@ -98,6 +98,9 @@ module Jekyll
'coderay_bold_every' => 10,
'coderay_css' => 'style'
}
+ },
+ 'redcloth' => {
+ 'hard_breaks' => true
}
}
View
18 lib/jekyll/converters/textile.rb
@@ -27,7 +27,23 @@ def output_ext(ext)
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
View
86 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 "<p>line1<br />\nline2</p>", @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 "<p>line1<br />\nline2</p>", @textile.convert("p. line1\nline2").strip
+ end
+ end
+
+ 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 "<p>line1<br />\nline2</p>", @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 "<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
Please sign in to comment.
Something went wrong with that request. Please try again.