Skip to content

Commit b1d6b5e

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

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

list-table/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,33 @@ For example when we change the first line of the previous example to:
119119
the second column will be three times as wide as the first column.
120120

121121
<!-- no demo because GFM does not support inline CSS -->
122+
123+
## Header rows
124+
125+
You can configure how many rows are part of the table head
126+
with the `header-rows` attribute (which defaults to 1).
127+
128+
```
129+
:::{.list-table header-rows=0}
130+
* - row 1, column 1
131+
- row 1, column 2
132+
133+
* - row 2, column 1
134+
- row 2, column 2
135+
:::
136+
```
137+
138+
results in:
139+
140+
<table>
141+
<tbody>
142+
<tr>
143+
<td>row 1, column 1</td>
144+
<td>row 1, column 2</td>
145+
</tr>
146+
<tr>
147+
<td>row 2, column 1</td>
148+
<td>row 2, column 2</td>
149+
</tr>
150+
</tbody>
151+
</table>

list-table/expected.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@
4646
</tr>
4747
</tbody>
4848
</table>
49+
<table>
50+
<tbody>
51+
<tr class="odd">
52+
<td>row 1, column 1</td>
53+
<td>row 1, column 2</td>
54+
</tr>
55+
<tr class="even">
56+
<td>row 2, column 1</td>
57+
<td>row 2, column 2</td>
58+
</tr>
59+
</tbody>
60+
</table>

list-table/list-table.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ local function process(div)
104104
table.insert(rows, row)
105105
end
106106

107+
local header_row_count = tonumber(div.attr.attributes['header-rows']) or 1
108+
div.attr.attributes['header-rows'] = nil
109+
107110
local colspecs = get_colspecs(div.attr.attributes, #rows[1][2])
108-
local thead_rows = {table.remove(rows, 1)}
111+
local thead_rows = {}
112+
for i = 1, header_row_count do
113+
table.insert(thead_rows, table.remove(rows, 1))
114+
end
109115

110116
local table_foot = {{}, {}};
111117
return pandoc.Table(

list-table/sample.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@
2626
- row 3, column 2
2727
:::
2828

29+
:::{.list-table header-rows=0}
30+
* - row 1, column 1
31+
- row 1, column 2
32+
33+
* - row 2, column 1
34+
- row 2, column 2
35+
:::

0 commit comments

Comments
 (0)