Repository navigation
feat(theme): import custom editor themes from a folder - #4318
Open
jamesfredley wants to merge 2 commits into
Open
jamesfredley wants to merge 2 commits into
jamesfredley wants to merge 2 commits into
Conversation
Add support for user-provided editor themes, addressing the long-standing request in marktext#174 (and the confusion in marktext#3402 / marktext#3873, where users dropped a theme file in a folder and expected it to appear in the Theme menu). A custom theme is a single `<id>.theme.css` file in `<userData>/themes/editor` (a sibling of the existing `themes/export` used for export themes). The main process reads the folder, parses an optional `@name` / `@type` header, sanitizes the CSS, and exposes the themes over typed IPC. The renderer registers them and applies them through addThemeStyle's default branch; they appear under "Custom Themes" in the Theme menu and in Preferences -> Theme. The previously disabled "Open themes folder" / "Import Theme" UI is enabled and wired up. Security: the editor renderer runs with webSecurity:false, so custom CSS is sanitized in the main process before it is applied - @import, @font-face and any url() / image-set() value (remote, file: and data:) are removed. Custom themes are therefore colors-only and cannot load external resources. Adds unit tests (metadata parser, sanitizer, renderer registry), an e2e test that seeds a theme and verifies discovery + application, and end-user docs documenting the file format with a complete example. Closes marktext#174
…istry Address review feedback on the custom editor themes feature: - importCustomTheme: remove the copied file when the imported theme cannot be read back, so an unreadable file is not left behind to fail every future scan or block re-importing the same id. - loadCustomThemes: clear the renderer registry when a refresh fails, so getCustomTheme/getCustomThemes never serve stale descriptors after an IPC error (callers treat the empty result as "no custom themes"). - Fix doc comments to consistently reference <userData>/themes/editor. - Add a regression test asserting the registry is cleared on failed refresh.
Jocs
force-pushed
the
feat/import-custom-themes
branch
from
October 23, 2026 17:33
ac3b38b to
af8e1cb
Compare
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.
Closes #174
Summary
Adds support for user-provided editor themes, a long-standing request (#174). A custom theme is a single
<id>.theme.cssfile placed in<userData>/themes/editor/(a sibling of the existing<userData>/themes/export/used for export themes). It is auto-discovered and listed under Custom Themes in the Theme menu and in Preferences -> Theme, and applies to the app like a built-in theme. This also enables the previously-disabled "Open themes folder" / "Import Theme" UI.How it works:
<userData>/themes/editor/*.theme.css, parses an optional@name/@typeheader, sanitizes the CSS, and exposes the themes over a typed IPC contract (mt::themes::list-custom/import-custom/open-folder).addThemeStyle's default branch (injected viatextContent), and merges custom themes into the preview grid, the mode dropdowns, and the native menu. A custom@type darktheme also drives the darkbodyclass andnativeTheme.themeSource..cssinto the folder and applies it immediately; Open themes folder reveals the folder for manual drops.Security
The editor renderer runs with
webSecurity: false, so untrusted theme CSS is sanitized in the main process before it is applied:@import,@namespace,@font-face, and anyurl()/image-set()/image()value (remote,file:anddata:) are removed. CSS escapes are decoded first so the denylist cannot be bypassed with, for example,\75 rl(...). Custom themes are therefore colors-only (no external images or fonts). This is best-effort hardening, not a sandbox; the existing "Custom CSS" box remains the raw, unsanitized escape hatch.Type of change
Test plan
packages/desktop/test/e2e/custom-themes.spec.ts): seeds themes in<userData>/themes/editor, then asserts IPC discovery, that selecting a custom dark theme from the Theme menu appliesbody.dark, that the sanitized CSS is injected, and that a custom light theme removesbody.dark.pnpm lint,pnpm typecheck,pnpm test:unit(579 passing),pnpm build, andpnpm test:e2e(77 passing) all green.Notes for reviewers [optional]
<userData>/themes/editor/, deliberately separate from<userData>/themes/export/(export/PDF themes).THEMES.md(the "planned for a future release" placeholder is replaced).customThemes/importFailedi18n keys were added to every locale with English values for translators to localize later.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.