Skip to content

Commit

Permalink
Correctly calculate table cell width when subsequent cell has a longe…
Browse files Browse the repository at this point in the history
…r format than the content of the cell
  • Loading branch information
hasty committed Aug 9, 2024
1 parent b957b97 commit 5ac2d70
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 97 deletions.
7 changes: 6 additions & 1 deletion asciidoc/render/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func renderRow(cxt Target, cells []*tableCell, colOffsets []int, columns []*asci
index += 2
effectiveFormat := inheritColumnFormat(c.formatter, i, columns)

if i == len(cells)-1 || i+colSpan > len(cells)-1 {
if i == len(cells)-1 || i+colSpan > len(cells)-1 { // Either this is the last cell, or all subsequent cells are blank
writeCellValue(cxt, c, c.width, index, effectiveFormat)
break
}
Expand Down Expand Up @@ -229,6 +229,11 @@ func offsetsForRow(cells []*tableCell) (offsets []int) {
if nextCell.formatter != nil {
format = renderTableCellFormat(nextCell.formatter)
c.margin = utf8.RuneCountInString(format)
if c.width != 0 {
c.width += c.margin + 1 // We added two spaces above
} else if !c.blank {
c.width += c.margin // Empty cell, we only added one space above
}
width += c.margin
}
break
Expand Down
Loading

0 comments on commit 5ac2d70

Please sign in to comment.