Skip to content

Commit 49f4597

Browse files
Breaking Change: more configurable table behavior
# Details * fat_tables option removed * table_style option added * If fat_tables option was not being set default behavior remains the same * If fat_tables option was set to false setting table_style option to 'normal' will result in the same behavior * Setting table_style to 'none' is new behavior and will stop rendering markdown tables: #21
1 parent 3811dbf commit 49f4597

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

Diff for: README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ require('render-markdown').setup({
133133
-- conceallevel used for buffer when being rendered
134134
rendered = 3,
135135
},
136-
-- Add a line above and below tables to complete look, ends up like a window
137-
fat_tables = true,
136+
-- Determines how tables are rendered
137+
-- full: adds a line above and below tables + normal behavior
138+
-- normal: renders the rows of tables
139+
-- none: disables rendering, use this if you prefer having cell highlights
140+
table_style = 'full',
138141
-- Define the highlight groups to use when rendering various components
139142
highlights = {
140143
heading = {

Diff for: doc/render-markdown.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ modified by the user.
162162
-- conceallevel used for buffer when being rendered
163163
rendered = 3,
164164
},
165-
-- Add a line above and below tables to complete look, ends up like a window
166-
fat_tables = true,
165+
-- Determines how tables are rendered
166+
-- full: adds a line above and below tables + normal behavior
167+
-- normal: renders the rows of tables
168+
-- none: disables rendering, use this if you prefer having cell highlights
169+
table_style = 'full',
167170
-- Define the highlight groups to use when rendering various components
168171
highlights = {
169172
heading = {

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

+23-21
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ M.render = function(namespace, root, buf)
9999
})
100100
end
101101
elseif capture == 'table' then
102-
if state.config.fat_tables then
102+
if state.config.table_style == 'full' then
103103
local lines = vim.api.nvim_buf_get_lines(buf, start_row, end_row, false)
104104
local table_head = list.first(lines)
105105
local table_tail = list.last(lines)
@@ -123,28 +123,30 @@ M.render = function(namespace, root, buf)
123123
end
124124
end
125125
elseif vim.tbl_contains({ 'table_head', 'table_delim', 'table_row' }, capture) then
126-
local row = value:gsub('|', '')
127-
if capture == 'table_delim' then
128-
-- Order matters here, in particular handling inner intersections before left & right
129-
row = row:gsub('-', '')
130-
:gsub(' ', '')
131-
:gsub('─│─', '─┼─')
132-
:gsub('│─', '├─')
133-
:gsub('─│', '─┤')
134-
end
126+
if vim.tbl_contains({ 'full', 'normal' }, state.config.table_style) then
127+
local row = value:gsub('|', '')
128+
if capture == 'table_delim' then
129+
-- Order matters here, in particular handling inner intersections before left & right
130+
row = row:gsub('-', '')
131+
:gsub(' ', '')
132+
:gsub('─│─', '─┼─')
133+
:gsub('│─', '├─')
134+
:gsub('─│', '─┤')
135+
end
135136

136-
local highlight = highlights.table.head
137-
if capture == 'table_row' then
138-
highlight = highlights.table.row
139-
end
137+
local highlight = highlights.table.head
138+
if capture == 'table_row' then
139+
highlight = highlights.table.row
140+
end
140141

141-
local virt_text = { row, highlight }
142-
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, start_col, {
143-
end_row = end_row,
144-
end_col = end_col,
145-
virt_text = { virt_text },
146-
virt_text_pos = 'overlay',
147-
})
142+
local virt_text = { row, highlight }
143+
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, start_col, {
144+
end_row = end_row,
145+
end_col = end_col,
146+
virt_text = { virt_text },
147+
virt_text_pos = 'overlay',
148+
})
149+
end
148150
else
149151
-- Should only get here if user provides custom capture, currently unhandled
150152
logger.error('Unhandled markdown capture: ' .. capture)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ local M = {}
4848
---@field public checkbox? render.md.UserCheckbox
4949
---@field public quote? string
5050
---@field public conceal? render.md.UserConceal
51-
---@field public fat_tables? boolean
51+
---@field public table_style? 'full'|'normal'|'none'
5252
---@field public highlights? render.md.UserHighlights
5353

5454
---@param opts? render.md.UserConfig
@@ -106,7 +106,7 @@ function M.setup(opts)
106106
default = vim.opt.conceallevel:get(),
107107
rendered = 3,
108108
},
109-
fat_tables = true,
109+
table_style = 'full',
110110
highlights = {
111111
heading = {
112112
backgrounds = { 'DiffAdd', 'DiffChange', 'DiffDelete' },

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
---@field public checkbox render.md.Checkbox
4343
---@field public quote string
4444
---@field public conceal render.md.Conceal
45-
---@field public fat_tables boolean
45+
---@field public table_style 'full'|'normal'|'none'
4646
---@field public highlights render.md.Highlights
4747

4848
---@class render.md.State

0 commit comments

Comments
 (0)