Skip to content

Commit 4a18e9d

Browse files
committed
Size the annotated copy button margin in the code font size
The margin multiplied $code-block-font-size inside calc(), which only matches the gutter for length units. A percentage, which a theme or a brand typography size can set, resolved against the scaffold width in a margin, and pushed the button about 290px into the code. The button now takes the code block font size itself, so it shares the pre's em, and the margin repeats the gutter's own calc(20px + 0.5em) plus 5px. That holds for any value the pre accepts. The copy icon is sized in rem, so it keeps its size.
1 parent 69fce03 commit 4a18e9d

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎src/resources/formats/html/bootstrap/_bootstrap-rules.scss‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,11 +1997,12 @@ textarea {
19971997

19981998
// Code Annotation
19991999

2000-
// The copy button is a sibling of div.sourceCode, so its em is not the code
2001-
// font size. Clear the gutter (calc(20px + 0.5em) in code font size) plus the
2002-
// default 5px margin.
2000+
// The copy button is a sibling of div.sourceCode, so it takes the code font
2001+
// size here to share the gutter's em, then clears the gutter
2002+
// (calc(20px + 0.5em)) plus the default 5px margin. Its icon is sized in rem.
20032003
.code-copy-outer-scaffold:has(pre.code-annotated) > .code-copy-button {
2004-
margin-right: calc(20px + 0.5 * #{$code-block-font-size} + 5px);
2004+
font-size: $code-block-font-size;
2005+
margin-right: calc(20px + 0.5em + 5px);
20052006
margin-top: 0;
20062007
padding-bottom: 0;
20072008
padding-top: 3px;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "Code copy button and code annotation marker (code block font size in percent)"
3+
format:
4+
html:
5+
theme: [default, code-annotation-copy-button-font-size-percent.scss]
6+
code-annotations: hover
7+
---
8+
9+
```{.python}
10+
import polars as pl # <1>
11+
```
12+
13+
1. This is a code block with a copy button and an annotation.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*-- scss:defaults --*/
2+
$code-block-font-size: 75%;

‎tests/integration/playwright/tests/html-code-annotation-copy-button.spec.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const testCases = [
1919
name: "hover with a custom code block font size",
2020
url: "html/code-annotation-copy-button-font-size.html",
2121
},
22+
{
23+
name: "hover with a code block font size in percent",
24+
url: "html/code-annotation-copy-button-font-size-percent.html",
25+
},
2226
];
2327

2428
test.describe("code copy button and code annotation marker", () => {

0 commit comments

Comments
 (0)