Skip to content

Commit c83fc56

Browse files
feat: support heading border per level
## Details Discussion: #240 This allows the `heading.border` config to be a list of booleans. This works in exactly the same way as padding and margin settings which use a clamp to index into the list if multiple values are specified.
1 parent 43ab634 commit c83fc56

File tree

7 files changed

+13
-5
lines changed

7 files changed

+13
-5
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ require('render-markdown').setup({
245245
-- Can also be a list of integers in which case the 'level' is used to index into the list using a clamp
246246
min_width = 0,
247247
-- Determines if a border is added above and below headings
248+
-- Can also be a list of booleans in which case the 'level' is used to index into the list using a clamp
248249
border = false,
249250
-- Always use virtual lines for heading borders instead of attempting to use empty lines
250251
border_virtual = false,
@@ -651,6 +652,7 @@ require('render-markdown').setup({
651652
-- Can also be a list of integers in which case the 'level' is used to index into the list using a clamp
652653
min_width = 0,
653654
-- Determines if a border is added above and below headings
655+
-- Can also be a list of booleans in which case the 'level' is used to index into the list using a clamp
654656
border = false,
655657
-- Always use virtual lines for heading borders instead of attempting to use empty lines
656658
border_virtual = false,

Diff for: doc/render-markdown.txt

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Default Configuration ~
292292
-- Can also be a list of integers in which case the 'level' is used to index into the list using a clamp
293293
min_width = 0,
294294
-- Determines if a border is added above and below headings
295+
-- Can also be a list of booleans in which case the 'level' is used to index into the list using a clamp
295296
border = false,
296297
-- Always use virtual lines for heading borders instead of attempting to use empty lines
297298
border_virtual = false,
@@ -696,6 +697,7 @@ Heading Configuration ~
696697
-- Can also be a list of integers in which case the 'level' is used to index into the list using a clamp
697698
min_width = 0,
698699
-- Determines if a border is added above and below headings
700+
-- Can also be a list of booleans in which case the 'level' is used to index into the list using a clamp
699701
border = false,
700702
-- Always use virtual lines for heading borders instead of attempting to use empty lines
701703
border_virtual = false,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.5.10'
7+
M.version = '7.5.11'
88

99
function M.check()
1010
M.start('version')

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ local M = {}
170170
---@field public left_pad? number|number[]
171171
---@field public right_pad? number|number[]
172172
---@field public min_width? integer|integer[]
173-
---@field public border? boolean
173+
---@field public border? boolean|boolean[]
174174
---@field public border_virtual? boolean
175175
---@field public border_prefix? boolean
176176
---@field public above? string
@@ -363,6 +363,7 @@ M.default_config = {
363363
-- Can also be a list of integers in which case the 'level' is used to index into the list using a clamp
364364
min_width = 0,
365365
-- Determines if a border is added above and below headings
366+
-- Can also be a list of booleans in which case the 'level' is used to index into the list using a clamp
366367
border = false,
367368
-- Always use virtual lines for heading borders instead of attempting to use empty lines
368369
border_virtual = false,

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local colors = require('render-markdown.colors')
1616
---@field left_pad number
1717
---@field right_pad number
1818
---@field min_width integer
19+
---@field border boolean
1920
---@field end_row integer
2021

2122
---@class render.md.width.Heading
@@ -55,6 +56,7 @@ function Render:setup()
5556
left_pad = List.clamp(self.heading.left_pad, level) or 0,
5657
right_pad = List.clamp(self.heading.right_pad, level) or 0,
5758
min_width = List.clamp(self.heading.min_width, level) or 0,
59+
border = List.clamp(self.heading.border, level) or false,
5860
end_row = self.node.end_row + (atx and 1 or 0),
5961
}
6062

@@ -178,7 +180,7 @@ end
178180
---@param width render.md.width.Heading
179181
function Render:border(width)
180182
-- Only atx headings support borders
181-
if not self.heading.border or not self.data.atx then
183+
if not self.data.border or not self.data.atx then
182184
return
183185
end
184186

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ function M.validate()
153153
end)
154154
:nested('heading', function(heading)
155155
heading
156-
:type({ 'enabled', 'sign', 'border', 'border_virtual', 'border_prefix' }, 'boolean')
156+
:type({ 'enabled', 'sign', 'border_virtual', 'border_prefix' }, 'boolean')
157157
:type({ 'above', 'below' }, 'string')
158+
:list('border', 'boolean', 'boolean')
158159
:list({ 'left_margin', 'left_pad', 'right_pad', 'min_width' }, 'number', 'number')
159160
:list({ 'icons', 'signs', 'backgrounds', 'foregrounds' }, 'string')
160161
:one_of('position', { 'overlay', 'inline' })

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
---@field public left_pad number|number[]
144144
---@field public right_pad number|number[]
145145
---@field public min_width integer|integer[]
146-
---@field public border boolean
146+
---@field public border boolean|boolean[]
147147
---@field public border_virtual boolean
148148
---@field public border_prefix boolean
149149
---@field public above string

0 commit comments

Comments
 (0)