summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2014-07-14 23:30:07 -0600
committerDan Allen <dan.j.allen@gmail.com>2014-07-14 23:30:07 -0600
commitbd4eff491ee69fc754492ff6d281b7bf4542ca1c (patch)
tree3983f3fd68938bdf37ab9d9074b6158727553c40
parent49fbbdd5c30187d3f95dc959fdbb459c8e502648 (diff)
resolves #924 correctly calculate columns if colspan used in 1st row of table
-rw-r--r--lib/asciidoctor/table.rb12
-rw-r--r--test/tables_test.rb16
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/asciidoctor/table.rb b/lib/asciidoctor/table.rb
index 763b3821..b531fcac 100644
--- a/lib/asciidoctor/table.rb
+++ b/lib/asciidoctor/table.rb
@@ -461,11 +461,15 @@ class Table::ParserContext
end
end
- 1.upto(repeat) {|i|
+ 1.upto(repeat) do |i|
# make column resolving an operation
if @col_count == -1
- @table.columns << Table::Column.new(@table, @current_row.size + i - 1)
- column = @table.columns[-1]
+ @table.columns << (column = Table::Column.new(@table, @current_row.size + i - 1))
+ if cell_spec && (cell_spec.has_key? 'colspan') && (extra_cols = cell_spec['colspan'].to_i - 1) > 0
+ extra_cols.times do |j|
+ @table.columns << Table::Column.new(@table, @current_row.size + i + j - 1)
+ end
+ end
else
# QUESTION is this right for cells that span columns?
column = @table.columns[@current_row.size]
@@ -481,7 +485,7 @@ class Table::ParserContext
# don't close the row if we're on the first line and the column count has not been set explicitly
# TODO perhaps the col_count/linenum logic should be in end_of_row? (or a should_end_row? method)
close_row if end_of_row? && (@col_count != -1 || @linenum > 0 || (eol && i == repeat))
- }
+ end
@open_cell = false
nil
end
diff --git a/test/tables_test.rb b/test/tables_test.rb
index 1bef4880..6e8dc387 100644
--- a/test/tables_test.rb
+++ b/test/tables_test.rb
@@ -487,6 +487,22 @@ d|9 2+>|10
assert_css 'table > tbody > tr:nth-child(4) > td:nth-child(2).halign-right.valign-top[colspan="2"] p code', output, 1
end
+ test 'sets up columns correctly if first row has cell that spans columns' do
+ input = <<-EOS
+|===
+2+^|AAA |CCC
+|AAA |BBB |CCC
+|AAA |BBB |CCC
+|===
+ EOS
+ output = render_embedded_string input
+ assert_css 'table > tbody > tr:nth-child(1) > td', output, 2
+ assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1)[colspan="2"]', output, 1
+ assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2):not([colspan])', output, 1
+ assert_css 'table > tbody > tr:nth-child(2) > td:not([colspan])', output, 3
+ assert_css 'table > tbody > tr:nth-child(3) > td:not([colspan])', output, 3
+ end
+
test 'supports repeating cells' do
input = <<-EOS
|===