Skip to content

Commit 7a43c8b

Browse files
fix: ignore inline highlights that start or end in nested node
## Details Issue: #568 Since inline highlights are not actually part of the parser they are calculated by finding text inside `==`. This means it picks up text that starts / ends in code spans, emphasis blocks, and all other kinds of nested inline nodes. As a simple fix for this we now check that the start and end are at the top level, meaning the node type is `inline`.
1 parent 26097a4 commit 7a43c8b

3 files changed

Lines changed: 36 additions & 19 deletions

File tree

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.5 Last change: 2025 December 11
1+
*render-markdown.txt* For NVIM v0.11.5 Last change: 2025 December 14
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.10.7'
9+
M.version = '8.10.8'
1010

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

lua/render-markdown/render/inline/highlight.lua

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,45 @@ end
1818
---@protected
1919
function Render:run()
2020
for _, range in ipairs(self.node:find('==[^=]+==')) do
21-
-- hide first 2 equal signs
22-
self:hide(range[1], range[2], range[2] + 2)
23-
-- hide last 2 equal signs
24-
self:hide(range[3], range[4] - 2, range[4])
21+
local top_level = self:top_level(range[1], range[2])
22+
and self:top_level(range[3], range[4])
23+
if top_level then
24+
-- hide first 2 equal signs
25+
self:hide(range[1], range[2], range[2] + 2)
26+
-- hide last 2 equal signs
27+
self:hide(range[3], range[4] - 2, range[4])
2528

26-
local custom = self:custom(range, { 0, 2, 0, -2 })
27-
local highlight = self.config.highlight
28-
if custom then
29-
-- hide custom prefix
30-
self:hide(range[1], range[2] + 2, range[2] + 2 + #custom.prefix)
31-
highlight = custom.highlight
32-
end
29+
local custom = self:custom(range, { 0, 2, 0, -2 })
30+
local highlight = self.config.highlight
31+
if custom then
32+
-- hide custom prefix
33+
self:hide(range[1], range[2] + 2, range[2] + 2 + #custom.prefix)
34+
highlight = custom.highlight
35+
end
3336

34-
-- highlight contents
35-
self.marks:add(self.config, false, range[1], range[2], {
36-
end_row = range[3],
37-
end_col = range[4],
38-
hl_group = highlight,
39-
})
37+
-- highlight contents
38+
self.marks:add(self.config, false, range[1], range[2], {
39+
end_row = range[3],
40+
end_col = range[4],
41+
hl_group = highlight,
42+
})
43+
end
4044
end
4145
end
4246

47+
---@private
48+
---@param row integer
49+
---@param col integer
50+
---@return boolean
51+
function Render:top_level(row, col)
52+
local node = vim.treesitter.get_node({
53+
bufnr = self.context.buf,
54+
pos = { row, col },
55+
ignore_injections = false,
56+
})
57+
return node and node:type() == 'inline' or false
58+
end
59+
4360
---@private
4461
---@param row integer
4562
---@param start_col integer

0 commit comments

Comments
 (0)