@@ -12,6 +12,7 @@ local colors = require('render-markdown.colors')
1212--- @field margin integer
1313--- @field language_padding integer
1414--- @field padding integer
15+ --- @field width integer
1516--- @field max_width integer
1617--- @field empty_rows integer[]
1718--- @field indent integer
@@ -62,6 +63,7 @@ function Render:setup()
6263 margin = self :offset (self .code .left_margin , max_width , ' left' ),
6364 language_padding = language_padding ,
6465 padding = left_padding ,
66+ width = self .code .width == ' block' and max_width or vim .o .columns ,
6567 max_width = max_width ,
6668 empty_rows = empty_rows ,
6769 indent = self :indent_size (),
@@ -97,7 +99,7 @@ function Render:render()
9799
98100 local icon = self :language ()
99101 local start_row , end_row = self .node .start_row , self .node .end_row - 1
100- self :border (start_row , self .code .above , not icon and self :hidden (self .data .code_node ))
102+ self :border (start_row , self .code .above , not icon and self :concealed (self .data .code_node ))
101103 self :border (end_row , self .code .below , true )
102104 if background then
103105 self :background (start_row + 1 , end_row - 1 )
@@ -135,7 +137,7 @@ function Render:language()
135137 end
136138
137139 if self .code .position == ' left' then
138- if self .code .language_name and self :hidden (node ) then
140+ if self .code .language_name and self :concealed (node ) then
139141 -- Code blocks pick up varying amounts of leading white space depending
140142 -- on the context they are in. This is lumped into the delimiter node
141143 -- and as a result, after concealing, the extmark would be shifted.
@@ -173,9 +175,9 @@ function Render:border(row, border, context_hidden)
173175 return
174176 end
175177 local delim_node = self .node :child (' fenced_code_block_delimiter' , row )
176- if self .code .border == ' thin' and context_hidden and self :hidden (delim_node ) then
177- local width = self .code .width == ' block ' and self .data .max_width or vim . o . columns
178- local line = { { border :rep (width - self . data . col ), colors .bg_to_fg (self .code .highlight ) } }
178+ if self .code .border == ' thin' and context_hidden and self :concealed (delim_node ) then
179+ local width = self .data .width - self .data .col
180+ local line = { { border :rep (width ), colors .bg_to_fg (self .code .highlight ) } }
179181 self .marks :add (' code_border' , row , self .data .col , {
180182 virt_text = line ,
181183 virt_text_pos = ' overlay' ,
188190--- @private
189191--- @param node ? render.md.Node
190192--- @return boolean
191- function Render :hidden (node )
193+ function Render :concealed (node )
192194 -- TODO(0.11): handle conceal_lines
193195 -- - Use self.context:hidden(node) to determine if a node is hidden
194196 -- - Default highlights remove the fenced code block delimiter lines along with
@@ -214,7 +216,7 @@ function Render:background(start_row, end_row)
214216 local win_col , padding = 0 , {}
215217 if self .code .width == ' block' then
216218 win_col = self .data .margin + self .data .max_width + self .data .indent
217- table.insert (padding , self : pad ( vim .o .columns * 2 ) )
219+ self : append (padding , vim .o .columns * 2 )
218220 end
219221 for row = start_row , end_row do
220222 self .marks :add (' code_background' , row , self .data .col , {
@@ -244,26 +246,22 @@ function Render:left_pad(background)
244246 -- Use lowest priority (0) to include all other marks in padding when code block is at edge
245247 -- Use medium priority (1000) to include border marks while likely avoiding other plugin
246248 local priority = self .data .col == 0 and 0 or 1000
247- local fill_text = self :pad (self .data .col )
248- local margin_text = self :pad (margin )
249- local padding_text = self :pad (padding , background and self .code .highlight or nil )
249+ local highlight = background and self .code .highlight or nil
250250
251- local start_row , end_row = self .node .start_row , ( self .node .end_row - 1 )
251+ local start_row , end_row = self .node .start_row , self .node .end_row - 1
252252 for row = start_row , end_row do
253- local virt_text = {}
254- if self .data .col > 0 and vim .tbl_contains (self .data .empty_rows , row ) then
255- table.insert (virt_text , fill_text )
256- end
257- if margin > 0 then
258- table.insert (virt_text , margin_text )
253+ local line = {}
254+ if vim .tbl_contains (self .data .empty_rows , row ) then
255+ self :append (line , self .data .col )
259256 end
260- if padding > 0 and row > start_row and row < end_row then
261- table.insert (virt_text , padding_text )
257+ self :append (line , margin )
258+ if row > start_row and row < end_row then
259+ self :append (line , padding , highlight )
262260 end
263- if # virt_text > 0 then
261+ if # line > 0 then
264262 self .marks :add (false , row , self .data .col , {
265263 priority = priority ,
266- virt_text = virt_text ,
264+ virt_text = line ,
267265 virt_text_pos = ' inline' ,
268266 })
269267 end
0 commit comments