@@ -46,8 +46,17 @@ function Render:render()
4646 return
4747 end
4848 local level , root = self .node :level_in_section (' list' )
49- self :icon (level )
50- self :padding (root )
49+ --- @type render.md.BulletContext
50+ local ctx = {
51+ level = level ,
52+ index = self .node :sibling_count (' list_item' ),
53+ value = self .data .marker .text ,
54+ }
55+ local icon = self :get_icon (ctx )
56+ local left_pad = self :get_padding (ctx , self .bullet .left_pad )
57+ local right_pad = self :get_padding (ctx , self .bullet .right_pad )
58+ self :add_icon (icon )
59+ self :add_padding (left_pad , right_pad , root )
5160 end
5261end
5362
@@ -83,46 +92,63 @@ function Render:highlight_scope()
8392end
8493
8594--- @private
86- --- @param level integer
87- function Render :icon (level )
88- local node = self .data .marker
89- local index = self .node :sibling_count (' list_item' )
95+ --- @param ctx render.md.BulletContext
96+ --- @return string ?
97+ function Render :get_icon (ctx )
9098 local icons = self .data .ordered and self .bullet .ordered_icons or self .bullet .icons
91- local icon = nil
9299 if type (icons ) == ' function' then
93- icon = icons ({ level = level , index = index , value = node . text } )
100+ return icons (ctx )
94101 else
95- icon = List .cycle (icons , level )
102+ local icon = List .cycle (icons , ctx . level )
96103 if type (icon ) == ' table' then
97- icon = List .clamp (icon , index )
104+ return List .clamp (icon , ctx .index )
105+ else
106+ return icon
98107 end
99108 end
109+ end
110+
111+ --- @private
112+ --- @param ctx render.md.BulletContext
113+ --- @param pad render.md.bullet.Padding
114+ --- @return integer
115+ function Render :get_padding (ctx , pad )
116+ if type (pad ) == ' function' then
117+ return pad (ctx )
118+ else
119+ return pad
120+ end
121+ end
122+
123+ --- @private
124+ --- @param icon string ?
125+ function Render :add_icon (icon )
100126 if icon == nil then
101127 return
102128 end
103129 local text = Str .pad (self .data .spaces ) .. icon
104- local position , conceal = ' overlay' , nil
105- if Str .width (text ) > Str .width (node .text ) then
106- position , conceal = ' inline' , ' '
107- end
108- self .marks :add_over (' bullet' , node , {
130+ local overflow = Str .width (text ) > Str .width (self .data .marker .text )
131+ self .marks :add_over (' bullet' , self .data .marker , {
109132 virt_text = { { text , self .bullet .highlight } },
110- virt_text_pos = position ,
111- conceal = conceal ,
133+ virt_text_pos = overflow and ' inline ' or ' overlay ' ,
134+ conceal = overflow and ' ' or nil ,
112135 })
113136end
114137
115138--- @private
139+ --- @param left_pad integer
140+ --- @param right_pad integer
116141--- @param root ? render.md.Node
117- function Render :padding ( root )
118- if self . bullet . left_pad <= 0 and self . bullet . right_pad <= 0 then
142+ function Render :add_padding ( left_pad , right_pad , root )
143+ if left_pad <= 0 and right_pad <= 0 then
119144 return
120145 end
121- local left_col = root ~= nil and root .start_col or self .node .start_col
122- for row = self .node .start_row , self :end_row (root ) - 1 do
123- local right_col = row == self .node .start_row and self .data .marker .end_col - 1 or left_col
124- self :padding_mark (row , left_col , self .bullet .left_pad )
125- self :padding_mark (row , right_col , self .bullet .right_pad )
146+ local start_row , end_row = self .node .start_row , self :end_row (root )
147+ for row = start_row , end_row - 1 do
148+ local left_col = root ~= nil and root .start_col or self .node .start_col
149+ local right_col = row == start_row and self .data .marker .end_col - 1 or left_col
150+ self :side_padding (row , left_col , left_pad )
151+ self :side_padding (row , right_col , right_pad )
126152 end
127153end
128154
@@ -133,26 +159,26 @@ function Render:end_row(root)
133159 local next_list = self .node :child (' list' )
134160 if next_list ~= nil then
135161 return next_list .start_row
136- end
137- local end_row = self .node .end_row
138- -- On the last item of the root list ignore the last line if it is empty
139- if root ~= nil and root .end_row == end_row then
140- if Str .width (self .node :line (' last' , 0 )) == 0 then
141- return end_row - 1
162+ else
163+ local row = self .node .end_row
164+ -- On the last item of the root list ignore the last line if it is empty
165+ if root ~= nil and root .end_row == row and Str .width (root :line (' last' , 0 )) == 0 then
166+ return row - 1
167+ else
168+ return row
142169 end
143170 end
144- return end_row
145171end
146172
147173--- @private
148174--- @param row integer
149175--- @param col integer
150176--- @param amount integer
151- function Render :padding_mark (row , col , amount )
177+ function Render :side_padding (row , col , amount )
152178 if amount > 0 then
153179 self .marks :add (false , row , col , {
154180 priority = 0 ,
155- virt_text = { self :padding_text (amount ) },
181+ virt_text = { self :pad (amount ) },
156182 virt_text_pos = ' inline' ,
157183 })
158184 end
0 commit comments