Skip to content

Commit ac3639d

Browse files
chore: add default implementations for base render
## Details Rather than having `setup` and `run` be type annotated methods on the Base render module, add actual methods for them. Both implementations throw exceptions, which should make catching any extensions that don't have their own implementations easier, though not by much. Mostly just a preference thing.
1 parent 4f05de7 commit ac3639d

File tree

5 files changed

+66
-49
lines changed

5 files changed

+66
-49
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Pre-release
44

5+
### Features
6+
7+
- allow checkbox to render bullet [#423](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/423)
8+
[a1b0988](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/a1b0988f5ab26698afb56b9c2f0525a4de1195c1)
9+
- include highlight query files in checkhealth [4f05de7](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/4f05de7536571e231b66dd0363af347b162b5fd7)
10+
511
## 8.4.0 (2025-05-08)
612

713
### Features

lua/render-markdown/debug/validator.lua

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ local Kind = {
1313

1414
---@class render.md.debug.ValidatorSpec
1515
---@field private validator render.md.debug.Validator
16-
---@field private data? table<string, any>
16+
---@field private config? table<string, any>
1717
---@field private nilable boolean
1818
---@field private path string[]
1919
---@field private specs table<string, render.md.debug.Spec>
2020
local Spec = {}
2121
Spec.__index = Spec
2222

2323
---@param validator render.md.debug.Validator
24-
---@param data? table<string, any>
24+
---@param config? table<string, any>
2525
---@param nilable boolean
2626
---@param path? string[]
2727
---@param key any
2828
---@return render.md.debug.ValidatorSpec
29-
function Spec.new(validator, data, nilable, path, key)
29+
function Spec.new(validator, config, nilable, path, key)
3030
local self = setmetatable({}, Spec)
3131
self.validator = validator
32-
self.data = data
32+
self.config = config
3333
self.nilable = nilable
3434
self.path = vim.list_extend({}, path or {})
35-
if self.data and key then
36-
self.data = self.data[key]
37-
self.data = type(self.data) == 'table' and self.data or nil
35+
if self.config and key then
36+
self.config = self.config[key]
37+
self.config = type(self.config) == 'table' and self.config or nil
3838
self.path[#self.path + 1] = tostring(key)
3939
end
4040
self.specs = {}
@@ -44,7 +44,7 @@ end
4444
---@param f fun(spec: render.md.debug.ValidatorSpec)
4545
---@param nilable? boolean
4646
function Spec:each(f, nilable)
47-
local keys = self.data and vim.tbl_keys(self.data) or {}
47+
local keys = self.config and vim.tbl_keys(self.config) or {}
4848
self:nested(keys, f, nilable)
4949
end
5050

@@ -58,7 +58,7 @@ function Spec:nested(keys, f, nilable)
5858
end
5959
for _, key in ipairs(keys) do
6060
self:type(key, 'table')
61-
f(Spec.new(self.validator, self.data, nilable, self.path, key))
61+
f(Spec.new(self.validator, self.config, nilable, self.path, key))
6262
end
6363
end
6464

@@ -187,7 +187,7 @@ end
187187
---@param message string
188188
---@param validation fun(v: any): boolean, string?
189189
function Spec:add(keys, kind, message, validation)
190-
if self.data then
190+
if self.config then
191191
keys = type(keys) == 'table' and keys or { keys }
192192
for _, key in ipairs(keys) do
193193
self.specs[key] = {
@@ -200,10 +200,10 @@ function Spec:add(keys, kind, message, validation)
200200
end
201201

202202
function Spec:check()
203-
if not self.data or vim.tbl_count(self.specs) == 0 then
203+
if not self.config or vim.tbl_count(self.specs) == 0 then
204204
return
205205
end
206-
self.validator:check(self.path, self.data, self.specs)
206+
self.validator:check(self.path, self.config, self.specs)
207207
end
208208

209209
---@class render.md.debug.Validator
@@ -221,13 +221,13 @@ end
221221
Validator.spec = Spec.new
222222

223223
---@param path string[]
224-
---@param data table<string, any>
224+
---@param config table<string, any>
225225
---@param specs table<string, render.md.debug.Spec>
226-
function Validator:check(path, data, specs)
226+
function Validator:check(path, config, specs)
227227
for key, spec in pairs(specs) do
228228
local root = vim.list_extend({}, path)
229229
root[#root + 1] = tostring(key)
230-
local value = data[key]
230+
local value = config[key]
231231
local ok, info = spec.validation(value)
232232
if not ok then
233233
local actual
@@ -246,7 +246,7 @@ function Validator:check(path, data, specs)
246246
self.errors[#self.errors + 1] = message
247247
end
248248
end
249-
for key in pairs(data) do
249+
for key in pairs(config) do
250250
local root = vim.list_extend({}, path)
251251
root[#root + 1] = tostring(key)
252252
if not specs[key] then

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.4.2'
8+
M.version = '8.4.3'
99

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

lua/render-markdown/render/base.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ local colors = require('render-markdown.core.colors')
55
---@field protected context render.md.request.Context
66
---@field protected marks render.md.Marks
77
---@field protected node render.md.Node
8-
---@field protected setup fun(self: render.md.Render): boolean
9-
---@field protected run fun(self: render.md.Render)
108
local Base = {}
119
Base.__index = Base
1210

@@ -27,6 +25,17 @@ function Base:execute(context, marks, node)
2725
end
2826
end
2927

28+
---@protected
29+
---@return boolean
30+
function Base:setup()
31+
error('unimplemented', 2)
32+
end
33+
34+
---@protected
35+
function Base:run()
36+
error('unimplemented', 2)
37+
end
38+
3039
---@protected
3140
---@return render.md.Line
3241
function Base:line()
@@ -45,7 +54,7 @@ end
4554
---@param highlight? string
4655
function Base:sign(enabled, text, highlight)
4756
local config = self.context.config.sign
48-
if not config.enabled or not enabled or not text then
57+
if not enabled or not text or not config.enabled then
4958
return
5059
end
5160
local sign_highlight = config.highlight

lua/render-markdown/render/markdown/code.lua

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function Render:offset(value, used)
5959
end
6060
local result = Env.win.percent(self.context.win, value, used)
6161
if self.node.text:find('\t') then
62-
-- rounds to the next multiple of tab
62+
-- round to the next multiple of tab
6363
local tab = Env.buf.get(self.context.buf, 'tabstop')
6464
result = math.ceil(result / tab) * tab
6565
end
@@ -73,17 +73,17 @@ function Render:run()
7373
self.marks:over(true, language, { conceal = '' })
7474

7575
local start_row = self.node.start_row
76-
local top = self.node:child('fenced_code_block_delimiter', start_row)
77-
self.marks:over(true, top, { conceal = '' })
76+
local above = self.node:child('fenced_code_block_delimiter', start_row)
77+
self.marks:over(true, above, { conceal = '' })
7878

7979
local end_row = self.node.end_row - 1
80-
local bottom = self.node:child('fenced_code_block_delimiter', end_row)
81-
self.marks:over(true, bottom, { conceal = '' })
80+
local below = self.node:child('fenced_code_block_delimiter', end_row)
81+
self.marks:over(true, below, { conceal = '' })
8282

83-
local icon = self:language(language, top)
83+
local icon = self:language(language, above)
8484
local has_more = info and language and info.end_col > language.end_col
85-
self:border(top, true, not icon and not has_more)
86-
self:border(bottom, false, true)
85+
self:border(above, self.config.above, not icon and not has_more)
86+
self:border(below, self.config.below, true)
8787

8888
local background = self:background_enabled(language)
8989
if background then
@@ -158,29 +158,31 @@ end
158158

159159
---@private
160160
---@param node? render.md.Node
161-
---@param above boolean
161+
---@param icon string
162162
---@param empty boolean
163-
function Render:border(node, above, empty)
163+
function Render:border(node, icon, empty)
164164
local kind = self.config.border
165165
local highlight = self.config.highlight_border
166-
if kind == 'none' or type(highlight) == 'boolean' or not node then
167-
-- skip
168-
elseif kind == 'thick' or not empty then
169-
self:background(node.start_row, node.start_row, highlight)
170-
elseif
171-
kind == 'hide' and self.marks:over(true, node, { conceal_lines = '' })
172-
then
173-
-- successfully added
174-
else
175-
local row, col = node.start_row, self.node.start_col
176-
local border = above and self.config.above or self.config.below
177-
local width = self.config.width == 'block' and self.data.body - col
178-
or vim.o.columns
179-
self.marks:add('code_border', row, col, {
180-
virt_text = { { border:rep(width), colors.bg_as_fg(highlight) } },
181-
virt_text_pos = 'overlay',
182-
})
166+
if not node or kind == 'none' or type(highlight) == 'boolean' then
167+
return
168+
end
169+
local row = node.start_row
170+
if kind == 'thick' or not empty then
171+
self:background(row, row, highlight)
172+
return
173+
end
174+
if kind == 'hide' then
175+
if self.marks:over(true, node, { conceal_lines = '' }) then
176+
return
177+
end
183178
end
179+
local col = self.node.start_col
180+
local block = self.config.width == 'block'
181+
local width = block and self.data.body - col or vim.o.columns
182+
self.marks:add('code_border', row, col, {
183+
virt_text = { { icon:rep(width), colors.bg_as_fg(highlight) } },
184+
virt_text_pos = 'overlay',
185+
})
184186
end
185187

186188
---@private
@@ -241,8 +243,8 @@ function Render:padding(background)
241243
return
242244
end
243245

244-
-- use lowest priority (0) to include all other marks in padding when code block is at edge
245-
-- use medium priority (1000) to include border marks while likely avoiding other plugins
246+
-- 0 | low | includes other marks in padding when code block is at edge
247+
-- 1000 | medium | includes border marks while likely avoiding other plugins
246248
local priority = col == 0 and 0 or 1000
247249
local highlight = background and self.config.highlight or nil
248250

0 commit comments

Comments
 (0)