diff --git a/README.md b/README.md index 7506dd0..88997a6 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Live **Markdown preview** for Neovim with first-class **Mermaid diagram** suppor instance_mode = "takeover", -- "takeover" (one tab) or "multi" (tab per instance) port = 0, -- 0 = auto (8421 for takeover, OS-assigned for multi) open_browser = true, + theme = "dark", -- "dark" or "light"; initial preview theme debounce_ms = 300, }) end, @@ -120,6 +121,8 @@ require("markdown_preview").setup({ mermaid_renderer = "js", -- "js" (browser mermaid.js) or "rust" (mmdr CLI, ~400x faster) + theme = "dark", -- "dark" or "light"; initial preview theme (toggleable in browser) + scroll_sync = true, -- browser follows cursor position -- Fraction (0–1): vertical position of the final line when scrolled to end. diff --git a/assets/index.html b/assets/index.html index 4dd3148..1ac18f2 100644 --- a/assets/index.html +++ b/assets/index.html @@ -1,5 +1,5 @@ - + @@ -879,7 +879,7 @@

Markdown Preview

// ── State ───────────────────────────────────────────────────── let lastContent = null; - let currentTheme = 'dark'; + let currentTheme = document.documentElement.dataset.theme || 'dark'; let mermaidIdCounter = 0; let sseConnected = false; const loadedPacks = new Set(); @@ -1427,7 +1427,7 @@

Markdown Preview

// ── Boot ────────────────────────────────────────────────────── (async function boot() { try { - applyTheme('dark'); + applyTheme(currentTheme); await sync(true); } catch (e) { console.error('[markdown-preview] boot error:', e); diff --git a/lua/markdown_preview/init.lua b/lua/markdown_preview/init.lua index 9cff795..7968142 100644 --- a/lua/markdown_preview/init.lua +++ b/lua/markdown_preview/init.lua @@ -37,6 +37,9 @@ M.config = { scroll_sync = true, -- sync browser scroll to cursor position + -- "dark" or "light"; determines the initial theme of the preview page + theme = "dark", + -- Fraction (0–1): vertical position of the final line when scrolled to end. -- 0.5 = middle of viewport (default), 1.0 = bottom edge (no extra space) bottom_padding = 0.5, @@ -95,6 +98,7 @@ local function write_index(dir) end local content = util.read_text(src) content = content:gsub("__BOTTOM_PADDING__", tostring(M.config.bottom_padding)) + content = content:gsub("__THEME__", M.config.theme) util.write_text(dst, content) return dst end