Skip to content

Fix code copy button and spacing for code blocks at callout edges - #15138

Merged
cderv merged 4 commits into
mainfrom
fix/issue-13446
Oct 22, 2026
Merged

cderv merged 4 commits into
mainfrom
fix/issue-13446

Conversation

@cderv

@cderv cderv commented Oct 21, 2026

Copy link
Copy Markdown
Member

Since #13024 wrapped code blocks in div.code-copy-outer-scaffold (first released in v1.8.15), a code block that starts or ends a callout has its copy button above the code frame, half outside it, and gets much more space than a paragraph at the same edge.

Stacked on #15136 (#13444), which it needs for annotated code blocks in callouts. It should be merged after it.

Root cause

The callout edge rules in _bootstrap-rules.scss were written for div.sourceCode, but the edge child is now the scaffold, or a .cell around it.

  • The 0.5rem padding of .callout-body > :first-child and :last-child lands on the scaffold. It stops the 1em margin of div.sourceCode from collapsing, so the code moves down while the button stays at top: 0 of the scaffold.
  • :last-child:not(.sourceCode) was meant to exempt code blocks, but the scaffold is not .sourceCode.
  • The > div > :last-child branch now matches the copy button itself, which gets an extra padding-bottom.

Fix

At a callout edge, the scaffold (or a cell whose edge child is the scaffold) gets the spacing as margin instead of padding, and div.sourceCode drops its own margin there. The button is back 5px inside the code frame, and code at the edge gets the same spacing as a paragraph in the same callout. The copy button is excluded from the > div > :last-child rule. The rules are based on the CSS suggested in the issue thread.

The cell rules use :has() to only apply when code is at the edge of the cell, so a cell ending with its output keeps its current spacing.

This is a visible change compared to 1.7, where the callout padding applied to div.sourceCode itself, so the code frame was flush to the callout header (#13238). #13238 also asks to change padding to margin for other first children of a callout, which changes more than code blocks, so it is not part of this PR.

Moving the margin onto the scaffold for every code block was considered, as the same offset happens in sections using the column grid (#15137). That rule adds 17px of space in tabsets and between a filename header and its code, as these contexts reset the margin on div.sourceCode, and the callout edge rules would still be needed. The grid case is tracked separately in #15137.

No backport is planned: the regression is from v1.8.15 and the stable release is v1.10.

Fixes #13446

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR
AI-assisted PR
  • AI tool used: Claude Code
  • Codebase grounding: local clone
  • Human review: I have reviewed, tested, and verified the AI-generated content before submitting.

Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.

@posit-snyk-bot

posit-snyk-bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

✅ 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.

@cderv
cderv added this pull request to stack #15142 October 22, 2026 09:10
Base automatically changed from fix/issue-13444 to main October 22, 2026 14:08
cderv added 4 commits October 22, 2026 16:08
Since code blocks are wrapped in .code-copy-outer-scaffold, the callout
first/last-child rules hit the scaffold instead of div.sourceCode. The
padding-top added to a first child stopped the code block's own 1em margin
from collapsing, and the absolutely positioned copy button anchors to the
scaffold's padding box, so in a default-style callout starting with code
the button sat about 19px above the code, half outside it. The
last-child rules, which meant to exempt code blocks with
:not(.sourceCode), padded the scaffold too, leaving an extra gap below
code at the end of a callout. The `> div > :last-child` branch also
matched the button itself, the scaffold's last child, and gave it 8.5px
of bottom padding.

At a callout edge, the scaffold is now spaced with margin instead of
padding and the inner div.sourceCode margin is dropped, for bare code
blocks and for cells whose code is at that edge. The button sits 5px
inside the code top, as it does outside callouts, and code at the top or
bottom of a callout gets the same gap as a paragraph there. This is a
visible change from 1.7, where the code frame of a titled callout sat
flush against the header. The general padding-to-margin change asked for
in #13238 touches non-code first children too and is left out.

Fixes #13446
Each block now reads as code at the first or last edge of a callout
body, with the long shared selector prefix written once. The compiled
CSS is byte-identical to the flat form.
With the copy button back inside the code frame, an annotated first line
in a callout puts the button over the annotation marker, the same overlap
#13444 fixes outside callouts. A hit test on the marker covers the
callout case. It fails without the annotated button rule and passes with
it.

That rule also drops the annotated button's top margin, so its position
is now compared with an annotated block outside a callout instead of a
plain one.
@cderv
cderv merged commit 48b6c55 into main Oct 22, 2026
50 of 52 checks passed
@cderv
cderv deleted the fix/issue-13446 branch October 22, 2026 15:57
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.

Code-copy button outside of code blocks

2 participants