@@ -177,7 +177,7 @@ function M.code(config, buf, info)
177177 if not code .enabled or code .style == ' none' then
178178 return {}
179179 end
180- local code_block = code_block_parser .parse (buf , info )
180+ local code_block = code_block_parser .parse (code , buf , info )
181181 if code_block == nil then
182182 return {}
183183 end
@@ -217,33 +217,52 @@ function M.language(config, buf, code_block, add_background)
217217 if code .sign then
218218 list .add_mark (marks , M .sign (config , info , icon , icon_highlight ))
219219 end
220- -- Requires inline extmarks
221- if not util .has_10 then
222- return marks , false
223- end
224- local icon_text = icon .. ' '
225- if ts .hidden (buf , info ) then
226- -- Code blocks will pick up varying amounts of leading white space depending on the
227- -- context they are in. This gets lumped into the delimiter node and as a result,
228- -- after concealing, the extmark will be left shifted. Logic below accounts for this.
229- icon_text = str .pad (code_block .leading_spaces , icon_text .. info .text )
230- end
231220 local highlight = { icon_highlight }
232221 if add_background then
233222 table.insert (highlight , code .highlight )
234223 end
235- --- @type render.md.Mark
236- local language_marker = {
237- conceal = true ,
238- start_row = info .start_row ,
239- start_col = info .start_col ,
240- opts = {
241- virt_text = { { icon_text , highlight } },
242- virt_text_pos = ' inline' ,
243- },
244- }
245- list .add_mark (marks , language_marker )
246- return marks , true
224+ -- Requires inline extmarks
225+ if code .position == ' left' and util .has_10 then
226+ local icon_text = icon .. ' '
227+ if ts .hidden (buf , info ) then
228+ -- Code blocks will pick up varying amounts of leading white space depending on the
229+ -- context they are in. This gets lumped into the delimiter node and as a result,
230+ -- after concealing, the extmark will be left shifted. Logic below accounts for this.
231+ icon_text = str .pad (code_block .leading_spaces , icon_text .. info .text )
232+ end
233+ --- @type render.md.Mark
234+ local language_marker = {
235+ conceal = true ,
236+ start_row = info .start_row ,
237+ start_col = info .start_col ,
238+ opts = {
239+ virt_text = { { icon_text , highlight } },
240+ virt_text_pos = ' inline' ,
241+ },
242+ }
243+ list .add_mark (marks , language_marker )
244+ return marks , true
245+ elseif code .position == ' right' then
246+ local icon_text = icon .. ' ' .. info .text
247+ local win_col = code_block .longest_line
248+ if code .width == ' block' then
249+ win_col = win_col - str .width (icon_text )
250+ end
251+ --- @type render.md.Mark
252+ local language_marker = {
253+ conceal = true ,
254+ start_row = info .start_row ,
255+ start_col = 0 ,
256+ opts = {
257+ virt_text = { { icon_text , highlight } },
258+ virt_text_win_col = win_col ,
259+ },
260+ }
261+ list .add_mark (marks , language_marker )
262+ return marks , true
263+ else
264+ return marks , false
265+ end
247266end
248267
249268--- @private
255274function M .code_background (config , buf , code_block , icon_added )
256275 local code = config .code
257276
258- local width
259- if code .width == ' block' then
260- local lines = vim .api .nvim_buf_get_lines (buf , code_block .start_row , code_block .end_row , true )
261- local code_width = vim .fn .max (vim .tbl_map (str .width , lines ))
262- width = code .left_pad + code_width + code .right_pad
263- else
264- width = context .get (buf ):get_width ()
265- end
266-
267277 local marks = {}
268-
269278 if code .border == ' thin' then
270- local border_width = width - code_block .col
279+ local border_width = code_block . width - code_block .col
271280 if not icon_added and ts .hidden (buf , code_block .code_info ) and ts .hidden (buf , code_block .start_delim ) then
272281 --- @type render.md.Mark
273282 local start_mark = {
@@ -323,15 +332,13 @@ function M.code_background(config, buf, code_block, icon_added)
323332 start_col = 0 ,
324333 opts = {
325334 priority = 0 ,
326- hl_mode = ' replace' ,
327335 virt_text = { { padding , ' Normal' } },
328- virt_text_win_col = width ,
336+ virt_text_win_col = code_block . width ,
329337 },
330338 }
331339 list .add_mark (marks , block_background_mark )
332340 end
333341 end
334-
335342 return marks
336343end
337344
0 commit comments