forked from MeanderingProgrammer/render-markdown.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split README into different docs so main doc can be more focussed
- Loading branch information
1 parent
66645df
commit 0d6ebe0
Showing
8 changed files
with
212 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Custom Handlers | ||
|
||
Custom handlers allow users to integrate custom rendering for either unsupported | ||
languages or to override / extend builtin implementations. | ||
|
||
Custom handlers are ran identically to builtin ones, so by writing custom `extmark`s | ||
(see :h nvim_buf_set_extmark()) to the `namespace` this plugin will handle clearing | ||
the `extmark`s on mode changes as well as re-rendering when needed. | ||
|
||
## Interface | ||
|
||
Each handler must conform to the following interface: | ||
|
||
```lua | ||
---@class render.md.Handler | ||
---@field public render fun(namespace: integer, root: TSNode, buf: integer) | ||
---@field public extends? boolean | ||
``` | ||
|
||
The `render` function parameters are: | ||
|
||
- `namespace`: The id that this plugin interacts with when setting and clearing `extmark`s | ||
- `root`: The root treesitter node for the specified language | ||
- `buf`: The buffer containing the root node | ||
|
||
The `extends` parameter defines whether the builtin handler should still be run in | ||
conjunction with this one. Defaults to `false`. | ||
|
||
This is a high level interface, as such creating, parsing, and iterating through | ||
a treesitter query is entirely up to the user if the functionality they want needs | ||
this. We do not provide any convenience functions, but you are more than welcome | ||
to use patterns from the builtin handlers. | ||
|
||
## Example 1: Disable a Builtin | ||
|
||
By not specifying the `extends` field and leaving the `render` implementation blank | ||
we can disable a builtin handler. Though this has little benefit and can be accomplished | ||
in other ways such as setting `{ latex_enabled = false }` for `LaTeX`. | ||
|
||
Still as a toy example disabling the `LaTeX` handler can be done with: | ||
|
||
```lua | ||
require('render-markdown').setup({ | ||
custom_handlers = { | ||
latex = { render = function() end }, | ||
}, | ||
} | ||
``` | ||
|
||
## Example 2: Highlight `python` Function Definitions | ||
|
||
This will require a treesitter query and using the range values of nodes. | ||
|
||
```lua | ||
-- Parse query outside of the render function to avoid doing it for each call | ||
local query = vim.treesitter.query.parse('python', '(function_definition) @def') | ||
local function render_pyth for id, node in query:iter_captures(root, buf) do | ||
local capture = query.captures[id] | ||
local start_row, _, _, _ = node:range() | ||
if capture == 'def' then | ||
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, 0, { | ||
end_row = start_row + 1, | ||
end_col = 0, | ||
hl_group = 'DiffDelete', | ||
hl_eol = true, | ||
}) | ||
end | ||
end | ||
end | ||
require('render-markdown').setup({ | ||
custom_handlers = { | ||
python = { render = render_python }, | ||
}, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Limitations | ||
|
||
## Text Boundaries | ||
|
||
[ISSUE #35](https://github.com/MeanderingProgrammer/markdown.nvim/issues/35) | ||
|
||
Text that extends beyond available space will overwrite content. | ||
|
||
## `LaTeX` Formula Positioning | ||
|
||
[ISSUE #6](https://github.com/MeanderingProgrammer/markdown.nvim/issues/6) | ||
|
||
`LaTeX` formula evaluations are placed above text rather than overlayed. | ||
|
||
## Which Key Limiting Modes | ||
|
||
[ISSUE #43](https://github.com/MeanderingProgrammer/markdown.nvim/issues/43) | ||
|
||
Since `which-key` interjects when writing commands it can effectively limit the | ||
number of modes available to the user. | ||
|
||
This varies by configuration. An example is having the `operators` preset enabled | ||
will prevent the user from entering the operator pending mode. Since this mode cannot | ||
be reached this plugin cannot not do anything special in the operator pending state, | ||
since it effectively does not exist. | ||
|
||
This is expected behavior by `which-key`: [ISSUE #534](https://github.com/folke/which-key.nvim/issues/534) | ||
|
||
## Telescope Opening File | ||
|
||
Since `telescope` performs several mode change operations to enable previewing and | ||
other nice things like setting `marks` when changing buffers there are scenarios | ||
where a `markdown` file will not render when it is initially opened through `telescope`. | ||
|
||
An example of this is when opening a file using `live_grep` and default settings. | ||
The issue stems from `telescope` running two `normal` mode commands in the process | ||
of opening a file. At the time of writing these are: | ||
|
||
- Center preview windows on the correct line: [here](https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/previewers/buffer_previewer.lua#L549) | ||
- Set a `mark` prior to opening a file: [here](https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/actions/set.lua#L177) | ||
|
||
Something about the way these are done causes the file to appear be opened in `insert` | ||
mode despite being in `normal` mode. Additionally there is no `ModeChanged` event | ||
that occurs after this to go back to `normal` mode. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Markdown Ecosystem | ||
|
||
There are many `markdown` plugins that specialize in different aspects of interacting | ||
with `markdown` files. This plugin specializes in rendering the buffer inside of | ||
Neovim, for instance. As a result some plugins will clash with this one, whereas | ||
other plugins handle orthogonal concerns and can be used in addition to this one. | ||
Below is a categorized (incomplete) list of available plugins. | ||
|
||
## Render in Neovim | ||
|
||
Using any of these plugins with this one will likely lead to undesired behavior as | ||
different functionality will clash. | ||
|
||
- [headlines.nvim](https://github.com/lukas-reineke/headlines.nvim) - Same high | ||
level idea and starting point of this plugin, but with different feature sets | ||
|
||
## Render in Browser | ||
|
||
These can be used as a second pass to get a real preview of the `markdown` file. | ||
Since they do not interact with the buffer directly there should be no issues. | ||
|
||
- [markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim) | ||
- [vim-markdown-composer](https://github.com/euclio/vim-markdown-composer) | ||
|
||
## Orthogonal | ||
|
||
These plugins handle functions completely separate from rendering and should also | ||
have no issues running alongside this plugin. | ||
|
||
- Any LSP which provides standard LSP capabilities, such as: | ||
- [marksman](https://github.com/artempyanykh/marksman) - General completion, | ||
definition, and reference functionality | ||
- [markdown-oxide](https://github.com/Feel-ix-343/markdown-oxide) - Adds Obsidian | ||
PKM features to LSP | ||
- [markdown.nvim](https://github.com/tadmccorkle/markdown.nvim) - Adds `markdown` | ||
specific keybindings for interacting with `markdown` files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Purpose | ||
|
||
There are many existing markdown rendering plugins in the Neovim ecosystem. However, | ||
most of these rely on syncing a separate browser window with the buffer. This is | ||
the correct way to do things to get full feature support, however I wanted something | ||
that worked completely inside of Neovim and made things look slightly "nicer". | ||
|
||
The closest one I found to this was [headlines.nvim](https://github.com/lukas-reineke/headlines.nvim), | ||
which is an awesome plugin that I took several ideas from. However it just didn't | ||
have quite what I was looking for. In particular I wanted something that would | ||
disappear completely when editing a file and quickly render some style when viewing | ||
the file. Hence this plugin. |
Oops, something went wrong.