Skip to content

Keep the .cell wrapper around knitr floats so Typst doesn't double-wrap tables - #767

Draft
gordonwoodhull wants to merge 2 commits into
mainfrom
bugfix/bd-gb6u8qsz-table-extra-wrapper
Draft

gordonwoodhull wants to merge 2 commits into
mainfrom
bugfix/bd-gb6u8qsz-table-extra-wrapper

Conversation

@gordonwoodhull

Copy link
Copy Markdown
Member

A captioned table produced by a knitr chunk (for example knitr::kable() with #| label: tbl-… and #| tbl-cap:) rendered to Typst as

#figure([
#block[
#table(

The extra #block[ between #figure([ and #table( is the shape Quarto's issue 10086 fix removes.

The cause was in q2's float desugaring. A .cell #tbl-… div was turned into a FloatRefTarget with the .cell div discarded. Quarto's Typst post filter only marks cell-output-display as scaffolding, so it disappears from the output, when it sits under a .cell parent. Without that parent, the div reached Pandoc's Typst writer and came out as a block.

q2 now keeps the .cell div around the float and leaves only the cell-output-display divs inside it, as Quarto's parsefiguredivs.lua does for non-layout cells. Layout cells and cells with no output div are unchanged.

The same knitr table now produces #figure([ followed directly by #table(, matching Quarto. typst/tbl-align-issue10086.qmd is ported from Quarto's smoke-all corpus with its two assertions. The first requires that shape, and the second rejects a block wrapped around the whole figure.

q2's output for this fixture was centered before and after, so the rendered PDF is unchanged. The fix guards against the double-wrapped #block[ #figure([ #block[ shape, which left-aligns the figure in Quarto when the scaffold rule fails to match. Because the .cell div is back, that shape would now reappear if the scaffold rule stopped matching. The second assertion covers that case.

Not addressed: for echo: true chunks using the #| label: shorthand, the code listing is still placed inside the figure, where Quarto puts it above.

…ap tables

A captioned knitr table rendered to Typst with an extra #block[ between
#figure([ and #table(. The float desugaring turned a .cell #tbl-* div
into a FloatRefTarget and discarded the .cell div, so Quarto's Typst
post filter never marked cell-output-display as scaffolding.

Keep the .cell div around the float with only the cell-output-display
divs inside it, as Quarto's parsefiguredivs.lua does for non-layout
cells. Port Quarto's tbl-align-issue10086 smoke-all fixture.
@posit-snyk-bot

posit-snyk-bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

CI has no R/knitr runtime, so the test failed with 'Engine knitr is
registered but its runtime is not available'. Declare tests.run.requires
so the harness skips it when knitr is missing.
@gordonwoodhull

gordonwoodhull commented Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

(I honestly kind of hate the div shuffling and wish it were better in q2. Hard for me to merge this because it's a test for a regression in Q1, but there doesn't seem to be any corresponding bug to regress in q2. I'll probably let this draft PR decay and then close it, unless we find we need it later.)

This branch has not been deployed

No deployments
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.

2 participants