@@ -12,6 +12,7 @@ local colors = require('render-markdown.colors')
12
12
--- @field margin integer
13
13
--- @field language_padding integer
14
14
--- @field padding integer
15
+ --- @field width integer
15
16
--- @field max_width integer
16
17
--- @field empty_rows integer[]
17
18
--- @field indent integer
@@ -62,6 +63,7 @@ function Render:setup()
62
63
margin = self :offset (self .code .left_margin , max_width , ' left' ),
63
64
language_padding = language_padding ,
64
65
padding = left_padding ,
66
+ width = self .code .width == ' block' and max_width or vim .o .columns ,
65
67
max_width = max_width ,
66
68
empty_rows = empty_rows ,
67
69
indent = self :indent_size (),
@@ -97,7 +99,7 @@ function Render:render()
97
99
98
100
local icon = self :language ()
99
101
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 ))
101
103
self :border (end_row , self .code .below , true )
102
104
if background then
103
105
self :background (start_row + 1 , end_row - 1 )
@@ -135,7 +137,7 @@ function Render:language()
135
137
end
136
138
137
139
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
139
141
-- Code blocks pick up varying amounts of leading white space depending
140
142
-- on the context they are in. This is lumped into the delimiter node
141
143
-- and as a result, after concealing, the extmark would be shifted.
@@ -173,9 +175,9 @@ function Render:border(row, border, context_hidden)
173
175
return
174
176
end
175
177
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 ) } }
179
181
self .marks :add (' code_border' , row , self .data .col , {
180
182
virt_text = line ,
181
183
virt_text_pos = ' overlay' ,
188
190
--- @private
189
191
--- @param node ? render.md.Node
190
192
--- @return boolean
191
- function Render :hidden (node )
193
+ function Render :concealed (node )
192
194
-- TODO(0.11): handle conceal_lines
193
195
-- - Use self.context:hidden(node) to determine if a node is hidden
194
196
-- - Default highlights remove the fenced code block delimiter lines along with
@@ -214,7 +216,7 @@ function Render:background(start_row, end_row)
214
216
local win_col , padding = 0 , {}
215
217
if self .code .width == ' block' then
216
218
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 )
218
220
end
219
221
for row = start_row , end_row do
220
222
self .marks :add (' code_background' , row , self .data .col , {
@@ -244,26 +246,22 @@ function Render:left_pad(background)
244
246
-- Use lowest priority (0) to include all other marks in padding when code block is at edge
245
247
-- Use medium priority (1000) to include border marks while likely avoiding other plugin
246
248
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
250
250
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
252
252
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 )
259
256
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 )
262
260
end
263
- if # virt_text > 0 then
261
+ if # line > 0 then
264
262
self .marks :add (false , row , self .data .col , {
265
263
priority = priority ,
266
- virt_text = virt_text ,
264
+ virt_text = line ,
267
265
virt_text_pos = ' inline' ,
268
266
})
269
267
end
0 commit comments