Skip to content

Commit bd482f9

Browse files
chore(refactor): store node associated with columns when parsing tables
1 parent 1641b43 commit bd482f9

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
- support math superscript characters and body transformer for footnotes [48934b4](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/48934b49a2363b49ae1d698ed4cb30fb79d7efe8)
1515
- disable code based on languages [#596](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/596)
1616
[477997f](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/477997fc95432e9241e8cabaebfcda998863b2d6)
17+
- allow custom link icons to be disabled for images [8a71090](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/8a710903a95053955a063949a434189987387818)
18+
- heading icon eol position [#593](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/593)
19+
[1641b43](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/1641b434bda26e0f4e3610985b3357fc213cf834)
1720

1821
### Bug Fixes
1922

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.6 Last change: 2026 March 02
1+
*render-markdown.txt* For NVIM v0.11.6 Last change: 2026 March 04
22

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

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local state = require('render-markdown.state')
66
local M = {}
77

88
---@private
9-
M.version = '8.11.12'
9+
M.version = '8.11.13'
1010

1111
function M.check()
1212
M.start('versions')

lua/render-markdown/render/markdown/table.lua

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ local Alignment = {
2929
---@field cols render.md.table.body.Col[]
3030

3131
---@class render.md.table.body.Col
32-
---@field row integer
33-
---@field start_col integer
34-
---@field end_col integer
32+
---@field node render.md.Node
3533
---@field width integer
3634
---@field space render.md.table.Space
3735

@@ -187,9 +185,7 @@ function Render:parse_body_row(node, num_cols)
187185
+ self.config.cell_offset({ node = cell:get() })
188186
assert(width >= 0, 'invalid table layout')
189187
cols[#cols + 1] = {
190-
row = cell.start_row,
191-
start_col = cell.start_col,
192-
end_col = cell.end_col,
188+
node = cell,
193189
width = width,
194190
space = {
195191
-- gap between the cell start and the pipe start
@@ -292,6 +288,7 @@ function Render:row(row)
292288

293289
if vim.tbl_contains({ 'trimmed', 'padded' }, self.config.cell) then
294290
for i, col in ipairs(row.cols) do
291+
local node = col.node
295292
local delim = self.data.delim.cols[i]
296293
local space = col.space
297294
local fill = delim.width - col.width
@@ -301,25 +298,25 @@ function Render:row(row)
301298
if not self.context.conceal:enabled() then
302299
-- result: ----XXXXXXX--_______
303300
-- without concealing it is impossible to do full alignment
304-
self:shift(col, 'right', fill)
301+
self:shift(node, 'right', fill)
305302
elseif delim.alignment == Alignment.center then
306303
-- (7 + 2 - 4) // 2 = 5 // 2 = 2 -> move two spaces to the right
307304
-- result: __----XXXXXXX--_____
308305
local shift = math.floor((fill + space.right - space.left) / 2)
309-
self:shift(col, 'left', shift)
310-
self:shift(col, 'right', fill - shift)
306+
self:shift(node, 'left', shift)
307+
self:shift(node, 'right', fill - shift)
311308
elseif delim.alignment == Alignment.right then
312309
-- 2 - 1 = 1 -> conceal one space on right side
313310
-- result: -_______----XXXXXXX-
314311
local shift = space.right - self.config.padding
315-
self:shift(col, 'left', fill + shift)
316-
self:shift(col, 'right', -shift)
312+
self:shift(node, 'left', fill + shift)
313+
self:shift(node, 'right', -shift)
317314
else
318315
-- 4 - 1 = 3 -> conceal three spaces on left side
319316
-- result: -XXXXXXX--_______---
320317
local shift = space.left - self.config.padding
321-
self:shift(col, 'left', -shift)
322-
self:shift(col, 'right', fill + shift)
318+
self:shift(node, 'left', -shift)
319+
self:shift(node, 'right', fill + shift)
323320
end
324321
end
325322
elseif self.config.cell == 'overlay' then
@@ -332,22 +329,22 @@ end
332329

333330
---Use low priority to include pipe marks
334331
---@private
335-
---@param col render.md.table.body.Col
332+
---@param node render.md.Node
336333
---@param side 'left'|'right'
337334
---@param amount integer
338-
function Render:shift(col, side, amount)
339-
local column = side == 'left' and col.start_col or col.end_col
335+
function Render:shift(node, side, amount)
336+
local col = side == 'left' and node.start_col or node.end_col
340337
if amount > 0 then
341-
self.marks:add(self.config, true, col.row, column, {
338+
self.marks:add(self.config, true, node.start_row, col, {
342339
priority = 0,
343340
virt_text = self:line():pad(amount, self.config.filler):get(),
344341
virt_text_pos = 'inline',
345342
})
346343
elseif amount < 0 then
347344
amount = amount - self.context.conceal:width('', 1)
348-
self.marks:add(self.config, true, col.row, column + amount, {
345+
self.marks:add(self.config, true, node.start_row, col + amount, {
349346
priority = 0,
350-
end_col = column,
347+
end_col = col,
351348
conceal = '',
352349
})
353350
end

0 commit comments

Comments
 (0)