Skip to content

Commit 1f42551

Browse files
committed
add list-table syntax compatible with fenced-div floats
1 parent 581057a commit 1f42551

File tree

2 files changed

+105
-6
lines changed

2 files changed

+105
-6
lines changed

src/resources/filters/modules/listtable.lua

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,40 @@ local function new_cell(contents)
120120
end
121121

122122
local function process(div)
123-
if (div.attr.classes[1] ~= "list-table" and
124-
div.attr.classes[1] ~= "list-table-body") then return nil end
125-
local class = div.attr.classes[1]
126-
table.remove(div.attr.classes, 1)
127-
123+
local class
124+
local target_classes = {"list-table", "list-table-body"}
125+
for _, target in ipairs(target_classes) do
126+
if div.attr.classes:find(target) then
127+
class = target
128+
div.attr.classes = div.attr.classes:filter(
129+
function(cls) return cls ~= target end)
130+
end
131+
end
132+
if class == nil then return nil end
128133
if #div.content == 0 then return nil end
129134

130135
local content = blocks_skip_data_pos(div.content)
131136

132137
local caption = {}
138+
139+
-- look for a caption in front
133140
if content[1].t == "Para" then
134141
local para = table.remove(content, 1)
135142
caption = {pandoc.Plain(para.content)}
136143
end
137-
138144
if #content == 0 then return nil end
139145

140146
assert_(content[1].t == "BulletList",
141147
"expected bullet list, found " .. content[1].t, content[1])
142148
local list = content[1]
143149

150+
-- also look for a caption in back
151+
if content[2] and content[2].t == "Para" then
152+
local para = table.remove(content, 2)
153+
caption = {pandoc.Plain(para.content)}
154+
end
155+
156+
144157
-- rows points to the current body's rows
145158
local bodies = {attr=nil, {rows={}}}
146159
local rows = bodies[#bodies].rows
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: Table Crossref Test
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- - "div#tbl-list table"
8+
- "div#tbl-list-2 table"
9+
- "div#tbl-letters table"
10+
- "div#tbl-panel table"
11+
- "div#tbl-first table"
12+
- "div#tbl-second table"
13+
- []
14+
---
15+
16+
## Simple Crossref Table
17+
18+
| Col1 | Col2 | Col3 |
19+
|------|------|------|
20+
| A | B | C |
21+
| E | F | G |
22+
| A | G | G |
23+
24+
: My Caption {#tbl-letters}
25+
26+
See @tbl-letters.
27+
28+
## Sub tables
29+
30+
::: {#tbl-panel layout-ncol=2}
31+
| Col1 | Col2 | Col3 |
32+
|------|------|------|
33+
| A | B | C |
34+
| E | F | G |
35+
| A | G | G |
36+
37+
: First Table {#tbl-first}
38+
39+
| Col1 | Col2 | Col3 |
40+
|------|------|------|
41+
| A | B | C |
42+
| E | F | G |
43+
| A | G | G |
44+
45+
: Second Table {#tbl-second}
46+
47+
Main Caption
48+
:::
49+
50+
See @tbl-panel for details, especially @tbl-second.
51+
52+
## List tables
53+
54+
::: {#tbl-list .list-table}
55+
56+
This is a table caption. {tbl-colwidths=[20,40,40]}
57+
58+
* - Row 1, Col 1
59+
- Row 1, Col 2
60+
- Row 1, Col 3
61+
62+
* - Row 2, Col 1
63+
- Row 2, Col 2
64+
- Row 2, Col 3
65+
66+
:::
67+
68+
see @tbl-list.
69+
70+
Quarto syntax extension for `list-tables`: table ordering compatible with fenced-div crossrefs.
71+
72+
::: {#tbl-list-2 .list-table}
73+
74+
* - Row 1, Col 1
75+
- Row 1, Col 2
76+
- Row 1, Col 3
77+
78+
* - Row 2, Col 1
79+
- Row 2, Col 2
80+
- Row 2, Col 3
81+
82+
This is a table caption. {tbl-colwidths=[20,40,40]}
83+
84+
:::
85+
86+
See @tbl-list-2.

0 commit comments

Comments
 (0)