Custom heading typeface and heading text color - #121
Draft
dylandeheer wants to merge 1 commit into
Draft
Conversation
The theme can recolor every element except heading text (it inherits bodyText), and the heading config covers every metric except the face — so an embedder that wants serif display headings over a sans body has to fork. HeadingStyle.fontName picks a PostScript face for headings, honored exactly so the chosen weight survives; an unresolvable name falls back to the stock bold base font, like TaskCheckboxStyle's symbol fallback. MarkdownEditorTheme.headingText colors heading text while the `#` glyphs stay on headingMarker and inline constructs inside a heading keep their own ink. Emphasis inside a heading still composes on top of the configured face (traits added, family and per-level size kept). Both knobs default to nil, which keeps styling identical to before. Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Aug 4, 2026
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.
Motivation
An embedder that sets serif display headings over a sans body can't get there today: the theme routes every color through
MarkdownEditorThemeexcept heading text (headings inheritbodyTextfrom the view-level base attributes), andHeadingStylecovers every heading metric (per-level multipliers, top spacing) except the typeface — headings always derive from the single basefontNamewith the bold trait added. Those are the only two gaps we hit embedding the engine; this PR closes both without changing any default.What's added
Two optional knobs, both
nilby default:HeadingStyle.fontName: String?— PostScript face for heading text, resolved at the per-level multiplied size. The name is honored exactly, so the chosen weight survives (pick a-Bold/-Semiboldface for heavier headings); an unresolvable name falls back to the stock bold base font, mirroringTaskCheckboxStyle's symbol fallback. Emphasis inside a heading still composes on top of the configured face — bold/italic add traits while the family and per-level size are kept (# **n*o*des**stays consistent).MarkdownEditorTheme.headingText: NSColor?— foreground for heading text only. The#glyphs stay on the existingheadingMarker, and inline constructs inside a heading (links, inline code, extension spans) keep their own ink — the styler paints the heading range before the marker loop and the inline descent, so the existing later-range-wins layering does the rest.Behavior preservation
With both knobs
nilthe styler emits value-identical[StyledRange]output to 0.11.0 — same font resolution path, same emission order, no extra ranges. Covered by a test comparing explicit-nil configs against.defaultattribute-by-attribute.Tests
Tests/MarkdownEngineTests/HeadingFontAndColorTests.swift(8 tests, in the existing AST-styler test style):headingTextcolors content only;#markers keepheadingMarker; body keeps inheritingbodyText; links keep link ink; emphasis keeps the heading ink.defaultswift buildandswift testare green locally (the fourScrollingHeaderControlleranimation-timing expectations fail identically on the pristine0.11.0tag in my sandbox, so they're environmental, not from this change).Notes
0.11.0tag so we can pin the exact revision while this is reviewed — happy to rebase ontomain(only the CHANGELOG insertion point should touch).[Unreleased]; DocC comments on both new public fields.Made with Cursor
Follow-ups
This PR turned out to be the first of a family: embedding the engine against a full design spec surfaced a few more places where a knob (or a bugfix) was needed. Each is opened as its own focused draft, stacked on this branch (their diffs over this PR are single-feature; every default preserves today's rendering exactly):
linkcolor never reaches the screen (AppKit'slinkTextAttributesdefault overrides it)ListStyle.markerTextGap)theme.listMarkerink