@@ -177,6 +177,17 @@ M.render_code = function(buf, info)
177
177
if start_row == end_row - 1 then
178
178
return marks
179
179
end
180
+
181
+ local width = util .get_width (buf )
182
+ if code .width == ' block' then
183
+ width = 0
184
+ local lines = vim .api .nvim_buf_get_lines (buf , start_row , end_row , false )
185
+ for _ , line in ipairs (lines ) do
186
+ width = math.max (width , str .width (line ))
187
+ end
188
+ end
189
+ width = width + code .right_pad + code .left_pad
190
+
180
191
if code .border == ' thin' then
181
192
local code_start = ts .child (buf , info , ' fenced_code_block_delimiter' , info .start_row )
182
193
if # marks == 0 and ts .hidden (buf , code_info ) and ts .hidden (buf , code_start ) then
@@ -187,7 +198,7 @@ M.render_code = function(buf, info)
187
198
start_row = info .start_row ,
188
199
start_col = info .start_col ,
189
200
opts = {
190
- virt_text = { { code .above :rep (util . get_width ( buf ) ), colors .inverse (code .highlight ) } },
201
+ virt_text = { { code .above :rep (width ), colors .inverse (code .highlight ) } },
191
202
virt_text_pos = ' overlay' ,
192
203
},
193
204
}
@@ -202,7 +213,7 @@ M.render_code = function(buf, info)
202
213
start_row = info .end_row - 1 ,
203
214
start_col = info .start_col ,
204
215
opts = {
205
- virt_text = { { code .below :rep (util . get_width ( buf ) ), colors .inverse (code .highlight ) } },
216
+ virt_text = { { code .below :rep (width ), colors .inverse (code .highlight ) } },
206
217
virt_text_pos = ' overlay' ,
207
218
},
208
219
}
@@ -222,6 +233,27 @@ M.render_code = function(buf, info)
222
233
},
223
234
}
224
235
list .add (marks , background_mark )
236
+
237
+ if code .width == ' block' then
238
+ -- overwrite anything beyond block width + right_pad with Normal
239
+ local pad = str .pad (' ' , vim .o .columns * 2 )
240
+ for row = start_row , code .border == ' thin' and end_row or end_row - 1 do
241
+ --- @type render.md.Mark
242
+ local block_background_mark = {
243
+ conceal = false ,
244
+ start_row = row ,
245
+ start_col = 0 ,
246
+ opts = {
247
+ priority = 0 ,
248
+ hl_mode = ' combine' ,
249
+ virt_text = { { pad , ' Normal' } },
250
+ virt_text_win_col = width ,
251
+ },
252
+ }
253
+ list .add (marks , block_background_mark )
254
+ end
255
+ end
256
+
225
257
-- Requires inline extmarks
226
258
if not util .has_10 or code .left_pad <= 0 then
227
259
return marks
0 commit comments