summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2024-05-15 18:47:45 -0400
committerGitHub <noreply@github.com>2024-05-15 16:47:45 -0600
commit75102018aee78a7b7f174c8092e7fcba76609228 (patch)
tree74557f6dba98c8044a5c61afe0d2a1c51e7e616a /lib
parentdf9b7ec0e020b689bdf2354886b4adb7cbe2c15b (diff)
resolves #4587 only drop current row if colspan of last cell exceeds specified number of columns (PR #4588)
Diffstat (limited to 'lib')
-rw-r--r--lib/asciidoctor/table.rb27
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/asciidoctor/table.rb b/lib/asciidoctor/table.rb
index cc95a152..87ad4c7d 100644
--- a/lib/asciidoctor/table.rb
+++ b/lib/asciidoctor/table.rb
@@ -661,23 +661,24 @@ class Table::ParserContext
end
end
else
- # QUESTION is this right for cells that span columns?
- unless (column = @table.columns[@current_row.size])
- logger.error message_with_context 'dropping cell because it exceeds specified number of columns', source_location: @reader.cursor_before_mark
- return
- end
+ column = @table.columns[@current_row.size]
end
- cell = Table::Cell.new column, cell_text, cellspec, cursor: @reader.cursor_before_mark
+ cell = Table::Cell.new column, cell_text, cellspec, cursor: (cursor_before_mark = @reader.cursor_before_mark)
@reader.mark
unless !cell.rowspan || cell.rowspan == 1
activate_rowspan(cell.rowspan, (cell.colspan || 1))
end
@column_visits += (cell.colspan || 1)
@current_row << cell
- # don't close the row if we're on the first line and the column count has not been set explicitly
- # TODO perhaps the colcount/linenum logic should be in end_of_row? (or a should_end_row? method)
- close_row if end_of_row? && (@colcount != -1 || @linenum > 0 || (eol && i == repeat))
+ if (row_status = end_of_row?) > -1 && (@colcount != -1 || @linenum > 0 || (eol && i == repeat))
+ if row_status > 0
+ logger.error message_with_context 'dropping cell because it exceeds specified number of columns', source_location: cursor_before_mark
+ close_row true
+ else
+ close_row
+ end
+ end
end
@cell_open = false
nil
@@ -689,8 +690,8 @@ class Table::ParserContext
# Array and counter variables.
#
# returns nothing
- def close_row
- @table.rows.body << @current_row
+ def close_row drop = false
+ @table.rows.body << @current_row unless drop
# don't have to account for active rowspans here
# since we know this is first row
@colcount = @column_visits if @colcount == -1
@@ -711,8 +712,10 @@ class Table::ParserContext
end
# Internal: Check whether we've met the number of effective columns for the current row.
+ #
+ # returns -1 if not at end of row, 0 if exactly at end of row, and 1 if overruns end of row
def end_of_row?
- @colcount == -1 || effective_column_visits == @colcount
+ @colcount == -1 ? 0 : effective_column_visits <=> @colcount
end
# Internal: Calculate the effective column visits, which consists of the number of