From e208cc724459b135a7ec6688ef01c09526b84a3f Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 21 May 2024 13:36:31 -0700 Subject: [PATCH] lua,cap-location - detect and handle cap-location for pandoc.Table --- news/changelog-1.5.md | 1 + .../filters/customnodes/floatreftarget.lua | 8 ++++++-- src/resources/filters/quarto-post/html.lua | 7 +++++++ tests/docs/smoke-all/2024/05/21/9734-a.qmd | 17 +++++++++++++++++ tests/docs/smoke-all/2024/05/21/9734-b.qmd | 18 ++++++++++++++++++ tests/docs/smoke-all/2024/05/21/9734-c.qmd | 16 ++++++++++++++++ 6 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests/docs/smoke-all/2024/05/21/9734-a.qmd create mode 100644 tests/docs/smoke-all/2024/05/21/9734-b.qmd create mode 100644 tests/docs/smoke-all/2024/05/21/9734-c.qmd diff --git a/news/changelog-1.5.md b/news/changelog-1.5.md index 56ea764431b..867cf03e3ee 100644 --- a/news/changelog-1.5.md +++ b/news/changelog-1.5.md @@ -12,6 +12,7 @@ All changes included in 1.5: - ([#9539](https://github.com/quarto-dev/quarto-cli/issues/9539)): Improve SCSS of title blocks to avoid overwide columns in grid layout. - Improve accessibility `role` for `aria-expandable` elements by ensuring their role supports the `aria-expanded` attribute. - ([#3178](https://github.com/quarto-dev/quarto-cli/issues/3178)): TOC now correctly expands when web page has no content to scroll to. +- ([#9734](https://github.com/quarto-dev/quarto-cli/issues/9734)): Fix issue with unlabeled tables and `tbl-cap-location` information. ## PDF Format diff --git a/src/resources/filters/customnodes/floatreftarget.lua b/src/resources/filters/customnodes/floatreftarget.lua index 979745eb3b9..1002857fd91 100644 --- a/src/resources/filters/customnodes/floatreftarget.lua +++ b/src/resources/filters/customnodes/floatreftarget.lua @@ -118,9 +118,13 @@ function cap_location(obj) -- ref-parents ref = refType(obj.identifier) or refType(obj.attributes["ref-parent"] or "") end - -- last resort, pretend we're a figure if ref == nil or crossref.categories.by_ref_type[ref] == nil then - ref = "fig" + if obj.t == "Table" then + ref = "tbl" + else + -- last resort, pretend we're a figure + ref = "fig" + end end local qualified_key = ref .. '-cap-location' local result = ( diff --git a/src/resources/filters/quarto-post/html.lua b/src/resources/filters/quarto-post/html.lua index 8cc80f8dfd0..adfe5d33a8f 100644 --- a/src/resources/filters/quarto-post/html.lua +++ b/src/resources/filters/quarto-post/html.lua @@ -22,6 +22,13 @@ function render_html_fixups() end return { + Table = function(tbl) + -- this requires bootstrap CSS + if quarto.doc.crossref.cap_location(tbl) == "top" then + tbl.classes:insert("caption-top") + return tbl + end + end, Figure = function(fig) if #fig.content ~= 1 then return nil diff --git a/tests/docs/smoke-all/2024/05/21/9734-a.qmd b/tests/docs/smoke-all/2024/05/21/9734-a.qmd new file mode 100644 index 00000000000..890bacba47e --- /dev/null +++ b/tests/docs/smoke-all/2024/05/21/9734-a.qmd @@ -0,0 +1,17 @@ +--- +title: Table caption location +tbl-cap-location: top +format: html +_quarto: + tests: + html: + ensureHtmlElements: + - ["table.caption-top"] +--- + +| Col1 | Col2 | Col3 | +|------|------|------| +| A | B | C | +| E | F | G | + +: A non-labelled table with a caption diff --git a/tests/docs/smoke-all/2024/05/21/9734-b.qmd b/tests/docs/smoke-all/2024/05/21/9734-b.qmd new file mode 100644 index 00000000000..f37af25e180 --- /dev/null +++ b/tests/docs/smoke-all/2024/05/21/9734-b.qmd @@ -0,0 +1,18 @@ +--- +title: Table caption location +tbl-cap-location: bottom +format: html +_quarto: + tests: + html: + ensureHtmlElements: + - [] + - ["table.caption-top"] +--- + +| Col1 | Col2 | Col3 | +|------|------|------| +| A | B | C | +| E | F | G | + +: A non-labelled table with a caption diff --git a/tests/docs/smoke-all/2024/05/21/9734-c.qmd b/tests/docs/smoke-all/2024/05/21/9734-c.qmd new file mode 100644 index 00000000000..94177650033 --- /dev/null +++ b/tests/docs/smoke-all/2024/05/21/9734-c.qmd @@ -0,0 +1,16 @@ +--- +title: Table caption location +format: html +_quarto: + tests: + html: + ensureHtmlElements: + - ["table.caption-top"] +--- + +| Col1 | Col2 | Col3 | +|------|------|------| +| A | B | C | +| E | F | G | + +: A non-labelled table with a caption