Skip to content

Commit d9562fb

Browse files
not-my-profiletarleb
authored andcommitted
list-table: support individual cell alignment
1 parent 9fbe267 commit d9562fb

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

list-table/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,8 @@ results in:
230230
</tr>
231231
</tbody>
232232
</table>
233+
234+
Individual cell alignment is also supported via the `align` attribute.
235+
Expected values are `l`, `r`, `c` for left, right and center respectively.
236+
(Please mind that contrary to [column alignments](#column-alignments)
237+
this attribute is singular).

list-table/expected.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
</tr>
8888
<tr class="even">
8989
<td>reStructuredText</td>
90-
<td><code>``code``</code></td>
90+
<td style="text-align: center;"> <code>``code``</code></td>
9191
</tr>
9292
</tbody>
9393
</table>

list-table/list-table.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ else
77
error("pandoc version >=2.11 is required")
88
end
99

10+
local alignments = {
11+
d = 'AlignDefault',
12+
l = 'AlignLeft',
13+
r = 'AlignRight',
14+
c = 'AlignCenter'
15+
}
16+
1017
local function get_colspecs(div_attributes, column_count)
1118
-- list of (align, width) pairs
1219
local colspecs = {}
@@ -16,12 +23,6 @@ local function get_colspecs(div_attributes, column_count)
1623
end
1724

1825
if div_attributes.aligns then
19-
local alignments = {
20-
d = 'AlignDefault',
21-
l = 'AlignLeft',
22-
r = 'AlignRight',
23-
c = 'AlignCenter'
24-
}
2526
local i = 1
2627
for a in div_attributes.aligns:gmatch('[^,]') do
2728
assert(alignments[a] ~= nil,
@@ -82,6 +83,8 @@ local function new_cell(contents)
8283
attr.attributes.colspan = nil
8384
rowspan = attr.attributes.rowspan or 1
8485
attr.attributes.rowspan = nil
86+
align = alignments[attr.attributes.align] or pandoc.AlignDefault
87+
attr.attributes.align = nil
8588
end
8689
end
8790
end

list-table/sample.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
- `` `code` ``
5353

5454
* - reStructuredText
55-
- ` ``code`` `
55+
- []{align=c} ` ``code`` `
5656
:::

0 commit comments

Comments
 (0)