Skip to content

Commit fb00297

Browse files
Add fat_tables feature, adds row above and below pipe tables to complete enclosed look
1 parent 0da97c0 commit fb00297

File tree

7 files changed

+44
-1
lines changed

7 files changed

+44
-1
lines changed

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ require('render-markdown').setup({
6969
(block_quote (block_quote_marker) @quote_marker)
7070
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
7171
72+
(pipe_table) @table
7273
(pipe_table_header) @table_head
7374
(pipe_table_delimiter_row) @table_delim
7475
(pipe_table_row) @table_row
@@ -95,6 +96,8 @@ require('render-markdown').setup({
9596
-- conceallevel used for buffer when being rendered
9697
rendered = 3,
9798
},
99+
-- Add a line above and below tables to complete look, ends up like a window
100+
fat_tables = true,
98101
-- Define the highlight groups to use when rendering various components
99102
highlights = {
100103
heading = {

Diff for: demo/demo.gif

39 KB
Loading

Diff for: justfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
default_zoom := '10'
1+
default_zoom := '3'
22

33
demo zoom=default_zoom:
44
rm -f demo/demo.gif

Diff for: lua/render-markdown/init.lua

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ local M = {}
3232
---@field public bullet? string
3333
---@field public quote? string
3434
---@field public conceal? UserConceal
35+
---@field public fat_tables? boolean
3536
---@field public highlights? UserHighlights
3637

3738
---@param opts UserConfig|nil
@@ -59,6 +60,7 @@ function M.setup(opts)
5960
(block_quote (block_quote_marker) @quote_marker)
6061
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
6162
63+
(pipe_table) @table
6264
(pipe_table_header) @table_head
6365
(pipe_table_delimiter_row) @table_delim
6466
(pipe_table_row) @table_row
@@ -75,6 +77,7 @@ function M.setup(opts)
7577
default = vim.opt.conceallevel:get(),
7678
rendered = 3,
7779
},
80+
fat_tables = true,
7881
highlights = {
7982
heading = {
8083
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },

Diff for: lua/render-markdown/list.lua

+12
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ function M.clamp_last(values, index)
1414
return values[math.min(index, #values)]
1515
end
1616

17+
---@param values string[]
18+
---@return string
19+
function M.first(values)
20+
return values[1]
21+
end
22+
23+
---@param values string[]
24+
---@return string
25+
function M.last(values)
26+
return values[#values]
27+
end
28+
1729
return M

Diff for: lua/render-markdown/state.lua

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
---@field public bullet string
2828
---@field public quote string
2929
---@field public conceal Conceal
30+
---@field public fat_tables boolean
3031
---@field public highlights Highlights
3132

3233
---@class State

Diff for: lua/render-markdown/ui.lua

+24
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,30 @@ M.markdown = function(root)
8888
virt_text = { virt_text },
8989
virt_text_pos = 'overlay',
9090
})
91+
elseif capture == 'table' then
92+
if state.config.fat_tables then
93+
local lines = vim.api.nvim_buf_get_lines(0, start_row, end_row, false)
94+
local table_head = list.first(lines)
95+
local table_tail = list.last(lines)
96+
if #table_head == #table_tail then
97+
local headings = vim.split(table_head, '|', { plain = true, trimempty = true })
98+
local sections = vim.tbl_map(function(part)
99+
return string.rep('', #part)
100+
end, headings)
101+
102+
local line_above = { { '' .. table.concat(sections, '') .. '', highlights.table.head } }
103+
vim.api.nvim_buf_set_extmark(0, M.namespace, start_row, start_col, {
104+
virt_lines_above = true,
105+
virt_lines = { line_above },
106+
})
107+
108+
local line_below = { { '' .. table.concat(sections, '') .. '', highlights.table.row } }
109+
vim.api.nvim_buf_set_extmark(0, M.namespace, end_row, start_col, {
110+
virt_lines_above = true,
111+
virt_lines = { line_below },
112+
})
113+
end
114+
end
91115
elseif vim.tbl_contains({ 'table_head', 'table_delim', 'table_row' }, capture) then
92116
local row = value:gsub('|', '')
93117
if capture == 'table_delim' then

0 commit comments

Comments
 (0)