diff options
-rw-r--r-- | lib/redcloth3.rb | 6 | ||||
-rw-r--r-- | test/unit/helpers/application_helper_test.rb | 20 |
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/redcloth3.rb b/lib/redcloth3.rb index 638ef6d97..220617f14 100644 --- a/lib/redcloth3.rb +++ b/lib/redcloth3.rb @@ -1051,7 +1051,11 @@ class RedCloth3 < String else htmlesc( aftertag, :NoQuotes ) if aftertag line = "<redpre##{ @pre_list.length }>" - @pre_list << "#{ $3.gsub(/<(#{ OFFTAGS })[^>]*>/, '<\\1>') }#{ aftertag }" + $3.match(/<#{ OFFTAGS }([^>]*)>/) + tag = $1 + $2.to_s.match(/(class\=\S+)/i) + tag << " #{$1}" if $1 + @pre_list << "<#{ tag }>#{ aftertag }" end elsif $1 and codepre > 0 if codepre - used_offtags.length > 0 diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index cbf5a54bc..b3ff974e9 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -192,8 +192,9 @@ class ApplicationHelperTest < HelperTestCase "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>", "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", "<!-- opening comment" => "<p><!-- opening comment</p>", - # remove attributes - "<pre class='foo'>some text</pre>" => "<pre>some text</pre>", + # remove attributes except class + "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>", + "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>", } to_test.each { |text, result| assert_equal result, textilizable(text) } end @@ -207,6 +208,21 @@ class ApplicationHelperTest < HelperTestCase to_test.each { |text, result| assert_equal result, textilizable(text) } end + def syntax_highlight + raw = <<-RAW +<pre><code class="ruby"> +# Some ruby code here +</pre></code> +RAW + + expected = <<-EXPECTED +<pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span> +</pre></code> +EXPECTED + + assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') + end + def test_wiki_links_in_tables to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => '<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' + |