Skip to content

feat: update Dash rendering logic to support percentage width and alignment style #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -391,9 +391,13 @@ require('render-markdown').setup({
-- The icon gets repeated across the window's width
icon = '─',
-- Width of the generated line:
-- <integer>: a hard coded width value
-- full: full width of the window
-- full: full width of the window
-- <number>: a hard coded width value
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
width = 'full',
-- Amount of margin to add to the left of dash
-- If a floating point value < 1 is provided it is treated as a percentage of the available window space
left_margin = 0,
-- Highlight for the whole line generated from the icon
highlight = 'RenderMarkdownDash',
},
15 changes: 11 additions & 4 deletions lua/render-markdown/render/dash.lua
Original file line number Diff line number Diff line change
@@ -16,17 +16,24 @@ end

function Render:render()
local width = self.dash.width
width = type(width) == 'number' and width or vim.o.columns
local virt_text = { self.dash.icon:rep(width), self.dash.highlight }
width = type(width) == 'number' and self.context:resolve_offset(width, 0) or vim.o.columns
self.dash.left_margin = self.dash.left_margin or 0
local margin = self.context:resolve_offset(self.dash.left_margin, width)

local virt_text = {}
if margin > 0 then
table.insert(virt_text, self:padding_text(margin))
end
table.insert(virt_text, { self.dash.icon:rep(width), self.dash.highlight })

local start_row, end_row = self.node.start_row, self.node.end_row - 1
self.marks:add('dash', start_row, 0, {
virt_text = { virt_text },
virt_text = virt_text,
virt_text_pos = 'overlay',
})
if end_row > start_row then
self.marks:add('dash', end_row, 0, {
virt_text = { virt_text },
virt_text = virt_text,
virt_text_pos = 'overlay',
})
end
3 changes: 2 additions & 1 deletion lua/render-markdown/types.lua
Original file line number Diff line number Diff line change
@@ -120,7 +120,8 @@
---@class (exact) render.md.Dash
---@field public enabled boolean
---@field public icon string
---@field public width 'full'|integer
---@field public width 'full'|number
---@field public left_margin number
---@field public highlight string

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