Skip to content

Commit 57c7f33

Browse files
feat: configurable indent for first line of paragraph
## Details Request: #417 Add `paragraph.indent` configuration option. Functions similarly to `paragraph.left_margin` but only applies to the first row of each paragraph, mimicking the behavior of most word processors. By default set to 0, resulting in no visible change out of the box. Since we only query for paragraphs directly under sections this should avoid any edge cases with paragraphs under list items and other ways paragraphs get nested. Other changes: - Add `indent` module for computing line / size / level, create in `base` rather than containing all the logic directly. - Make the separation between `core` and `lib` meaningful. Anything that gets `setup` from state or initialized through plugin directory goes in `core`. All other modules go in `lib`: - colors : root -> core - command : root -> core - manager : root -> core - config : root -> lib - presets : root -> lib - buffer : core -> lib - context : core -> lib - conceal : core -> lib - extmark : core -> lib - range : core -> lib - ts : integ -> core - icons : integ -> lib - As a result the only remaining modules at the root are: - api : in case user requires it - health : convention - init : convention - state : LazyVim requires it - types : best location, can move at any time - Aliases types that get resolved to a concrete value at runtime like heading icons now get generic names like `String` or `Integer`, no more field specific names like `Icons`. - `config/custom_handlers.lua` -> `config/handlers.lua` - add an alias for `string|string[]` in the context of highlights - `render.md.callback` -> `render.md.on` - remove `indent` field from code render data, compute where needed - remove all `require` statements from top of `api` module - update CHANGELOG
1 parent 8c33733 commit 57c7f33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+346
-294
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
- set quote highlights for 6 levels of nesting [7051859](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/70518594a4bf1a35d4e331677dd86bc065e599a4)
1717
[cyberdream](https://github.com/scottmckendry/cyberdream.nvim/pull/182)
1818
- use conceal lines for setext heading underline [78ffe3b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/78ffe3b0500bbc7e37fabde723d96661538e8b32)
19+
- improve debug command [40fff90](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/40fff90caccb4a1c902681f0440806ee9ae95d0b)
20+
- use selene to prevent accidental print statements [7f81e9d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7f81e9dcc15504c044f20df39d28a590cd5c6ca5)
1921

2022
### Bug Fixes
2123

2224
- more robust icon provider resolution [#403](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/403)
2325
[dfffdd2](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/dfffdd221570d36ac80d1a599643140a319a36de)
2426
- disable line wrapping in LSP hover docs in some cases [#408](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/408)
2527
[080104e](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/080104e4dce26819efb4f4c83d1b7b2d82b96f7c)
28+
- handle spaces before atx headings [bd56575](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/bd5657594bf1a96b04f900c87e8d74226a54d832)
29+
- remove accidental vim.print [bff12b4](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/bff12b4655d1537cf0f10859fcd63ef2cec65010)
2630

2731
### Collaborator Shoutouts
2832

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ require('render-markdown').setup({
404404
-- | function | `value(context)` |
405405
-- | number | `value` |
406406
left_margin = 0,
407+
-- Amount of padding to add to the first line of each paragraph.
408+
-- Output is evaluated using the same logic as 'left_margin'.
409+
indent = 0,
407410
-- Minimum width to use for paragraphs.
408411
min_width = 0,
409412
},
@@ -992,6 +995,9 @@ require('render-markdown').setup({
992995
-- | function | `value(context)` |
993996
-- | number | `value` |
994997
left_margin = 0,
998+
-- Amount of padding to add to the first line of each paragraph.
999+
-- Output is evaluated using the same logic as 'left_margin'.
1000+
indent = 0,
9951001
-- Minimum width to use for paragraphs.
9961002
min_width = 0,
9971003
},

doc/custom-handlers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Each handler must conform to the following interface:
3636

3737
---@class (exact) render.md.mark.Text
3838
---@field [1] string text
39-
---@field [2] string|string[] highlights
39+
---@field [2] render.md.mark.Hl highlight
40+
41+
---@alias render.md.mark.Hl string|string[]
4042
```
4143

4244
The `parse` function takes a `ctx` parameter whose fields are:

doc/render-markdown.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.1 Last change: 2025 April 30
1+
*render-markdown.txt* For NVIM v0.11.1 Last change: 2025 May 02
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -469,6 +469,9 @@ Default Configuration ~
469469
-- | function | `value(context)` |
470470
-- | number | `value` |
471471
left_margin = 0,
472+
-- Amount of padding to add to the first line of each paragraph.
473+
-- Output is evaluated using the same logic as 'left_margin'.
474+
indent = 0,
472475
-- Minimum width to use for paragraphs.
473476
min_width = 0,
474477
},
@@ -1053,6 +1056,9 @@ Paragraph Configuration ~
10531056
-- | function | `value(context)` |
10541057
-- | number | `value` |
10551058
left_margin = 0,
1059+
-- Amount of padding to add to the first line of each paragraph.
1060+
-- Output is evaluated using the same logic as 'left_margin'.
1061+
indent = 0,
10561062
-- Minimum width to use for paragraphs.
10571063
min_width = 0,
10581064
},

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
init := "tests/minimal_init.lua"
22
settings := "{ minimal_init = " + quote(init) + ", sequential = true, keep_going = false }"
33

4-
default: update check test health
4+
default: update check test bench health
55

66
update:
77
# keep documentation in sync with code

lua/render-markdown/api.lua

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
1-
local manager = require('render-markdown.manager')
2-
local state = require('render-markdown.state')
3-
41
---@class render.md.Api
52
local M = {}
63

74
function M.enable()
8-
manager.set_all(true)
5+
require('render-markdown.core.manager').set_all(true)
96
end
107

118
function M.buf_enable()
12-
manager.set_current(true)
9+
require('render-markdown.core.manager').set_current(true)
1310
end
1411

1512
function M.disable()
16-
manager.set_all(false)
13+
require('render-markdown.core.manager').set_all(false)
1714
end
1815

1916
function M.buf_disable()
20-
manager.set_current(false)
17+
require('render-markdown.core.manager').set_current(false)
2118
end
2219

2320
function M.toggle()
24-
manager.set_all()
21+
require('render-markdown.core.manager').set_all()
2522
end
2623

2724
function M.buf_toggle()
28-
manager.set_current()
25+
require('render-markdown.core.manager').set_current()
2926
end
3027

3128
function M.log()
3229
require('render-markdown.core.log').open()
3330
end
3431

3532
function M.expand()
36-
state.modify_anti_conceal(1)
33+
require('render-markdown.state').modify_anti_conceal(1)
3734
M.enable()
3835
end
3936

4037
function M.contract()
41-
state.modify_anti_conceal(-1)
38+
require('render-markdown.state').modify_anti_conceal(-1)
4239
M.enable()
4340
end
4441

@@ -47,7 +44,7 @@ function M.debug()
4744
end
4845

4946
function M.config()
50-
local difference = state.difference()
47+
local difference = require('render-markdown.state').difference()
5148
if not difference then
5249
-- selene: allow(deprecated)
5350
vim.print('default configuration')

lua/render-markdown/config/anti_conceal.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local Element = {
2525
sign = 'sign',
2626
}
2727

28-
---@class render.md.anti.conceal
28+
---@class render.md.anti.conceal.Cfg
2929
local M = {}
3030

3131
---@type render.md.anti.conceal.Config

lua/render-markdown/config/base.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
---@alias render.md.Modes boolean|string[]
66

7-
---@class render.md.base
7+
---@class render.md.base.Cfg
88
local M = {}
99

1010
---@enum render.md.base.Width

lua/render-markdown/config/bullet.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---@class (exact) render.md.bullet.Config: render.md.base.Config
2-
---@field icons render.md.bullet.Text
3-
---@field ordered_icons render.md.bullet.Text
4-
---@field left_pad render.md.bullet.Int
5-
---@field right_pad render.md.bullet.Int
6-
---@field highlight render.md.bullet.Text
7-
---@field scope_highlight render.md.bullet.Text
2+
---@field icons render.md.bullet.String
3+
---@field ordered_icons render.md.bullet.String
4+
---@field left_pad render.md.bullet.Integer
5+
---@field right_pad render.md.bullet.Integer
6+
---@field highlight render.md.bullet.String
7+
---@field scope_highlight render.md.bullet.String
88

99
---@class (exact) render.md.bullet.Context
1010
---@field level integer
1111
---@field index integer
1212
---@field value string
1313

14-
---@alias render.md.bullet.Text
14+
---@alias render.md.bullet.String
1515
---| string
1616
---| string[]
1717
---| string[][]
1818
---| fun(ctx: render.md.bullet.Context): string?
1919

20-
---@alias render.md.bullet.Int
20+
---@alias render.md.bullet.Integer
2121
---| integer
2222
---| fun(ctx: render.md.bullet.Context): integer
2323

24-
---@class render.md.bullet
24+
---@class render.md.bullet.Cfg
2525
local M = {}
2626

2727
---@type render.md.bullet.Config

lua/render-markdown/config/callout.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
---@field quote_icon? string
66
---@field category? string
77

8-
---@class render.md.callout
8+
---@class render.md.callout.Cfg
99
local M = {}
1010

1111
-- stylua: ignore

lua/render-markdown/config/checkbox.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
---@field highlight string
1616
---@field scope_highlight? string
1717

18-
---@class render.md.checkbox
18+
---@class render.md.checkbox.Cfg
1919
local M = {}
2020

2121
---@type render.md.checkbox.Config

lua/render-markdown/config/code.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local Border = {
4545
none = 'none',
4646
}
4747

48-
---@class render.md.code
48+
---@class render.md.code.Cfg
4949
local M = {}
5050

5151
---@type render.md.code.Config

lua/render-markdown/config/completions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
---@field callout fun(value: render.md.callout.Config): boolean
1212
---@field checkbox fun(value: render.md.checkbox.custom.Config): boolean
1313

14-
---@class render.md.completions
14+
---@class render.md.completions.Cfg
1515
local M = {}
1616

1717
---@type render.md.completions.Config

lua/render-markdown/config/dash.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
---@alias render.md.dash.Width 'full'|number
88

9-
---@class render.md.dash
9+
---@class render.md.dash.Cfg
1010
local M = {}
1111

1212
---@type render.md.dash.Config

lua/render-markdown/config/document.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
---@field char_patterns string[]
66
---@field line_patterns string[]
77

8-
---@class render.md.document
8+
---@class render.md.document.Cfg
99
local M = {}
1010

1111
---@type render.md.document.Config

lua/render-markdown/config/custom_handlers.lua renamed to lua/render-markdown/config/handlers.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
---@class render.md.custom.handlers
1+
---@class (exact) render.md.Handler
2+
---@field extends? boolean
3+
---@field parse fun(ctx: render.md.handler.Context): render.md.Mark[]
4+
5+
---@class (exact) render.md.handler.Context
6+
---@field buf integer
7+
---@field root TSNode
8+
9+
---@class render.md.handlers.Cfg
210
local M = {}
311

412
---@type table<string, render.md.Handler>

lua/render-markdown/config/heading.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---@field atx boolean
33
---@field setext boolean
44
---@field sign boolean
5-
---@field icons render.md.heading.Icons
5+
---@field icons render.md.heading.String
66
---@field position render.md.heading.Position
77
---@field signs string[]
88
---@field width render.md.base.Width|(render.md.base.Width)[]
@@ -23,7 +23,7 @@
2323
---@field level integer
2424
---@field sections integer[]
2525

26-
---@alias render.md.heading.Icons
26+
---@alias render.md.heading.String
2727
---| string[]
2828
---| fun(ctx: render.md.heading.Context): string?
2929

@@ -40,7 +40,7 @@ local Position = {
4040
---@field background? string
4141
---@field foreground? string
4242

43-
---@class render.md.heading
43+
---@class render.md.heading.Cfg
4444
local M = {}
4545

4646
---@type render.md.heading.Config

lua/render-markdown/config/html.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
---@field icon string
1212
---@field highlight string
1313

14-
---@class render.md.html
14+
---@class render.md.html.Cfg
1515
local M = {}
1616

1717
---@type render.md.html.Config

lua/render-markdown/config/indent.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
---@field icon string
66
---@field highlight string
77

8-
---@class render.md.indent
8+
---@class render.md.indent.Cfg
99
local M = {}
1010

1111
---@type render.md.indent.Config

lua/render-markdown/config/injections.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---@field enabled boolean
33
---@field query string
44

5-
---@class render.md.injection
5+
---@class render.md.injection.Cfg
66
local M = {}
77

88
---@type table<string, render.md.injection.Config>

lua/render-markdown/config/inline_highlight.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@class (exact) render.md.inline.highlight.Config: render.md.base.Config
22
---@field highlight string
33

4-
---@class render.md.inline.highlight
4+
---@class render.md.inline.highlight.Cfg
55
local M = {}
66

77
---@type render.md.inline.highlight.Config

lua/render-markdown/config/latex.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local Position = {
1111
below = 'below',
1212
}
1313

14-
---@class render.md.latex
14+
---@class render.md.latex.Cfg
1515
local M = {}
1616

1717
---@type render.md.latex.Config

lua/render-markdown/config/link.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local Kind = {
3939
suffix = 'suffix',
4040
}
4141

42-
---@class render.md.link
42+
---@class render.md.link.Cfg
4343
local M = {}
4444

4545
---@type render.md.link.Config

lua/render-markdown/config/on.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
---@class (exact) render.md.callback.Config
2-
---@field attach fun(ctx: render.md.callback.attach.Context)
3-
---@field initial fun(ctx: render.md.callback.render.Context)
4-
---@field render fun(ctx: render.md.callback.render.Context)
5-
---@field clear fun(ctx: render.md.callback.render.Context)
1+
---@class (exact) render.md.on.Config
2+
---@field attach fun(ctx: render.md.on.attach.Context)
3+
---@field initial fun(ctx: render.md.on.render.Context)
4+
---@field render fun(ctx: render.md.on.render.Context)
5+
---@field clear fun(ctx: render.md.on.render.Context)
66

7-
---@class (exact) render.md.callback.attach.Context
7+
---@class (exact) render.md.on.attach.Context
88
---@field buf integer
99

10-
---@class (exact) render.md.callback.render.Context
10+
---@class (exact) render.md.on.render.Context
1111
---@field buf integer
1212
---@field win integer
1313

14-
---@class render.md.callback
14+
---@class render.md.on.Cfg
1515
local M = {}
1616

17-
---@type render.md.callback.Config
17+
---@type render.md.on.Config
1818
M.default = {
1919
-- Called when plugin initially attaches to a buffer.
2020
attach = function() end,

0 commit comments

Comments
 (0)