Skip to content

Commit e208cc7

Browse files
committed
lua,cap-location - detect and handle cap-location for pandoc.Table
1 parent 896849b commit e208cc7

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

news/changelog-1.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All changes included in 1.5:
1212
- ([#9539](https://github.com/quarto-dev/quarto-cli/issues/9539)): Improve SCSS of title blocks to avoid overwide columns in grid layout.
1313
- Improve accessibility `role` for `aria-expandable` elements by ensuring their role supports the `aria-expanded` attribute.
1414
- ([#3178](https://github.com/quarto-dev/quarto-cli/issues/3178)): TOC now correctly expands when web page has no content to scroll to.
15+
- ([#9734](https://github.com/quarto-dev/quarto-cli/issues/9734)): Fix issue with unlabeled tables and `tbl-cap-location` information.
1516

1617
## PDF Format
1718

src/resources/filters/customnodes/floatreftarget.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ function cap_location(obj)
118118
-- ref-parents
119119
ref = refType(obj.identifier) or refType(obj.attributes["ref-parent"] or "")
120120
end
121-
-- last resort, pretend we're a figure
122121
if ref == nil or crossref.categories.by_ref_type[ref] == nil then
123-
ref = "fig"
122+
if obj.t == "Table" then
123+
ref = "tbl"
124+
else
125+
-- last resort, pretend we're a figure
126+
ref = "fig"
127+
end
124128
end
125129
local qualified_key = ref .. '-cap-location'
126130
local result = (

src/resources/filters/quarto-post/html.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ function render_html_fixups()
2222
end
2323

2424
return {
25+
Table = function(tbl)
26+
-- this requires bootstrap CSS
27+
if quarto.doc.crossref.cap_location(tbl) == "top" then
28+
tbl.classes:insert("caption-top")
29+
return tbl
30+
end
31+
end,
2532
Figure = function(fig)
2633
if #fig.content ~= 1 then
2734
return nil
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Table caption location
3+
tbl-cap-location: top
4+
format: html
5+
_quarto:
6+
tests:
7+
html:
8+
ensureHtmlElements:
9+
- ["table.caption-top"]
10+
---
11+
12+
| Col1 | Col2 | Col3 |
13+
|------|------|------|
14+
| A | B | C |
15+
| E | F | G |
16+
17+
: A non-labelled table with a caption
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Table caption location
3+
tbl-cap-location: bottom
4+
format: html
5+
_quarto:
6+
tests:
7+
html:
8+
ensureHtmlElements:
9+
- []
10+
- ["table.caption-top"]
11+
---
12+
13+
| Col1 | Col2 | Col3 |
14+
|------|------|------|
15+
| A | B | C |
16+
| E | F | G |
17+
18+
: A non-labelled table with a caption
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Table caption location
3+
format: html
4+
_quarto:
5+
tests:
6+
html:
7+
ensureHtmlElements:
8+
- ["table.caption-top"]
9+
---
10+
11+
| Col1 | Col2 | Col3 |
12+
|------|------|------|
13+
| A | B | C |
14+
| E | F | G |
15+
16+
: A non-labelled table with a caption

0 commit comments

Comments
 (0)