Skip to content

feat(crepe): add --crepe-base-font-size theme variable - #2432

Merged
Saul-Mirone merged 1 commit into
mainfrom
feat/crepe-base-font-size
Jul 29, 2026
Merged

Saul-Mirone merged 1 commit into
mainfrom
feat/crepe-base-font-size

Conversation

@Saul-Mirone

Copy link
Copy Markdown
Member
  • I read the contributing guide
  • I agree to follow the code of conduct

Summary

Closes #2315.

Crepe's font sizes were hardcoded in px across the theme (p = 16px, h1h6 = 42/36/32/28/24/18px, plus 11–16px in tables, code blocks, tooltips, menus, etc.). Anyone who wanted a different base size — e.g. 14px to match the rest of their app — had to override every rule by hand.

This adds a single --crepe-base-font-size custom property (default 16px) that scales the whole editor in one line:

.milkdown {
  --crepe-base-font-size: 14px;
}

How it works:

  • The base is anchored on .milkdown (next to the existing font-family: var(--crepe-font-default)), and declared in every theme so it's discoverable alongside the other --crepe-font-* variables.
  • Main content (reset.css h1h6, p) uses em ratios of the base with unitless line-heights, so leading scales with the font.
  • UI chrome (tables, code-block chrome, tooltips, slash menu, top bar, image block, AI panel, diff controls) uses calc(var(--crepe-base-font-size, 16px) * <ratio>) rather than em. em would be wrong here because it resolves against local context: the .ai-instruction panel sets a font-size its children override (so em would compound), and .milkdown-diff-controls render inline inside headings of varying size (so em would balloon). calc(base * ratio) is context-independent and reproduces the current pixels exactly at the 16px default.

Default rendering is unchanged — this is purely additive.

How did you test this change?

pnpm --filter=@milkdown/crepe build:theme (PostCSS) passes.

Ran the crepe story (e2e) and measured computed font-size on injected content + chrome at three base values. At the default the values are byte-identical to main; changing the variable scales everything proportionally:

element default (16px) --crepe-base-font-size: 14px : 20px
h1 42px (unchanged) 36.75px 52.5px
h2 36px (unchanged) 31.5px 45px
h6 18px (unchanged) 15.75px 22.5px
p 16px (unchanged) 14px 20px
top bar / slash menu / link tooltip 14px (unchanged) 12.25px 17.5px

No em compounding (verified the .ai-instruction subtree and inline diff controls resolve directly from the base).

Introduce a single `--crepe-base-font-size` custom property (default 16px)
so the whole editor's font size can be scaled in one line instead of
overriding every hardcoded rule.

The base is anchored on `.milkdown`; content headings/paragraphs use `em`
ratios with unitless line-heights, and all UI chrome font sizes use
`calc(var(--crepe-base-font-size, 16px) * ratio)` so they track the base
independently of local context. Default rendering is unchanged.

Closes #2315
Copilot AI review requested due to automatic review settings July 29, 2026 08:49
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
milkdown-storybook Ready Ready Preview, Comment Jul 29, 2026 8:49am

Request Review

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b28f53f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@milkdown/components

npm i https://pkg.pr.new/@milkdown/components@2432

@milkdown/core

npm i https://pkg.pr.new/@milkdown/core@2432

@milkdown/crepe

npm i https://pkg.pr.new/@milkdown/crepe@2432

@milkdown/ctx

npm i https://pkg.pr.new/@milkdown/ctx@2432

@milkdown/exception

npm i https://pkg.pr.new/@milkdown/exception@2432

@milkdown/kit

npm i https://pkg.pr.new/@milkdown/kit@2432

@milkdown/prose

npm i https://pkg.pr.new/@milkdown/prose@2432

@milkdown/transformer

npm i https://pkg.pr.new/@milkdown/transformer@2432

@milkdown/utils

npm i https://pkg.pr.new/@milkdown/utils@2432

@milkdown/react

npm i https://pkg.pr.new/@milkdown/react@2432

@milkdown/vue

npm i https://pkg.pr.new/@milkdown/vue@2432

@milkdown/plugin-automd

npm i https://pkg.pr.new/@milkdown/plugin-automd@2432

@milkdown/plugin-block

npm i https://pkg.pr.new/@milkdown/plugin-block@2432

@milkdown/plugin-clipboard

npm i https://pkg.pr.new/@milkdown/plugin-clipboard@2432

@milkdown/plugin-collab

npm i https://pkg.pr.new/@milkdown/plugin-collab@2432

@milkdown/plugin-cursor

npm i https://pkg.pr.new/@milkdown/plugin-cursor@2432

@milkdown/plugin-diff

npm i https://pkg.pr.new/@milkdown/plugin-diff@2432

@milkdown/plugin-emoji

npm i https://pkg.pr.new/@milkdown/plugin-emoji@2432

@milkdown/plugin-highlight

npm i https://pkg.pr.new/@milkdown/plugin-highlight@2432

