@@ -45,7 +45,10 @@ function Render:setup()
45
45
return false
46
46
end
47
47
48
- local delim , table_rows = nil , {}
48
+ --- @type render.md.table.DelimRow ?
49
+ local delim = nil
50
+ --- @type render.md.Node[]
51
+ local table_rows = {}
49
52
self .node :for_each_child (function (row )
50
53
if row .type == ' pipe_table_delimiter_row' then
51
54
delim = self :parse_delim (row )
@@ -57,11 +60,13 @@ function Render:setup()
57
60
end
58
61
end
59
62
end )
63
+
60
64
-- Ensure delimiter and rows exist for table
61
65
if delim == nil or # table_rows == 0 then
62
66
return false
63
67
end
64
68
69
+ --- @type render.md.table.Row[]
65
70
local rows = {}
66
71
table.sort (table_rows )
67
72
for _ , table_row in ipairs (table_rows ) do
@@ -70,14 +75,16 @@ function Render:setup()
70
75
table.insert (rows , row )
71
76
end
72
77
end
73
- -- Store the max width information in the delimiter
78
+
79
+ -- Store the max width in the delimiter
74
80
for _ , row in ipairs (rows ) do
75
81
for i , column in ipairs (row .columns ) do
76
- local delim_column , width = delim . columns [ i ], column .width
82
+ local width = column .width
77
83
if self .table .cell == ' trimmed' then
78
84
local space_available = column .space .left + column .space .right - (2 * self .table .padding )
79
85
width = width - math.max (space_available , 0 )
80
86
end
87
+ local delim_column = delim .columns [i ]
81
88
delim_column .width = math.max (delim_column .width , width )
82
89
end
83
90
end
@@ -95,6 +102,7 @@ function Render:parse_delim(row)
95
102
if pipes == nil or cells == nil then
96
103
return nil
97
104
end
105
+ --- @type render.md.table.DelimColumn[]
98
106
local columns = {}
99
107
for i , cell in ipairs (cells ) do
100
108
local width = pipes [i + 1 ].start_col - pipes [i ].end_col
@@ -106,22 +114,25 @@ function Render:parse_delim(row)
106
114
elseif self .table .cell == ' trimmed' then
107
115
width = self .table .min_width
108
116
end
109
- table.insert (columns , { width = width , alignment = Render .alignment (cell ) })
117
+ --- @type render.md.table.DelimColumn
118
+ local column = { width = width , alignment = Render .alignment (cell ) }
119
+ table.insert (columns , column )
110
120
end
121
+ --- @type render.md.table.DelimRow
111
122
return { node = row , columns = columns }
112
123
end
113
124
114
125
--- @private
115
- --- @param cell render.md.Node
126
+ --- @param node render.md.Node
116
127
--- @return render.md.table.Alignment
117
- function Render .alignment (cell )
118
- local align_left = cell :child (' pipe_table_align_left' ) ~= nil
119
- local align_right = cell :child (' pipe_table_align_right' ) ~= nil
120
- if align_left and align_right then
128
+ function Render .alignment (node )
129
+ local has_left = node :child (' pipe_table_align_left' ) ~= nil
130
+ local has_right = node :child (' pipe_table_align_right' ) ~= nil
131
+ if has_left and has_right then
121
132
return ' center'
122
- elseif align_left then
133
+ elseif has_left then
123
134
return ' left'
124
- elseif align_right then
135
+ elseif has_right then
125
136
return ' right'
126
137
else
127
138
return ' default'
@@ -137,6 +148,7 @@ function Render:parse_row(row, num_columns)
137
148
if pipes == nil or cells == nil or # cells ~= num_columns then
138
149
return nil
139
150
end
151
+ --- @type render.md.table.Column[]
140
152
local columns = {}
141
153
for i , cell in ipairs (cells ) do
142
154
local start_col , end_col = pipes [i ].end_col , pipes [i + 1 ].start_col
@@ -152,14 +164,17 @@ function Render:parse_row(row, num_columns)
152
164
if width < 0 then
153
165
return nil
154
166
end
155
- table.insert (columns , {
167
+ --- @type render.md.table.Column
168
+ local column = {
156
169
row = cell .start_row ,
157
170
start_col = cell .start_col ,
158
171
end_col = cell .end_col ,
159
172
width = width ,
160
173
space = space ,
161
- })
174
+ }
175
+ table.insert (columns , column )
162
176
end
177
+ --- @type render.md.table.Row
163
178
return { node = row , pipes = pipes , columns = columns }
164
179
end
165
180
@@ -200,20 +215,20 @@ end
200
215
function Render :delimiter ()
201
216
local delim , border = self .data .delim , self .table .border
202
217
218
+ local indicator , icon = self .table .alignment_indicator , border [11 ]
203
219
local sections = Iter .list .map (delim .columns , function (column )
204
- local indicator , box = self .table .alignment_indicator , border [11 ]
205
220
-- If column is small there's no good place to put the alignment indicator
206
221
-- Alignment indicator must be exactly one character wide
207
222
-- Do not put an indicator for default alignment
208
223
if column .width < 3 or Str .width (indicator ) ~= 1 or column .alignment == ' default' then
209
- return box :rep (column .width )
224
+ return icon :rep (column .width )
210
225
end
211
226
if column .alignment == ' left' then
212
- return indicator .. box :rep (column .width - 1 )
227
+ return indicator .. icon :rep (column .width - 1 )
213
228
elseif column .alignment == ' right' then
214
- return box :rep (column .width - 1 ) .. indicator
229
+ return icon :rep (column .width - 1 ) .. indicator
215
230
else
216
- return indicator .. box :rep (column .width - 2 ) .. indicator
231
+ return indicator .. icon :rep (column .width - 2 ) .. indicator
217
232
end
218
233
end )
219
234
@@ -250,7 +265,10 @@ function Render:row(row)
250
265
for i , column in ipairs (row .columns ) do
251
266
local delim_column = delim .columns [i ]
252
267
local filler = delim_column .width - column .width
253
- if delim_column .alignment == ' center' then
268
+ if not self .context .conceal .enabled then
269
+ -- Without concealing it is impossible to do full alignment
270
+ self :shift (column , ' right' , filler )
271
+ elseif delim_column .alignment == ' center' then
254
272
local shift = math.floor ((filler + column .space .right - column .space .left ) / 2 )
255
273
self :shift (column , ' left' , shift )
256
274
self :shift (column , ' right' , filler - shift )
@@ -290,6 +308,7 @@ function Render:shift(column, side, amount)
290
308
virt_text_pos = ' inline' ,
291
309
})
292
310
elseif amount < 0 then
311
+ amount = amount - self .context .conceal .block
293
312
self .marks :add (true , column .row , col + amount , {
294
313
priority = 0 ,
295
314
end_col = col ,
0 commit comments