Skip to content

Commit 3987ff9

Browse files
authored
Merge pull request #13055 from quarto-dev/floatref/table-with-caption
floatref - avoid caption duplication on Div Crossref with captioned Markdown table
2 parents 54f4d4c + 44f8164 commit 3987ff9

File tree

6 files changed

+206
-14
lines changed

6 files changed

+206
-14
lines changed

dev-docs/feature-format-matrix/qmd-files/crossref/float/table/document.qmd

Lines changed: 127 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ format:
1515
revealjs:
1616
quality: 2
1717
auto-stretch: false
18+
slide-level: 3
1819
beamer:
1920
output-ext: tex
2021
quality: 2
@@ -28,46 +29,90 @@ _quarto:
2829
-
2930
- "div#tbl-1.quarto-float figure.quarto-float.quarto-float-tbl table"
3031
- "div#tbl-2.quarto-float figure.quarto-float.quarto-float-tbl img"
32+
- "div#tbl-3.quarto-float figure.quarto-float.quarto-float-tbl table"
33+
- "div#tbl-4.quarto-float figure.quarto-float.quarto-float-tbl table"
34+
- "div#tbl-5.quarto-float figure.quarto-float.quarto-float-tbl table"
35+
- "div#tbl-6.quarto-float figure.quarto-float.quarto-float-tbl table"
3136
- "div#tbl-1.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
3237
- "div#tbl-2.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
38+
- "div#tbl-3.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
39+
- "div#tbl-4.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
40+
- "div#tbl-5.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
41+
- "div#tbl-6.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
3342
- "a[href=\"#tbl-1\"].quarto-xref"
3443
- "a[href=\"#tbl-2\"].quarto-xref"
44+
- "a[href=\"#tbl-3\"].quarto-xref"
45+
- "a[href=\"#tbl-4\"].quarto-xref"
46+
- "a[href=\"#tbl-5\"].quarto-xref"
47+
- "a[href=\"#tbl-6\"].quarto-xref"
3548
dashboard: *dom-tests
3649
revealjs:
3750
ensureHtmlElements:
3851
-
3952
- "div#tbl-1.quarto-float figure.quarto-float.quarto-float-tbl table"
4053
- "div#tbl-2.quarto-float figure.quarto-float.quarto-float-tbl img"
54+
- "div#tbl-3.quarto-float figure.quarto-float.quarto-float-tbl table"
55+
- "div#tbl-4.quarto-float figure.quarto-float.quarto-float-tbl table"
56+
- "div#tbl-5.quarto-float figure.quarto-float.quarto-float-tbl table"
57+
- "div#tbl-6.quarto-float figure.quarto-float.quarto-float-tbl table"
4158
- "div#tbl-1.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
4259
- "div#tbl-2.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
60+
- "div#tbl-3.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
61+
- "div#tbl-4.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
62+
- "div#tbl-5.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
63+
- "div#tbl-6.quarto-float figure.quarto-float.quarto-float-tbl figcaption"
4364
- "a[href=\"#/tbl-1\"].quarto-xref"
4465
- "a[href=\"#/tbl-2\"].quarto-xref"
66+
- "a[href=\"#/tbl-3\"].quarto-xref"
67+
- "a[href=\"#/tbl-4\"].quarto-xref"
68+
- "a[href=\"#/tbl-5\"].quarto-xref"
69+
- "a[href=\"#/tbl-6\"].quarto-xref"
4570
latex: &latex-tests
4671
ensureFileRegexMatches:
4772
-
48-
- "\\\\ref\\{tbl-1\\}"
49-
- "\\\\ref\\{tbl-2\\}"
50-
- "\\\\label\\{tbl-1\\}"
51-
- "\\\\label\\{tbl-2\\}"
52-
- "\\\\begin\\{longtable\\}"
53-
- "\\\\includegraphics.*media.*table\\.jpg"
73+
- '\\ref\{tbl-1\}'
74+
- '\\ref\{tbl-2\}'
75+
- '\\ref\{tbl-3\}'
76+
- '\\ref\{tbl-4\}'
77+
- '\\ref\{tbl-5\}'
78+
- '\\ref\{tbl-6\}'
79+
- '\label\{tbl-1\}'
80+
- '\label\{tbl-2\}'
81+
- '\label\{tbl-3\}'
82+
- '\label\{tbl-4\}'
83+
- '\label\{tbl-5\}'
84+
- '\label\{tbl-6\}'
85+
- '\\begin\{longtable\}'
86+
- '\\includegraphics.*media.*table\.jpg'
5487
beamer: *latex-tests
5588
typst:
5689
ensureTypstFileRegexMatches:
5790
-
5891
- '\<tbl-1\>'
5992
- '\<tbl-2\>'
93+
- '\<tbl-3\>'
94+
- '\<tbl-4\>'
95+
- '\<tbl-5\>'
96+
- '\<tbl-6\>'
6097
- '#ref\(\<tbl-1\>, supplement: \[Table\]\)'
6198
- '#ref\(\<tbl-2\>, supplement: \[Table\]\)'
99+
- '#ref\(\<tbl-3\>, supplement: \[Table\]\)'
100+
- '#ref\(\<tbl-4\>, supplement: \[Table\]\)'
101+
- '#ref\(\<tbl-5\>, supplement: \[Table\]\)'
102+
- '#ref\(\<tbl-6\>, supplement: \[Table\]\)'
62103
docusaurus-md:
63104
ensureFileRegexMatches:
64105
-
65-
- "\\<div id=\"tbl-1\"\\>"
66-
- "\\<div id=\"tbl-2\"\\>"
67-
- "text-align: left.*Left"
68-
- "text-align: right.*Right"
69-
- "text-align: center.*Center"
70-
- "\\!\\[\\]\\(.*media.*table\\.jpg\\)"
106+
- '\<div id="tbl-1"\>'
107+
- '\<div id="tbl-2"\>'
108+
- '\<div id="tbl-3"\>'
109+
- '\<div id="tbl-4"\>'
110+
- '\<div id="tbl-5"\>'
111+
- '\<div id="tbl-6"\>'
112+
- 'text-align: left.*Left'
113+
- 'text-align: right.*Right'
114+
- 'text-align: center.*Center'
115+
- '\!\[\]\(.*media.*table\.jpg\)'
71116
---
72117

