Skip to content

Commit 931b5e3

Browse files
authored
feat: update Dash rendering logic to support percentage width and alignment style (#272)
* feat: update Dash rendering logic to support percentage width and center alignment * doc: Updated README.md with additional options for width and alignment in the render-markdown setup. * fix: Fixed alignment issues in dash rendering. * CR: Update Dash rendering options and keep consistent with headings & code blocks. --------- Co-authored-by: Kurama <[email protected]>
1 parent 0022a57 commit 931b5e3

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,13 @@ require('render-markdown').setup({
391391
-- The icon gets repeated across the window's width
392392
icon = '',
393393
-- Width of the generated line:
394-
-- <integer>: a hard coded width value
395-
-- full: full width of the window
394+
-- full: full width of the window
395+
-- <number>: a hard coded width value
396+
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
396397
width = 'full',
398+
-- Amount of margin to add to the left of dash
399+
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
400+
left_margin = 0,
397401
-- Highlight for the whole line generated from the icon
398402
highlight = 'RenderMarkdownDash',
399403
},

lua/render-markdown/render/dash.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@ end
1616

1717
function Render:render()
1818
local width = self.dash.width
19-
width = type(width) == 'number' and width or vim.o.columns
20-
local virt_text = { self.dash.icon:rep(width), self.dash.highlight }
19+
width = type(width) == 'number' and self.context:resolve_offset(width, 0) or vim.o.columns
20+
self.dash.left_margin = self.dash.left_margin or 0
21+
local margin = self.context:resolve_offset(self.dash.left_margin, width)
22+
23+
local virt_text = {}
24+
if margin > 0 then
25+
table.insert(virt_text, self:padding_text(margin))
26+
end
27+
table.insert(virt_text, { self.dash.icon:rep(width), self.dash.highlight })
2128

2229
local start_row, end_row = self.node.start_row, self.node.end_row - 1
2330
self.marks:add('dash', start_row, 0, {
24-
virt_text = { virt_text },
31+
virt_text = virt_text,
2532
virt_text_pos = 'overlay',
2633
})
2734
if end_row > start_row then
2835
self.marks:add('dash', end_row, 0, {
29-
virt_text = { virt_text },
36+
virt_text = virt_text,
3037
virt_text_pos = 'overlay',
3138
})
3239
end

lua/render-markdown/types.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@
120120
---@class (exact) render.md.Dash
121121
---@field public enabled boolean
122122
---@field public icon string
123-
---@field public width 'full'|integer
123+
---@field public width 'full'|number
124+
---@field public left_margin number
124125
---@field public highlight string
125126

126127
---@class (exact) render.md.Code

0 commit comments

Comments
 (0)