Skip to content

Commit 0d6ebe0

Browse files
Split README into different docs so main doc can be more focussed
1 parent 66645df commit 0d6ebe0

File tree

8 files changed

+212
-302
lines changed

8 files changed

+212
-302
lines changed

README.md

Lines changed: 9 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ Plugin to improve viewing Markdown files in Neovim
2626
- Support for [callouts](https://github.com/orgs/community/discussions/16925)
2727
- Support custom handlers which are ran identically to builtin handlers
2828

29-
# Limitations
30-
31-
- Text that extends beyond available space will overwrite content [#35](https://github.com/MeanderingProgrammer/markdown.nvim/issues/35)
32-
- `LaTeX` formula evaluations are placed above rather than overlayed [#6](https://github.com/MeanderingProgrammer/markdown.nvim/issues/6)
33-
3429
# Dependencies
3530

3631
- [treesitter](https://github.com/nvim-treesitter/nvim-treesitter) parsers:
@@ -251,7 +246,7 @@ require('render-markdown').setup({
251246

252247
- Function can also be accessed directly through `require('render-markdown').toggle()`
253248

254-
# For `vimwiki` Users
249+
# Note to `vimwiki` Users
255250

256251
If you use [vimwiki](https://github.com/vimwiki/vimwiki), because it overrides the
257252
`filetype` of `markdown` files there are additional setup steps.
@@ -270,127 +265,12 @@ require('render-markdown').setup({
270265
vim.treesitter.language.register('markdown', 'vimwiki')
271266
```
272267

273-
# Custom Handlers
274-
275-
Custom handlers allow users to integrate custom rendering for either unsupported
276-
languages or to override / extend the builtin implementations.
277-
278-
This can also be used to disable a builtin handler, by not specifying the `extends`
279-
field and leaving the implementation blank. Though this has little benefit and
280-
can be accomplished in other ways such as setting `{ latex_enabled = false }`
281-
for `LaTeX`.
282-
283-
Still as an example disabling the `LaTeX` handler can be done with:
284-
285-
```lua
286-
require('render-markdown').setup({
287-
custom_handlers = {
288-
latex = { render = function() end },
289-
},
290-
}
291-
```
292-
293-
Each handler must conform to the following interface:
294-
295-
```lua
296-
---@class render.md.Handler
297-
---@field public render fun(namespace: integer, root: TSNode, buf: integer)
298-
---@field public extends? boolean
299-
```
300-
301-
The `render` function parameters are:
302-
303-
- `namespace`: The id that this plugin interacts with when setting and clearing `extmark`s
304-
- `root`: The root treesitter node for the specified language
305-
- `buf`: The buffer containing the root node
306-
307-
The `extends` parameter defines whether the builtin handler should still be run in
308-
conjunction with this one. Defaults to `false`.
309-
310-
Custom handlers are ran identically to builtin ones, so by writing custom `extmark`s
311-
(see :h nvim_buf_set_extmark()) to the provided `namespace` this plugin will handle
312-
clearing the `extmark`s on mode changes as well as re-calling the `render` function
313-
when needed.
314-
315-
This is a high level interface, as such creating, parsing, and iterating through
316-
a treesitter query is entirely up to the user if the functionality they want needs
317-
this. We do not provide any convenience functions, but you are more than welcome
318-
to use patterns from the builtin handlers.
319-
320-
## More Complex Example
321-
322-
Lets say for `python` we want to highlight lines with function definitions.
323-
324-
```lua
325-
-- Parse query outside of the render function to avoid doing it for each call
326-
local query = vim.treesitter.query.parse('python', '(function_definition) @def')
327-
local function render_python(namespace, root, buf)
328-
for id, node in query:iter_captures(root, buf) do
329-
local capture = query.captures[id]
330-
local start_row, _, _, _ = node:range()
331-
if capture == 'def' then
332-
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, 0, {
333-
end_row = start_row + 1,
334-
end_col = 0,
335-
hl_group = 'DiffDelete',
336-
hl_eol = true,
337-
})
338-
end
339-
end
340-
end
341-
require('render-markdown').setup({
342-
custom_handlers = {
343-
python = { render = render_python },
344-
},
345-
}
346-
```
347-
348-
# Purpose
349-
350-
There are many existing markdown rendering plugins in the Neovim ecosystem. However,
351-
most of these rely on syncing a separate browser window with the buffer. This is
352-
the correct way to do things to get full feature support, however I wanted something
353-
that worked completely inside of Neovim and made things look slightly "nicer".
354-
355-
The closest one I found to this was [headlines.nvim](https://github.com/lukas-reineke/headlines.nvim),
356-
which is an awesome plugin that I took several ideas from. However it just didn't
357-
have quite what I was looking for. In particular I wanted something that would
358-
disappear completely when editing a file and quickly render some style when viewing
359-
the file. Hence this plugin.
360-
361-
# Markdown Ecosystem
362-
363-
There are many `markdown` plugins that specialize in different aspects of interacting
364-
with `markdown` files. This plugin specializes in rendering the buffer inside of
365-
Neovim, for instance. As a result some plugins will clash with this one, whereas
366-
other plugins handle orthogonal concerns and can be used in addition to this one.
367-
Below is a categorized (incomplete) list of available plugins.
368-
369-
## Render in Neovim
370-
371-
Using any of these plugins with this one will likely lead to undesired behavior as
372-
different functionality will clash.
373-
374-
- [headlines.nvim](https://github.com/lukas-reineke/headlines.nvim) - Same high
375-
level idea and starting point of this plugin, but with different feature sets
376-
377-
## Render in Browser
378-
379-
These can be used as a second pass to get a real preview of the `markdown` file.
380-
Since they do not interact with the buffer directly there should be no issues.
381-
382-
- [markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim)
383-
- [vim-markdown-composer](https://github.com/euclio/vim-markdown-composer)
384-
385-
## Orthogonal
386-
387-
These plugins handle functions completely separate from rendering and should also
388-
have no issues running alongside this plugin.
268+
# Additional Info
389269

390-
- Any LSP which provides standard LSP capabilities, such as:
391-
- [marksman](https://github.com/artempyanykh/marksman) - General completion,
392-
definition, and reference functionality
393-
- [markdown-oxide](https://github.com/Feel-ix-343/markdown-oxide) - Adds Obsidian
394-
PKM features to LSP
395-
- [markdown.nvim](https://github.com/tadmccorkle/markdown.nvim) - Adds `markdown`
396-
specific keybindings for interacting with `markdown` files
270+
- [Limitations](doc/limitations.md): Known limitations of this plugin
271+
- [Custom Handlers](doc/custom-handlers.md): Allow users to integrate custom rendering
272+
for either unsupported languages or to override / extend builtin implementations
273+
- [Troubleshooting Guide](doc/troubleshooting.md)
274+
- [Purpose](doc/purpose.md): Why this plugin exists
275+
- [Markdown Ecosystem](doc/markdown-ecosystem.md): Information about other `markdown`
276+
related plugins and how they co-exist

doc/custom-handlers.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Custom Handlers
2+
3+
Custom handlers allow users to integrate custom rendering for either unsupported
4+
languages or to override / extend builtin implementations.
5+
6+
Custom handlers are ran identically to builtin ones, so by writing custom `extmark`s
7+
(see :h nvim_buf_set_extmark()) to the `namespace` this plugin will handle clearing
8+
the `extmark`s on mode changes as well as re-rendering when needed.
9+
10+
## Interface
11+
12+
Each handler must conform to the following interface:
13+
14+
```lua
15+
---@class render.md.Handler
16+
---@field public render fun(namespace: integer, root: TSNode, buf: integer)
17+
---@field public extends? boolean
18+
```
19+
20+
The `render` function parameters are:
21+
22+
- `namespace`: The id that this plugin interacts with when setting and clearing `extmark`s
23+
- `root`: The root treesitter node for the specified language
24+
- `buf`: The buffer containing the root node
25+
26+
The `extends` parameter defines whether the builtin handler should still be run in
27+
conjunction with this one. Defaults to `false`.
28+
29+
This is a high level interface, as such creating, parsing, and iterating through
30+
a treesitter query is entirely up to the user if the functionality they want needs
31+
this. We do not provide any convenience functions, but you are more than welcome
32+
to use patterns from the builtin handlers.
33+
34+
## Example 1: Disable a Builtin
35+
36+
By not specifying the `extends` field and leaving the `render` implementation blank
37+
we can disable a builtin handler. Though this has little benefit and can be accomplished
38+
in other ways such as setting `{ latex_enabled = false }` for `LaTeX`.
39+
40+
Still as a toy example disabling the `LaTeX` handler can be done with:
41+
42+
```lua
43+
require('render-markdown').setup({
44+
custom_handlers = {
45+
latex = { render = function() end },
46+
},
47+
}
48+
```
49+
50+
## Example 2: Highlight `python` Function Definitions
51+
52+
This will require a treesitter query and using the range values of nodes.
53+
54+
```lua
55+
-- Parse query outside of the render function to avoid doing it for each call
56+
local query = vim.treesitter.query.parse('python', '(function_definition) @def')
57+
local function render_pyth for id, node in query:iter_captures(root, buf) do
58+
local capture = query.captures[id]
59+
local start_row, _, _, _ = node:range()
60+
if capture == 'def' then
61+
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, 0, {
62+
end_row = start_row + 1,
63+
end_col = 0,
64+
hl_group = 'DiffDelete',
65+
hl_eol = true,
66+
})
67+
end
68+
end
69+
end
70+
require('render-markdown').setup({
71+
custom_handlers = {
72+
python = { render = render_python },
73+
},
74+
}
75+
```

doc/limitations.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Limitations
2+
3+
## Text Boundaries
4+
5+
[ISSUE #35](https://github.com/MeanderingProgrammer/markdown.nvim/issues/35)
6+
7+
Text that extends beyond available space will overwrite content.
8+
9+
## `LaTeX` Formula Positioning
10+
11+
[ISSUE #6](https://github.com/MeanderingProgrammer/markdown.nvim/issues/6)
12+
13+
`LaTeX` formula evaluations are placed above text rather than overlayed.
14+
15+
## Which Key Limiting Modes
16+
17+
[ISSUE #43](https://github.com/MeanderingProgrammer/markdown.nvim/issues/43)
18+
19+
Since `which-key` interjects when writing commands it can effectively limit the
20+
number of modes available to the user.
21+
22+
This varies by configuration. An example is having the `operators` preset enabled
23+
will prevent the user from entering the operator pending mode. Since this mode cannot
24+
be reached this plugin cannot not do anything special in the operator pending state,
25+
since it effectively does not exist.
26+
27+
This is expected behavior by `which-key`: [ISSUE #534](https://github.com/folke/which-key.nvim/issues/534)
28+
29+
## Telescope Opening File
30+
31+
Since `telescope` performs several mode change operations to enable previewing and
32+
other nice things like setting `marks` when changing buffers there are scenarios
33+
where a `markdown` file will not render when it is initially opened through `telescope`.
34+
35+
An example of this is when opening a file using `live_grep` and default settings.
36+
The issue stems from `telescope` running two `normal` mode commands in the process
37+
of opening a file. At the time of writing these are:
38+
39+
- Center preview windows on the correct line: [here](https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/previewers/buffer_previewer.lua#L549)
40+
- Set a `mark` prior to opening a file: [here](https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/actions/set.lua#L177)
41+
42+
Something about the way these are done causes the file to appear be opened in `insert`
43+
mode despite being in `normal` mode. Additionally there is no `ModeChanged` event
44+
that occurs after this to go back to `normal` mode.

doc/markdown-ecosystem.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Markdown Ecosystem
2+
3+
There are many `markdown` plugins that specialize in different aspects of interacting
4+
with `markdown` files. This plugin specializes in rendering the buffer inside of
5+
Neovim, for instance. As a result some plugins will clash with this one, whereas
6+
other plugins handle orthogonal concerns and can be used in addition to this one.
7+
Below is a categorized (incomplete) list of available plugins.
8+
9+
## Render in Neovim
10+
11+
Using any of these plugins with this one will likely lead to undesired behavior as
12+
different functionality will clash.
13+
14+
- [headlines.nvim](https://github.com/lukas-reineke/headlines.nvim) - Same high
15+
level idea and starting point of this plugin, but with different feature sets
16+
17+
## Render in Browser
18+
19+
These can be used as a second pass to get a real preview of the `markdown` file.
20+
Since they do not interact with the buffer directly there should be no issues.
21+
22+
- [markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim)
23+
- [vim-markdown-composer](https://github.com/euclio/vim-markdown-composer)
24+
25+
## Orthogonal
26+
27+
These plugins handle functions completely separate from rendering and should also
28+
have no issues running alongside this plugin.
29+
30+
- Any LSP which provides standard LSP capabilities, such as:
31+
- [marksman](https://github.com/artempyanykh/marksman) - General completion,
32+
definition, and reference functionality
33+
- [markdown-oxide](https://github.com/Feel-ix-343/markdown-oxide) - Adds Obsidian
34+
PKM features to LSP
35+
- [markdown.nvim](https://github.com/tadmccorkle/markdown.nvim) - Adds `markdown`
36+
specific keybindings for interacting with `markdown` files

doc/purpose.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Purpose
2+
3+
There are many existing markdown rendering plugins in the Neovim ecosystem. However,
4+
most of these rely on syncing a separate browser window with the buffer. This is
5+
the correct way to do things to get full feature support, however I wanted something
6+
that worked completely inside of Neovim and made things look slightly "nicer".
7+
8+
The closest one I found to this was [headlines.nvim](https://github.com/lukas-reineke/headlines.nvim),
9+
which is an awesome plugin that I took several ideas from. However it just didn't
10+
have quite what I was looking for. In particular I wanted something that would
11+
disappear completely when editing a file and quickly render some style when viewing
12+
the file. Hence this plugin.

0 commit comments

Comments
 (0)