Skip to content

Commit 98f9965

Browse files
chore: update unit testing, use vim.iter in tests, gate repeat blankline marks on version
1 parent 4c823b1 commit 98f9965

17 files changed

+292
-242
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
### Features
66

77
- handle imperfectly spaced tables using max width [166a254](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/166a254aaf5b4333fe015a29a66ad99c276538ea)
8+
- anti-conceal margin [abc02f3](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/abc02f35cd6cb28e9b8eb37c88fc863a546367bf)
9+
- log error when mark is skipped [#132](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/132)
10+
[7986be4](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7986be47531d652e950776536987e01dd5b55b94)
11+
12+
### Bug Fixes
13+
14+
- wiki links nested in tables [72688ba](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/72688baea4ef0ed605033bf654b54d801b6a5f01)
15+
- code block background when indented in lists [#133](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/133)
16+
[4c823b1](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/4c823b1df151dbf1ed3ddaacac517be606b1e145)
817

918
## 6.1.0 (2024-08-11)
1019

doc/todo.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# TODOs
22

3-
- See if there is a stable way to align table cells according to delimiter
4-
alignment info.
53
- Potentially change LuaRocks icon dependency to [mini.icons](https://luarocks.org/modules/neorocks/mini.icons)

lua/render-markdown/handler/markdown.lua

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function Handler:heading(info)
115115
virt_text_win_col = width,
116116
})
117117
end
118+
118119
if heading.border then
119120
self:heading_border(info, level, foreground, colors.inverse(background), width)
120121
end
@@ -239,13 +240,8 @@ function Handler:dash(info)
239240
return
240241
end
241242

242-
local width
243-
if dash.width == 'full' then
244-
width = self.context:get_width()
245-
else
246-
---@type integer
247-
width = dash.width
248-
end
243+
local width = dash.width
244+
width = type(width) == 'number' and width or self.context:get_width()
249245

250246
self:add(true, info.start_row, 0, {
251247
virt_text = { { dash.icon:rep(width), dash.highlight } },
@@ -377,12 +373,7 @@ function Handler:code_left_pad(code_block, add_background)
377373
return
378374
end
379375
local padding = str.pad(code.left_pad)
380-
local highlight
381-
if add_background then
382-
highlight = code.highlight
383-
else
384-
highlight = 'Normal'
385-
end
376+
local highlight = add_background and code.highlight or 'Normal'
386377
for row = code_block.start_row, code_block.end_row - 1 do
387378
-- Uses a low priority so other marks are loaded first and included in padding
388379
self:add(false, row, code_block.col, {
@@ -479,11 +470,8 @@ function Handler:quote_marker(info, block_quote)
479470
if not quote.enabled then
480471
return
481472
end
482-
local highlight = quote.highlight
483473
local callout = component.callout(self.config, block_quote.text, 'contains')
484-
if callout ~= nil then
485-
highlight = callout.highlight
486-
end
474+
local highlight = callout ~= nil and callout.highlight or quote.highlight
487475
self:add(true, info.start_row, info.start_col, {
488476
end_row = info.end_row,
489477
end_col = info.end_col,

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.1.5'
8+
M.version = '6.1.6'
99

1010
function M.check()
1111
vim.health.start('render-markdown.nvim [version]')

lua/render-markdown/list.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function M.add_mark(marks, conceal, start_row, start_col, opts)
2222
logger.error('inline marks require neovim >= 0.10.0', mark)
2323
return false
2424
end
25+
if opts.virt_text_repeat_linebreak ~= nil and not util.has_10 then
26+
logger.error('repeat linebreak marks require neovim >= 0.10.0', mark)
27+
return false
28+
end
2529
logger.debug('mark', mark)
2630
table.insert(marks, mark)
2731
return true

lua/render-markdown/parser/code_block.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ function M.parse(config, context, info)
2626
return nil
2727
end
2828
local code_info = info:child('info_string', info.start_row)
29-
local language_info = nil
30-
if code_info ~= nil then
31-
language_info = code_info:child('language', info.start_row)
32-
end
29+
local language_info = code_info ~= nil and code_info:child('language', info.start_row) or nil
3330
local longest_line, width = M.get_width(config, context, info)
3431
---@type render.md.parsed.CodeBlock
3532
return {

tests/ad_hoc_spec.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ describe('ad_hoc.md', function()
2323
util.setup('tests/data/ad_hoc.md')
2424

2525
local expected = {}
26+
2627
vim.list_extend(expected, util.heading(0, 1))
28+
2729
vim.list_extend(expected, {
2830
wiki_link(4, 0, 13, 'Basic One'),
2931
wiki_link(6, 0, 23, 'With Alias'),

tests/box_dash_quote_spec.lua

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ local util = require('tests.util')
88
---@param custom boolean
99
---@return render.md.MarkInfo[]
1010
local function checkbox(row, icon, highlight, custom)
11-
local virt_text_pos
12-
local conceal
13-
if custom then
14-
virt_text_pos = 'inline'
15-
conceal = ''
16-
else
17-
virt_text_pos = 'overlay'
18-
conceal = nil
19-
end
2011
---@type render.md.MarkInfo
2112
local conceal_mark = {
2213
row = { row, row },
@@ -28,37 +19,38 @@ local function checkbox(row, icon, highlight, custom)
2819
row = { row, row },
2920
col = { 2, 5 },
3021
virt_text = { { icon, util.hl(highlight) } },
31-
virt_text_pos = virt_text_pos,
32-
conceal = conceal,
22+
virt_text_pos = custom and 'inline' or 'overlay',
23+
conceal = custom and '' or nil,
3324
}
3425
return { conceal_mark, checkbox_mark }
3526
end
3627

28+
---@param row integer
29+
---@return render.md.MarkInfo
30+
local function dash(row)
31+
---@type render.md.MarkInfo
32+
return {
33+
row = { row },
34+
col = { 0 },
35+
virt_text = { { string.rep('', vim.opt.columns:get()), util.hl('Dash') } },
36+
virt_text_pos = 'overlay',
37+
}
38+
end
39+
3740
describe('box_dash_quote.md', function()
3841
it('default', function()
3942
util.setup('demo/box_dash_quote.md')
4043

4144
local expected = {}
4245

43-
-- Heading
4446
vim.list_extend(expected, util.heading(0, 1))
4547

46-
-- Checkboxes
4748
vim.list_extend(expected, checkbox(2, ' 󰄱 ', 'Unchecked', false))
4849
vim.list_extend(expected, checkbox(3, ' 󰱒 ', 'Checked', false))
4950
vim.list_extend(expected, checkbox(4, ' 󰥔 ', 'Todo', true))
5051

51-
-- Line break
52-
vim.list_extend(expected, {
53-
{
54-
row = { 6 },
55-
col = { 0 },
56-
virt_text = { { string.rep('', vim.opt.columns:get()), util.hl('Dash') } },
57-
virt_text_pos = 'overlay',
58-
},
59-
})
52+
table.insert(expected, dash(6))
6053

61-
-- Quote lines
6254
vim.list_extend(expected, {
6355
util.quote(8, ' %s ', 'Quote'),
6456
util.quote(9, ' %s ', 'Quote'),

tests/callout_spec.lua

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,55 +33,53 @@ describe('callout.md', function()
3333
local expected = {}
3434

3535
local note_start = 0
36-
vim.list_extend(expected, util.heading(note_start, 1))
3736
vim.list_extend(expected, {
38-
util.quote(note_start + 2, '%s ', info), -- Quote start
39-
callout(note_start + 2, 2, 9, '󰋽 Note', info), -- Callout text
40-
util.quote(note_start + 3, '%s', info), -- Quote continued
37+
util.heading(note_start, 1),
38+
util.quote(note_start + 2, '%s ', info),
39+
callout(note_start + 2, 2, 9, '󰋽 Note', info),
40+
util.quote(note_start + 3, '%s', info),
4141
util.quote(note_start + 4, '%s ', info),
4242
util.quote(note_start + 5, '%s', info),
4343
util.quote(note_start + 6, '%s ', info),
4444
})
4545

4646
local tip_start = 8
47-
vim.list_extend(expected, util.heading(tip_start, 1))
4847
vim.list_extend(expected, {
49-
util.quote(tip_start + 2, '%s ', ok), -- Quote start
50-
callout(tip_start + 2, 2, 8, '󰌶 Tip', ok), -- Callout text
51-
util.quote(tip_start + 3, '%s', ok), -- Quote continued
48+
util.heading(tip_start, 1),
49+
util.quote(tip_start + 2, '%s ', ok),
50+
callout(tip_start + 2, 2, 8, '󰌶 Tip', ok),
51+
util.quote(tip_start + 3, '%s', ok),
5252
util.quote(tip_start + 4, '%s ', ok),
53-
util.code_block_row(tip_start + 4, 2),
54-
})
55-
vim.list_extend(expected, util.code_language(tip_start + 4, 5, 8, 'lua'))
56-
vim.list_extend(expected, {
53+
util.code_row(tip_start + 4, 2),
54+
util.code_language(tip_start + 4, 5, 8, 'lua'),
5755
util.quote(tip_start + 5, '%s ', ok),
58-
util.code_block_row(tip_start + 5, 2),
56+
util.code_row(tip_start + 5, 2),
5957
util.quote(tip_start + 6, '%s ', ok),
6058
util.code_below(tip_start + 6, 2),
6159
})
6260

6361
local important_start = 16
64-
vim.list_extend(expected, util.heading(important_start, 1))
6562
vim.list_extend(expected, {
66-
util.quote(important_start + 2, '%s ', hint), -- Quote start
67-
callout(important_start + 2, 2, 14, '󰅾 Important', hint), -- Callout text
68-
util.quote(important_start + 3, '%s ', hint), -- Quote continued
63+
util.heading(important_start, 1),
64+
util.quote(important_start + 2, '%s ', hint),
65+
callout(important_start + 2, 2, 14, '󰅾 Important', hint),
66+
util.quote(important_start + 3, '%s ', hint),
6967
})
7068

7169
local warning_start = 21
72-
vim.list_extend(expected, util.heading(warning_start, 1))
7370
vim.list_extend(expected, {
74-
util.quote(warning_start + 2, '%s ', warn), -- Quote start
75-
callout(warning_start + 2, 2, 12, '󰀪 Custom Title', warn, ''), -- Callout text
76-
util.quote(warning_start + 3, '%s ', warn), -- Quote continued
71+
util.heading(warning_start, 1),
72+
util.quote(warning_start + 2, '%s ', warn),
73+
callout(warning_start + 2, 2, 12, '󰀪 Custom Title', warn, ''),
74+
util.quote(warning_start + 3, '%s ', warn),
7775
})
7876

7977
local caution_start = 26
80-
vim.list_extend(expected, util.heading(caution_start, 1))
8178
vim.list_extend(expected, {
82-
util.quote(caution_start + 2, '%s ', error), -- Quote start
83-
callout(caution_start + 2, 2, 12, '󰳦 Caution', error), -- Callout text
84-
util.quote(caution_start + 3, '%s ', error), -- Quote continued
79+
util.heading(caution_start, 1),
80+
util.quote(caution_start + 2, '%s ', error),
81+
callout(caution_start + 2, 2, 12, '󰳦 Caution', error),
82+
util.quote(caution_start + 3, '%s ', error),
8583
})
8684

8785
vim.list_extend(expected, util.heading(31, 1))

tests/code_spec.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---@module 'luassert'
2+
3+
local util = require('tests.util')
4+
5+
describe('code.md', function()
6+
it('default', function()
7+
util.setup('tests/data/code.md')
8+
9+
local expected = {}
10+
11+
vim.list_extend(expected, util.heading(0, 1))
12+
13+
vim.list_extend(expected, {
14+
util.bullet(2, 0, 1),
15+
util.code_row(4, 2),
16+
util.code_language(4, 5, 8, 'lua'),
17+
util.code_row(5, 2),
18+
util.code_row(6, 2),
19+
util.code_below(7, 2),
20+
})
21+
22+
vim.list_extend(expected, {
23+
util.bullet(9, 0, 1),
24+
util.code_row(11, 2),
25+
util.code_language(11, 5, 8, 'lua'),
26+
util.code_row(12, 2),
27+
-- TODO: look into fixing indented code with blank lines
28+
-- probably need to fill with inline extmark
29+
util.code_row(13, 0),
30+
util.code_row(14, 2),
31+
util.code_below(15, 2),
32+
})
33+
34+
local actual = util.get_actual_marks()
35+
util.marks_are_equal(expected, actual)
36+
end)
37+
end)

0 commit comments

Comments
 (0)