@milkdown/plugin-history

npm i https://pkg.pr.new/@milkdown/plugin-history@2432

@milkdown/plugin-indent

npm i https://pkg.pr.new/@milkdown/plugin-indent@2432

@milkdown/plugin-listener

npm i https://pkg.pr.new/@milkdown/plugin-listener@2432

@milkdown/plugin-prism

npm i https://pkg.pr.new/@milkdown/plugin-prism@2432

@milkdown/plugin-slash

npm i https://pkg.pr.new/@milkdown/plugin-slash@2432

@milkdown/plugin-streaming

npm i https://pkg.pr.new/@milkdown/plugin-streaming@2432

@milkdown/plugin-tooltip

npm i https://pkg.pr.new/@milkdown/plugin-tooltip@2432

@milkdown/plugin-trailing

npm i https://pkg.pr.new/@milkdown/plugin-trailing@2432

@milkdown/plugin-upload

npm i https://pkg.pr.new/@milkdown/plugin-upload@2432

@milkdown/preset-commonmark

npm i https://pkg.pr.new/@milkdown/preset-commonmark@2432

@milkdown/preset-gfm

npm i https://pkg.pr.new/@milkdown/preset-gfm@2432

@milkdown/theme-nord

npm i https://pkg.pr.new/@milkdown/theme-nord@2432

commit: b28f53f

Copilot AI left a comment

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.

Pull request overview

Adds a new Crepe theme CSS custom property, --crepe-base-font-size (default 16px), intended to let consumers scale Crepe’s typography/UI fonts without individually overriding many font-size rules.

Changes:

  • Introduces --crepe-base-font-size: 16px in each built-in Crepe theme’s .milkdown variable block.
  • Anchors the editor’s base font size via font-size: var(--crepe-base-font-size, 16px) and converts heading/body typography in reset.css to em + unitless line-height.
  • Replaces hard-coded UI font-size values across common theme CSS with calc(var(--crepe-base-font-size, 16px) * <ratio>) and documents the new variable in docs/api/crepe.md.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/crepe/src/theme/nord/style.css Declares --crepe-base-font-size in theme variables.
packages/crepe/src/theme/nord-dark/style.css Declares --crepe-base-font-size in theme variables.
packages/crepe/src/theme/frame/style.css Declares --crepe-base-font-size in theme variables.
packages/crepe/src/theme/frame-dark/style.css Declares --crepe-base-font-size in theme variables.
packages/crepe/src/theme/crepe/style.css Declares --crepe-base-font-size in theme variables.
packages/crepe/src/theme/crepe-dark/style.css Declares --crepe-base-font-size in theme variables.
packages/crepe/src/theme/common/reset.css Sets the editor base font-size and converts headings/paragraphs to em sizing.
packages/crepe/src/theme/common/top-bar.css Switches top-bar font sizing to base-driven calc(...).
packages/crepe/src/theme/common/table.css Switches table UI font sizing to base-driven calc(...).
packages/crepe/src/theme/common/link-tooltip.css Switches tooltip/link editor font sizing to base-driven calc(...).
packages/crepe/src/theme/common/image-block.css Switches image block font sizing to base-driven variable/calc.
packages/crepe/src/theme/common/diff.css Switches diff UI font sizing to base-driven calc(...).
packages/crepe/src/theme/common/code-mirror.css Switches code-mirror UI font sizing to base-driven calc(...).
packages/crepe/src/theme/common/block-edit.css Switches slash menu/block edit UI font sizing to base-driven calc(...).
packages/crepe/src/theme/common/ai.css Switches AI panel UI font sizing to base-driven calc(...).
docs/api/crepe.md Documents overriding theme variables, including --crepe-base-font-size.
Comments suppressed due to low confidence (1)

packages/crepe/src/theme/common/code-mirror.css:168

  • line-height: 16px doesn’t scale with the new base-driven font-size. With larger --crepe-base-font-size values, the text can become taller than 16px and may clip inside the control. Consider expressing line-height relative to the base as well (or as a unitless multiplier) to keep the original proportions.
        background: var(--crepe-color-surface-low);
        color: var(--crepe-color-on-surface-variant);
        border-radius: 4px;
        font-size: calc(var(--crepe-base-font-size, 16px) * 0.75);
        font-weight: 600;
        line-height: 16px;
        margin-bottom: 8px;

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

border-radius: 4px;
font-size: 12px;
font-size: calc(var(--crepe-base-font-size, 16px) * 0.75);
line-height: 16px;
@Saul-Mirone
Saul-Mirone added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit aa6fba3 Jul 29, 2026
18 checks passed
@Saul-Mirone
Saul-Mirone deleted the feat/crepe-base-font-size branch July 29, 2026 09:48
@github-actions github-actions Bot mentioned this pull request Aug 3, 2026
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.

[Feature] Adding --crepe-font-size variable to themes

2 participants