Skip to content

Commit e0ac5a4

Browse files
not-my-profiletarleb
authored andcommitted
list-table: implement header-cols
1 parent b1d6b5e commit e0ac5a4

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

list-table/README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ the second column will be three times as wide as the first column.
120120

121121
<!-- no demo because GFM does not support inline CSS -->
122122

123-
## Header rows
123+
## Header rows & columns
124124

125125
You can configure how many rows are part of the table head
126126
with the `header-rows` attribute (which defaults to 1).
@@ -149,3 +149,40 @@ results in:
149149
</tr>
150150
</tbody>
151151
</table>
152+
153+
The same also works for `header-cols` (which however defaults to 0).
154+
For example:
155+
156+
```
157+
:::{.list-table header-cols=1}
158+
* - Name
159+
- Initial release
160+
161+
* - Markdown
162+
- 2004
163+
164+
* - reStructuredText
165+
- 2002
166+
:::
167+
```
168+
169+
results in:
170+
171+
<table>
172+
<thead>
173+
<tr>
174+
<th>Name</th>
175+
<th>Initial release</th>
176+
</tr>
177+
</thead>
178+
<tbody>
179+
<tr>
180+
<th>Markdown</th>
181+
<td>2004</td>
182+
</tr>
183+
<tr>
184+
<th>reStructuredText</th>
185+
<td>2002</td>
186+
</tr>
187+
</tbody>
188+
</table>

list-table/expected.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@
5858
</tr>
5959
</tbody>
6060
</table>
61+
<table>
62+
<thead>
63+
<tr class="header">
64+
<th>row 1, column 1</th>
65+
<th>row 1, column 2</th>
66+
</tr>
67+
</thead>
68+
<tbody>
69+
<tr class="odd">
70+
<th>row 2, column 1</th>
71+
<td>row 2, column 2</td>
72+
</tr>
73+
</tbody>
74+
</table>

list-table/list-table.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ local function new_table_head(rows)
5252
return {{}, rows}
5353
end
5454

55-
local function new_table_body(rows)
55+
local function new_table_body(rows, header_col_count)
5656
return {
5757
attr = {},
5858
body = rows,
5959
head = {},
60-
row_head_columns = 0
60+
row_head_columns = header_col_count
6161
}
6262
end
6363

@@ -107,6 +107,9 @@ local function process(div)
107107
local header_row_count = tonumber(div.attr.attributes['header-rows']) or 1
108108
div.attr.attributes['header-rows'] = nil
109109

110+
local header_col_count = tonumber(div.attr.attributes['header-cols']) or 0
111+
div.attr.attributes['header-cols'] = nil
112+
110113
local colspecs = get_colspecs(div.attr.attributes, #rows[1][2])
111114
local thead_rows = {}
112115
for i = 1, header_row_count do
@@ -118,7 +121,7 @@ local function process(div)
118121
{long = caption, short = {}},
119122
colspecs,
120123
new_table_head(thead_rows),
121-
{new_table_body(rows)},
124+
{new_table_body(rows, header_col_count)},
122125
table_foot,
123126
div.attr
124127
)

list-table/sample.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@
3333
* - row 2, column 1
3434
- row 2, column 2
3535
:::
36+
37+
:::{.list-table header-cols=1}
38+
* - row 1, column 1
39+
- row 1, column 2
40+
41+
* - row 2, column 1
42+
- row 2, column 2
43+
:::

0 commit comments

Comments
 (0)