73118
## Crossreferenceable "Table"s
@@ -95,3 +140,73 @@ This is the caption for the table rendered as an image.
95140
:::
96141

97142
See @tbl-2.
143+
144+
## Markdown syntax
145+
146+
The crossref Div syntax can also be used to insert a markdown table
147+
148+
- either using Quarto Caption syntax (paragraph below the table) - See @tbl-3
149+
- either using the Pandoc Table Caption syntax - See @tbl-4
150+
- either using `tbl-cap` attributes when this is an output of computations - See @tbl-5
151+
- either using `tbl-cap` attributes on Crossref Div - See @tbl-6
152+
153+
### Quarto Syntax in Div {#quarto-in-div}
154+
155+
::: {#tbl-3}
156+
157+
| Default | Left | Right | Center |
158+
|---------|:-----|------:|:------:|
159+
| 12 | 12 | 12 | 12 |
160+
| 123 | 123 | 123 | 123 |
161+
| 1 | 1 | 1 | 1 |
162+
163+
This is the caption for the table
164+
:::
165+
166+
### Pandoc Table Caption Syntax {#pandoc-in-div}
167+
168+
::: {#tbl-4}
169+
170+
| Default | Left | Right | Center |
171+
|---------|:-----|------:|:------:|
172+
| 12 | 12 | 12 | 12 |
173+
| 123 | 123 | 123 | 123 |
174+
| 1 | 1 | 1 | 1 |
175+
176+
: This is the caption for the table
177+
178+
:::
179+
180+
### Using Div attribute on .cell div {#div-attr}
181+
182+
When using something like
183+
184+
```{{r}}
185+
#| tbl-cap: "My caption could run over several lines, if the world is round"
186+
#| label: tbl-my_cap
187+
188+
knitr::kable(iris[1:6,])
189+
```
190+
191+
::: {#tbl-5 .cell tbl-cap='This is the caption for the table'}
192+
193+
| Default | Left | Right | Center |
194+
|---------|:-----|------:|:------:|
195+
| 12 | 12 | 12 | 12 |
196+
| 123 | 123 | 123 | 123 |
197+
| 1 | 1 | 1 | 1 |
198+
199+
:::
200+
201+
202+
### Using Div attribute on Cross ref div
203+
204+
::: {#tbl-6 tbl-cap='This is the caption for the table'}
205+
206+
| Default | Left | Right | Center |
207+
|---------|:-----|------:|:------:|
208+
| 12 | 12 | 12 | 12 |
209+
| 123 | 123 | 123 | 123 |
210+
| 1 | 1 | 1 | 1 |
211+
212+
:::

news/changelog-1.8.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All changes included in 1.8:
66
- ([#12625](https://github.com/quarto-dev/quarto-cli/pull/12625)): Fire resize event on window when light/dark toggle is clicked, to tell widgets to resize.
77
- ([#12657](https://github.com/quarto-dev/quarto-cli/pull/12657)): Load Giscus in generated script tag, to avoid wrong-theming in Chrome.
88
- ([#12780](https://github.com/quarto-dev/quarto-cli/issues/12780)): `keep-ipynb: true` now works again correctly and intermediate `.quarto_ipynb` is not removed.
9+
- ([#13051](https://github.com/quarto-dev/quarto-cli/issues/13051)): Fixed support for captioned Markdown table inside Div syntax for crossref. This is special handling, but this could be output by function like `knitr::kable()` with old option support.
910

1011
## Dependencies
1112

src/resources/filters/quarto-pre/parsefiguredivs.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ function parse_floatreftargets()
267267
if table.caption.long and next(table.caption.long) then
268268
found_caption = true
269269
caption = table.caption.long[1] -- what if there's more than one entry here?
270+
-- table caption should be removed from the table as we'll handle it
271+
table.caption = pandoc.Caption{}
270272
return table
271273
end
272274
end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: Crossref Div with Markdown captioned table do not duplicate caption
3+
format: html
4+
keep-tex: true
5+
keep-typ: true
6+
_quarto:
7+
tests:
8+
html:
9+
ensureHtmlElements:
10+
-
11+
- 'div#tbl-1.quarto-float figure.quarto-float.quarto-float-tbl table'
12+
- 'div#tbl-2.quarto-float figure.quarto-float.quarto-float-tbl table'
13+
- 'a[href="#tbl-1"].quarto-xref'
14+
- 'a[href="#tbl-2"].quarto-xref'
15+
-
16+
- 'div#tbl-1.quarto-float table caption'
17+
- 'div#tbl-2.quarto-float table caption'
18+
revealjs:
19+
ensureHtmlElements:
20+
-
21+
- 'div#tbl-1.quarto-float figure.quarto-float.quarto-float-tbl table'
22+
- 'div#tbl-2.quarto-float figure.quarto-float.quarto-float-tbl table'
23+
- 'a[href="#/tbl-1"].quarto-xref'
24+
- 'a[href="#/tbl-2"].quarto-xref'
25+
-
26+
- 'div#tbl-1.quarto-float table caption'
27+
- 'div#tbl-2.quarto-float table caption'
28+
docx:
29+
ensureDocxXpath:
30+
-
31+
- "//w:tbl//w:p//w:r//w:t[contains(text(), \"Table\u00a01\")]"
32+
- "//w:tbl//w:p//w:r//w:t[contains(text(), \"Table\u00a02\")]"
33+
- "//w:hyperlink[@w:anchor='tbl-1']"
34+
- "//w:hyperlink[@w:anchor='tbl-2']"
35+
-
36+
- "//w:tbl//w:tbl//w:tblCaption[contains(@w:val, 'caption for the table 1')]"
37+
- "//w:tbl//w:tbl//w:tblCaption[contains(@w:val, 'caption for the table 2')]"
38+
---
39+
40+
Pandoc's support Caption on Markdown table through a specific syntax: https://pandoc.org/MANUAL.html#extension-table_captions
41+
42+
This test ensure we do catch the caption and do not duplicate
43+
44+
## Using `:` syntax
45+
46+
::: {#tbl-1}
47+
48+
| Default | Left | Right | Center |
49+
|---------|:-----|------:|:------:|
50+
| 12 | 12 | 12 | 12 |
51+
| 123 | 123 | 123 | 123 |
52+
| 1 | 1 | 1 | 1 |
53+
54+
: This is the caption for the table 1
55+
56+
:::
57+
58+
See @tbl-1
59+
60+
## Using `Table:` syntax
61+
62+
::: {#tbl-2}
63+
64+
| Default | Left | Right | Center |
65+
|---------|:-----|------:|:------:|
66+
| 12 | 12 | 12 | 12 |
67+
| 123 | 123 | 123 | 123 |
68+
| 1 | 1 | 1 | 1 |
69+
70+
Table: This is the caption for the table 2
71+
72+
:::
73+
74+
See @tbl-2

tests/new-smoke-all-test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ _quarto:
6262
ensureDocxRegexMatches:
6363
- []
6464
- []
65-
ensureDocxXPath:
65+
ensureDocxXpath:
6666
- []
6767
- []
6868
pptx:

tests/new-smoke-all-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ _quarto:
6060
ensureDocxRegexMatches:
6161
- []
6262
- []
63-
ensureDocxXPath:
63+
ensureDocxXpath:
6464
- []
6565
- []
6666
pptx:

0 commit comments

Comments
 (0)