Skip to content

fix alignment with concealed text #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lua/render-markdown/render/markdown/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,26 @@ function Render:row(row)

if vim.tbl_contains({ 'trimmed', 'padded' }, self.config.cell) then
for i, col in ipairs(row.cols) do
-- recalculate widths should table cells contain concealed text
local highlights = vim.api.nvim_buf_get_extmarks(
0,
-1,
{ col.row, col.start_col },
{ col.row, col.end_col },
{ details = true, type = 'highlight' }
)
for _, conceal_highlight in ipairs(highlights) do
if conceal_highlight[4].hl_group == 'Conceal' then
local new_width = col.width
- (conceal_highlight[4].end_col - conceal_highlight[3])
if conceal_highlight[4].virt_text then
new_width = new_width
+ #conceal_highlight[4].virt_text[1]
end
col.width = new_width
end
end

local delim_col = self.data.delim.cols[i]
-- amount of space needed to get column to target width
local fill = delim_col.width - col.width
Expand Down