feat(muya): expose themeable CSS variables and diagram theming by Jocs · Pull Request #4382 · marktext/marktext · GitHub
Skip to content

feat(muya): expose themeable CSS variables and diagram theming - #4382

Merged
Jocs merged 3 commits into
developfrom
feat/muya-themeable-css
Jun 8, 2026
Merged

Jocs merged 3 commits into
developfrom
feat/muya-themeable-css

Conversation

@Jocs

@Jocs Jocs commented Jun 8, 2026

Copy link
Copy Markdown
Member

What & why

Part of the muyajs → @muyajs/core migration: makes packages/muya's CSS
themeable so the desktop app's 32 themes can later drive it via CSS custom
properties (the same way the legacy packages/muyajs engine is themed today).

Scope is strictly CSS under packages/muya/src/assets/styles/ — no .ts files
touched. The default light theme renders identically: every new variable is
applied as var(--name, <fallback>) where the fallback is muya's exact current
hardcoded / opacity-tier value, so nothing changes visually until a theme
overrides a variable.

C1 — themeable CSS custom properties

New variables defined in index.css :root (defaults in parentheses) and used
at their call sites:

Variable Default (fallback) Usage site
--editor-area-width 800px .mu-container max-width
--link-color rgb(20 86 240) a.mu-inline-rule, span.mu-inline-rule.mu-link
--h1-color … --h6-color var(--editor-color-80) each .mu-container h1…h6
--blockquote-text-color var(--editor-color-50) .mu-container blockquote
--blockquote-border-color var(--editor-color-30) .mu-container blockquote::before
--hr-color var(--editor-color-10) .mu-thematic-break::before
--strong-color inherit strong.mu-inline-rule
--em-color inherit em.mu-inline-rule
--list-marker-color inherit order/bullet list ::marker
--button-bg-color-active var(--button-bg-color) :root (theme hook)
--button-border-active var(--button-border) :root (theme hook)
--button-border-focus var(--button-border) :root (theme hook)

Notes:

  • strong/em/list markers previously had no explicit color (they inherit
    the editor color). Defaulting the new vars to inherit keeps that behavior
    exactly while giving themes a recolor hook.
  • muya has no hardcoded :active/:focus button styles in these files, so the
    button active/focus vars are added as :root hooks (defaulting to the resting
    button look) for desktop-theme parity rather than rewriting nonexistent rules.
  • The variable names mirror the desktop themes' existing camelCase set
    (--h1Color, --blockquoteTextColor, --linkColor, --editorAreaWidth, …),
    kebab-cased to match muya's convention, so the eventual wiring is 1:1.

C2 — diagram SVG per-theme recoloring

Ported marktext's legacy block (packages/muyajs/themes/default.css
figure[data-role] svg …, ~lines 689-720) into blockSyntax.css, adapted to
muya's live DOM (figure.mu-diagram-block .mu-diagram-preview svg) and
kebab-cased vars (--editor-bg-color, --editor-color). Mermaid and vega-lite
render an inline <svg> whose default black-on-white fill/stroke values are
rewritten to the editor's theme colors, so diagrams follow the active theme —
including dark themes that override those two vars. The rules are additive and
entirely theme-driven; on the bundled light theme --editor-bg-color is white
and --editor-color is the editor text color, so diagrams look unchanged.

Verification

  • pnpm -C packages/muya lint:types — pass
  • pnpm -C packages/muya build — pass
  • pnpm -C packages/muya test — 388 passed
  • pnpm -C packages/muya test:spec — 1347 passed
  • pnpm -C packages/muya lint (ESLint, CI-gated) — 0 errors

Note on lint:css: pnpm -C packages/muya lint:css currently crashes
(TypeError: Cannot read properties of undefined (reading 'unprefixed')) on a
clean develop checkout, before any change in this PR — it is a
pre-existing tooling issue: stylelint-config-rational-order@0.1.2 bundles
stylelint-order@2.2.1 / stylelint@^9, which is incompatible with the
installed stylelint@17's PostCSS AST. CI's muya-lint workflow runs only
lint + lint:types, not lint:css, so it is not gated there. The CSS in
this PR was validated against stylelint-config-standard (plus the repo's
custom rule overrides) with zero violations.

