Skip to content

Commit ff1b449

Browse files
feat: Add dash.width option
## Details Add dash.width option which is either the string 'full' or an integer. When it is 'full' the dashed line will extend across the entire line, which is the current behavior and the default value. When it is a number the width of the dashed line will be the hard coded value provided. Original PR: #92 Co-Authored-By: Zeioth <[email protected]>
1 parent 3b8f191 commit ff1b449

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ require('render-markdown').setup({
254254
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
255255
-- The icon gets repeated across the window's width
256256
icon = '',
257+
-- Width of the generated line, either the 'full' window width or a hard coded value
258+
width = 'full',
257259
-- Highlight for the whole line generated from the icon
258260
highlight = 'RenderMarkdownDash',
259261
},
@@ -497,6 +499,8 @@ require('render-markdown').setup({
497499
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
498500
-- The icon gets repeated across the window's width
499501
icon = '',
502+
-- Width of the generated line, either the 'full' window width or a hard coded value
503+
width = 'full',
500504
-- Highlight for the whole line generated from the icon
501505
highlight = 'RenderMarkdownDash',
502506
},

Diff for: doc/render-markdown.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 July 23
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 July 24
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -294,6 +294,8 @@ Full Default Configuration ~
294294
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
295295
-- The icon gets repeated across the window's width
296296
icon = '─',
297+
-- Width of the generated line, either the 'full' window width or a hard coded value
298+
width = 'full',
297299
-- Highlight for the whole line generated from the icon
298300
highlight = 'RenderMarkdownDash',
299301
},
@@ -538,6 +540,8 @@ DASHED LINE *render-markdown-setup-dashed-line*
538540
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
539541
-- The icon gets repeated across the window's width
540542
icon = '─',
543+
-- Width of the generated line, either the 'full' window width or a hard coded value
544+
width = 'full',
541545
-- Highlight for the whole line generated from the icon
542546
highlight = 'RenderMarkdownDash',
543547
},

Diff for: lua/render-markdown/handler/markdown.lua

+10-1
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,22 @@ M.render_dash = function(buf, info)
139139
if not dash.enabled then
140140
return nil
141141
end
142+
143+
local width
144+
if dash.width == 'full' then
145+
width = util.get_width(buf)
146+
else
147+
---@type integer
148+
width = dash.width
149+
end
150+
142151
---@type render.md.Mark
143152
return {
144153
conceal = true,
145154
start_row = info.start_row,
146155
start_col = 0,
147156
opts = {
148-
virt_text = { { dash.icon:rep(util.get_width(buf)), dash.highlight } },
157+
virt_text = { { dash.icon:rep(width), dash.highlight } },
149158
virt_text_pos = 'overlay',
150159
},
151160
}

Diff for: lua/render-markdown/init.lua

+11-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ local M = {}
4444
---@field public rendered? string
4545
---@field public highlight? string
4646

47+
---@class render.md.UserQuote
48+
---@field public enabled? boolean
49+
---@field public icon? string
50+
---@field public highlight? string
51+
4752
---@class render.md.UserCheckboxComponent
4853
---@field public icon? string
4954
---@field public highlight? string
@@ -59,9 +64,10 @@ local M = {}
5964
---@field public icons? string[]
6065
---@field public highlight? string
6166

62-
---@class render.md.UserBasicComponent
67+
---@class render.md.UserDash
6368
---@field public enabled? boolean
6469
---@field public icon? string
70+
---@field public width? 'full'|integer
6571
---@field public highlight? string
6672

6773
---@class render.md.UserCode
@@ -111,10 +117,10 @@ local M = {}
111117
---@field public latex? render.md.UserLatex
112118
---@field public heading? render.md.UserHeading
113119
---@field public code? render.md.UserCode
114-
---@field public dash? render.md.UserBasicComponent
120+
---@field public dash? render.md.UserDash
115121
---@field public bullet? render.md.UserBullet
116122
---@field public checkbox? render.md.UserCheckbox
117-
---@field public quote? render.md.UserBasicComponent
123+
---@field public quote? render.md.UserQuote
118124
---@field public pipe_table? render.md.UserPipeTable
119125
---@field public callout? table<string, render.md.UserCustomComponent>
120126
---@field public link? render.md.UserLink
@@ -270,6 +276,8 @@ M.default_config = {
270276
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
271277
-- The icon gets repeated across the window's width
272278
icon = '',
279+
-- Width of the generated line, either the 'full' window width or a hard coded value
280+
width = 'full',
273281
-- Highlight for the whole line generated from the icon
274282
highlight = 'RenderMarkdownDash',
275283
},

Diff for: lua/render-markdown/state.lua

+15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ function state.validate()
2424
}
2525
end
2626

27+
---@param value any
28+
---@param valid_values string[]
29+
---@param valid_type type
30+
---@return vim.validate.Spec
31+
local function one_of_or(value, valid_values, valid_type)
32+
return {
33+
value,
34+
function(v)
35+
return vim.tbl_contains(valid_values, v) or type(v) == valid_type
36+
end,
37+
'one of ' .. vim.inspect(valid_values) .. ' or ' .. valid_type,
38+
}
39+
end
40+
2741
---@param value string[]
2842
---@return vim.validate.Spec
2943
local function string_array(value)
@@ -133,6 +147,7 @@ function state.validate()
133147
append_errors('render-markdown.dash', dash, {
134148
enabled = { dash.enabled, 'boolean' },
135149
icon = { dash.icon, 'string' },
150+
width = one_of_or(dash.width, { 'full' }, 'number'),
136151
highlight = { dash.highlight, 'string' },
137152
})
138153

Diff for: lua/render-markdown/types.lua

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
---@field public rendered string
3030
---@field public highlight string
3131

32+
---@class render.md.Quote
33+
---@field public enabled boolean
34+
---@field public icon string
35+
---@field public highlight string
36+
3237
---@class render.md.CheckboxComponent
3338
---@field public icon string
3439
---@field public highlight string
@@ -44,9 +49,10 @@
4449
---@field public icons string[]
4550
---@field public highlight string
4651

47-
---@class render.md.BasicComponent
52+
---@class render.md.Dash
4853
---@field public enabled boolean
4954
---@field public icon string
55+
---@field public width 'full'|integer
5056
---@field public highlight string
5157

5258
---@class render.md.Code
@@ -96,10 +102,10 @@
96102
---@field public latex render.md.Latex
97103
---@field public heading render.md.Heading
98104
---@field public code render.md.Code
99-
---@field public dash render.md.BasicComponent
105+
---@field public dash render.md.Dash
100106
---@field public bullet render.md.Bullet
101107
---@field public checkbox render.md.Checkbox
102-
---@field public quote render.md.BasicComponent
108+
---@field public quote render.md.Quote
103109
---@field public pipe_table render.md.PipeTable
104110
---@field public callout table<string, render.md.CustomComponent>
105111
---@field public link render.md.Link

0 commit comments

Comments
 (0)