Skip to content

Commit 96988cc

Browse files
feat: add presets for lazy & obsidian
## Details Adds the notion of presets which provide partial configurations. The order to resolve values is user configuration > preset > default configuration. There are 3 possible values: - none: does nothing - lazy: attempts to stay up to date with LazyVim distribution. If LazyVim ever uses a preset I'll need to figure something out. - obsidian: currently sets rendering to all modes using anti conceal to show current line only. Will evolve over time to look more obsidian like.
1 parent e455c4f commit 96988cc

File tree

7 files changed

+59
-4
lines changed

7 files changed

+59
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ require('render-markdown').setup({
130130
-- Milliseconds that must pass before updating marks, updates occur
131131
-- within the context of the visible window, not the entire buffer
132132
debounce = 100,
133+
-- Pre configured settings that will attempt to mimic various target
134+
-- user experiences. Any user provided settings will take precedence.
135+
-- obsidian: mimic Obsidian UI
136+
-- lazy: will attempt to stay up to date with LazyVim configuration
137+
-- none: does nothing
138+
preset = 'none',
133139
-- Capture groups that get pulled from markdown
134140
markdown_query = [[
135141
(atx_heading [

doc/render-markdown.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ Full Default Configuration ~
162162
-- Milliseconds that must pass before updating marks, updates occur
163163
-- within the context of the visible window, not the entire buffer
164164
debounce = 100,
165+
-- Pre configured settings that will attempt to mimic various target
166+
-- user experiences. Any user provided settings will take precedence.
167+
-- obsidian: mimic Obsidian UI
168+
-- lazy: will attempt to stay up to date with LazyVim configuration
169+
-- none: does nothing
170+
preset = 'none',
165171
-- Capture groups that get pulled from markdown
166172
markdown_query = [[
167173
(atx_heading [

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

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

lua/render-markdown/init.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ local M = {}
133133
---@field public win_options? table<string, render.md.UserWindowOption>
134134

135135
---@class (exact) render.md.UserConfig: render.md.UserBufferConfig
136+
---@field public preset? 'none'|'lazy'|'obsidian'
136137
---@field public markdown_query? string
137138
---@field public markdown_quote_query? string
138139
---@field public inline_query? string
@@ -154,6 +155,12 @@ M.default_config = {
154155
-- Milliseconds that must pass before updating marks, updates occur
155156
-- within the context of the visible window, not the entire buffer
156157
debounce = 100,
158+
-- Pre configured settings that will attempt to mimic various target
159+
-- user experiences. Any user provided settings will take precedence.
160+
-- obsidian: mimic Obsidian UI
161+
-- lazy: will attempt to stay up to date with LazyVim configuration
162+
-- none: does nothing
163+
preset = 'none',
157164
-- Capture groups that get pulled from markdown
158165
markdown_query = [[
159166
(atx_heading [
@@ -500,7 +507,7 @@ function M.setup(opts)
500507
-- has already been initialized by the user.
501508
local state = require('render-markdown.state')
502509
if not state.initialized() or vim.tbl_count(opts or {}) > 0 then
503-
state.setup(M.default_config, opts)
510+
state.setup(M.default_config, opts or {})
504511
state.invalidate_cache()
505512
require('render-markdown.ui').invalidate_cache()
506513
end

lua/render-markdown/presets.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---@class render.md.Presets
2+
local M = {}
3+
4+
---@param user_config render.md.UserConfig
5+
---@return render.md.UserConfig
6+
function M.get(user_config)
7+
local name = user_config.preset
8+
if name == 'obsidian' then
9+
---@type render.md.UserConfig
10+
return {
11+
render_modes = { 'n', 'v', 'i', 'c' },
12+
}
13+
elseif name == 'lazy' then
14+
---https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/markdown.lua
15+
---@type render.md.UserConfig
16+
return {
17+
file_types = { 'markdown', 'norg', 'rmd', 'org' },
18+
code = {
19+
sign = false,
20+
width = 'block',
21+
right_pad = 1,
22+
},
23+
heading = {
24+
sign = false,
25+
icons = {},
26+
},
27+
}
28+
else
29+
return {}
30+
end
31+
end
32+
33+
return M

lua/render-markdown/state.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local presets = require('render-markdown.presets')
12
local util = require('render-markdown.util')
23

34
---@type table<integer, render.md.BufferConfig>
@@ -22,9 +23,9 @@ function M.initialized()
2223
end
2324

2425
---@param default_config render.md.Config
25-
---@param user_config? render.md.UserConfig
26+
---@param user_config render.md.UserConfig
2627
function M.setup(default_config, user_config)
27-
local config = vim.tbl_deep_extend('force', default_config, user_config or {})
28+
local config = vim.tbl_deep_extend('force', default_config, presets.get(user_config), user_config)
2829
M.config = config
2930
M.enabled = config.enabled
3031
M.log_level = config.log_level
@@ -337,6 +338,7 @@ function M.validate()
337338
link = { config.link, 'table' },
338339
sign = { config.sign, 'table' },
339340
win_options = { config.win_options, 'table' },
341+
preset = one_of(config.preset, { 'none', 'lazy', 'obsidian' }, {}, false),
340342
markdown_query = { config.markdown_query, 'string' },
341343
markdown_quote_query = { config.markdown_quote_query, 'string' },
342344
inline_query = { config.inline_query, 'string' },

lua/render-markdown/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
---@field public win_options table<string, render.md.WindowOption>
123123

124124
---@class (exact) render.md.Config: render.md.BufferConfig
125+
---@field public preset 'none'|'lazy'|'obsidian'
125126
---@field public markdown_query string
126127
---@field public markdown_quote_query string
127128
---@field public inline_query string

0 commit comments

Comments
 (0)