fix(preview): inline code in a heading sits on the heading's baseline (#681) - #685
Merged
Conversation
…#681) Two causes, one per stylesheet. A heading is a flex container so the fold chevron can sit beside its text, which makes every element inside it a flex item; `flex-start` then pinned each one to the top of the line rather than standing it on the baseline, and the smaller the element the further it floated. That is not specific to code — images and KaTeX in headings float the same way. And the Code Font Size setting is an absolute px, so inline code stayed 14px inside a 24px `##`. GitHub sizes it at 85% of whatever contains it; that rule is now restored for headings only, leaving the setting to mean what it says in prose and in code blocks.
This was referenced Aug 22, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
Closes #681, reported by @ac-ekm with a side-by-side against GitHub:
## Heading \code` Test` rendered the code span small and floating above the words around it instead of on their baseline.Measured on that exact heading, in the preview:
##Mechanism
Two independent causes, one per stylesheet, which is why the screenshot shows both a size and a position problem.
The float.
.foldable-headerisdisplay: flexso the fold chevron can sit beside the heading text. That makes every element inside a heading a flex item — an inline<code>, an image, a KaTeX span — andalign-items: flex-startpins each one to the top of the line instead of standing it on the text's baseline. The smaller the element, the further it floats. So this was never about code: anything shorter than the heading's line box has been riding high in every heading since folds were added.align-items: baselineis what inline layout would have done, and the chevron is unaffected because its own rule positions it.The size. The Code Font Size setting is injected as an absolute
--code-font-sizeand applied with!important, which overrides GitHub'scode { font-size: 85% }. Absolute px is right for code sitting in prose — a reader picked that number so code is legible next to their body text — and wrong for code sitting in a heading, where it does not scale: 14px inside a 24px##, 14px inside a 32px#. The 85% rule is restored for headings only.!importanton the new rule because the rule it has to beat is!importanttoo; specificity alone cannot answer that.Scope
Body text and code blocks keep answering to the setting — the fix is scoped to
h1–h6, so nothing a reader set for reading code changes.The deeper question the flex container raises is left alone: a heading arguably should not be a flex container at all, and the chevron could be positioned absolutely in the gutter the way GitHub places its anchor links. That would also restore true inline wrapping for headings that mix text and elements. It is a bigger change to a surface that fold state, the TOC and the export path all read, and this fix does not need it — measured, a long heading with inline code still wraps to the same height it did before.
Tests
scripts/headingInlineCode.test.ts, three source-shape assertions: the heading rule aligns onbaselineand notflex-start, headings size inline code at0.85em, and the--code-font-sizerule is still there for everything else. Both halves are CSS the browser resolves, so nothing that runs code can see them — and the second test is what stops a future edit from "simplifying" the heading rule back into the general one.Revert either half and the matching test goes red.
Verification
The table above was measured in Chromium against the dev server, with
window.__TAURI_INTERNALS__stubbed andrender_markdownreturning a fixture — readinggetComputedStyleandgetBoundingClientRectoff the rendered heading, including a long heading that wraps.Not verified: how it looks on Windows, where the report came from. The rules are platform-independent, and the fix moves the same two numbers everywhere, but nobody has run it there. The exported HTML and printed PDF inherit both stylesheets, so both routes get the same fix without a change of their own — that path was reasoned about, not run.