Skip to content

Commit f84eeae

Browse files
feat: table min width property
## Details Allows users to specify a minimum column width to use for padded cell style. Other minor changes: - Add a "help" issue template - Remove running luarocks packaging workflow on pull requests
1 parent ec21879 commit f84eeae

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

.github/ISSUE_TEMPLATE/help.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Help
2+
description: Advice on how to do something
3+
title: "help: "
4+
labels: [question]
5+
body:
6+
- type: textarea
7+
attributes:
8+
label: Description
9+
description: What is it you're trying to do?
10+
validations:
11+
required: true

.github/workflows/luarocks.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Luarocks
22

33
on:
4-
pull_request: # Tests packaging on PR
54
workflow_dispatch:
65
push:
76
tags:

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ require('render-markdown').setup({
425425
-- raw: replaces only the '|' characters in each row, leaving the cells unmodified
426426
-- padded: raw + cells are padded with inline extmarks to make up for any concealed text
427427
cell = 'padded',
428-
-- Gets placed in delimiter row for each column, position is based on alignmnet
429-
alignment_indicator = '',
428+
-- Minimum column width to use for padded cell
429+
min_width = 0,
430430
-- Characters used to replace table border
431431
-- Correspond to top(3), delimiter(3), bottom(3), vertical, & horizontal
432432
-- stylua: ignore
@@ -436,6 +436,8 @@ require('render-markdown').setup({
436436
'', '', '',
437437
'', '',
438438
},
439+
-- Gets placed in delimiter row for each column, position is based on alignmnet
440+
alignment_indicator = '',
439441
-- Highlight for table heading, delimiter, and the line above
440442
head = 'RenderMarkdownTableHead',
441443
-- Highlight for everything else, main table rows and the line below
@@ -818,8 +820,8 @@ require('render-markdown').setup({
818820
-- raw: replaces only the '|' characters in each row, leaving the cells unmodified
819821
-- padded: raw + cells are padded with inline extmarks to make up for any concealed text
820822
cell = 'padded',
821-
-- Gets placed in delimiter row for each column, position is based on alignmnet
822-
alignment_indicator = '',
823+
-- Minimum column width to use for padded cell
824+
min_width = 0,
823825
-- Characters used to replace table border
824826
-- Correspond to top(3), delimiter(3), bottom(3), vertical, & horizontal
825827
-- stylua: ignore
@@ -829,6 +831,8 @@ require('render-markdown').setup({
829831
'', '', '',
830832
'', '',
831833
},
834+
-- Gets placed in delimiter row for each column, position is based on alignmnet
835+
alignment_indicator = '',
832836
-- Highlight for table heading, delimiter, and the line above
833837
head = 'RenderMarkdownTableHead',
834838
-- Highlight for everything else, main table rows and the line below

doc/render-markdown.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 September 14
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 September 15
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -458,8 +458,8 @@ Full Default Configuration ~
458458
-- raw: replaces only the '|' characters in each row, leaving the cells unmodified
459459
-- padded: raw + cells are padded with inline extmarks to make up for any concealed text
460460
cell = 'padded',
461-
-- Gets placed in delimiter row for each column, position is based on alignmnet
462-
alignment_indicator = '━',
461+
-- Minimum column width to use for padded cell
462+
min_width = 0,
463463
-- Characters used to replace table border
464464
-- Correspond to top(3), delimiter(3), bottom(3), vertical, & horizontal
465465
-- stylua: ignore
@@ -469,6 +469,8 @@ Full Default Configuration ~
469469
'└', '┴', '┘',
470470
'│', '─',
471471
},
472+
-- Gets placed in delimiter row for each column, position is based on alignmnet
473+
alignment_indicator = '━',
472474
-- Highlight for table heading, delimiter, and the line above
473475
head = 'RenderMarkdownTableHead',
474476
-- Highlight for everything else, main table rows and the line below
@@ -863,8 +865,8 @@ Wiki Page
863865
-- raw: replaces only the '|' characters in each row, leaving the cells unmodified
864866
-- padded: raw + cells are padded with inline extmarks to make up for any concealed text
865867
cell = 'padded',
866-
-- Gets placed in delimiter row for each column, position is based on alignmnet
867-
alignment_indicator = '━',
868+
-- Minimum column width to use for padded cell
869+
min_width = 0,
868870
-- Characters used to replace table border
869871
-- Correspond to top(3), delimiter(3), bottom(3), vertical, & horizontal
870872
-- stylua: ignore
@@ -874,6 +876,8 @@ Wiki Page
874876
'└', '┴', '┘',
875877
'│', '─',
876878
},
879+
-- Gets placed in delimiter row for each column, position is based on alignmnet
880+
alignment_indicator = '━',
877881
-- Highlight for table heading, delimiter, and the line above
878882
head = 'RenderMarkdownTableHead',
879883
-- Highlight for everything else, main table rows and the line below

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.0.2'
7+
M.version = '7.0.3'
88

99
function M.check()
1010
M.start('version')

lua/render-markdown/init.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ local M = {}
5858
---@field public preset? render.md.table.Preset
5959
---@field public style? render.md.table.Style
6060
---@field public cell? render.md.table.Cell
61+
---@field public min_width? integer
6162
---@field public border? string[]
6263
---@field public alignment_indicator? string
6364
---@field public head? string
@@ -489,8 +490,8 @@ M.default_config = {
489490
-- raw: replaces only the '|' characters in each row, leaving the cells unmodified
490491
-- padded: raw + cells are padded with inline extmarks to make up for any concealed text
491492
cell = 'padded',
492-
-- Gets placed in delimiter row for each column, position is based on alignmnet
493-
alignment_indicator = '',
493+
-- Minimum column width to use for padded cell
494+
min_width = 0,
494495
-- Characters used to replace table border
495496
-- Correspond to top(3), delimiter(3), bottom(3), vertical, & horizontal
496497
-- stylua: ignore
@@ -500,6 +501,8 @@ M.default_config = {
500501
'', '', '',
501502
'', '',
502503
},
504+
-- Gets placed in delimiter row for each column, position is based on alignmnet
505+
alignment_indicator = '',
503506
-- Highlight for table heading, delimiter, and the line above
504507
head = 'RenderMarkdownTableHead',
505508
-- Highlight for everything else, main table rows and the line below

lua/render-markdown/render/table.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function Render:setup()
5555
local delim, table_rows = nil, {}
5656
self.info:for_each_child(function(row)
5757
if row.type == 'pipe_table_delimiter_row' then
58-
delim = Render.parse_delim(row)
58+
delim = self:parse_delim(row)
5959
elseif self.context:contains_info(row) then
6060
if vim.tbl_contains({ 'pipe_table_header', 'pipe_table_row' }, row.type) then
6161
table.insert(table_rows, row)
@@ -92,22 +92,25 @@ end
9292
---@private
9393
---@param row render.md.NodeInfo
9494
---@return render.md.table.DelimRow?
95-
function Render.parse_delim(row)
95+
function Render:parse_delim(row)
9696
local pipes, cells = Render.parse_row_data(row, 'pipe_table_delimiter_cell')
9797
if pipes == nil or cells == nil then
9898
return nil
9999
end
100+
local min_width = self.table.cell == 'padded' and self.table.min_width or 0
100101
local columns = {}
101-
for i = 1, #cells do
102-
local cell, width = cells[i], pipes[i + 1].start_col - pipes[i].end_col
102+
for i, cell in ipairs(cells) do
103+
local width = pipes[i + 1].start_col - pipes[i].end_col
103104
if width < 0 then
104105
return nil
105106
end
107+
width = math.max(width, min_width)
106108
table.insert(columns, { width = width, alignment = Render.alignment(cell) })
107109
end
108110
return { info = row, columns = columns }
109111
end
110112

113+
---@private
111114
---@param cell render.md.NodeInfo
112115
---@return render.md.table.Alignment
113116
function Render.alignment(cell)
@@ -134,8 +137,8 @@ function Render:parse_row(row, num_columns)
134137
return nil
135138
end
136139
local columns = {}
137-
for i = 1, #cells do
138-
local cell, width = cells[i], pipes[i + 1].start_col - pipes[i].end_col
140+
for i, cell in ipairs(cells) do
141+
local width = pipes[i + 1].start_col - pipes[i].end_col
139142
-- Account for double width glyphs by replacing cell spacing with width
140143
width = width - (cell.end_col - cell.start_col) + self.context:width(cell)
141144
if width < 0 then

lua/render-markdown/state.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ function M.validate()
335335
preset = one_of(pipe_table.preset, { 'none', 'round', 'double', 'heavy' }, {}, nilable),
336336
style = one_of(pipe_table.style, { 'full', 'normal', 'none' }, {}, nilable),
337337
cell = one_of(pipe_table.cell, { 'padded', 'raw', 'overlay' }, {}, nilable),
338+
min_width = { pipe_table.min_width, 'number', nilable },
338339
border = string_array(pipe_table.border, nilable),
339340
alignment_indicator = { pipe_table.alignment_indicator, 'string', nilable },
340341
head = { pipe_table.head, 'string', nilable },

lua/render-markdown/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
---@field public preset render.md.table.Preset
4444
---@field public style render.md.table.Style
4545
---@field public cell render.md.table.Cell
46+
---@field public min_width integer
4647
---@field public border string[]
4748
---@field public alignment_indicator string
4849
---@field public head string

0 commit comments

Comments
 (0)