]> source.dussan.org Git - redmine.git/commitdiff
Allow empty cells in wiki tables.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 4 Jun 2008 17:12:59 +0000 (17:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 4 Jun 2008 17:12:59 +0000 (17:12 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1490 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redcloth.rb
test/unit/helpers/application_helper_test.rb

index 344fd6c78e8bb0e329b31cbc95c3c4bd65a491bd..3880eb9d3d8adce5b093156c373e3e964f7d5352 100644 (file)
@@ -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<t#{ ctyp }#{ catts }>#{ cell }</t#{ ctyp }>" 
-                    end
+                    catts = shelve( catts ) if catts
+                    cells << "\t\t\t<t#{ ctyp }#{ catts }>#{ cell }</t#{ ctyp }>" 
                 end
                 ratts = shelve( ratts ) if ratts
                 rows << "\t\t<tr#{ ratts }>\n#{ cells.join( "\n" ) }\n\t\t</tr>"
index f8bf4a602e33621880c1a10acb7cf7b9727752f8..937d8aa20b144e6ccb81a49ff525571eb7c6578e 100644 (file)
@@ -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|" => 
-                 '<tr><td>Cell 11</td><td>Cell 12</td><td>Cell 13</td></tr>' +
-                 '<tr><td>Cell 21</td><td>Cell 22</td></tr>' +
-                 '<tr><td>Cell 31</td><td>Cell 33</td></tr>',
-                 
-               "|[[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]]|" =>
                  '<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' +
                  '<td><a href="/wiki/ecookbook/Other_Page" class="wiki-page new">Other title</a></td>' +
                  '</tr><tr><td>Cell 21</td><td><a href="/wiki/ecookbook/Last_page" class="wiki-page new">Last page</a></td></tr>'
@@ -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
+<p>This is a table with empty cells:</p>
+
+<table>
+  <tr><td>cell11</td><td>cell12</td><td></td></tr>
+  <tr><td>cell21</td><td></td><td>cell23</td></tr>
+  <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
+</table>
+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!/)