@@ -101,7 +101,6 @@ function Handler:heading(info)
101101 })
102102
103103 local width = self :heading_width (info , icon_width )
104-
105104 if heading .width == ' block' then
106105 -- Overwrite anything beyond width with Normal
107106 self :add (true , info .start_row , 0 , {
@@ -110,33 +109,8 @@ function Handler:heading(info)
110109 virt_text_win_col = width ,
111110 })
112111 end
113-
114112 if heading .border then
115- local text_above = { heading .above :rep (width ), colors .inverse (background ) }
116- if info :line (' above' ) == ' ' and info .start_row - 1 ~= self .last_heading_border then
117- self :add (true , info .start_row - 1 , 0 , {
118- virt_text = { text_above },
119- virt_text_pos = ' overlay' ,
120- })
121- else
122- self :add (false , info .start_row , 0 , {
123- virt_lines = { { text_above } },
124- virt_lines_above = true ,
125- })
126- end
127-
128- local text_below = { heading .below :rep (width ), colors .inverse (background ) }
129- if info :line (' below' ) == ' ' then
130- self :add (true , info .end_row + 1 , 0 , {
131- virt_text = { text_below },
132- virt_text_pos = ' overlay' ,
133- })
134- self .last_heading_border = info .end_row + 1
135- else
136- self :add (false , info .end_row , 0 , {
137- virt_lines = { { text_below } },
138- })
139- end
113+ self :heading_border (info , level , foreground , colors .inverse (background ), width )
140114 end
141115
142116 if heading .left_pad > 0 then
@@ -205,6 +179,51 @@ function Handler:heading_width(info, icon_width)
205179 end
206180end
207181
182+ --- @private
183+ --- @param info render.md.NodeInfo
184+ --- @param level integer
185+ --- @param foreground string
186+ --- @param background string
187+ --- @param width integer
188+ function Handler :heading_border (info , level , foreground , background , width )
189+ local heading = self .config .heading
190+ local prefix = heading .border_prefix and level or 0
191+
192+ local line_above = {
193+ { heading .above :rep (heading .left_pad ), background },
194+ { heading .above :rep (prefix ), foreground },
195+ { heading .above :rep (width - heading .left_pad - prefix ), background },
196+ }
197+ if str .width (info :line (' above' )) == 0 and info .start_row - 1 ~= self .last_heading_border then
198+ self :add (true , info .start_row - 1 , 0 , {
199+ virt_text = line_above ,
200+ virt_text_pos = ' overlay' ,
201+ })
202+ else
203+ self :add (false , info .start_row , 0 , {
204+ virt_lines = { line_above },
205+ virt_lines_above = true ,
206+ })
207+ end
208+
209+ local line_below = {
210+ { heading .below :rep (heading .left_pad ), background },
211+ { heading .below :rep (prefix ), foreground },
212+ { heading .below :rep (width - heading .left_pad - prefix ), background },
213+ }
214+ if str .width (info :line (' below' )) == 0 then
215+ self :add (true , info .end_row + 1 , 0 , {
216+ virt_text = line_below ,
217+ virt_text_pos = ' overlay' ,
218+ })
219+ self .last_heading_border = info .end_row + 1
220+ else
221+ self :add (false , info .end_row , 0 , {
222+ virt_lines = { line_below },
223+ })
224+ end
225+ end
226+
208227--- @private
209228--- @param info render.md.NodeInfo
210229function Handler :dash (info )
0 commit comments