Skip to content

Commit 5e12ecf

Browse files
authored
Merge pull request #13534 from quarto-dev/feature/list-tables
fenced div syntax for `Feature/list tables`
2 parents 77308ca + c5cd449 commit 5e12ecf

File tree

4 files changed

+152
-8
lines changed

4 files changed

+152
-8
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

tests/docs/crossrefs/tables.qmd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
---
22
title: Table Crossref Test
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- []
8+
- []
39
---
410

511
## Simple Crossref Table
@@ -54,4 +60,4 @@ This has a caption. {tbl-colwidths=[20,40,40]}
5460

5561
:::
5662

57-
see @tbl-list.
63+
see @tbl-list.
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.

tests/docs/smoke-all/table/list_table.qmd

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ _quarto:
44
tests:
55
html:
66
ensureHtmlElements:
7-
- ["table"]
7+
- - "table"
8+
- "div#fig-list-table table" # fenced div syntax using a different prefix
9+
- "div#tbl-list-table-2 table" # fenced div syntax inside list-table (ie, captions last)
810
- ["div.list-table"]
911
---
1012

@@ -57,3 +59,40 @@ _quarto:
5759
* `QUARTO_LOG_FORMAT` is the same as using `--log-format` at command line. It is used to set the format for the log. Possible values are `plain` (default) and `json-stream`.
5860
5961
:::
62+
63+
64+
::: {#fig-list-table}
65+
66+
::: {.list-table widths="0.2,0.4,0.4"}
67+
68+
* - Row 1, Col 1
69+
- Row 1, Col 2
70+
- Row 1, Col 3
71+
72+
* - Row 2, Col 1
73+
- Row 2, Col 2
74+
- Row 2, Col 3
75+
76+
:::
77+
78+
A caption.
79+
80+
:::
81+
82+
see @fig-list-table.
83+
84+
::: {#tbl-list-table-2 .list-table}
85+
86+
* - Row 1, Col 1
87+
- Row 1, Col 2
88+
- Row 1, Col 3
89+
90+
* - Row 2, Col 1
91+
- Row 2, Col 2
92+
- Row 2, Col 3
93+
94+
This has a caption. {tbl-colwidths=[20,40,40]}
95+
96+
:::
97+
98+
see @tbl-list-table-2.

0 commit comments

Comments
 (0)