Skip to content

Commit b2b1353

Browse files
fix: link icons following long checkboxes
## Details Issue: #564 When checkboxes are wide (either from padding or from a lot of custom text), a combination of overlay and inline virtual text is used to render them. The problem is that the inline text (which appears at the end) can use the same column value as inline link icons if a link is the first thing after the checkbox, resulting in the inline text "swapping" positions. The fix is to use a really high priority value for inline link icons as those should always appear next to the link they are for. By fixing the link icon to the right location the inline checkbox text naturally ends up in the correct location as well. This change is also applied to wiki links, though is not strictly necessary in that context. Unrelated change, use custom style when parsing queries, less noise.
1 parent 84432cb commit b2b1353

9 files changed

Lines changed: 53 additions & 60 deletions

File tree

lua/render-markdown/handler/html.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ local M = {}
88
---@param ctx render.md.handler.Context
99
---@return render.md.Mark[]
1010
function M.parse(ctx)
11-
local query = ts.parse(
12-
'html',
13-
[[
14-
(comment) @comment
15-
(element) @tag
16-
]]
17-
)
11+
-- stylua: ignore
12+
local query = ts.parse('html', [[
13+
(comment) @comment
14+
(element) @tag
15+
]])
1816
---@type table<string, render.md.Render>
1917
local renders = {
2018
comment = require('render-markdown.render.html.comment'),

lua/render-markdown/handler/markdown.lua

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,33 @@ local M = {}
88
---@param ctx render.md.handler.Context
99
---@return render.md.Mark[]
1010
function M.parse(ctx)
11-
local query = ts.parse(
12-
'markdown',
13-
[[
14-
(fenced_code_block) @code
11+
-- stylua: ignore
12+
local query = ts.parse('markdown', [[
13+
(fenced_code_block) @code
1514
16-
[
17-
(thematic_break)
18-
(minus_metadata)
19-
(plus_metadata)
20-
] @dash
15+
[
16+
(thematic_break)
17+
(minus_metadata)
18+
(plus_metadata)
19+
] @dash
2120
22-
(document) @document
21+
(document) @document
2322
24-
[
25-
(atx_heading)
26-
(setext_heading)
27-
] @heading
23+
[
24+
(atx_heading)
25+
(setext_heading)
26+
] @heading
2827
29-
(list_item) @list
28+
(list_item) @list
3029
31-
(section (paragraph) @paragraph)
30+
(section (paragraph) @paragraph)
3231
33-
(block_quote) @quote
32+
(block_quote) @quote
3433
35-
(section) @section
34+
(section) @section
3635
37-
(pipe_table) @table
38-
]]
39-
)
36+
(pipe_table) @table
37+
]])
4038
---@type table<string, render.md.Render>
4139
local renders = {
4240
code = require('render-markdown.render.markdown.code'),

lua/render-markdown/handler/markdown_inline.lua

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,23 @@ local M = {}
88
---@param ctx render.md.handler.Context
99
---@return render.md.Mark[]
1010
function M.parse(ctx)
11-
local query = ts.parse(
12-
'markdown_inline',
13-
[[
14-
(code_span) @code
11+
-- stylua: ignore
12+
local query = ts.parse('markdown_inline', [[
13+
(code_span) @code
1514
16-
((inline) @highlight
17-
(#lua-match? @highlight "==[^=]+=="))
15+
((inline) @highlight
16+
(#lua-match? @highlight "==[^=]+=="))
1817
19-
[
20-
(email_autolink)
21-
(full_reference_link)
22-
(image)
23-
(inline_link)
24-
(uri_autolink)
25-
] @link
18+
[
19+
(email_autolink)
20+
(full_reference_link)
21+
(image)
22+
(inline_link)
23+
(uri_autolink)
24+
] @link
2625
27-
(shortcut_link) @shortcut
28-
]]
29-
)
26+
(shortcut_link) @shortcut
27+
]])
3028
---@type table<string, render.md.Render>
3129
local renders = {
3230
code = require('render-markdown.render.inline.code'),

lua/render-markdown/handler/yaml.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ local M = {}
88
---@param ctx render.md.handler.Context
99
---@return render.md.Mark[]
1010
function M.parse(ctx)
11-
local query = ts.parse(
12-
'yaml',
13-
[[
14-
(block_sequence_item) @bullet
11+
-- stylua: ignore
12+
local query = ts.parse('yaml', [[
13+
(block_sequence_item) @bullet
1514
16-
((double_quote_scalar) @link
17-
(#lua-match? @link "^\"%[%[.+%]%]\"$"))
18-
]]
19-
)
15+
((double_quote_scalar) @link
16+
(#lua-match? @link "^\"%[%[.+%]%]\"$"))
17+
]])
2018
---@type table<string, render.md.Render>
2119
local renders = {
2220
bullet = require('render-markdown.render.yaml.bullet'),

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.10.5'
9+
M.version = '8.10.6'
1010

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

lua/render-markdown/render/common/wiki.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function Render:run()
5151
if not body then
5252
-- add icon
5353
self.marks:add(self.config, 'link', row, start_col, {
54+
priority = 9000,
5455
hl_mode = 'combine',
5556
virt_text = { icon },
5657
virt_text_pos = 'inline',

lua/render-markdown/render/inline/link.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ end
4949
---@protected
5050
function Render:run()
5151
self.marks:start(self.config, 'link', self.node, {
52+
priority = 9000,
5253
hl_mode = 'combine',
5354
virt_text = { self.data.icon },
5455
virt_text_pos = 'inline',

lua/render-markdown/render/markdown/quote.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ end
8181

8282
---@private
8383
function Render:markers()
84-
local query = ts.parse(
85-
'markdown',
86-
[[
87-
(block_quote_marker) @marker
88-
(block_continuation) @continuation
89-
]]
90-
)
84+
-- stylua: ignore
85+
local query = ts.parse('markdown', [[
86+
(block_quote_marker) @marker
87+
(block_continuation) @continuation
88+
]])
9189
self.context.view:nodes(self.node:get(), query, function(capture, node)
9290
if capture == 'marker' then
9391
-- marker nodes are a single '>' at the start of a block quote

tests/util.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function M.link(kind)
133133
local highlight = kind == 'wiki' and 'RmWikiLink' or 'RmLink'
134134
---@type vim.api.keyset.set_extmark
135135
return {
136+
priority = 9000,
136137
hl_mode = 'combine',
137138
virt_text = { { icons[kind], highlight } },
138139
virt_text_pos = 'inline',

0 commit comments

Comments
 (0)