Skip to content

Commit 8d4a2e4

Browse files
Brooooooklynclaude
andcommitted
fix(md): keep the heading anchor clear of the heading text in every font
The `#` anchor floated at the heading's start with a fixed -0.87em margin, so it stayed clear only while the glyph was at most 0.64em wide. On fonts with a wider `#` (the Linux CI runner has one) it pushed the heading text over by a few pixels, and the layout test from #811 failed on main in both directions. The anchor is now absolutely placed with its end edge on the heading's start edge (`inset-inline-end: 100%`), so it never covers the text and still mirrors on right-to-left pages. The layout test widens the `#` with letter spacing, so it fails with the old rule on any machine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 13ca7fb commit 8d4a2e4

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎packages/md/src/theme/prose.css‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
.void-md h4,
4545
.void-md h5,
4646
.void-md h6 {
47+
position: relative;
4748
font-weight: 600;
4849
line-height: 1.3;
4950
margin-top: 1.5em;
@@ -162,9 +163,10 @@
162163
}
163164

164165
/* Anchor links */
166+
/* Ends at the heading's start edge, so a wide "#" in any font never covers the text. */
165167
.void-md .header-anchor {
166-
float: inline-start;
167-
margin-inline-start: -0.87em;
168+
position: absolute;
169+
inset-inline-end: 100%;
168170
padding-inline-end: 0.23em;
169171
font-weight: 500;
170172
opacity: 0;

‎packages/md/test/integration/theme-layout.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ beforeAll(async () => {
1414
const nested = await compile('- [ ] parent\n - [x] child\n - [ ] another child');
1515
const loose = await compile('- [ ] first paragraph\n\n second paragraph\n\n- ordinary item');
1616
const code = await compile('## Heading\n\n```js\nconst x = 1;\n```');
17-
html = `<style>${css}</style><main class="void-md" style="margin: 40px">
17+
// A wide "#" (as some fonts draw it) must still end before the heading text.
18+
html = `<style>${css}</style><style>#code .header-anchor { letter-spacing: 0.5em }</style>
19+
<main class="void-md" style="margin: 40px">
1820
<section id="nested">${nested.html}</section>
1921
<section id="loose">${loose.html}</section>
2022
<section id="code">${code.html}</section>

0 commit comments

Comments
 (0)