@@ -72,6 +72,18 @@ function Render:render()
7272 self :conceal_underline ()
7373end
7474
75+ --- @param position ' above' | ' below'
76+ --- @param info render.md.NodeInfo
77+ --- @param last_heading integer
78+ --- @return boolean
79+ function Render :has_space_for_border (position , info , last_heading )
80+ if position == ' above' then
81+ return str .width (info :line (' above' )) == 0 and info .start_row - 1 ~= last_heading
82+ else
83+ return str .width (self .info :line (' below' )) == 0
84+ end
85+ end
86+
7587--- @private
7688--- @return integer
7789function Render :icon ()
@@ -174,7 +186,7 @@ function Render:border(width)
174186 { self .heading .above :rep (prefix ), self .data .foreground },
175187 { self .heading .above :rep (width - self .heading .left_pad - prefix ), background },
176188 }
177- if str . width ( self . info : line (' above' )) == 0 and self .info . start_row - 1 ~= self .context .last_heading then
189+ if self : has_space_for_border (' above' , self .info , self .context .last_heading ) then
178190 self .marks :add (true , self .info .start_row - 1 , 0 , {
179191 virt_text = line_above ,
180192 virt_text_pos = ' overlay' ,
@@ -191,7 +203,7 @@ function Render:border(width)
191203 { self .heading .below :rep (prefix ), self .data .foreground },
192204 { self .heading .below :rep (width - self .heading .left_pad - prefix ), background },
193205 }
194- if str . width ( self . info : line (' below' )) == 0 then
206+ if self : has_space_for_border (' below' , self . info , self . context . last_heading ) then
195207 self .marks :add (true , self .info .end_row + 1 , 0 , {
196208 virt_text = line_below ,
197209 virt_text_pos = ' overlay' ,
0 commit comments