Skip to content

fix: keep heading alignment stable when addSectionLinks is false#5172

Merged
marcoscaceres merged 5 commits intospeced:mainfrom
saschabuehrle:fix/issue-4448
Apr 13, 2026
Merged

fix: keep heading alignment stable when addSectionLinks is false#5172
marcoscaceres merged 5 commits intospeced:mainfrom
saschabuehrle:fix/issue-4448

Conversation

@saschabuehrle
Copy link
Copy Markdown
Contributor

Fixes #4448

The heading offset is now applied only when a heading actually has an adjacent section self-link. With addSectionLinks: false, numbered headings keep the same alignment as when links are enabled.

Greetings, saschabuehrle

Copy link
Copy Markdown
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix, @saschabuehrle! This landed fast after we triaged #4448 earlier today.

The approach is clean: adding :has(+ a.self-link) ensures the heading offset only applies when the self-link element is present. When addSectionLinks is false, headings stay in their natural position.

Approving as-is. CSS visual tests are hard in this codebase and the fix is visually verifiable.

@marcoscaceres marcoscaceres enabled auto-merge (squash) April 12, 2026 13:47
@marcoscaceres marcoscaceres requested a review from Copilot April 13, 2026 10:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts ReSpec’s heading styling so the left offset is applied only when a heading actually has an adjacent section self-link, keeping heading alignment stable when addSectionLinks: false (fixes #4448).

Changes:

  • Scope the heading left-offset rule to headings that have an adjacent a.self-link sibling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

:is(h2, h3, h4, h5, h6):not(#toc > h2, #abstract > h2, #sotd > h2, .head > h2) {
:is(h2, h3, h4, h5, h6):not(#toc > h2, #abstract > h2, #sotd > h2, .head > h2):has(+ a.self-link) {
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using :has(+ a.self-link) ties this layout fix to support for the relational pseudo-class; in browsers that don’t support :has(), the entire rule will be dropped and headings will no longer be offset when section links are enabled (regression from previous behavior). Since the markup already wraps only section-link headings in .header-wrapper (created only when conf.addSectionLinks is true in core/id-headers.js), consider targeting .header-wrapper > :is(h2, h3, h4, h5, h6) instead to avoid :has() and keep behavior consistent across browsers.

Suggested change
:is(h2, h3, h4, h5, h6):not(#toc > h2, #abstract > h2, #sotd > h2, .head > h2):has(+ a.self-link) {
.header-wrapper > :is(h2, h3, h4, h5, h6) {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine so long as it works in across latest browser engines.

@saschabuehrle can you confirm that it's ok across Firefox, Safari, and Chrome?

@marcoscaceres marcoscaceres merged commit b15e92e into speced:main Apr 13, 2026
12 checks passed
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.

Headings not aligned without addSectionLinks

3 participants