AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(editor): separate custom theme code backgrounds from quotes
tianma-ifbae23dc060e8
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex 156f2764..75ecb783 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -4308,6 +4308,7 @@ const RichEditorPane = ({"--editor-theme-light-heading": customEditorTheme.light.heading,"--editor-theme-light-accent": customEditorTheme.light.accent,"--editor-theme-light-soft": customEditorTheme.light.soft,+ "--editor-theme-light-code-bg": customEditorTheme.light.codeBackground,"--editor-theme-light-border": customEditorTheme.light.border,"--editor-theme-dark-bg": customEditorTheme.dark.background,"--editor-theme-dark-text": customEditorTheme.dark.text,@@ -4315,6 +4316,7 @@ const RichEditorPane = ({"--editor-theme-dark-heading": customEditorTheme.dark.heading,"--editor-theme-dark-accent": customEditorTheme.dark.accent,"--editor-theme-dark-soft": customEditorTheme.dark.soft,+ "--editor-theme-dark-code-bg": customEditorTheme.dark.codeBackground,"--editor-theme-dark-border": customEditorTheme.dark.border,}: {}),diff --git a/apps/web/src/components/ThemeProvider.tsx b/apps/web/src/components/ThemeProvider.tsxindex 39cf8d1b..e01cff7b 100644--- a/apps/web/src/components/ThemeProvider.tsx+++ b/apps/web/src/components/ThemeProvider.tsx@@ -3,6 +3,7 @@ import {DEFAULT_CUSTOM_DARK_COLORS,DEFAULT_CUSTOM_EDITOR_THEME,DEFAULT_CUSTOM_LIGHT_COLORS,+ normalizeThemeColors,type CustomEditorTheme,type ThemeColors,} from "@/lib/custom-editor-theme";@@ -197,18 +198,6 @@ export const getStoredEditorTheme = (): string => {return readLocalStorageItem(EDITOR_THEME_STORAGE_KEY) || "default";};-const isHexColor = (value: unknown): value is string => typeof value === "string" && /^#[0-9a-f]{6}$/i.test(value);--const normalizeThemeColors = (value: Partial<ThemeColors> | undefined, fallback: ThemeColors): ThemeColors => ({- background: isHexColor(value?.background) ? value.background : fallback.background,- text: isHexColor(value?.text) ? value.text : fallback.text,- muted: isHexColor(value?.muted) ? value.muted : fallback.muted,- heading: isHexColor(value?.heading) ? value.heading : fallback.heading,- accent: isHexColor(value?.accent) ? value.accent : fallback.accent,- soft: isHexColor(value?.soft) ? value.soft : fallback.soft,- border: isHexColor(value?.border) ? value.border : fallback.border,-});-const normalizeCustomEditorTheme = (theme: CustomEditorTheme): CustomEditorTheme => ({...theme,light: normalizeThemeColors(theme.light, DEFAULT_CUSTOM_LIGHT_COLORS),@@ -239,7 +228,7 @@ export const getStoredCustomEditorThemes = (): CustomEditorTheme[] => {const migratedTheme: CustomEditorTheme = {id: "custom-migrated",name: oldTheme.name || "My custom theme",- light: {+ light: normalizeThemeColors({background: oldTheme.background || DEFAULT_CUSTOM_LIGHT_COLORS.background,text: oldTheme.text || DEFAULT_CUSTOM_LIGHT_COLORS.text,muted: oldTheme.muted || DEFAULT_CUSTOM_LIGHT_COLORS.muted,@@ -247,7 +236,7 @@ export const getStoredCustomEditorThemes = (): CustomEditorTheme[] => {accent: oldTheme.accent || DEFAULT_CUSTOM_LIGHT_COLORS.accent,soft: oldTheme.soft || DEFAULT_CUSTOM_LIGHT_COLORS.soft,border: oldTheme.border || DEFAULT_CUSTOM_LIGHT_COLORS.border,- },+ }, DEFAULT_CUSTOM_LIGHT_COLORS),dark: DEFAULT_CUSTOM_DARK_COLORS,customCss: "",};diff --git a/apps/web/src/components/settings/CustomEditorThemeDialog.tsx b/apps/web/src/components/settings/CustomEditorThemeDialog.tsxindex e381fa53..559da53b 100644--- a/apps/web/src/components/settings/CustomEditorThemeDialog.tsx+++ b/apps/web/src/components/settings/CustomEditorThemeDialog.tsx@@ -42,6 +42,7 @@ const COLOR_FIELDS = [["heading", "settings.customEditorTheme.heading"],["accent", "settings.customEditorTheme.accent"],["soft", "settings.customEditorTheme.soft"],+ ["codeBackground", "settings.customEditorTheme.codeBackground"],["border", "settings.customEditorTheme.border"],] as const;@@ -196,6 +197,7 @@ export const CustomEditorThemeDialog = ({/><Inputvalue={activeColors[key]}+ aria-label={t(labelKey)}onChange={(event) => updateColor(key as keyof ThemeColors, event.target.value)}maxLength={7}className="h-7 w-20 px-1.5 font-mono text-[11px]"@@ -239,6 +241,7 @@ export const CustomEditorThemeDialog = ({className="ProseMirror p-3 text-xs leading-6"style={{color: activeColors.text,+ padding: "0.75rem",}}>{draft.customCss && (@@ -254,6 +257,27 @@ export const CustomEditorThemeDialog = ({<strong style={{ color: activeColors.accent }}>{t("settings.customEditorTheme.previewAccent")}</strong>+ <blockquote+ style={{+ background: activeColors.soft,+ color: activeColors.muted,+ borderColor: activeColors.accent,+ margin: "0.75rem 0 0",+ padding: "0.8rem 1rem",+ }}+ >+ <p>{t("settings.customEditorTheme.previewQuote")}</p>+ <pre+ style={{+ background: activeColors.codeBackground,+ color: activeColors.text,+ borderColor: activeColors.border,+ marginBottom: 0,+ }}+ >+ <code style={{ background: "transparent", color: "inherit" }}>{'const message = "Hello, EdgeEver!";'}</code>+ </pre>+ </blockquote></div></div></div>diff --git a/apps/web/src/lib/custom-editor-theme.test.mjs b/apps/web/src/lib/custom-editor-theme.test.mjsindex ddb5efa0..cd2a0922 100644--- a/apps/web/src/lib/custom-editor-theme.test.mjs+++ b/apps/web/src/lib/custom-editor-theme.test.mjs@@ -3,6 +3,9 @@ import {CUSTOM_EDITOR_THEME_FILE_SCHEMA,CUSTOM_EDITOR_THEME_FILE_VERSION,CustomEditorThemeFileError,+ DEFAULT_CUSTOM_LIGHT_COLORS,+ DEFAULT_CUSTOM_DARK_COLORS,+ normalizeThemeColors,customEditorThemeFileName,getEditorThemeContrastIssues,parseCustomEditorThemeFile,@@ -19,6 +22,7 @@ const theme = {heading: "#000000",accent: "#087f5b",soft: "#f1f5f9",+ codeBackground: "#e2e8f0",border: "#cbd5e1",},dark: {@@ -28,6 +32,7 @@ const theme = {heading: "#ffffff",accent: "#34d399",soft: "#1f2937",+ codeBackground: "#303b49",border: "#475569",},customCss: "h1 { font-style: italic; }",@@ -49,6 +54,34 @@ describe("custom editor theme files", () => {});});+ test("migrates old version 1 files using each mode's existing palette", () => {+ const legacy = JSON.parse(serializeCustomEditorTheme(theme));+ delete legacy.light.codeBackground;+ delete legacy.dark.codeBackground;+ const imported = parseCustomEditorThemeFile(JSON.stringify(legacy));+ for (const [mode, fallback] of [["light", DEFAULT_CUSTOM_LIGHT_COLORS], ["dark", DEFAULT_CUSTOM_DARK_COLORS]]) {+ const normalized = normalizeThemeColors(legacy[mode], fallback);+ expect(imported[mode]).toEqual(normalized);+ expect(normalized.codeBackground).toMatch(/^#[0-9a-f]{6}$/);+ expect(normalized.codeBackground).not.toBe(normalized.soft);+ for (const field of Object.keys(legacy[mode])) expect(normalized[field]).toBe(legacy[mode][field]);+ }+ expect(imported.light.codeBackground).not.toBe(imported.dark.codeBackground);+ });++ test("preserves chosen code backgrounds and rejects malformed imported values", () => {+ expect(normalizeThemeColors(theme.light, DEFAULT_CUSTOM_LIGHT_COLORS)).toEqual(theme.light);+ for (const invalid of ["red", "", null, 123]) {+ const document = JSON.parse(serializeCustomEditorTheme(theme));+ document.dark.codeBackground = invalid;+ expect(() => parseCustomEditorThemeFile(JSON.stringify(document))).toThrow(CustomEditorThemeFileError);+ }+ });++ test("warns when code text is unreadable on its own background", () => {+ expect(getEditorThemeContrastIssues({ ...theme.light, codeBackground: theme.light.text })).toEqual(["codeBackground"]);+ });+test("rejects invalid colors and unsupported versions", () => {const invalidColor = JSON.parse(serializeCustomEditorTheme(theme));invalidColor.light.text = "red";@@ -67,7 +100,7 @@ describe("custom editor theme files", () => {test("reports low contrast without making the theme structurally invalid", () => {expect(getEditorThemeContrastIssues({ ...theme.light, text: "#fefefe", accent: "#eeeeee" }))- .toEqual(["text", "accent"]);+ .toEqual(["text", "accent", "codeBackground"]);});test("creates a filesystem-safe descriptive filename", () => {diff --git a/apps/web/src/lib/custom-editor-theme.ts b/apps/web/src/lib/custom-editor-theme.tsindex 0db89a5e..fe5d5a59 100644--- a/apps/web/src/lib/custom-editor-theme.ts+++ b/apps/web/src/lib/custom-editor-theme.ts@@ -7,6 +7,7 @@ export interface ThemeColors {heading: string;accent: string;soft: string;+ codeBackground: string;border: string;}@@ -25,6 +26,7 @@ export const DEFAULT_CUSTOM_LIGHT_COLORS: ThemeColors = {heading: "#1c1917",accent: "#0f766e",soft: "#f0fdfa",+ codeBackground: "#e0ece9",border: "#99f6e4",};@@ -35,6 +37,7 @@ export const DEFAULT_CUSTOM_DARK_COLORS: ThemeColors = {heading: "#fafaf9",accent: "#2dd4bf",soft: "#292524",+ codeBackground: "#3a3635",border: "#44403c",};@@ -51,12 +54,13 @@ export const CUSTOM_EDITOR_THEME_FILE_VERSION = 1;export const MAX_CUSTOM_EDITOR_THEME_FILE_BYTES = 64 * 1024;export const MAX_CUSTOM_EDITOR_THEME_CSS_LENGTH = 2000;-const COLOR_FIELDS = ["background", "text", "muted", "heading", "accent", "soft", "border"] as const;+const LEGACY_COLOR_FIELDS = ["background", "text", "muted", "heading", "accent", "soft", "border"] as const;+const COLOR_FIELDS = [...LEGACY_COLOR_FIELDS, "codeBackground"] as const;const HEX_COLOR_PATTERN = /^#[0-9a-f]{6}$/i;type PortableCustomEditorTheme = Omit<CustomEditorTheme, "id">;-export type EditorThemeContrastIssue = "text" | "muted" | "heading" | "accent";+export type EditorThemeContrastIssue = "text" | "muted" | "heading" | "accent" | "codeBackground";export type CustomEditorThemeFileErrorCode = "invalidFile" | "unsupportedVersion" | "fileTooLarge";export class CustomEditorThemeFileError extends Error {@@ -75,12 +79,36 @@ const isRecord = (value: unknown): value is Record<string, unknown> =>export const isValidThemeColors = (value: unknown): value is ThemeColors =>isRecord(value) && COLOR_FIELDS.every((field) => typeof value[field] === "string" && HEX_COLOR_PATTERN.test(value[field]));+// Follow the existing palette: darken light quote surfaces and lighten dark ones.+const deriveCodeBackground = (soft: string, text: string) => `#${[1, 3, 5].map((offset) =>+ Math.round(Number.parseInt(soft.slice(offset, offset + 2), 16) * 0.92+ + Number.parseInt(text.slice(offset, offset + 2), 16) * 0.08).toString(16).padStart(2, "0"),+).join("")}`;++export const normalizeThemeColors = (value: Partial<ThemeColors> | undefined, fallback: ThemeColors): ThemeColors => {+ const colors = { ...fallback };+ for (const field of COLOR_FIELDS) {+ const color = value?.[field];+ if (typeof color === "string" && HEX_COLOR_PATTERN.test(color)) colors[field] = color;+ }+ if (typeof value?.codeBackground !== "string" || !HEX_COLOR_PATTERN.test(value.codeBackground)) {+ colors.codeBackground = deriveCodeBackground(colors.soft, colors.text);+ }+ return colors;+};++const isValidImportedThemeColors = (value: unknown): value is Partial<ThemeColors> =>+ isRecord(value)+ && LEGACY_COLOR_FIELDS.every((field) => typeof value[field] === "string" && HEX_COLOR_PATTERN.test(value[field]))+ && (value.codeBackground === undefined || (typeof value.codeBackground === "string" && HEX_COLOR_PATTERN.test(value.codeBackground)));+export const getEditorThemeContrastIssues = (colors: ThemeColors): EditorThemeContrastIssue[] => {const issues: EditorThemeContrastIssue[] = [];if (contrastRatio(colors.text, colors.background) < 4.5) issues.push("text");if (contrastRatio(colors.muted, colors.soft) < 4.5) issues.push("muted");if (contrastRatio(colors.heading, colors.background) < 4.5) issues.push("heading");if (contrastRatio(colors.accent, colors.background) < 3) issues.push("accent");+ if (contrastRatio(colors.text, colors.codeBackground) < 4.5) issues.push("codeBackground");return issues;};@@ -113,7 +141,7 @@ export const parseCustomEditorThemeFile = (source: string): PortableCustomEditorif (typeof parsed.name !== "string" || parsed.name.trim().length === 0 || parsed.name.trim().length > 32) {throw new CustomEditorThemeFileError("invalidFile", "Editor theme name must contain 1 to 32 characters.");}- if (!isValidThemeColors(parsed.light) || !isValidThemeColors(parsed.dark)) {+ if (!isValidImportedThemeColors(parsed.light) || !isValidImportedThemeColors(parsed.dark)) {throw new CustomEditorThemeFileError("invalidFile", "Editor theme colors must use six-digit hex values.");}if (parsed.customCss !== undefined && (typeof parsed.customCss !== "string" || parsed.customCss.length > MAX_CUSTOM_EDITOR_THEME_CSS_LENGTH)) {@@ -122,8 +150,8 @@ export const parseCustomEditorThemeFile = (source: string): PortableCustomEditorreturn {name: parsed.name.trim(),- light: parsed.light,- dark: parsed.dark,+ light: normalizeThemeColors(parsed.light, DEFAULT_CUSTOM_LIGHT_COLORS),+ dark: normalizeThemeColors(parsed.dark, DEFAULT_CUSTOM_DARK_COLORS),customCss: parsed.customCss ?? "",};};diff --git a/apps/web/src/lib/wechat-copy.ts b/apps/web/src/lib/wechat-copy.tsindex 7ba2f57a..24823956 100644--- a/apps/web/src/lib/wechat-copy.ts+++ b/apps/web/src/lib/wechat-copy.ts@@ -60,13 +60,14 @@ const THEME_BLOCK_STYLES: Record<string, { block: string; label: string }> = {const applyInlineStyles = (root: HTMLElement,editorTheme?: string,- customColors?: { bg: string; text: string; accent: string; soft: string; border: string } | null,+ customColors?: { bg: string; text: string; accent: string; soft: string; codeBackground: string; border: string } | null,customCss?: string) => {const textColor = customColors ? customColors.text : "#333";const bgColors = customColors ? customColors.bg : "#ffffff";const accent = customColors ? customColors.accent : "#059669";const soft = customColors ? customColors.soft : "#f0fdfa";+ const codeBackground = customColors ? customColors.codeBackground : "#f6f8fa";const border = customColors ? customColors.border : "#e5e7eb";const customStyles = customCss ? parseCustomCssToStyles(customCss) : null;@@ -91,9 +92,9 @@ const applyInlineStyles = (} else if (tagName === "a") {style = `color: ${accent}; text-decoration: underline;`;} else if (tagName === "code") {- style = `padding: 0.15em 0.35em; border-radius: 3px; background: ${soft}; color: ${textColor}; font-family: Menlo, Consolas, monospace; font-size: 0.9em;`;+ style = `padding: 0.15em 0.35em; border-radius: 3px; background: ${codeBackground}; color: ${textColor}; font-family: Menlo, Consolas, monospace; font-size: 0.9em;`;} else if (tagName === "pre") {- style = `margin: 1em 0; padding: 12px 14px; overflow: hidden; border-radius: 6px; background: ${soft}; color: ${textColor}; line-height: 1.6; text-align: left;`;+ style = `margin: 1em 0; padding: 12px 14px; overflow: hidden; border-radius: 6px; background: ${codeBackground}; color: ${textColor}; line-height: 1.6; text-align: left;`;} else if (tagName === "hr") {style = `margin: 1.5em 0; border: 0; border-top: 1px solid ${border};`;} else if (tagName === "th") {@@ -403,14 +404,16 @@ export const buildWeChatClipboardHtml = async (editor: Editor) => {const closestContainer = editor.view.dom.closest<HTMLElement>("[data-editor-theme]");const editorTheme = closestContainer?.dataset.editorTheme;- let customColors: { bg: string; text: string; accent: string; soft: string; border: string } | null = null;+ let customColors: { bg: string; text: string; accent: string; soft: string; codeBackground: string; border: string } | null = null;if (closestContainer && editorTheme === "custom") {+ const colors = getComputedStyle(closestContainer);customColors = {- bg: closestContainer.style.getPropertyValue("--editor-theme-bg") || "#ffffff",- text: closestContainer.style.getPropertyValue("--editor-theme-text") || "#1f2937",- accent: closestContainer.style.getPropertyValue("--editor-theme-accent") || "#059669",- soft: closestContainer.style.getPropertyValue("--editor-theme-soft") || "#ecfdf5",- border: closestContainer.style.getPropertyValue("--editor-theme-border") || "#a7f3d0",+ bg: colors.getPropertyValue("--editor-theme-bg") || "#ffffff",+ text: colors.getPropertyValue("--editor-theme-text") || "#1f2937",+ accent: colors.getPropertyValue("--editor-theme-accent") || "#059669",+ soft: colors.getPropertyValue("--editor-theme-soft") || "#ecfdf5",+ codeBackground: colors.getPropertyValue("--editor-theme-code-bg") || "#e0ece9",+ border: colors.getPropertyValue("--editor-theme-border") || "#a7f3d0",};}@@ -435,14 +438,16 @@ export const copyMarkdownToWeChat = async (markdown: string) => {const closestContainer = document.querySelector<HTMLElement>("[data-editor-theme]");const editorTheme = closestContainer?.dataset.editorTheme;- let customColors: { bg: string; text: string; accent: string; soft: string; border: string } | null = null;+ let customColors: { bg: string; text: string; accent: string; soft: string; codeBackground: string; border: string } | null = null;if (closestContainer && editorTheme === "custom") {+ const colors = getComputedStyle(closestContainer);customColors = {- bg: closestContainer.style.getPropertyValue("--editor-theme-bg") || "#ffffff",- text: closestContainer.style.getPropertyValue("--editor-theme-text") || "#1f2937",- accent: closestContainer.style.getPropertyValue("--editor-theme-accent") || "#059669",- soft: closestContainer.style.getPropertyValue("--editor-theme-soft") || "#ecfdf5",- border: closestContainer.style.getPropertyValue("--editor-theme-border") || "#a7f3d0",+ bg: colors.getPropertyValue("--editor-theme-bg") || "#ffffff",+ text: colors.getPropertyValue("--editor-theme-text") || "#1f2937",+ accent: colors.getPropertyValue("--editor-theme-accent") || "#059669",+ soft: colors.getPropertyValue("--editor-theme-soft") || "#ecfdf5",+ codeBackground: colors.getPropertyValue("--editor-theme-code-bg") || "#e0ece9",+ border: colors.getPropertyValue("--editor-theme-border") || "#a7f3d0",};}diff --git a/apps/web/src/styles/editor-themes/base.css b/apps/web/src/styles/editor-themes/base.cssindex 92d357dd..8d88a311 100644--- a/apps/web/src/styles/editor-themes/base.css+++ b/apps/web/src/styles/editor-themes/base.css@@ -23,6 +23,7 @@--editor-theme-heading: var(--editor-theme-light-heading);--editor-theme-accent: var(--editor-theme-light-accent);--editor-theme-soft: var(--editor-theme-light-soft);+ --editor-theme-code-bg: var(--editor-theme-light-code-bg);--editor-theme-border: var(--editor-theme-light-border);}@@ -33,6 +34,7 @@--editor-theme-heading: var(--editor-theme-dark-heading);--editor-theme-accent: var(--editor-theme-dark-accent);--editor-theme-soft: var(--editor-theme-dark-soft);+ --editor-theme-code-bg: var(--editor-theme-dark-code-bg);--editor-theme-border: var(--editor-theme-dark-border);}.edgeever-editor[data-editor-theme]:not([data-editor-theme="default"]) .ProseMirror {diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex a5b293b3..81fc0e34 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -322,6 +322,8 @@ export const enUS = {accent: "Accent",soft: "Soft background",border: "Border",+ codeBackground: "Code background",+ previewQuote: "A code block inside a quote should have a distinct background.",previewTitle: "Theme preview",previewBody: "This is a body text preview to help you evaluate the color combination.",previewMuted: "Muted supporting text should remain clear on the soft background.",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex 3f662c92..f0318edb 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -322,6 +322,8 @@ export const zhCN = {accent: "强调色",soft: "柔和背景",border: "边框色",+ codeBackground: "代码背景色",+ previewQuote: "引用中的代码块应有独立、清晰可辨的背景。",previewTitle: "主题预览",previewBody: "这是一段正文预览,用来感受背景、文字和边框的组合效果。",previewMuted: "辅助说明文字需要在柔和背景上保持清晰。",