From 735db3dae5c16d13bf7ae3af992bb9b23644a4fa Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 4 Jun 2008 17:12:59 +0000 Subject: [PATCH] Allow empty cells in wiki tables. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1490 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redcloth.rb | 17 ++++-------- test/unit/helpers/application_helper_test.rb | 29 ++++++++++++++++---- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/redcloth.rb b/lib/redcloth.rb index 344fd6c78..3880eb9d3 100644 --- a/lib/redcloth.rb +++ b/lib/redcloth.rb @@ -504,26 +504,19 @@ class RedCloth < String tatts = shelve( tatts ) if tatts rows = [] - fullrow. - split( /\|$/m ). - delete_if { |x| x.empty? }. - each do |row| - + fullrow.each_line do |row| ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/m - cells = [] - #row.split( /\(?!\[\[[^\]])|(?![^\[]\]\])/ ).each do |cell| - row.split( /\|(?![^\[\|]*\]\])/ ).each do |cell| + row.split( /(\|)(?![^\[\|]*\]\])/ )[1..-2].each do |cell| + next if cell == '|' ctyp = 'd' ctyp = 'h' if cell =~ /^_/ catts = '' catts, cell = pba( $1, 'td' ), $2 if cell =~ /^(_?#{S}#{A}#{C}\. ?)(.*)/ - unless cell.strip.empty? - catts = shelve( catts ) if catts - cells << "\t\t\t#{ cell }" - end + catts = shelve( catts ) if catts + cells << "\t\t\t#{ cell }" end ratts = shelve( ratts ) if ratts rows << "\t\t\n#{ cells.join( "\n" ) }\n\t\t" diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index f8bf4a602..937d8aa20 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -152,12 +152,7 @@ class ApplicationHelperTest < HelperTestCase end def test_wiki_links_in_tables - to_test = {"|Cell 11|Cell 12|Cell 13|\n|Cell 21|Cell 22||\n|Cell 31||Cell 33|" => - 'Cell 11Cell 12Cell 13' + - 'Cell 21Cell 22' + - 'Cell 31Cell 33', - - "|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => + to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => 'Link title' + 'Other title' + 'Cell 21Last page' @@ -218,6 +213,28 @@ EXPECTED assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') end + def test_table + raw = <<-RAW +This is a table with empty cells: + +|cell11|cell12|| +|cell21||cell23| +|cell31|cell32|cell33| +RAW + + expected = <<-EXPECTED +

This is a table with empty cells:

+ + + + + +
cell11cell12
cell21cell23
cell31cell32cell33
+EXPECTED + + assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') + end + def test_macro_hello_world text = "{{hello_world}}" assert textilizable(text).match(/Hello world!/) -- 2.39.5