From 8d4a2e42dcde6e148eb81f20cd7f84e08d564561 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 13 Nov 2026 22:38:22 +0800 Subject: [PATCH] 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 --- packages/md/src/theme/prose.css | 6 ++++-- packages/md/test/integration/theme-layout.test.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/md/src/theme/prose.css b/packages/md/src/theme/prose.css index 1f33919ef..86176892f 100644 --- a/packages/md/src/theme/prose.css +++ b/packages/md/src/theme/prose.css @@ -44,6 +44,7 @@ .void-md h4, .void-md h5, .void-md h6 { + position: relative; font-weight: 600; line-height: 1.3; margin-top: 1.5em; @@ -162,9 +163,10 @@ } /* Anchor links */ +/* Ends at the heading's start edge, so a wide "#" in any font never covers the text. */ .void-md .header-anchor { - float: inline-start; - margin-inline-start: -0.87em; + position: absolute; + inset-inline-end: 100%; padding-inline-end: 0.23em; font-weight: 500; opacity: 0; diff --git a/packages/md/test/integration/theme-layout.test.ts b/packages/md/test/integration/theme-layout.test.ts index 3f50a8039..f9990c0f3 100644 --- a/packages/md/test/integration/theme-layout.test.ts +++ b/packages/md/test/integration/theme-layout.test.ts @@ -14,7 +14,9 @@ beforeAll(async () => { const nested = await compile('- [ ] parent\n - [x] child\n - [ ] another child'); const loose = await compile('- [ ] first paragraph\n\n second paragraph\n\n- ordinary item'); const code = await compile('## Heading\n\n```js\nconst x = 1;\n```'); - html = `
+ // A wide "#" (as some fonts draw it) must still end before the heading text. + html = ` +
${nested.html}
${loose.html}
${code.html}