@@ -67,49 +67,10 @@ M.render_heading = function(buf, info)
67
67
local marks = {}
68
68
69
69
local level = str .width (info .text )
70
- local foreground = list .clamp (heading .foregrounds , level )
71
70
local icon = list .cycle (heading .icons , level )
71
+ local foreground = list .clamp (heading .foregrounds , level )
72
72
local background = list .clamp (heading .backgrounds , level )
73
73
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
98
- --- @type render.md.Mark
99
- local icon_mark = {
100
- conceal = true ,
101
- start_row = info .start_row ,
102
- start_col = info .start_col ,
103
- opts = {
104
- end_row = info .end_row ,
105
- end_col = info .end_col ,
106
- virt_text = { { str .pad (icon , padding ), { foreground , background } } },
107
- virt_text_pos = ' overlay' ,
108
- },
109
- }
110
- list .add (marks , icon_mark )
111
- end
112
- end
113
74
--- @type render.md.Mark
114
75
local background_mark = {
115
76
conceal = true ,
@@ -126,7 +87,46 @@ M.render_heading = function(buf, info)
126
87
if heading .sign then
127
88
list .add (marks , M .render_sign (buf , info , list .cycle (heading .signs , level ), foreground ))
128
89
end
129
-
90
+ if icon == nil then
91
+ return marks
92
+ end
93
+ -- Available width is level + 1 - concealed, where level = number of `#` characters, one
94
+ -- is added to account for the space after the last `#` but before the heading title,
95
+ -- and concealed text is subtracted since that space is not usable
96
+ local padding = level + 1 - ts .concealed (buf , info ) - str .width (icon )
97
+ if padding < 0 then
98
+ -- Requires inline extmarks to place when there is not enough space available
99
+ if util .has_10 then
100
+ --- @type render.md.Mark
101
+ local icon_mark = {
102
+ conceal = true ,
103
+ start_row = info .start_row ,
104
+ start_col = info .start_col ,
105
+ opts = {
106
+ end_row = info .end_row ,
107
+ end_col = info .end_col ,
108
+ virt_text = { { icon , { foreground , background } } },
109
+ virt_text_pos = ' inline' ,
110
+ conceal = ' ' ,
111
+ },
112
+ }
113
+ list .add (marks , icon_mark )
114
+ end
115
+ else
116
+ --- @type render.md.Mark
117
+ local icon_mark = {
118
+ conceal = true ,
119
+ start_row = info .start_row ,
120
+ start_col = info .start_col ,
121
+ opts = {
122
+ end_row = info .end_row ,
123
+ end_col = info .end_col ,
124
+ virt_text = { { str .pad (icon , padding ), { foreground , background } } },
125
+ virt_text_pos = ' overlay' ,
126
+ },
127
+ }
128
+ list .add (marks , icon_mark )
129
+ end
130
130
return marks
131
131
end
132
132
@@ -333,12 +333,15 @@ M.render_list_marker = function(buf, info)
333
333
if not bullet .enabled then
334
334
return nil
335
335
end
336
+ local level = ts .level_in_section (info , ' list' )
337
+ local icon = list .cycle (bullet .icons , level )
338
+ if icon == nil then
339
+ return nil
340
+ end
336
341
-- List markers from tree-sitter should have leading spaces removed, however there are known
337
342
-- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
338
343
-- As a result we handle leading spaces here, can remove if this gets fixed upstream
339
344
local leading_spaces = str .leading_spaces (info .text )
340
- local level = ts .level_in_section (info , ' list' )
341
- local icon = list .cycle (bullet .icons , level )
342
345
--- @type render.md.Mark
343
346
return {
344
347
conceal = true ,
@@ -408,12 +411,12 @@ end
408
411
--- @private
409
412
--- @param buf integer
410
413
--- @param info render.md.NodeInfo
411
- --- @param text string
414
+ --- @param text string ?
412
415
--- @param highlight string
413
416
--- @return render.md.Mark ?
414
417
M .render_sign = function (buf , info , text , highlight )
415
418
local sign = state .config .sign
416
- if not sign .enabled then
419
+ if not sign .enabled or text == nil then
417
420
return nil
418
421
end
419
422
if vim .tbl_contains (sign .exclude .buftypes , util .get_buf (buf , ' buftype' )) then
0 commit comments