Skip to content

Commit

Permalink
fix(renderer): Fixed a bug causing the last line to have border place…
Browse files Browse the repository at this point in the history
…d on the wrong column

Added some validation to check for these types of lines(also checks the
trailing characters).
  • Loading branch information
OXY2DEV committed Aug 4, 2024
1 parent 777c6aa commit e102b06
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lua/markview/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
45 changes: 45 additions & 0 deletions showcases/demo.md
Original file line number Diff line number Diff line change
@@ -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)
<[email protected]>

## 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 |


<!--
vim:nospell
-->
37 changes: 37 additions & 0 deletions showcases/hybrid_mode.md
Original file line number Diff line number Diff line change
@@ -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
---
<!---
vim:nospell:tw=78:siso=0:cmdheight=0:
-->

0 comments on commit e102b06

Please sign in to comment.