diff --git a/src/resources/filters/modules/listtable.lua b/src/resources/filters/modules/listtable.lua index d6a038de8f0..adfde0fb4a0 100644 --- a/src/resources/filters/modules/listtable.lua +++ b/src/resources/filters/modules/listtable.lua @@ -120,27 +120,40 @@ local function new_cell(contents) end local function process(div) - if (div.attr.classes[1] ~= "list-table" and - div.attr.classes[1] ~= "list-table-body") then return nil end - local class = div.attr.classes[1] - table.remove(div.attr.classes, 1) - + local class + local target_classes = {"list-table", "list-table-body"} + for _, target in ipairs(target_classes) do + if div.attr.classes:find(target) then + class = target + div.attr.classes = div.attr.classes:filter( + function(cls) return cls ~= target end) + end + end + if class == nil then return nil end if #div.content == 0 then return nil end local content = blocks_skip_data_pos(div.content) local caption = {} + + -- look for a caption in front if content[1].t == "Para" then local para = table.remove(content, 1) caption = {pandoc.Plain(para.content)} end - if #content == 0 then return nil end assert_(content[1].t == "BulletList", "expected bullet list, found " .. content[1].t, content[1]) local list = content[1] + -- also look for a caption in back + if content[2] and content[2].t == "Para" then + local para = table.remove(content, 2) + caption = {pandoc.Plain(para.content)} + end + + -- rows points to the current body's rows local bodies = {attr=nil, {rows={}}} local rows = bodies[#bodies].rows diff --git a/tests/docs/crossrefs/tables.qmd b/tests/docs/crossrefs/tables.qmd index 1ff018d517c..621786c6a55 100644 --- a/tests/docs/crossrefs/tables.qmd +++ b/tests/docs/crossrefs/tables.qmd @@ -1,5 +1,11 @@ --- title: Table Crossref Test +_quarto: + tests: + html: + ensureHtmlElements: + - [] + - [] --- ## Simple Crossref Table @@ -54,4 +60,4 @@ This has a caption. {tbl-colwidths=[20,40,40]} ::: -see @tbl-list. \ No newline at end of file +see @tbl-list. diff --git a/tests/docs/smoke-all/crossrefs/tables/simple.qmd b/tests/docs/smoke-all/crossrefs/tables/simple.qmd new file mode 100644 index 00000000000..b32f680af1a --- /dev/null +++ b/tests/docs/smoke-all/crossrefs/tables/simple.qmd @@ -0,0 +1,86 @@ +--- +title: Table Crossref Test +_quarto: + tests: + html: + ensureHtmlElements: + - - "div#tbl-list table" + - "div#tbl-list-2 table" + - "div#tbl-letters table" + - "div#tbl-panel table" + - "div#tbl-first table" + - "div#tbl-second table" + - [] +--- + +## Simple Crossref Table + +| Col1 | Col2 | Col3 | +|------|------|------| +| A | B | C | +| E | F | G | +| A | G | G | + +: My Caption {#tbl-letters} + +See @tbl-letters. + +## Sub tables + +::: {#tbl-panel layout-ncol=2} +| Col1 | Col2 | Col3 | +|------|------|------| +| A | B | C | +| E | F | G | +| A | G | G | + +: First Table {#tbl-first} + +| Col1 | Col2 | Col3 | +|------|------|------| +| A | B | C | +| E | F | G | +| A | G | G | + +: Second Table {#tbl-second} + +Main Caption +::: + +See @tbl-panel for details, especially @tbl-second. + +## List tables + +::: {#tbl-list .list-table} + +This is a table caption. {tbl-colwidths=[20,40,40]} + +* - Row 1, Col 1 + - Row 1, Col 2 + - Row 1, Col 3 + +* - Row 2, Col 1 + - Row 2, Col 2 + - Row 2, Col 3 + +::: + +see @tbl-list. + +Quarto syntax extension for `list-tables`: table ordering compatible with fenced-div crossrefs. + +::: {#tbl-list-2 .list-table} + +* - Row 1, Col 1 + - Row 1, Col 2 + - Row 1, Col 3 + +* - Row 2, Col 1 + - Row 2, Col 2 + - Row 2, Col 3 + +This is a table caption. {tbl-colwidths=[20,40,40]} + +::: + +See @tbl-list-2. diff --git a/tests/docs/smoke-all/table/list_table.qmd b/tests/docs/smoke-all/table/list_table.qmd index 01b63d0608c..94a8b54d660 100644 --- a/tests/docs/smoke-all/table/list_table.qmd +++ b/tests/docs/smoke-all/table/list_table.qmd @@ -4,7 +4,9 @@ _quarto: tests: html: ensureHtmlElements: - - ["table"] + - - "table" + - "div#fig-list-table table" # fenced div syntax using a different prefix + - "div#tbl-list-table-2 table" # fenced div syntax inside list-table (ie, captions last) - ["div.list-table"] --- @@ -57,3 +59,40 @@ _quarto: * `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`. ::: + + +::: {#fig-list-table} + +::: {.list-table widths="0.2,0.4,0.4"} + +* - Row 1, Col 1 + - Row 1, Col 2 + - Row 1, Col 3 + +* - Row 2, Col 1 + - Row 2, Col 2 + - Row 2, Col 3 + +::: + +A caption. + +::: + +see @fig-list-table. + +::: {#tbl-list-table-2 .list-table} + +* - Row 1, Col 1 + - Row 1, Col 2 + - Row 1, Col 3 + +* - Row 2, Col 1 + - Row 2, Col 2 + - Row 2, Col 3 + +This has a caption. {tbl-colwidths=[20,40,40]} + +::: + +see @tbl-list-table-2. \ No newline at end of file