Skip to content

Commit dfd69a1

Browse files
chore(refactor): use add_start helper for adding mark to the start of another node
1 parent 6d446de commit dfd69a1

File tree

12 files changed

+32
-40
lines changed

12 files changed

+32
-40
lines changed

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 0.10.0 Last change: 2025 February 19
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 February 20
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
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.0.5'
8+
M.version = '8.0.6'
99

1010
function M.check()
1111
M.start('version')

lua/render-markdown/lib/list.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ function Marks:get()
2929
return self.marks
3030
end
3131

32+
---@param element boolean|render.md.Element
33+
---@param node render.md.Node
34+
---@param opts vim.api.keyset.set_extmark
35+
---@return boolean
36+
function Marks:add_start(element, node, opts)
37+
return self:add(element, node.start_row, node.start_col, opts)
38+
end
39+
3240
---@param element boolean|render.md.Element
3341
---@param node render.md.Node
3442
---@param opts vim.api.keyset.set_extmark

lua/render-markdown/render/base.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Base:sign(text, highlight)
3838
if highlight ~= nil then
3939
sign_highlight = colors.combine(highlight, sign_highlight)
4040
end
41-
self.marks:add('sign', self.node.start_row, self.node.start_col, {
41+
self.marks:add_start('sign', self.node, {
4242
sign_text = text,
4343
sign_hl_group = sign_highlight,
4444
})
@@ -55,9 +55,7 @@ function Base:checkbox_scope(paragraph, highlight)
5555
if paragraph == nil then
5656
return
5757
end
58-
self.marks:add_over('check_scope', paragraph, {
59-
hl_group = highlight,
60-
})
58+
self.marks:add_over('check_scope', paragraph, { hl_group = highlight })
6159
end
6260

6361
---@protected

lua/render-markdown/render/code.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ function Render:language()
135135

136136
if self.code.position == 'left' then
137137
if self.code.language_name and self:hidden(node) then
138-
-- Code blocks will pick up varying amounts of leading white space depending on the
139-
-- context they are in. This gets lumped into the delimiter node and as a result,
140-
-- after concealing, the extmark will be left shifted. Logic below accounts for this.
138+
-- Code blocks pick up varying amounts of leading white space depending
139+
-- on the context they are in. This is lumped into the delimiter node and
140+
-- as a result, after concealing, the extmark would be shifted.
141141
local padding = Str.spaces('start', self.node.text) + self.data.language_padding
142142
icon_text = Str.pad(padding) .. icon_text .. node.text
143143
end
144-
return self.marks:add('code_language', node.start_row, node.start_col, {
144+
return self.marks:add_start('code_language', node, {
145145
virt_text = { { icon_text, highlight } },
146146
virt_text_pos = 'inline',
147147
})

lua/render-markdown/render/code_inline.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ function Render:setup()
1818
end
1919

2020
function Render:render()
21-
self.marks:add_over('code_background', self.node, {
22-
hl_group = self.code.highlight_inline,
23-
})
24-
self:side_padding(self.node.start_row, self.node.start_col)
25-
self:side_padding(self.node.end_row, self.node.end_col)
21+
local highlight = self.code.highlight_inline
22+
self.marks:add_over('code_background', self.node, { hl_group = highlight })
23+
self:side_padding(highlight, self.node.start_row, self.node.start_col)
24+
self:side_padding(highlight, self.node.end_row, self.node.end_col)
2625
end
2726

2827
---@private
28+
---@param highlight string
2929
---@param row integer
3030
---@param col integer
31-
function Render:side_padding(row, col)
32-
local padding, highlight = self.code.inline_pad, self.code.highlight_inline
31+
function Render:side_padding(highlight, row, col)
32+
local padding = self.code.inline_pad
3333
if padding > 0 then
3434
self.marks:add(true, row, col, {
3535
priority = 0,

lua/render-markdown/render/heading.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ function Render:icon()
123123
return width
124124
end
125125
if self.heading.position == 'right' then
126-
self.marks:add_over(true, marker, {
127-
conceal = '',
128-
}, { 0, 0, 0, 1 })
126+
self.marks:add_over(true, marker, { conceal = '' }, { 0, 0, 0, 1 })
129127
self.marks:add_over('head_icon', marker, {
130128
priority = 1000,
131129
virt_text = { { icon, highlight } },
@@ -320,9 +318,7 @@ end
320318

321319
---@private
322320
function Render:conceal_underline()
323-
self.marks:add_over(true, self.data.marker, {
324-
conceal = '',
325-
})
321+
self.marks:add_over(true, self.data.marker, { conceal = '' })
326322
end
327323

328324
return Render

lua/render-markdown/render/html_comment.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ function Render:setup()
1515
end
1616

1717
function Render:render()
18-
self.marks:add_over(true, self.node, {
19-
conceal = '',
20-
})
18+
self.marks:add_over(true, self.node, { conceal = '' })
2119
if self.comment.text ~= nil then
2220
self.marks:add_over(true, self.node, {
2321
virt_text = { { self.comment.text, self.comment.highlight } },

lua/render-markdown/render/html_tag.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222
function Render:render()
2323
self:hide('start_tag')
2424
self:hide('end_tag')
25-
self.marks:add(false, self.node.start_row, self.node.start_col, {
25+
self.marks:add_start(false, self.node, {
2626
virt_text = { { self.tag.icon, self.tag.highlight } },
2727
virt_text_pos = 'inline',
2828
})
@@ -33,9 +33,7 @@ end
3333
function Render:hide(child)
3434
local node = self.node:child(child)
3535
if node ~= nil then
36-
self.marks:add_over(true, node, {
37-
conceal = '',
38-
})
36+
self.marks:add_over(true, node, { conceal = '' })
3937
end
4038
end
4139

lua/render-markdown/render/link.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ function Render:render()
4545
})
4646
if self.data.autolink then
4747
self:hide_bracket(self.node.start_col)
48-
self.marks:add_over('link', self.node, {
49-
hl_group = self.data.highlight,
50-
})
48+
self.marks:add_over('link', self.node, { hl_group = self.data.highlight })
5149
self:hide_bracket(self.node.end_col - 1)
5250
end
5351
end

0 commit comments

Comments
 (0)