Skip to content

Commit

Permalink
fix: Plugin now recognizes escaped columns
Browse files Browse the repository at this point in the history
The plugin now accueately shows tables who have `\|` in them. Fixes
visual bug when rendering `noice.nvim`'s README.
  • Loading branch information
OXY2DEV committed Aug 25, 2024
1 parent 1193286 commit 28c70aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lua/markview/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,20 @@ parser.md = function (buffer, TStree, from, to)
table.insert(table_structure, "unknown");
end

for col in vim.treesitter.get_node_text(row, buffer):gmatch("%s*|([^|\n]*)") do
if col ~= "" then
local t_col = nil;

for col in vim.treesitter.get_node_text(row, buffer):gmatch("|([^|\n]*)") do
if col:match("\\$") then
t_col = col .. "|";
elseif col ~= "" then
table.insert(tmp, "|")
table.insert(tmp, col)
table.insert(tmp, (t_col or "") .. col)

t_col = nil;
end
end

table.insert(tmp, "|")

table.insert(rows, tmp)
end

Expand Down
2 changes: 1 addition & 1 deletion lua/markview/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ local table_header = function (buffer, content, config_table)
vim.api.nvim_buf_set_extmark(buffer, renderer.namespace, row_start, col_start + curr_col + #col, {
virt_text_pos = "inline",
virt_text = {
{ string.rep("X", (actual_width - width)) }
{ string.rep(" ", (actual_width - width)) }
}
});
elseif align == "right" then
Expand Down

0 comments on commit 28c70aa

Please sign in to comment.