diff --git a/lua/markview/renderer.lua b/lua/markview/renderer.lua index 5cffe69..0b8ee82 100644 --- a/lua/markview/renderer.lua +++ b/lua/markview/renderer.lua @@ -1022,10 +1022,19 @@ renderer.render_code_blocks = function (buffer, content, config_table) }); end - vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_end - 1, content.col_start + 3, { + -- The text on the final line + -- We need to get the tail section to see if it contains ``` + local block_end_line = vim.api.nvim_buf_get_lines(buffer, content.row_end - 1, content.row_end, false)[1]; + local tail_section = vim.fn.strcharpart(block_end_line or "", content.col_start); + + if tail_section:match("```$") then + tail_section = tail_section:gsub("```$", ""); + end + + vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_end - 1, vim.fn.strchars(block_end_line or ""), { virt_text_pos = config_table.position or "inline", virt_text = { - { string.rep(config_table.pad_char or " ", block_length + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) }, + { string.rep(config_table.pad_char or " ", (block_length - vim.fn.strchars(tail_section)) + ((config_table.pad_amount or 1) * 2)), set_hl(config_table.hl) }, }, hl_mode = "combine", @@ -1046,7 +1055,7 @@ renderer.render_code_blocks = function (buffer, content, config_table) } }) - local position, reduce_cols = get_str_width(text) + local position, reduce_cols = get_str_width(text); vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, content.row_start + line, position, { virt_text_pos = "inline", diff --git a/showcases/demo.md b/showcases/demo.md new file mode 100644 index 0000000..6881174 --- /dev/null +++ b/showcases/demo.md @@ -0,0 +1,45 @@ +# Makrview.nvim + +An experimental markdown previewer for Neovim. + +```lua +vim.print(require("markview").state); +``` + +## Tasks + +- [X] Stability improvements +- [ ] Rocks.nvim workflow +- [-] Wiki updates + +## Links + +[Markview.nvim](https://www.github.com/markview.nvim) +![Showcase](../img/showcase.jpg) + + +## Notifications + +>[!Important] +> Old presets are about to be removed. + +>[!Tip] +> Don't forget to check the wiki! + +>[!Warning] +> Only for Neovim `0.10.0` and higher. + +## Github Insights + +| Entry name | Entry value | +|:------------------------|:-----------------------| +| Git clones | 1008 | +| Visitors | 3801 | +| Stars | 777 | +| Lines added | 8426 | +| Lines deleted | 3158 | + + + diff --git a/showcases/hybrid_mode.md b/showcases/hybrid_mode.md new file mode 100644 index 0000000..162b5fa --- /dev/null +++ b/showcases/hybrid_mode.md @@ -0,0 +1,37 @@ +# Markview.nvim + +An experimental markdown previewer for Neovim. + +Hybrid mode: +A way to preview & edit at the same time +--- + +It is now possible to see previews as you type. + +It works for all kinds of elements such as `inline codes`, +*italic*, **bold** etc. + +It also works for block elements. + +```lua +vim.print("Hello world"); +``` + +>[!Tip] +> It can also work on nested elements. +> +> ```vim +> set scrolloff=0 +> ``` + +It even works on list items, +- Item 1 +- Item 2 + - Nested 1 + - Nested 2 + +--- + +