Skip to content

Commit 14a316a

Browse files
Add neovim 0.9.0 minimum version requirement, recommend 0.10.0
## Details Add version requirement for 0.9.0 in README and health check. - I believe everything used by this plugin should be available in 0.9.0 `vim.treesitter.query.parse` & all extmark features. Anything requiring 0.10.0 is gated behind a condition. - I haven't tested this directly, may need to update. Add recommended version for 0.10.0, using older should not break but will remove features, make this a warning in the health check. Minor unit test updates to construct table borders from lengths.
1 parent 9b771cc commit 14a316a

File tree

6 files changed

+86
-92
lines changed

6 files changed

+86
-92
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ Plugin to improve viewing Markdown files in Neovim
3434
- Disable rendering when file is larger than provided value
3535
- Support custom handlers which are ran identically to builtin handlers
3636

37-
# Dependencies
37+
# Requirements
3838

39+
- neovim `>= 0.9.0` (minimum) `>= 0.10.0` (recommended)
3940
- [treesitter](https://github.com/nvim-treesitter/nvim-treesitter) parsers:
4041
- [markdown & markdown_inline](https://github.com/tree-sitter-grammars/tree-sitter-markdown):
4142
Used to parse `markdown` files

doc/render-markdown.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Table of Contents *render-markdown-table-of-contents*
55

66
1. markdown.nvim |render-markdown-markdown.nvim|
77
2. Features |render-markdown-features|
8-
3. Dependencies |render-markdown-dependencies|
8+
3. Requirements |render-markdown-requirements|
99
4. Install |render-markdown-install|
1010
- lazy.nvim |render-markdown-install-lazy.nvim|
1111
- packer.nvim |render-markdown-install-packer.nvim|
@@ -65,8 +65,9 @@ Plugin to improve viewing Markdown files in Neovim
6565

6666

6767
==============================================================================
68-
3. Dependencies *render-markdown-dependencies*
68+
3. Requirements *render-markdown-requirements*
6969

70+
- neovim `>= 0.9.0` (minimum) `>= 0.10.0` (recommended)
7071
- treesitter <https://github.com/nvim-treesitter/nvim-treesitter> parsers:
7172
- markdown & markdown_inline <https://github.com/tree-sitter-grammars/tree-sitter-markdown>:
7273
Used to parse `markdown` files

lua/render-markdown/health.lua

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

66
function M.check()
7+
vim.health.start('markdown.nvim [neovim version]')
8+
M.version('0.9', '0.10')
9+
710
vim.health.start('markdown.nvim [configuration]')
811
local errors = state.validate()
912
if #errors == 0 then
@@ -45,6 +48,18 @@ function M.check()
4548
end
4649
end
4750

51+
---@param minimum string
52+
---@param recommended string
53+
function M.version(minimum, recommended)
54+
if vim.fn.has('nvim-' .. minimum) == 0 then
55+
vim.health.error('Version < ' .. minimum)
56+
elseif vim.fn.has('nvim-' .. recommended) == 0 then
57+
vim.health.warn('Version < ' .. recommended .. ' some features will not work')
58+
else
59+
vim.health.ok('Version >= ' .. recommended)
60+
end
61+
end
62+
4863
---@param name string
4964
---@param advice string?
5065
function M.check_parser(name, advice)

tests/list_table_spec.lua

+6-14
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ async_tests.describe('list_table.md', function()
77

88
local expected = {}
99

10-
-- Unordered list heading
11-
vim.list_extend(expected, util.heading(0, 1))
12-
1310
-- Unordered list
11+
vim.list_extend(expected, util.heading(0, 1))
1412
vim.list_extend(expected, {
1513
util.bullet(2, 0, 1), -- List Item 1
1614
util.link(2, 20, 47, false), -- List Item 1, link
@@ -24,32 +22,26 @@ async_tests.describe('list_table.md', function()
2422
util.bullet(9, 0, 1), -- List Item 3
2523
})
2624

27-
-- Ordered list heading
25+
-- Ordered list
2826
vim.list_extend(expected, util.heading(11, 1))
2927

30-
-- Table heading
28+
-- Table
3129
vim.list_extend(expected, util.heading(17, 1))
32-
33-
local table_outline = {
34-
'┌──────────────────┬────────────────────┐',
35-
'├──────────────────┼────────────────────┤',
36-
'└──────────────────┴────────────────────┘',
37-
}
3830
vim.list_extend(expected, {
3931
util.table_pipe(19, 0, true), -- Heading pipe 1
40-
util.table_border(19, table_outline[1], true), -- Above
32+
util.table_border(19, 'above', { 18, 20 }),
4133
util.inline_code(19, 2, 18), -- Inline code in heading
4234
util.table_padding(19, 19, 2), -- Heading padding 1
4335
util.table_pipe(19, 19, true), -- Heading pipe 2
4436
util.table_padding(19, 40, 2), -- Heading padding 2
4537
util.table_pipe(19, 40, true), -- Heading pipe 2
46-
util.table_row(20, 41, table_outline[2], true), -- Delimiter
38+
util.table_border(20, 'delimiter', { 18, 20 }),
4739
util.table_pipe(21, 0, false), -- Row 1 pipe 1
4840
util.table_pipe(21, 19, false), -- Row 1 pipe 2
4941
util.table_padding(21, 40, 4), -- Row 1 padding 2
5042
util.table_pipe(21, 40, false), -- Row 1 pipe 3
5143
util.table_pipe(22, 0, false), -- Row 2 pipe 1
52-
util.table_border(22, table_outline[3], false), -- Below
44+
util.table_border(22, 'below', { 18, 20 }),
5345
util.inline_code(22, 2, 15), -- Row 2 inline code
5446
util.table_padding(22, 19, 2), -- Row 2 padding 1
5547
util.table_pipe(22, 19, false), -- Row 2 pipe 2

tests/table_spec.lua

+26-64
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@ async_tests.describe('table.md', function()
77

88
local expected = {}
99

10-
-- Table with inline heading
10+
-- Table with inline
1111
vim.list_extend(expected, util.heading(0, 1))
12-
13-
local table_with_inline = {
14-
'┌───────────┬────────────────────────┐',
15-
'├───────────┼────────────────────────┤',
16-
'└───────────┴────────────────────────┘',
17-
}
1812
vim.list_extend(expected, {
1913
util.table_pipe(2, 0, true), -- Heading pipe 1
20-
util.table_border(2, table_with_inline[1], true), -- Above
14+
util.table_border(2, 'above', { 11, 24 }),
2115
util.table_pipe(2, 12, true), -- Heading pipe 2
2216
util.inline_code(2, 14, 25), -- Inline code in heading
2317
util.table_padding(2, 37, 2), -- Heading padding 2
2418
util.table_pipe(2, 37, true), -- Heading pipe 3
25-
util.table_row(3, 38, table_with_inline[2], true), -- Delimiter
19+
util.table_border(3, 'delimiter', { 11, 24 }),
2620
util.table_pipe(4, 0, false), -- Row pipe 1
27-
util.table_border(4, table_with_inline[3], false), -- Below
21+
util.table_border(4, 'below', { 11, 24 }),
2822
util.inline_code(4, 2, 12), -- Row inline code
2923
util.table_padding(4, 13, 2), -- Row padding 1
3024
util.table_pipe(4, 13, false), -- Row pipe 2
@@ -33,22 +27,16 @@ async_tests.describe('table.md', function()
3327
util.table_pipe(4, 39, false), -- Row pipe 3
3428
})
3529

36-
-- Table no inline heading
30+
-- Table no inline
3731
vim.list_extend(expected, util.heading(6, 1))
38-
39-
local table_no_inline = {
40-
'┌───────────┬───────────┐',
41-
'├───────────┼───────────┤',
42-
'└───────────┴───────────┘',
43-
}
4432
vim.list_extend(expected, {
4533
util.table_pipe(8, 0, true), -- Heading pipe 1
46-
util.table_border(8, table_no_inline[1], true), -- Above
34+
util.table_border(8, 'above', { 11, 11 }),
4735
util.table_pipe(8, 12, true), -- Heading pipe 2
4836
util.table_pipe(8, 24, true), -- Heading pipe 3
49-
util.table_row(9, 25, table_no_inline[2], true), -- Delimiter
37+
util.table_border(9, 'delimiter', { 11, 11 }),
5038
util.table_pipe(10, 0, false), -- Row pipe 1
51-
util.table_border(10, table_no_inline[3], false), -- Below
39+
util.table_border(10, 'below', { 11, 11 }),
5240
util.table_pipe(10, 12, false), -- Row pipe 2
5341
util.table_pipe(10, 24, false), -- Row pipe 3
5442
})
@@ -62,41 +50,31 @@ async_tests.describe('table.md', function()
6250

6351
local expected = {}
6452

65-
-- Table with inline heading
53+
-- Table with inline
6654
vim.list_extend(expected, util.heading(0, 1))
67-
68-
local table_with_inline = {
69-
'├───────────┼────────────────────────┤',
70-
}
7155
vim.list_extend(expected, {
7256
util.table_pipe(2, 0, true), -- Heading pipe 1
7357
util.table_pipe(2, 12, true), -- Heading pipe 2
7458
util.inline_code(2, 14, 25), -- Inline code in heading
7559
util.table_pipe(2, 37, true), -- Heading pipe 3
76-
util.table_row(3, 38, table_with_inline[1], true), -- Delimiter
60+
util.table_border(3, 'delimiter', { 11, 24 }),
7761
util.table_pipe(4, 0, false), -- Row pipe 1
7862
util.inline_code(4, 2, 12), -- Row inline code
7963
util.table_pipe(4, 13, false), -- Row pipe 2
8064
util.link(4, 15, 38, false), -- Row link
8165
util.table_pipe(4, 39, false), -- Row pipe 3
8266
})
8367

84-
-- Table no inline heading
68+
-- Table no inline
8569
vim.list_extend(expected, util.heading(6, 1))
86-
87-
local table_no_inline = {
88-
'┌───────────┬───────────┐',
89-
'├───────────┼───────────┤',
90-
'└───────────┴───────────┘',
91-
}
9270
vim.list_extend(expected, {
9371
util.table_pipe(8, 0, true), -- Heading pipe 1
94-
util.table_border(8, table_no_inline[1], true), -- Above
72+
util.table_border(8, 'above', { 11, 11 }),
9573
util.table_pipe(8, 12, true), -- Heading pipe 2
9674
util.table_pipe(8, 24, true), -- Heading pipe 3
97-
util.table_row(9, 25, table_no_inline[2], true), -- Delimiter
75+
util.table_border(9, 'delimiter', { 11, 11 }),
9876
util.table_pipe(10, 0, false), -- Row pipe 1
99-
util.table_border(10, table_no_inline[3], false), -- Below
77+
util.table_border(10, 'below', { 11, 11 }),
10078
util.table_pipe(10, 12, false), -- Row pipe 2
10179
util.table_pipe(10, 24, false), -- Row pipe 3
10280
})
@@ -110,43 +88,27 @@ async_tests.describe('table.md', function()
11088

11189
local expected = {}
11290

113-
-- Table with inline heading
91+
-- Table with inline
11492
vim.list_extend(expected, util.heading(0, 1))
115-
116-
local table_with_inline = {
117-
'┌───────────┬────────────────────────┐',
118-
'│ Heading 1 │ `Heading 2` │',
119-
'├───────────┼────────────────────────┤',
120-
'│ `Item 行` │ [link](https://行.com) │',
121-
'└───────────┴────────────────────────┘',
122-
}
12393
vim.list_extend(expected, {
124-
util.table_row(2, 38, table_with_inline[2], true), -- Heading
125-
util.table_border(2, table_with_inline[1], true), -- Above
94+
util.table_row(2, 38, '│ Heading 1 │ `Heading 2` │', true),
95+
util.table_border(2, 'above', { 11, 24 }),
12696
util.inline_code(2, 14, 25), -- Inline code in heading
127-
util.table_row(3, 38, table_with_inline[3], true), -- Delimiter
128-
util.table_row(4, 40, table_with_inline[4], false), -- Row
129-
util.table_border(4, table_with_inline[5], false), -- Below
97+
util.table_border(3, 'delimiter', { 11, 24 }),
98+
util.table_row(4, 40, '│ `Item 行` │ [link](https://行.com) │', false),
99+
util.table_border(4, 'below', { 11, 24 }),
130100
util.inline_code(4, 2, 12), -- Row inline code
131101
util.link(4, 15, 38, false), -- Row link
132102
})
133103

134-
-- Table no inline heading
104+
-- Table no inline
135105
vim.list_extend(expected, util.heading(6, 1))
136-
137-
local table_no_inline = {
138-
'┌───────────┬───────────┐',
139-
'│ Heading 1 │ Heading 2 │',
140-
'├───────────┼───────────┤',
141-
'│ Item 1 │ Item 2 │',
142-
'└───────────┴───────────┘',
143-
}
144106
vim.list_extend(expected, {
145-
util.table_row(8, 25, table_no_inline[2], true), -- Heading
146-
util.table_border(8, table_no_inline[1], true), -- Above
147-
util.table_row(9, 25, table_no_inline[3], true), -- Delimiter
148-
util.table_row(10, 25, table_no_inline[4], false), -- Row
149-
util.table_border(10, table_no_inline[5], false), -- Below
107+
util.table_row(8, 25, '│ Heading 1 │ Heading 2 │', true),
108+
util.table_border(8, 'above', { 11, 11 }),
109+
util.table_border(9, 'delimiter', { 11, 11 }),
110+
util.table_row(10, 25, '│ Item 1 │ Item 2 │', false),
111+
util.table_border(10, 'below', { 11, 11 }),
150112
})
151113

152114
local actual = util.get_actual_marks()

tests/util.lua

+34-11
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,43 @@ M.table_padding = function(row, col, spaces)
231231
end
232232

233233
---@param row integer
234-
---@param value string
235-
---@param head boolean
234+
---@param section 'above'|'delimiter'|'below'
235+
---@param lengths integer[]
236236
---@return render.md.MarkInfo
237-
M.table_border = function(row, value, head)
238-
local highlight = 'Normal'
239-
if head then
237+
M.table_border = function(row, section, lengths)
238+
local border
239+
local highlight
240+
if section == 'above' then
241+
border = { '', '', '' }
240242
highlight = '@markup.heading'
243+
elseif section == 'delimiter' then
244+
border = { '', '', '' }
245+
highlight = '@markup.heading'
246+
elseif section == 'below' then
247+
border = { '', '', '' }
248+
highlight = 'Normal'
249+
end
250+
251+
local parts = vim.tbl_map(function(length)
252+
return string.rep('', length)
253+
end, lengths)
254+
local value = border[1] .. table.concat(parts, border[2]) .. border[3]
255+
256+
if vim.tbl_contains({ 'above', 'below' }, section) then
257+
return {
258+
row = { row },
259+
col = { 0 },
260+
virt_lines = { { { value, highlight } } },
261+
virt_lines_above = section == 'above',
262+
}
263+
else
264+
return {
265+
row = { row, row },
266+
col = { 0, vim.fn.strdisplaywidth(value) },
267+
virt_text = { { value, highlight } },
268+
virt_text_pos = 'overlay',
269+
}
241270
end
242-
return {
243-
row = { row },
244-
col = { 0 },
245-
virt_lines = { { { value, highlight } } },
246-
virt_lines_above = head,
247-
}
248271
end
249272

250273
---@param row integer

0 commit comments

Comments
 (0)