Skip to content

Conversation

@cderv
Copy link
Collaborator

@cderv cderv commented Jul 10, 2025

closes #13051

when caption is taken on the table element, remove it from the table

this is because Quarto floatref processes the table caption and it needs to be removed from the table element so that it doesn't get inserted twice

This happens with syntax like

## Using `:` syntax

::: {#tbl-1}

| Default | Left | Right | Center |
|---------|:-----|------:|:------:|
| 12      | 12   |    12 |   12   |
| 123     | 123  |   123 |  123   |
| 1       | 1    |     1 |   1    |

: This is the caption for the table 1

:::

See @tbl-1

## Using `Table:` syntax

::: {#tbl-2}

| Default | Left | Right | Center |
|---------|:-----|------:|:------:|
| 12      | 12   |    12 |   12   |
| 123     | 123  |   123 |  123   |
| 1       | 1    |     1 |   1    |

Table: This is the caption for the table 2

:::

See @tbl-2

This PR adds also

  • Regression for this specific duplication
  • More supported syntax in ff-matrix with test

Note

The fix is a candidate for a backport as it was a regression in 1.7 from 8bec5e3
I'll do a PR once validated

cderv added 4 commits July 10, 2025 11:30
… the table

this is because Quarto floatref processes the table caption and it needs to be removed from the table element so that it doesn't get inserted twice
including the internal one from computation when using div attribute
@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Jul 10, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Comment on lines 270 to 271
-- table caption should be removed from the table as we'll handle it
table.caption.long = pandoc.Blocks({})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarleb in

There was suppression of the caption removal: 8bec5e3

it was tbl.caption.long = nil which seemed to be incorrect.

Is setting to empty block the more efficient way to remove the table.caption?

This is what we want to do here. Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pandoc 3.6.1 added a pandoc.Caption constructor, so the cleanest variant would probably be

table.caption = pandoc.Caption{}

This would also make sure that the short caption is reset. The short caption is intended to be used in the List of Tables, but it's not set in the default Markdown reader. But if that ever changes, then we capture that case as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed that. Changed done.

The short caption is intended to be used in the List of Tables

I wonder how we support that in Quarto. This would interesting support.

@cderv cderv requested a review from tarleb July 10, 2025 10:27
@cscheid
Copy link
Collaborator

cscheid commented Jul 10, 2025

This is a good improvement, but I don't think it's a bug, and so we don't need the hotfix. My understanding is that the Div syntax has always required a content element and a caption element. If it worked before it was an accident; we never promised it would work.

@cderv
Copy link
Collaborator Author

cderv commented Jul 10, 2025

My understanding is that the Div syntax has always required a content element and a caption element. If it worked before it was an accident; we never promised it would work.

I assumed from this code in 1.6 that we were supposed to support it

local caption = refCaptionFromDiv(div)
if caption ~= nil then
div.content:remove(#div.content)
elseif div.attributes[caption_attr_key] ~= nil then
caption = pandoc.Plain(string_to_quarto_ast_inlines(div.attributes[caption_attr_key]))
div.attributes[caption_attr_key] = nil
else
-- it's possible that the content of this div includes a table with a caption
-- so we'll go root around for that.
local found_caption = false
content = _quarto.ast.walk(content, {
Table = function(table)
if table.caption.long ~= nil then
found_caption = true
caption = table.caption.long[1] -- what if there's more than one entry here?
table.caption.long = nil
return table
end
end
})
-- luacov: disable
if content == nil then
internal_error()
return nil
end
-- luacov: enable
-- TODO are there other cases where we should look for captions?
if not found_caption then
caption = pandoc.Plain({})
end
end

As you can see, the logic is

So it was not document in our website, but it was working from this code base.

We had a caption removal at

which was removed accidentaly in 8bec5e3

So, based on Codebase this was working.

I am fine to not do the backport, but it seemed a good candidate based on this history.

@cderv cderv merged commit 3987ff9 into main Jul 10, 2025
2 checks passed
@cderv cderv deleted the floatref/table-with-caption branch July 10, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated captions in Quarto 1.8.16, 1, 1.7.32. Ok in 1.5.8

5 participants