Skip to content

markdown: Fix heading sizes and spacing in preview#54374

Merged
ChristopherBiscardi merged 2 commits intozed-industries:mainfrom
saberoueslati:fix/markdown-heading-sizes
Apr 22, 2026
Merged

markdown: Fix heading sizes and spacing in preview#54374
ChristopherBiscardi merged 2 commits intozed-industries:mainfrom
saberoueslati:fix/markdown-heading-sizes

Conversation

@saberoueslati
Copy link
Copy Markdown
Contributor

Context

Heading sizes in the markdown preview were nearly identical to body text, making # H1, ## H2, and ### H3 visually indistinguishable. The root cause was in MarkdownStyle::themed(): it set a heading_level_styles override with font sizes of rems(1.05–1.15), which silently replaced the correct sizes applied by apply_heading_style (via GPUI's text_3xl/text_2xl/text_xl utilities rems(1.875/1.5/1.25)). Removing that override restores the intended hierarchy. A mt_4() top margin was also added so consecutive headings have visual breathing room.

Closes #54358

Video of manual test below :

Screencast.from.2026-04-21.02-22-12.webm

How to Review

crates/markdown/src/markdown.rs Three changes:

  • (1) removed the heading_level_styles block from MarkdownStyle::themed() that was overriding heading font sizes with nearly-body-text values;
  • (2) added mt_4() to the heading div in push_markdown_heading for better vertical spacing;
  • (3) added test_heading_font_sizes_are_distinct which renders H1–H3 and a paragraph then asserts that line heights strictly decrease from H1 down to body text.

Self-Review Checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed heading sizes in the markdown preview to correctly reflect the H1–H6 size hierarchy, matching standard markdown renderers

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 21, 2026
@saberoueslati saberoueslati force-pushed the fix/markdown-heading-sizes branch from d8a2013 to 7f6cff1 Compare April 21, 2026 01:35
@saberoueslati saberoueslati marked this pull request as draft April 21, 2026 02:06
@danilo-leal danilo-leal self-assigned this Apr 21, 2026
@saberoueslati saberoueslati force-pushed the fix/markdown-heading-sizes branch from 7f6cff1 to 53560b9 Compare April 21, 2026 22:53
@saberoueslati saberoueslati marked this pull request as ready for review April 21, 2026 23:00
@saberoueslati
Copy link
Copy Markdown
Contributor Author

saberoueslati commented Apr 21, 2026

@danilo-leal, looking for feedback, @miguelraz suggested parity with VSCode might be needed in the issue #54358

The difference I found so far is the line under Heading 1 and 2, and the font is bolder in VSCode, as you see below. Should I add those?

Screenshots for reference below.

Zed screenshot

image

VScode screenshot

image

@ChristopherBiscardi
Copy link
Copy Markdown
Contributor

parity with VSCode might be needed

We don't need to exactly match everything vscode or another software does, especially with respect to bold or horizontal rules. Let's keep this scoped to the heading size differences so that headings like h1 vs h2 can be differentiated in the preview.

@ChristopherBiscardi
Copy link
Copy Markdown
Contributor

This looks better than it was to me. We can always make more improvements in the future. There's also another PR open to make some of these customizable that might land.

image

@ChristopherBiscardi ChristopherBiscardi merged commit d2ddb4b into zed-industries:main Apr 22, 2026
31 checks passed
@robinojw
Copy link
Copy Markdown
Contributor

Hi @ChristopherBiscardi noticed you just merged this, I've also updated the markdown rendering, any chance you could help find someone to review? #54003

@ChristopherBiscardi
Copy link
Copy Markdown
Contributor

@robinojw yes, I'm already looking at it. That's the PR I meant when I mentioned one above

pull Bot pushed a commit to VatsalSy/zed that referenced this pull request Apr 24, 2026
Follow up to zed-industries#54374 as that
removed the custom heading styles that were mostly tailored to the agent
panel. It makes sense for those values not to be the ones used for
general markdown rendering, but I think it's just too big for the agent
panel. So I'm sort of hijacking the `MarkdownFont::Agent` enum here so
that we can set it conditionally to just the agent context.

Release Notes:

- N/A
@yokhoe
Copy link
Copy Markdown

yokhoe commented Apr 29, 2026

Finally on this one. Thought I was taking crazy pills. Thanks for the quick turn around

ebaah46 pushed a commit to ebaah46/zed that referenced this pull request May 6, 2026
Follow up to zed-industries#54374 as that
removed the custom heading styles that were mostly tailored to the agent
panel. It makes sense for those values not to be the ones used for
general markdown rendering, but I think it's just too big for the agent
panel. So I'm sort of hijacking the `MarkdownFont::Agent` enum here so
that we can set it conditionally to just the agent context.

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different level markdown headings render as the same size

5 participants