Skip to content

Commit 78ffe3b

Browse files
feat: use conceal lines for setext heading underline
## Details Add `conceal_lines` extmark over setext heading underlines in addition to the normal `conceal`. Having both is fine so not adding any conditional logic around this one and keeping both around. Other minor changes: - use standard `@enum` behavior based on values rather than keys - use `tbl_values` instead of `tbl_keys` for validation for consistency - use an `enum` for log levels instead of an `alias` - use `number[]` for priorities instead of `integer[]` when sorting
1 parent 7051859 commit 78ffe3b

File tree

17 files changed

+71
-82
lines changed

17 files changed

+71
-82
lines changed

lua/render-markdown/config/anti_conceal.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
---@alias render.md.conceal.Ignore table<render.md.Element, render.md.Modes>
88

9-
---@enum (key) render.md.Element
9+
---@enum render.md.Element
1010
local Element = {
1111
head_icon = 'head_icon',
1212
head_background = 'head_background',
@@ -31,7 +31,7 @@ local M = {}
3131
function M.validate(spec)
3232
spec:type('enabled', 'boolean')
3333
spec:nested('ignore', function(ignore)
34-
for element in pairs(Element) do
34+
for _, element in pairs(Element) do
3535
ignore:list(element, 'string', { 'boolean', 'nil' })
3636
end
3737
ignore:check()

lua/render-markdown/config/code.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323
---@field highlight_fallback string
2424
---@field highlight_inline string
2525

26-
---@enum (key) render.md.code.Style
26+
---@enum render.md.code.Style
2727
local Style = {
2828
full = 'full',
2929
normal = 'normal',
3030
language = 'language',
3131
none = 'none',
3232
}
3333

34-
---@enum (key) render.md.code.Position
34+
---@enum render.md.code.Position
3535
local Position = {
3636
left = 'left',
3737
right = 'right',
3838
}
3939

40-
---@enum (key) render.md.code.Width
40+
---@enum render.md.code.Width
4141
local Width = {
4242
full = 'full',
4343
block = 'block',
4444
}
4545

46-
---@enum (key) render.md.code.Border
46+
---@enum render.md.code.Border
4747
local Border = {
4848
hide = 'hide',
4949
thin = 'thin',
@@ -57,18 +57,18 @@ local M = {}
5757
function M.validate(spec)
5858
require('render-markdown.config.base').validate(spec)
5959
spec:type('sign', 'boolean')
60-
spec:one_of('style', vim.tbl_keys(Style))
61-
spec:one_of('position', vim.tbl_keys(Position))
60+
spec:one_of('style', vim.tbl_values(Style))
61+
spec:one_of('position', vim.tbl_values(Position))
6262
spec:type('language_pad', 'number')
6363
spec:type('language_icon', 'boolean')
6464
spec:type('language_name', 'boolean')
6565
spec:list('disable_background', 'string', 'boolean')
66-
spec:one_of('width', vim.tbl_keys(Width))
66+
spec:one_of('width', vim.tbl_values(Width))
6767
spec:type('left_margin', 'number')
6868
spec:type('left_pad', 'number')
6969
spec:type('right_pad', 'number')
7070
spec:type('min_width', 'number')
71-
spec:one_of('border', vim.tbl_keys(Border))
71+
spec:one_of('border', vim.tbl_values(Border))
7272
spec:type('above', 'string')
7373
spec:type('below', 'string')
7474
spec:type('inline_left', 'string')

lua/render-markdown/config/heading.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
---| string[]
2828
---| fun(ctx: render.md.heading.Context): string?
2929

30-
---@enum (key) render.md.heading.Position
30+
---@enum render.md.heading.Position
3131
local Position = {
3232
overlay = 'overlay',
3333
inline = 'inline',
3434
right = 'right',
3535
}
3636

37-
---@enum (key) render.md.heading.Width
37+
---@enum render.md.heading.Width
3838
local Width = {
3939
full = 'full',
4040
block = 'block',
@@ -55,9 +55,9 @@ function M.validate(spec)
5555
spec:type('setext', 'boolean')
5656
spec:type('sign', 'boolean')
5757
spec:list('icons', 'string', 'function')
58-
spec:one_of('position', vim.tbl_keys(Position))
58+
spec:one_of('position', vim.tbl_values(Position))
5959
spec:list('signs', 'string')
60-
spec:one_or_list_of('width', vim.tbl_keys(Width))
60+
spec:one_or_list_of('width', vim.tbl_values(Width))
6161
spec:list('left_margin', 'number', 'number')
6262
spec:list('left_pad', 'number', 'number')
6363
spec:list('right_pad', 'number', 'number')

lua/render-markdown/config/latex.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
---@field top_pad integer
66
---@field bottom_pad integer
77

8-
---@enum (key) render.md.latex.Position
8+
---@enum render.md.latex.Position
99
local Position = {
1010
above = 'above',
1111
below = 'below',
@@ -18,7 +18,7 @@ function M.validate(spec)
1818
require('render-markdown.config.base').validate(spec)
1919
spec:type('converter', 'string')
2020
spec:type('highlight', 'string')
21-
spec:one_of('position', vim.tbl_keys(Position))
21+
spec:one_of('position', vim.tbl_values(Position))
2222
spec:type('top_pad', 'number')
2323
spec:type('bottom_pad', 'number')
2424
spec:check()

lua/render-markdown/config/link.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
---@field priority? integer
3434
---@field highlight? string
3535

36-
---@enum (key) render.md.link.custom.Kind
36+
---@enum render.md.link.custom.Kind
3737
local Kind = {
3838
pattern = 'pattern',
3939
suffix = 'suffix',
@@ -65,7 +65,7 @@ function M.validate(spec)
6565
patterns:each(function(pattern)
6666
pattern:type('pattern', 'string')
6767
pattern:type('icon', 'string')
68-
pattern:one_of('kind', vim.tbl_keys(Kind), 'nil')
68+
pattern:one_of('kind', vim.tbl_values(Kind), 'nil')
6969
pattern:type('priority', { 'number', 'nil' })
7070
pattern:type('highlight', { 'string', 'nil' })
7171
pattern:check()

lua/render-markdown/config/pipe_table.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
---@field row string
1111
---@field filler string
1212

13-
---@enum (key) render.md.table.Preset
13+
---@enum render.md.table.Preset
1414
local Preset = {
1515
none = 'none',
1616
round = 'round',
1717
double = 'double',
1818
heavy = 'heavy',
1919
}
2020

21-
---@enum (key) render.md.table.Style
21+
---@enum render.md.table.Style
2222
local Style = {
2323
full = 'full',
2424
normal = 'normal',
2525
none = 'none',
2626
}
2727

28-
---@enum (key) render.md.table.Cell
28+
---@enum render.md.table.Cell
2929
local Cell = {
3030
trimmed = 'trimmed',
3131
padded = 'padded',
@@ -38,9 +38,9 @@ local M = {}
3838
---@param spec render.md.debug.ValidatorSpec
3939
function M.validate(spec)
4040
require('render-markdown.config.base').validate(spec)
41-
spec:one_of('preset', vim.tbl_keys(Preset))
42-
spec:one_of('style', vim.tbl_keys(Style))
43-
spec:one_of('cell', vim.tbl_keys(Cell))
41+
spec:one_of('preset', vim.tbl_values(Preset))
42+
spec:one_of('style', vim.tbl_values(Style))
43+
spec:one_of('cell', vim.tbl_values(Cell))
4444
spec:type('padding', 'number')
4545
spec:type('min_width', 'number')
4646
spec:list('border', 'string')

lua/render-markdown/core/log.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ local Env = require('render-markdown.lib.env')
1010
---@field level render.md.log.Level
1111
---@field runtime boolean
1212

13-
---@alias render.md.log.Level 'off'|'debug'|'info'|'error'
13+
---@enum render.md.log.Level
14+
local Level = {
15+
debug = 'debug',
16+
info = 'info',
17+
error = 'error',
18+
off = 'off',
19+
}
1420

1521
---@class render.md.Log
1622
---@field private file string
@@ -108,7 +114,7 @@ end
108114
---@param name string
109115
---@param ... any
110116
function M.add(level, name, ...)
111-
if M.level_value(level) < M.level_value(M.config.level) then
117+
if M.level(level) < M.level(M.config.level) then
112118
return
113119
end
114120
local messages = {}
@@ -125,7 +131,7 @@ function M.add(level, name, ...)
125131
message = table.concat(messages, ' | '),
126132
}
127133
M.entries[#M.entries + 1] = entry
128-
-- Periodically flush logs to disk
134+
-- periodically flush logs to disk
129135
if #M.entries > 1000 then
130136
M.flush()
131137
end
@@ -134,14 +140,14 @@ end
134140
---@private
135141
---@param level render.md.log.Level
136142
---@return integer
137-
function M.level_value(level)
138-
if level == 'debug' then
143+
function M.level(level)
144+
if level == Level.debug then
139145
return 1
140-
elseif level == 'info' then
146+
elseif level == Level.info then
141147
return 2
142-
elseif level == 'error' then
148+
elseif level == Level.error then
143149
return 3
144-
elseif level == 'off' then
150+
elseif level == Level.off then
145151
return 4
146152
else
147153
return 0

lua/render-markdown/debug/marks.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ end
2525
---@return boolean
2626
function Mark.__lt(a, b)
2727
local as, bs = a:priorities(), b:priorities()
28-
for i = 1, math.max(#as, #bs) do
28+
assert(#as == #bs)
29+
for i = 1, #as do
2930
if as[i] ~= bs[i] then
3031
return as[i] < bs[i]
3132
end
@@ -34,13 +35,14 @@ function Mark.__lt(a, b)
3435
end
3536

3637
---@private
37-
---@return integer[]
38+
---@return number[]
3839
function Mark:priorities()
3940
local virt_row = 0
4041
if self.opts.virt_lines ~= nil then
4142
virt_row = self.opts.virt_lines_above and -0.5 or 0.5
4243
end
4344
local win_col = self.opts.virt_text_win_col or 0
45+
---@type number[]
4446
return {
4547
-- rows
4648
self.row[1] + virt_row,

lua/render-markdown/debug/validator.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Iter = require('render-markdown.lib.iter')
22

3-
---@enum (key) render.md.debug.spec.Kind
3+
---@enum render.md.debug.spec.Kind
44
local Kind = {
55
type = 'type',
66
value = 'value',
@@ -245,9 +245,10 @@ function Validator:check(path, data, specs)
245245
message = message .. ', but got: '
246246
if spec.kind == Kind.type then
247247
message = message .. type(value)
248-
end
249-
if spec.kind == Kind.value then
248+
elseif spec.kind == Kind.value then
250249
message = message .. vim.inspect(value)
250+
else
251+
error('invalid kind: ' .. spec.kind)
251252
end
252253
if info ~= nil then
253254
message = message .. string.format(', info: %s', info)

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.3.13'
8+
M.version = '8.3.14'
99

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

lua/render-markdown/lib/node.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Iter = require('render-markdown.lib.iter')
22
local Str = require('render-markdown.lib.str')
33

4-
---@enum (key) render.md.node.Position
4+
---@enum render.md.node.Position
55
local Position = {
66
above = 'above',
77
first = 'first',

lua/render-markdown/presets.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---@enum (key) render.md.config.Preset
1+
---@enum render.md.config.Preset
22
local Preset = {
33
none = 'none',
44
lazy = 'lazy',

lua/render-markdown/render/heading.lua

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function Render:render()
108108
self:border(box, false)
109109
else
110110
self.marks:over(true, self.data.marker, { conceal = '' })
111+
self.marks:over(true, self.data.marker, { conceal_lines = '' })
111112
end
112113
end
113114

@@ -231,6 +232,23 @@ function Render:background(box)
231232
end
232233
end
233234

235+
---@private
236+
---@param box render.md.heading.Box
237+
function Render:padding(box)
238+
local line = self:append({}, box.margin)
239+
self:append(line, box.padding, self.data.background)
240+
if #line == 0 then
241+
return
242+
end
243+
for row = self.node.start_row, self.node.end_row - 1 do
244+
self.marks:add(false, row, 0, {
245+
priority = 0,
246+
virt_text = line,
247+
virt_text_pos = 'inline',
248+
})
249+
end
250+
end
251+
234252
---@private
235253
---@param box render.md.heading.Box
236254
---@param above boolean
@@ -271,21 +289,4 @@ function Render:border(box, above)
271289
end
272290
end
273291

274-
---@private
275-
---@param box render.md.heading.Box
276-
function Render:padding(box)
277-
local line = self:append({}, box.margin)
278-
self:append(line, box.padding, self.data.background)
279-
if #line == 0 then
280-
return
281-
end
282-
for row = self.node.start_row, self.node.end_row - 1 do
283-
self.marks:add(false, row, 0, {
284-
priority = 0,
285-
virt_text = line,
286-
virt_text_pos = 'inline',
287-
})
288-
end
289-
end
290-
291292
return Render

lua/render-markdown/render/table.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local log = require('render-markdown.core.log')
1515
---@field width integer
1616
---@field alignment render.md.table.Alignment
1717

18-
---@enum (key) render.md.table.Alignment
18+
---@enum render.md.table.Alignment
1919
local Alignment = {
2020
left = 'left',
2121
right = 'right',

tests/ad_hoc_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ describe('ad hoc', function()
2626
virt_text_pos = 'inline',
2727
})
2828
marks:add(2, 2, 0, 3, util.conceal())
29+
marks:add(2, 2, 0, 3, util.conceal_lines())
2930
marks:add(2, 3, 0, 0, util.heading.bg(2))
3031
util.assert_view(marks, {
3132
'󰫎 󰲣 Heading 2 Line 1',
3233
' Heading 2 Line 2',
33-
'',
3434
})
3535
end)
3636

0 commit comments

Comments
 (0)