Skip to content

Commit f9d54a8

Browse files
authored
feat(heading): allow disabling heading icons by setting it to an empty list (#86)
1 parent 71782d7 commit f9d54a8

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

lua/render-markdown/handler/markdown.lua

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,30 @@ M.render_heading = function(buf, info)
7171
local icon = list.cycle(heading.icons, level)
7272
local background = list.clamp(heading.backgrounds, level)
7373

74-
-- Available width is level + 1 - concealed, where level = number of `#` characters, one
75-
-- is added to account for the space after the last `#` but before the heading title,
76-
-- and concealed text is subtracted since that space is not usable
77-
local padding = level + 1 - ts.concealed(buf, info) - str.width(icon)
78-
if padding < 0 then
79-
-- Requires inline extmarks to place when there is not enough space available
80-
if util.has_10 then
74+
if icon then
75+
-- Available width is level + 1 - concealed, where level = number of `#` characters, one
76+
-- is added to account for the space after the last `#` but before the heading title,
77+
-- and concealed text is subtracted since that space is not usable
78+
local padding = level + 1 - ts.concealed(buf, info) - str.width(icon)
79+
if padding < 0 then
80+
-- Requires inline extmarks to place when there is not enough space available
81+
if util.has_10 then
82+
---@type render.md.Mark
83+
local icon_mark = {
84+
conceal = true,
85+
start_row = info.start_row,
86+
start_col = info.start_col,
87+
opts = {
88+
end_row = info.end_row,
89+
end_col = info.end_col,
90+
virt_text = { { icon, { foreground, background } } },
91+
virt_text_pos = 'inline',
92+
conceal = '',
93+
},
94+
}
95+
list.add(marks, icon_mark)
96+
end
97+
else
8198
---@type render.md.Mark
8299
local icon_mark = {
83100
conceal = true,
@@ -86,27 +103,12 @@ M.render_heading = function(buf, info)
86103
opts = {
87104
end_row = info.end_row,
88105
end_col = info.end_col,
89-
virt_text = { { icon, { foreground, background } } },
90-
virt_text_pos = 'inline',
91-
conceal = '',
106+
virt_text = { { str.pad(icon, padding), { foreground, background } } },
107+
virt_text_pos = 'overlay',
92108
},
93109
}
94110
list.add(marks, icon_mark)
95111
end
96-
else
97-
---@type render.md.Mark
98-
local icon_mark = {
99-
conceal = true,
100-
start_row = info.start_row,
101-
start_col = info.start_col,
102-
opts = {
103-
end_row = info.end_row,
104-
end_col = info.end_col,
105-
virt_text = { { str.pad(icon, padding), { foreground, background } } },
106-
virt_text_pos = 'overlay',
107-
},
108-
}
109-
list.add(marks, icon_mark)
110112
end
111113
---@type render.md.Mark
112114
local background_mark = {

0 commit comments

Comments
 (0)