Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/public-lamps-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/starlight": patch
---

Fixes a layout issue and anchor links appearing for hidden headings, e.g. footnote headings, when `markdown.headingLinks` is enabled or the `<AnchorHeading>` component is used.
14 changes: 13 additions & 1 deletion packages/starlight/style/anchor-links.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ how we do it.
line-height: var(--sl-line-height-headings);
}

/* If the heading is hidden, remove the wrapper's box to avoid unwanted spacing. */
.sl-markdown-content .sl-heading-wrapper:has(> :first-child:is(.sr-only, [hidden])) {
display: contents;
}

/* We need to apply the same rule we use for heading spacing to the parent wrapper. */
.sl-markdown-content
:not(h1, h2, h3, h4, h5, h6, .sl-heading-wrapper)
Expand Down Expand Up @@ -75,7 +80,7 @@ how we do it.
/* ======================================================
HEADING
====================================================== */
.sl-markdown-content .sl-heading-wrapper > :first-child {
.sl-markdown-content .sl-heading-wrapper > :first-child:not([hidden]) {
display: inline;
/* Apply end-of-line padding to the heading element. */
padding-inline-end: var(--sl-anchor-icon-space);
Expand All @@ -96,6 +101,13 @@ how we do it.
display: inline-flex;
}

/* Hide anchor links for headings that are hidden. */
.sl-markdown-content
.sl-heading-wrapper:has(> :first-child:is(.sr-only, [hidden]))
> .sl-anchor-link {
display: none;
}

/* Increase clickable area for anchor links with a pseudo element that doesn’t impact layout. */
.sl-markdown-content .sl-anchor-link::after {
content: '';
Expand Down