Skip to content

Commit 786d643

Browse files
fix: ensure space for cell padding
## Details Issue: #287 We have a default padding of 1 set for pipe table cells. However when there is not actually enough space available to create this padding we end up with unhandled negative values which lead to poor rendering. To fix this adjust column width calculation to account for needed space. For example if we have a cell like `|foo|`, it would normally have a width of 3. Naturally there is not enough space on either side for padding. The fix adds to the width value for each cell to ensure it can allow for the specified amount of padding on both side, so now the width calculation is 5. With a column width of 5 and the cell still having an actual width of 3 we'll end up doing the correct thing and adding a space on both sides resulting in `| foo |`.
1 parent bab0663 commit 786d643

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

doc/render-markdown.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2025 January 06
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 January 07
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '7.8.2'
8+
M.version = '7.8.3'
99

1010
function M.check()
1111
M.start('version')

lua/render-markdown/render/table.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ function Render:setup()
9292
for _, row in ipairs(rows) do
9393
for i, column in ipairs(row.columns) do
9494
local width = column.width
95+
local space_available = column.space.left + column.space.right - (2 * self.table.padding)
96+
-- If we don't have enough space for padding add it to the width
97+
if space_available < 0 then
98+
width = width - space_available
99+
end
95100
if self.table.cell == 'trimmed' then
96-
local space_available = column.space.left + column.space.right - (2 * self.table.padding)
97101
width = width - math.max(space_available, 0)
98102
end
99103
local delim_column = delim.columns[i]

0 commit comments

Comments
 (0)