Skip to content

Commit 3b8f191

Browse files
Fix health check for right_pad & width fields
1 parent 8aff425 commit 3b8f191

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ require('render-markdown').setup({
230230
style = 'full',
231231
-- Amount of padding to add to the left of code blocks
232232
left_pad = 0,
233+
-- Amount of padding to add to the right of code blocks when width is 'block'
234+
right_pad = 0,
235+
-- Width of the code block background:
236+
-- block: width of the code block
237+
-- full: full width of the window
238+
width = 'full',
233239
-- Determins how the top / bottom of code block are rendered:
234240
-- thick: use the same highlight as the code body
235241
-- thin: when lines are empty overlay the above & below icons
@@ -460,6 +466,12 @@ require('render-markdown').setup({
460466
style = 'full',
461467
-- Amount of padding to add to the left of code blocks
462468
left_pad = 0,
469+
-- Amount of padding to add to the right of code blocks when width is 'block'
470+
right_pad = 0,
471+
-- Width of the code block background:
472+
-- block: width of the code block
473+
-- full: full width of the window
474+
width = 'full',
463475
-- Determins how the top / bottom of code block are rendered:
464476
-- thick: use the same highlight as the code body
465477
-- thin: when lines are empty overlay the above & below icons

doc/render-markdown.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ Full Default Configuration ~
270270
style = 'full',
271271
-- Amount of padding to add to the left of code blocks
272272
left_pad = 0,
273+
-- Amount of padding to add to the right of code blocks when width is 'block'
274+
right_pad = 0,
275+
-- Width of the code block background:
276+
-- block: width of the code block
277+
-- full: full width of the window
278+
width = 'full',
273279
-- Determins how the top / bottom of code block are rendered:
274280
-- thick: use the same highlight as the code body
275281
-- thin: when lines are empty overlay the above & below icons
@@ -500,6 +506,12 @@ CODE BLOCKS *render-markdown-setup-code-blocks*
500506
style = 'full',
501507
-- Amount of padding to add to the left of code blocks
502508
left_pad = 0,
509+
-- Amount of padding to add to the right of code blocks when width is 'block'
510+
right_pad = 0,
511+
-- Width of the code block background:
512+
-- block: width of the code block
513+
-- full: full width of the window
514+
width = 'full',
503515
-- Determins how the top / bottom of code block are rendered:
504516
-- thick: use the same highlight as the code body
505517
-- thin: when lines are empty overlay the above & below icons

lua/render-markdown/handler/markdown.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,10 @@ M.render_code = function(buf, info)
180180

181181
local width = util.get_width(buf)
182182
if code.width == 'block' then
183-
width = 0
184183
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
184+
local code_width = vim.fn.max(vim.tbl_map(str.width, lines))
185+
width = code.left_pad + code_width + code.right_pad
188186
end
189-
width = width + code.right_pad + code.left_pad
190187

191188
if code.border == 'thin' then
192189
local code_start = ts.child(buf, info, 'fenced_code_block_delimiter', info.start_row)
@@ -220,6 +217,7 @@ M.render_code = function(buf, info)
220217
list.add(marks, end_mark)
221218
end
222219
end
220+
223221
---@type render.md.Mark
224222
local background_mark = {
225223
conceal = false,

lua/render-markdown/init.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,12 @@ M.default_config = {
246246
style = 'full',
247247
-- Amount of padding to add to the left of code blocks
248248
left_pad = 0,
249-
-- Amount of padding to add to the right of code blocks
250-
-- when width is 'block'
249+
-- Amount of padding to add to the right of code blocks when width is 'block'
251250
right_pad = 0,
251+
-- Width of the code block background:
252+
-- block: width of the code block
253+
-- full: full width of the window
254+
width = 'full',
252255
-- Determins how the top / bottom of code block are rendered:
253256
-- thick: use the same highlight as the code body
254257
-- thin: when lines are empty overlay the above & below icons
@@ -260,10 +263,6 @@ M.default_config = {
260263
-- Highlight for code blocks & inline code
261264
highlight = 'RenderMarkdownCode',
262265
highlight_inline = 'RenderMarkdownCodeInline',
263-
-- Width of the code block background:
264-
-- * full: full width of the window
265-
-- * block: width of the code block
266-
width = 'full',
267266
},
268267
dash = {
269268
-- Turn on / off thematic break rendering

lua/render-markdown/state.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function state.validate()
120120
sign = { code.sign, 'boolean' },
121121
style = one_of(code.style, { 'full', 'normal', 'language', 'none' }),
122122
left_pad = { code.left_pad, 'number' },
123+
right_pad = { code.right_pad, 'number' },
124+
width = one_of(code.width, { 'full', 'block' }),
123125
border = one_of(code.border, { 'thin', 'thick' }),
124126
above = { code.above, 'string' },
125127
below = { code.below, 'string' },

lua/render-markdown/types.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
---@field public enabled boolean
5454
---@field public sign boolean
5555
---@field public style 'full'|'normal'|'language'|'none'
56-
---@field public width 'full'|'block'
5756
---@field public left_pad integer
5857
---@field public right_pad integer
58+
---@field public width 'full'|'block'
5959
---@field public border 'thin'|'thick'
6060
---@field public above string
6161
---@field public below string

0 commit comments

Comments
 (0)