diff --git a/src/core.js b/src/core.js index 0253b62..f851265 100644 --- a/src/core.js +++ b/src/core.js @@ -11,7 +11,7 @@ import { injectStyles } from './styles.js'; import { t as i18nT, getCurrentLocale, getLocaleDirection } from './i18n.js'; import { parseMarkdown } from './parser.js'; import { presetPlugins } from './plugins.js'; -import { getTheme } from './themes.js'; +import { getTheme, applyTheme, saveTheme } from './themes.js'; const MODES = ['edit', 'split', 'preview']; @@ -97,6 +97,13 @@ class MarkdownEditor { injectStyles(); this._buildDOM(); + + // 主题同步:用户显式传 theme 时覆盖全局 CSS 变量并持久化,否则尊重 localStorage + if (options.theme) { + applyTheme(this.config.theme); + saveTheme(this.config.theme); + } + this._buildToolbar(); this._bindEvents();