Skip to content

Commit 72688ba

Browse files
fix: wiki links nested in tables
1 parent abc02f3 commit 72688ba

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

Diff for: 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: 2024 August 11
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 August 12
22

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

Diff for: lua/render-markdown/context.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local util = require('render-markdown.util')
77
---@field private top integer
88
---@field private bottom integer
99
---@field private conceal? table<integer, [integer, integer][]>
10-
---@field private links table<integer, [integer, integer, string][]>
10+
---@field private links table<integer, [integer, integer, integer][]>
1111
local Context = {}
1212
Context.__index = Context
1313

@@ -30,22 +30,22 @@ function Context.new(buf, win, offset)
3030
end
3131

3232
---@param info render.md.NodeInfo
33-
---@param icon string
34-
function Context:add_link(info, icon)
33+
---@param amount integer
34+
function Context:add_offset(info, amount)
3535
local row = info.start_row
3636
if self.links[row] == nil then
3737
self.links[row] = {}
3838
end
39-
table.insert(self.links[row], { info.start_col, info.end_col, icon })
39+
table.insert(self.links[row], { info.start_col, info.end_col, amount })
4040
end
4141

4242
---@param info render.md.NodeInfo
4343
---@return integer
44-
function Context:link_width(info)
44+
function Context:get_offset(info)
4545
local result = 0
46-
for _, icon_range in ipairs(self.links[info.start_row] or {}) do
47-
if info.start_col < icon_range[2] and info.end_col > icon_range[1] then
48-
result = result + str.width(icon_range[3])
46+
for _, offset_range in ipairs(self.links[info.start_row] or {}) do
47+
if info.start_col < offset_range[2] and info.end_col > offset_range[1] then
48+
result = result + offset_range[3]
4949
end
5050
end
5151
return result

Diff for: lua/render-markdown/handler/markdown.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function Handler:heading_width(info, heading_width, icon_width)
178178
local width = heading.left_pad + icon_width + heading.right_pad
179179
local content = info:sibling('inline')
180180
if content ~= nil then
181-
width = width + str.width(content.text) + self.context:link_width(content) - self.context:concealed(content)
181+
width = width + str.width(content.text) + self.context:get_offset(content) - self.context:concealed(content)
182182
end
183183
return math.max(width, heading.min_width)
184184
else

Diff for: lua/render-markdown/handler/markdown_inline.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@ function Handler:wiki_link(info)
146146
local text = info.text:sub(2, -2)
147147
local parts = str.split(text, '|')
148148
local icon, highlight = self:dest_virt_text(parts[1])
149-
self:add(info.start_row, info.start_col - 1, {
149+
local link_text = icon .. parts[#parts]
150+
local added = self:add(info.start_row, info.start_col - 1, {
150151
end_row = info.end_row,
151152
end_col = info.end_col + 1,
152-
virt_text = { { icon .. parts[#parts], highlight } },
153+
virt_text = { { link_text, highlight } },
153154
virt_text_pos = 'inline',
154155
conceal = '',
155156
})
157+
if added then
158+
self.context:add_offset(info, str.width(link_text) - str.width(info.text))
159+
end
156160
end
157161

158162
---@private
@@ -169,7 +173,7 @@ function Handler:link(info)
169173
virt_text_pos = 'inline',
170174
})
171175
if added then
172-
self.context:add_link(info, icon)
176+
self.context:add_offset(info, str.width(icon))
173177
end
174178
end
175179

Diff for: lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.1.2'
8+
M.version = '6.1.3'
99

1010
function M.check()
1111
vim.health.start('render-markdown.nvim [version]')

Diff for: lua/render-markdown/parser/pipe_table.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function M.parse_row(context, info, num_columns)
145145
-- Account for double width glyphs by replacing cell spacing with text width
146146
width = width - (cell.end_col - cell.start_col) + str.width(cell.text)
147147
-- Remove concealed and add inlined text
148-
width = width - context:concealed(cell) + context:link_width(cell)
148+
width = width - context:concealed(cell) + context:get_offset(cell)
149149
if width < 0 then
150150
return nil
151151
end

0 commit comments

Comments
 (0)