🤖 Generated with Claude Code

Jocs and others added 2 commits June 8, 2026 11:48
Introduce CSS custom properties so desktop's 32 themes can later drive
muya's editor chrome (part of the muyajs -> @muyajs/core migration).
Each new variable defaults to muya's current hardcoded / opacity-tier
value via `var(--name, <fallback>)`, so the bundled light theme renders
identically.

Added in index.css `:root`:
- --editor-area-width (800px) for `.mu-container` max-width
- --link-color (rgb(20 86 240))
- --h1-color .. --h6-color (var(--editor-color-80))
- --blockquote-text-color (var(--editor-color-50))
- --blockquote-border-color (var(--editor-color-30))
- --hr-color (var(--editor-color-10))
- --strong-color / --em-color / --list-marker-color (inherit)
- --button-bg-color-active / --button-border-active / --button-border-focus

Usage sites updated in blockSyntax.css (container width, per-heading
colors, blockquote text + border, thematic break, list markers) and
inlineSyntax.css (link color, strong + em color).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Port marktext's legacy diagram-recoloring rules (packages/muyajs/themes/
default.css `figure[data-role] svg …`) into muya's blockSyntax.css,
adapted to muya's live DOM (`figure.mu-diagram-block .mu-diagram-preview
svg`) and kebab-cased vars (`--editor-bg-color`, `--editor-color`).

Mermaid and vega-lite render an inline <svg> whose default black-on-white
fills/strokes are rewritten to the editor's theme colors, so diagrams
follow the active theme (including dark themes that override those vars).
Additive and entirely theme-driven; the bundled light theme is unchanged
because `--editor-bg-color` is white and `--editor-color` is the editor
text color, matching the diagrams' original look.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 8, 2026 03:50

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

This PR makes Muya’s editor CSS themeable by introducing CSS custom properties (with fallbacks preserving current light-theme rendering) and adds theme-driven recoloring rules for inline diagram SVGs so diagrams follow the active editor theme.

Changes:

  • Introduces new :root CSS variables (e.g. editor width, link/heading/blockquote/list-marker colors, button active/focus hooks) intended for theme overrides.
  • Updates inline and block syntax styles to consume the new variables via var(--name, <fallback>).
  • Adds diagram <svg> fill/stroke overrides in blockSyntax.css to recolor default black/white diagram output using --editor-bg-color / --editor-color.

Reviewed changes

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

File Description
packages/muya/src/assets/styles/index.css Defines new themeable CSS custom properties (defaults) for editor layout and markdown element colors.
packages/muya/src/assets/styles/inlineSyntax.css Switches link color to a CSS variable and adds theme hooks for strong/em emphasis colors.
packages/muya/src/assets/styles/blockSyntax.css Makes container width and element colors themeable; adds list marker theming and diagram SVG recoloring rules.

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

Comment on lines +37 to +39

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch — corrected in a0dbcad. The comment no longer implies the desktop themes already use kebab-case; it now notes they currently use camelCase (--linkColor, --h1Color, …) and will be migrated to these kebab-case names as part of the muyajs → @muyajs/core move (the theme-migration stage). The variable defaults here are unchanged, so the bundled light theme still renders identically.

Address Copilot review on #4382. The comment implied the desktop themes
already use kebab-case overrides, but they currently use camelCase
(--linkColor, --h1Color, …). Clarify that consumers override per theme and
that the desktop themes will be migrated to these kebab-case names as part
of the muyajs -> @muyajs/core move.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jocs
Jocs merged commit 3a4e764 into develop Jun 8, 2026
9 checks passed
@Jocs
Jocs deleted the feat/muya-themeable-css branch June 8, 2026 04:17
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.

2 participants