From 28c70aa40554963cb79de80286f956edc3181bff Mon Sep 17 00:00:00 2001 From: Shawon Date: Sun, 25 Aug 2024 11:35:11 +0600 Subject: [PATCH] fix: Plugin now recognizes escaped columns The plugin now accueately shows tables who have `\|` in them. Fixes visual bug when rendering `noice.nvim`'s README. --- lua/markview/parser.lua | 13 +++++++++---- lua/markview/renderer.lua | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/markview/parser.lua b/lua/markview/parser.lua index 1f88b49..ab8a7d8 100644 --- a/lua/markview/parser.lua +++ b/lua/markview/parser.lua @@ -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 diff --git a/lua/markview/renderer.lua b/lua/markview/renderer.lua index 95ef7a1..5f51f20 100644 --- a/lua/markview/renderer.lua +++ b/lua/markview/renderer.lua @@ -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