Skip to content

Commit c4eb6bf

Browse files
feat: add preset to pipe table configuration
## Details Adds a preset field to the pipe_table configuration. The only value that does something currently is 'round' which sets the border to rounded characters rather than using right angles. Will likely add more values in the future since configuring a border is currently pretty verbose. User values still take precedence. Is currently pretty naive how overall preset and pipe table preset are combined since they do not share any values. If this changes then precedence will need to be established and will need to do some tbl_deep_extend type logic.
1 parent efeaf96 commit c4eb6bf

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ require('render-markdown').setup({
399399
pipe_table = {
400400
-- Turn on / off pipe table rendering
401401
enabled = true,
402+
-- Pre configured settings largely for setting table border easier
403+
-- round: use round border characters rather than right angles
404+
-- none: does nothing
405+
preset = 'none',
402406
-- Determines how the table as a whole is rendered:
403407
-- none: disables all rendering
404408
-- normal: applies the 'cell' style rendering to each row of the table
@@ -752,6 +756,10 @@ require('render-markdown').setup({
752756
pipe_table = {
753757
-- Turn on / off pipe table rendering
754758
enabled = true,
759+
-- Pre configured settings largely for setting table border easier
760+
-- round: use round border characters rather than right angles
761+
-- none: does nothing
762+
preset = 'none',
755763
-- Determines how the table as a whole is rendered:
756764
-- none: disables all rendering
757765
-- normal: applies the 'cell' style rendering to each row of the table

Diff for: doc/render-markdown.txt

+8
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ Full Default Configuration ~
428428
pipe_table = {
429429
-- Turn on / off pipe table rendering
430430
enabled = true,
431+
-- Pre configured settings largely for setting table border easier
432+
-- round: use round border characters rather than right angles
433+
-- none: does nothing
434+
preset = 'none',
431435
-- Determines how the table as a whole is rendered:
432436
-- none: disables all rendering
433437
-- normal: applies the 'cell' style rendering to each row of the table
@@ -793,6 +797,10 @@ Wiki Page
793797
pipe_table = {
794798
-- Turn on / off pipe table rendering
795799
enabled = true,
800+
-- Pre configured settings largely for setting table border easier
801+
-- round: use round border characters rather than right angles
802+
-- none: does nothing
803+
preset = 'none',
796804
-- Determines how the table as a whole is rendered:
797805
-- none: disables all rendering
798806
-- normal: applies the 'cell' style rendering to each row of the table

Diff for: lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.0.11'
8+
M.version = '6.0.12'
99

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

Diff for: lua/render-markdown/init.lua

+6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ local M = {}
3838
---@field public highlight? string
3939
---@field public custom? table<string, render.md.UserLinkComponent>
4040

41+
---@alias render.md.table.Preset 'none'|'round'
4142
---@alias render.md.table.Style 'full'|'normal'|'none'
4243
---@alias render.md.table.Cell 'padded'|'raw'|'overlay'
4344

4445
---@class (exact) render.md.UserPipeTable
4546
---@field public enabled? boolean
47+
---@field public preset? render.md.table.Preset
4648
---@field public style? render.md.table.Style
4749
---@field public cell? render.md.table.Cell
4850
---@field public border? string[]
@@ -423,6 +425,10 @@ M.default_config = {
423425
pipe_table = {
424426
-- Turn on / off pipe table rendering
425427
enabled = true,
428+
-- Pre configured settings largely for setting table border easier
429+
-- round: use round border characters rather than right angles
430+
-- none: does nothing
431+
preset = 'none',
426432
-- Determines how the table as a whole is rendered:
427433
-- none: disables all rendering
428434
-- normal: applies the 'cell' style rendering to each row of the table

Diff for: lua/render-markdown/presets.lua

+29-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ local M = {}
44
---@param user_config render.md.UserConfig
55
---@return render.md.UserConfig
66
function M.get(user_config)
7-
local name = user_config.preset
7+
local config = M.config_preset(user_config.preset)
8+
config.pipe_table = M.pipe_table_preset((user_config.pipe_table or {}).preset)
9+
return config
10+
end
11+
12+
---@private
13+
---@param name? render.md.config.Preset
14+
---@return render.md.UserConfig
15+
function M.config_preset(name)
816
if name == 'obsidian' then
917
---@type render.md.UserConfig
1018
return {
@@ -30,4 +38,24 @@ function M.get(user_config)
3038
end
3139
end
3240

41+
---@private
42+
---@param name? render.md.table.Preset
43+
---@return render.md.UserPipeTable
44+
function M.pipe_table_preset(name)
45+
if name == 'round' then
46+
---@type render.md.UserPipeTable
47+
return {
48+
-- stylua: ignore
49+
border = {
50+
'', '', '',
51+
'', '', '',
52+
'', '', '',
53+
'', '',
54+
},
55+
}
56+
else
57+
return {}
58+
end
59+
end
60+
3361
return M

Diff for: lua/render-markdown/state.lua

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ function M.validate()
300300
if pipe_table ~= nil then
301301
append_errors(path .. '.pipe_table', pipe_table, {
302302
enabled = { pipe_table.enabled, 'boolean', nilable },
303+
preset = one_of(pipe_table.preset, { 'none', 'round' }, {}, nilable),
303304
style = one_of(pipe_table.style, { 'full', 'normal', 'none' }, {}, nilable),
304305
cell = one_of(pipe_table.cell, { 'padded', 'raw', 'overlay' }, {}, nilable),
305306
border = string_array(pipe_table.border, nilable),

Diff for: lua/render-markdown/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
---@class (exact) render.md.PipeTable
3131
---@field public enabled boolean
32+
---@field public preset render.md.table.Preset
3233
---@field public style render.md.table.Style
3334
---@field public cell render.md.table.Cell
3435
---@field public border string[]

0 commit comments

Comments
 (0)