From 4be1a58a246b4ba61ba2b6a4224458ad2659db79 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 3 Nov 2010 23:32:55 -0500 Subject: [PATCH] Update RedCloth to 4.x Use Bundler to manage RedCloth gem. 4.x should be much faster and less buggy. Unfortunately, it doesn't support mixed Textile/Markdown syntax. So we keep an (appropriately renamed) copy of 3.x around, for the users of the "Mixed" text filter. --- Gemfile | 1 + app/controllers/wiki_controller.rb | 2 +- lib/chunks/engines.rb | 3 ++- lib/{redcloth.rb => oldredcloth.rb} | 2 +- test/unit/page_renderer_test.rb | 20 ++++++++++++++------ 5 files changed, 19 insertions(+), 9 deletions(-) rename lib/{redcloth.rb => oldredcloth.rb} (99%) diff --git a/Gemfile b/Gemfile index 73232e95..b7a1b4ca 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ gem "sqlite3-ruby", :require => "sqlite3" gem "itextomml", ">=1.4.5" gem "mongrel", ">=1.2.0.pre2" gem "rubyzip" +gem "RedCloth", ">=4.0.0" gem "erubis" gem "nokogiri" gem "rake" diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 01cca47b..21c21410 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -478,7 +478,7 @@ EOL "" end dir = Rails.root.join('public') - Dir["#{dir}/**/*"].each do |f| + Dir["#{dir}/{images,javascripts,s5,stylesheets}/**/*"].each do |f| zip_out.add "public#{f.sub(dir.to_s,'')}", f end end diff --git a/lib/chunks/engines.rb b/lib/chunks/engines.rb index 9ecc9f97..9c7d07d0 100644 --- a/lib/chunks/engines.rb +++ b/lib/chunks/engines.rb @@ -6,6 +6,7 @@ require 'maruku' require 'maruku/ext/math' require_dependency 'rdocsupport' require 'redcloth' +require 'oldredcloth' # The markup engines are Chunks that call the one of RedCloth # or RDoc to convert text. This markup occurs when the chunk is required @@ -113,7 +114,7 @@ module Engines class Mixed < AbstractEngine def mask @content.as_utf8 - redcloth = RedCloth.new(@content, @content.options[:engine_opts]) + redcloth = OldRedCloth.new(@content, @content.options[:engine_opts]) redcloth.filter_html = false redcloth.no_span_caps = false html = redcloth.to_html diff --git a/lib/redcloth.rb b/lib/oldredcloth.rb similarity index 99% rename from lib/redcloth.rb rename to lib/oldredcloth.rb index 03df12b3..4d45bbe8 100644 --- a/lib/redcloth.rb +++ b/lib/oldredcloth.rb @@ -164,7 +164,7 @@ # # class RedCloth::Textile.new( str ) -class RedCloth < String +class OldRedCloth < String VERSION = '3.0.3' DEFAULT_RULES = [:textile, :markdown] diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index d4d9ca31..530ebc77 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -358,11 +358,12 @@ END_THM assert_match_markup_parsed_as(re, textile_and_markdown) set_web_property :markup, :textile assert_markup_parsed_as( - "

Markdown heading
================

\n\n\n\t

Textile heading

" + - "\n\n\n\t

some text with styles

" + - "\n\n\n\t", + "

Markdown heading
\n====

\n

Textile heading

" + + "\n

some text with styles

" + + "\n", textile_and_markdown) - + +# Mixed Textile+Markdown markup not supported by RedCloth 4.x set_web_property :markup, :mixed assert_markup_parsed_as( "

Markdown heading

\n\n\n\t

Textile heading

\n\n\n\t" + @@ -370,7 +371,14 @@ END_THM "", textile_and_markdown) end - + + def test_textile_pre + set_web_property :markup, :textile + assert_markup_parsed_as("
\n\n  a == 16\n\n
\n

foo bar" + + "
\n


\n\n b == 16\n
\n

", + "
\n\n  a == 16\n\n
\nfoo bar\n
\n\n  b == 16\n\n
") + end + def test_rdoc set_web_property :markup, :rdoc @@ -461,7 +469,7 @@ END_THM set_web_property :markup, :textile assert_markup_parsed_as( "

$$foo?" + - "$$
$foo$$
\n$foo
?$

", "$$[[foo]]$$\n$[[foo]]$") end