Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/resources/filters/modules/listtable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tests/docs/crossrefs/tables.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---
title: Table Crossref Test
_quarto:
tests:
html:
ensureHtmlElements:
- []
- []
---

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

:::

see @tbl-list.
see @tbl-list.
86 changes: 86 additions & 0 deletions tests/docs/smoke-all/crossrefs/tables/simple.qmd
Original file line number Diff line number Diff line change
@@ -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.
41 changes: 40 additions & 1 deletion tests/docs/smoke-all/table/list_table.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
---

Expand Down Expand Up @@ -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.
Loading