Skip to content

Commit 9e3393b

Browse files
feat: add scope_highlight to list items
## Details Request: #354 Adds a `scope_highlight` parameter to the `bullet` configuration which is used in the same way as the `checkbox` equivalent to highlight the item. Also allows `highlight` to be the same type as `icons`, i.e. `string` | `string[]` | `string[][]` | `function`. The support for a plain string was added in this change as well to ensure backwards compatibility for the `highlight` configuration. Update documentation formatting and improve validation messages.
1 parent daaf7d7 commit 9e3393b

17 files changed

+1447
-1375
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ The fields impacted are:
549549
- Case insensitive callout matching [#74](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/74)
550550
[123048b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/123048b428eb85618780fcef9ea9f4d68b5d2508)
551551
- Improve lazy.nvim instructions [#80](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/80)
552-
- Improve LaTeX compatibility [#90](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/90)
552+
- Improve latex compatibility [#90](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/90)
553553
[695501b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/695501bd98b1f2ec052889fc4faef24dedd7091b)
554554
- Heading block width [#94](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/94)
555555
[426b135](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/426b13574c8264636e5660e5f5a3b4f5e3d5a937)
@@ -822,7 +822,7 @@ The fields impacted are:
822822
[fea6f3d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/fea6f3de62d864633ffe4e1e0fd92d1e746f77ed)
823823
- Use buffer parser to handle injections [#3](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/3)
824824
[e64255d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/e64255d52dcdf05eb37d9e93fbfd300648c4c4dd)
825-
- Add LaTeX support [#6](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/6)
825+
- Add latex support [#6](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/6)
826826
[138a796](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/138a7962fcbe9cddcb47cc40a58ec0f5ab99ddfe)
827827
[da85a5e](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/da85a5e5885f1a11ab2b7a9059c16f3eede89bfe)
828828
- Support block quotes [106946a](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/106946ae924706c885bda14a9160398e79880f30)
@@ -835,7 +835,7 @@ The fields impacted are:
835835
- Add fat tables option [fb00297](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/fb00297774c6f44c0cc3346459ed85168ac93dce)
836836
- Support list icon based on level [#1](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/1)
837837
[#11](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/11)
838-
- Refactor + LaTeX cache [2b98d16](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/2b98d16f938dc9cedaa5f1c0659081035655f781)
838+
- Refactor + latex cache [2b98d16](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/2b98d16f938dc9cedaa5f1c0659081035655f781)
839839
- Support horizontal break [af819f3](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/af819f39c63aeb09ff3801dbfd5188cea55e48e7)
840840
- Support checkboxes [90637a1](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/90637a1120de47a3be57b00b7db4eee0d24834c8)
841841

README.md

+505-485
Large diffs are not rendered by default.

benches/readme_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local util = require('benches.util')
44

55
describe('README.md', function()
66
it('default', function()
7-
local base_marks = 115
7+
local base_marks = 114
88
util.less_than(util.setup('README.md'), 60)
99
util.num_marks(base_marks)
1010

doc/custom-handlers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ For each `mark` in the return value the fields mean:
5252
By not specifying the `extends` field and having the `parse` implementation return
5353
an empty table we can disable a builtin handler. Though this has little benefit and
5454
can be accomplished in other ways like setting `{ latex = { enabled = false } }`
55-
for `LaTeX`.
55+
for `latex`.
5656

57-
Still as a toy example disabling the `LaTeX` handler can be done with:
57+
Still as a toy example disabling the `latex` handler can be done with:
5858

5959
```lua
6060
require('render-markdown').setup({

doc/limitations.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Limitations
22

3-
## `LaTeX` Formula Positioning
3+
## `latex` Formula Positioning
44

55
[ISSUE #6](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/6)
66

7-
`LaTeX` formula evaluations are placed above text rather than overlaid.
7+
`latex` formula evaluations are placed above text rather than overlaid.
88

9-
A way around this is to use a separate plugin for `LaTeX` and disable that feature
9+
A way around this is to use a separate plugin for `latex` and disable that feature
1010
in this plugin. Different plugins will have different setups, below are some examples:
1111

1212
[latex.nvim](https://github.com/ryleelyman/latex.nvim)

doc/render-markdown.txt

+505-485
Large diffs are not rendered by default.

doc/troubleshooting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugin is not functioning how you expect. As such it is recommended to go in ord
1111

1212
If there are any `errors` these should be looked at closely, `warnings` can largely
1313
be ignored. They are generated to help debug issues for less critical components,
14-
i.e. `LaTeX` support.
14+
i.e. `latex` support.
1515

1616
## Validate `filetype`
1717

lua/render-markdown/debug/validator.lua

+50-45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
local Iter = require('render-markdown.lib.iter')
22

3+
---@alias render.md.debug.SpecKind 'type'|'value'
4+
35
---@class render.md.debug.Spec
6+
---@field kind render.md.debug.SpecKind
47
---@field message string
58
---@field validation fun(value: any): boolean, string?
69

@@ -56,38 +59,39 @@ function Spec:nested(keys, f, nilable)
5659
end
5760

5861
---@param keys string|string[]
59-
---@param input_types type|type[]
62+
---@param ts type|type[]
6063
---@return render.md.debug.ValidatorSpec
61-
function Spec:type(keys, input_types)
62-
local types, message = self:handle_types(input_types, '')
63-
return self:add(keys, message, function(value)
64+
function Spec:type(keys, ts)
65+
local types, message = self:handle_types({}, ts)
66+
return self:add(keys, 'type', message, function(value)
6467
return vim.tbl_contains(types, type(value))
6568
end)
6669
end
6770

6871
---@param keys string|string[]
6972
---@param values string[]
70-
---@param input_types? type|type[]
73+
---@param ts? type|type[]
7174
---@return render.md.debug.ValidatorSpec
72-
function Spec:one_of(keys, values, input_types)
73-
local types, message = self:handle_types(input_types, 'one of ' .. vim.inspect(values))
74-
return self:add(keys, message, function(value)
75+
function Spec:one_of(keys, values, ts)
76+
local options = Iter.list.map(values, vim.inspect)
77+
local types, message = self:handle_types(options, ts)
78+
return self:add(keys, 'value', message, function(value)
7579
return vim.tbl_contains(values, value) or vim.tbl_contains(types, type(value))
7680
end)
7781
end
7882

7983
---@param keys string|string[]
80-
---@param list_type type
81-
---@param input_types? type|type[]
84+
---@param t type
85+
---@param ts? type|type[]
8286
---@return render.md.debug.ValidatorSpec
83-
function Spec:list(keys, list_type, input_types)
84-
local types, message = self:handle_types(input_types, list_type .. ' list')
85-
return self:add(keys, message, function(value)
87+
function Spec:list(keys, t, ts)
88+
local types, message = self:handle_types({ t .. '[]' }, ts)
89+
return self:add(keys, 'type', message, function(value)
8690
if vim.tbl_contains(types, type(value)) then
8791
return true
8892
elseif type(value) == 'table' then
8993
for i, item in ipairs(value) do
90-
if type(item) ~= list_type then
94+
if type(item) ~= t then
9195
return false, string.format('[%d] is %s', i, type(item))
9296
end
9397
end
@@ -99,23 +103,23 @@ function Spec:list(keys, list_type, input_types)
99103
end
100104

101105
---@param keys string|string[]
102-
---@param list_type type
103-
---@param input_types? type|type[]
106+
---@param t type
107+
---@param ts? type|type[]
104108
---@return render.md.debug.ValidatorSpec
105-
function Spec:list_or_list_of_list(keys, list_type, input_types)
106-
local types, message = self:handle_types(input_types, list_type .. ' list or list of list')
107-
return self:add(keys, message, function(value)
108-
if vim.tbl_contains(types, type(value)) then
109+
function Spec:nested_list(keys, t, ts)
110+
local types, message = self:handle_types({ t, t .. '[]', t .. '[][]' }, ts)
111+
return self:add(keys, 'type', message, function(value)
112+
if type(value) == t or vim.tbl_contains(types, type(value)) then
109113
return true
110114
elseif type(value) == 'table' then
111115
for i, item in ipairs(value) do
112116
if type(item) == 'table' then
113117
for j, nested in ipairs(item) do
114-
if type(nested) ~= list_type then
118+
if type(nested) ~= t then
115119
return false, string.format('[%d][%d] is %s', i, j, type(nested))
116120
end
117121
end
118-
elseif type(item) ~= list_type then
122+
elseif type(item) ~= t then
119123
return false, string.format('[%d] is %s', i, type(item))
120124
end
121125
end
@@ -128,11 +132,12 @@ end
128132

129133
---@param keys string|string[]
130134
---@param values string[]
131-
---@param input_types? type|type[]
135+
---@param ts? type|type[]
132136
---@return render.md.debug.ValidatorSpec
133-
function Spec:one_or_list_of(keys, values, input_types)
134-
local types, message = self:handle_types(input_types, 'one or list of ' .. vim.inspect(values))
135-
return self:add(keys, message, function(value)
137+
function Spec:one_or_list_of(keys, values, ts)
138+
local options = '(' .. table.concat(Iter.list.map(values, vim.inspect), '|') .. ')'
139+
local types, message = self:handle_types({ options, options .. '[]' }, ts)
140+
return self:add(keys, 'type', message, function(value)
136141
if vim.tbl_contains(types, type(value)) then
137142
return true
138143
elseif type(value) == 'string' then
@@ -151,41 +156,35 @@ function Spec:one_or_list_of(keys, values, input_types)
151156
end
152157

153158
---@private
154-
---@param input_types? type|type[]
155-
---@param prefix string
159+
---@param custom string[]
160+
---@param ts? type|type[]
156161
---@return type[], string
157-
function Spec:handle_types(input_types, prefix)
162+
function Spec:handle_types(custom, ts)
158163
local types = nil
159-
if input_types == nil then
164+
if ts == nil then
160165
types = {}
161-
elseif type(input_types) == 'string' then
162-
types = { input_types }
166+
elseif type(ts) == 'string' then
167+
types = { ts }
163168
else
164-
types = input_types
169+
types = ts
165170
end
166171
if self.nilable and not vim.tbl_contains(types, 'nil') then
167172
table.insert(types, 'nil')
168173
end
169-
local message = prefix
170-
if #types > 0 then
171-
if #message > 0 then
172-
message = message .. ' or '
173-
end
174-
message = message .. 'type ' .. table.concat(types, ' or ')
175-
end
176-
return types, message
174+
return types, table.concat(vim.list_extend(custom, types), ' or ')
177175
end
178176

179177
---@private
180178
---@param keys string|string[]
179+
---@param kind render.md.debug.SpecKind
181180
---@param message string
182181
---@param validation fun(v: any): boolean, string?
183182
---@return render.md.debug.ValidatorSpec
184-
function Spec:add(keys, message, validation)
183+
function Spec:add(keys, kind, message, validation)
185184
if self.config ~= nil then
186185
keys = type(keys) == 'table' and keys or { keys }
187186
for _, key in ipairs(keys) do
188-
self.specs[key] = { message = message, validation = validation }
187+
self.specs[key] = { kind = kind, message = message, validation = validation }
189188
end
190189
end
191190
return self
@@ -223,7 +222,13 @@ function Validator:check(path, config, specs)
223222
local value = config[key]
224223
local ok, info = spec.validation(value)
225224
if not ok then
226-
local message = string.format('%s.%s: expected %s, got %s', path, key, spec.message, type(value))
225+
local message = string.format('%s.%s - expected: %s', path, key, spec.message)
226+
if spec.kind == 'type' then
227+
message = message .. string.format(', but got: %s', type(value))
228+
end
229+
if spec.kind == 'value' then
230+
message = message .. string.format(', but got: %s', vim.inspect(value))
231+
end
227232
if info ~= nil then
228233
message = message .. string.format(', info: %s', info)
229234
end
@@ -232,7 +237,7 @@ function Validator:check(path, config, specs)
232237
end
233238
for key, _ in pairs(config) do
234239
if specs[key] == nil then
235-
local message = string.format('%s.%s: is not a valid key', path, key)
240+
local message = string.format('%s.%s - invalid key', path, key)
236241
table.insert(self.errors, message)
237242
end
238243
end

lua/render-markdown/health.lua

+1-1
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.0.16'
8+
M.version = '8.0.17'
99

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

0 commit comments

Comments
 (0)