feat: always-dark VS code blocks, remove Find button
- Replace github light/dark hljs themes with assets/hljs/vs-dark.css (#1e1e1e bg, VS token colors) - Drop the prefers-color-scheme stylesheet switch; code blocks stay dark in both themes - Remove the toolbar Find button and its strings/icon; Ctrl+F and the findbar are unchanged - Print keeps the dark background via print-color-adjust: exact - Delete unused github.min.css / github-dark.min.css
This commit is contained in:
44
src/main.rs
44
src/main.rs
@@ -144,7 +144,6 @@ struct Strings {
|
||||
btn_preview: &'static str,
|
||||
btn_new: &'static str,
|
||||
new_filename: &'static str,
|
||||
btn_search: &'static str,
|
||||
btn_zoom: &'static str,
|
||||
btn_zoom_out: &'static str,
|
||||
btn_zoom_reset: &'static str,
|
||||
@@ -170,7 +169,6 @@ impl Strings {
|
||||
btn_preview: "预览 (Cmd/Ctrl+E)",
|
||||
btn_new: "新建 Markdown (Cmd/Ctrl+N)",
|
||||
new_filename: "新建.md",
|
||||
btn_search: "搜索 (Cmd/Ctrl+F)",
|
||||
btn_zoom: "正文缩放",
|
||||
btn_zoom_out: "缩小正文 (Cmd/Ctrl+-)",
|
||||
btn_zoom_reset: "重置正文缩放 (Cmd/Ctrl+0)",
|
||||
@@ -192,7 +190,6 @@ impl Strings {
|
||||
btn_preview: "Preview (Cmd/Ctrl+E)",
|
||||
btn_new: "New Markdown (Cmd/Ctrl+N)",
|
||||
new_filename: "Untitled.md",
|
||||
btn_search: "Find (Cmd/Ctrl+F)",
|
||||
btn_zoom: "Content zoom",
|
||||
btn_zoom_out: "Zoom out (Cmd/Ctrl+-)",
|
||||
btn_zoom_reset: "Reset zoom (Cmd/Ctrl+0)",
|
||||
@@ -691,8 +688,8 @@ fn unique_heading_id(base: String, seen: &mut HashMap<String, usize>) -> String
|
||||
|
||||
// Embedded highlight.js + themes (offline)
|
||||
const HLJS_JS: &str = include_str!("../assets/hljs/highlight.min.js");
|
||||
const HLJS_LIGHT: &str = include_str!("../assets/hljs/github.min.css");
|
||||
const HLJS_DARK: &str = include_str!("../assets/hljs/github-dark.min.css");
|
||||
// Always-dark code blocks; app chrome still follows the system theme.
|
||||
const HLJS_CODE: &str = include_str!("../assets/hljs/vs-dark.css");
|
||||
// Extra language pack(s) not in the `common` bundle. Each file
|
||||
// ends with `hljs.registerLanguage(...)` and only works if evaluated
|
||||
// in the same scope as the main bundle — we concat them into hljs-src.
|
||||
@@ -1003,18 +1000,7 @@ fn build_page(
|
||||
format!(
|
||||
r#"<!DOCTYPE html><html><head><meta charset="utf-8">
|
||||
{base_tag}
|
||||
<style id="hljs-light">{css_light}</style>
|
||||
<style id="hljs-dark" media="not all">{css_dark}</style>
|
||||
<script>
|
||||
(function(){{
|
||||
var mq = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
function apply(e) {{
|
||||
document.getElementById('hljs-light').media = e.matches ? 'not all' : '';
|
||||
document.getElementById('hljs-dark').media = e.matches ? '' : 'not all';
|
||||
}}
|
||||
apply(mq); mq.addEventListener('change', apply);
|
||||
}})();
|
||||
</script>
|
||||
<style id="hljs-code">{css_code}</style>
|
||||
<style>
|
||||
:root {{ color-scheme: light dark; --chrome-top: 10px; --content-scale: 1; }}
|
||||
/* Reserve scrollbar space permanently so the fixed toolbar doesn't shift
|
||||
@@ -1051,7 +1037,8 @@ body.has-tabs {{ --chrome-top: 50px; }}
|
||||
#preview h1 {{ border-bottom: 1px solid #e1e4e8; padding-bottom: .3em; }}
|
||||
#preview h2 {{ border-bottom: 1px solid #e1e4e8; padding-bottom: .2em; }}
|
||||
#preview code {{ background: #f0f0f0; padding: 2px 6px; border-radius: 4px; font-size: 90%; }}
|
||||
#preview pre {{ background: #f6f8fa; padding: 16px; border-radius: 8px; overflow-x: auto; }}
|
||||
/* Code blocks stay dark (VS Dark) even in the light app theme. */
|
||||
#preview pre {{ background: #1e1e1e; color: #d4d4d4; padding: 16px; border-radius: 8px; overflow-x: auto; }}
|
||||
#preview pre code {{ background: none; padding: 0; font-size: 14px; }}
|
||||
#preview blockquote {{ border-left: 4px solid #ddd; margin: 0; padding: 0 1em; color: #666; }}
|
||||
#preview .markdown-alert-note,
|
||||
@@ -1243,8 +1230,7 @@ body.empty .toolbar {{ display: none !important; }}
|
||||
#preview h1, #preview h2 {{ border-color: #333; }}
|
||||
#preview .front-matter {{ border-color: #333; color: #a9b1ba; }}
|
||||
#preview .front-matter pre {{ background: transparent !important; }}
|
||||
#preview pre {{ background: #2d2d2d !important; }}
|
||||
#preview code:not(pre code) {{ background: #2d2d2d; }}
|
||||
#preview code:not(pre code) {{ background: #2d2d2d; }}
|
||||
#preview blockquote {{ border-color: #444; color: #aaa; }}
|
||||
#preview .markdown-alert-note,
|
||||
#preview .markdown-alert-tip,
|
||||
@@ -1305,7 +1291,6 @@ body.empty .toolbar {{ display: none !important; }}
|
||||
body.editing #preview {{ display: none; }}
|
||||
body.editing #editor {{ display: block; padding: 16px 24px; }}
|
||||
body.editing #app {{ max-width: none; padding: 0; }}
|
||||
body.editing #btn-search {{ display: none; }}
|
||||
|
||||
@page {{
|
||||
margin: 12mm;
|
||||
@@ -1316,11 +1301,11 @@ body.editing #btn-search {{ display: none; }}
|
||||
#preview {{ display: block !important; }}
|
||||
#app {{ max-width: none; padding: 0; }}
|
||||
#preview .mdp-table-wrap {{ width: auto; margin: 1em 0; transform: none; overflow: visible; }}
|
||||
#preview pre {{ -webkit-print-color-adjust: exact; print-color-adjust: exact; }}
|
||||
}}
|
||||
</style></head><body class="{body_class}">
|
||||
<div class="tabbar" id="tabbar"><div class="tabs" id="tabs"></div><div class="doc-stats" id="doc-stats" aria-live="polite"></div><button class="tab-open" id="tab-open" type="button" title="{btn_new}" aria-label="{btn_new}">+</button></div>
|
||||
<div class="toolbar">
|
||||
<button id="btn-search" title="{btn_search}" aria-label="{btn_search}"></button>
|
||||
<button id="btn-toggle" title="{btn_edit}" aria-label="{btn_edit}"></button>
|
||||
<div class="zoom-control" id="zoom-control">
|
||||
<button id="btn-zoom" title="{btn_zoom}" aria-label="{btn_zoom}"></button>
|
||||
@@ -1346,14 +1331,12 @@ body.editing #btn-search {{ display: none; }}
|
||||
(function(){{
|
||||
var ICON_EDIT = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>';
|
||||
var ICON_VIEW = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>';
|
||||
var ICON_SEARCH = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>';
|
||||
var ICON_ZOOM = '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/><path d="M8 11h6"/><path d="M11 8v6"/></svg>';
|
||||
var ICON_UP = '<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 15-6-6-6 6"/></svg>';
|
||||
var ICON_DOWN = '<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>';
|
||||
var ICON_CLOSE = '<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>';
|
||||
var L_EDIT = '{btn_edit}', L_VIEW = '{btn_preview}';
|
||||
|
||||
var btnSearch = document.getElementById('btn-search');
|
||||
var btnToggle = document.getElementById('btn-toggle');
|
||||
var btnZoom = document.getElementById('btn-zoom');
|
||||
var btnZoomOut = document.getElementById('btn-zoom-out');
|
||||
@@ -1390,7 +1373,6 @@ body.editing #btn-search {{ display: none; }}
|
||||
var zoomWheelAt = 0;
|
||||
var zoomPercent = 100;
|
||||
|
||||
btnSearch.innerHTML = ICON_SEARCH;
|
||||
btnToggle.innerHTML = ICON_EDIT;
|
||||
btnZoom.innerHTML = ICON_ZOOM;
|
||||
findPrev.innerHTML = ICON_UP;
|
||||
@@ -1667,7 +1649,6 @@ body.editing #btn-search {{ display: none; }}
|
||||
}};
|
||||
|
||||
tabOpen.addEventListener('click', newFile);
|
||||
btnSearch.addEventListener('click', showFind);
|
||||
document.addEventListener('click', function(e) {{
|
||||
var closeTab = e.target && e.target.closest ? e.target.closest('[data-close-tab]') : null;
|
||||
if (closeTab) {{
|
||||
@@ -1949,13 +1930,11 @@ window.__mdPreviewFeatureFlags = {{ math: {needs_math}, mermaid: {needs_mermaid}
|
||||
if(window.__enhancePreview)window.__enhancePreview();
|
||||
</script>
|
||||
</body></html>"#,
|
||||
css_light = HLJS_LIGHT,
|
||||
css_dark = HLJS_DARK,
|
||||
css_code = HLJS_CODE,
|
||||
base_tag = base_tag,
|
||||
preview_html = preview_html,
|
||||
raw_md_escaped = html_escape_ta(raw_md),
|
||||
btn_new = s.btn_new,
|
||||
btn_search = s.btn_search,
|
||||
btn_edit = s.btn_edit,
|
||||
btn_preview = s.btn_preview,
|
||||
btn_zoom = s.btn_zoom,
|
||||
@@ -2274,15 +2253,16 @@ mod tests {
|
||||
assert!(page.contains("window.ipc.postMessage('refresh')"));
|
||||
assert!(!page.contains("id=\"btn-open\""));
|
||||
assert!(!page.contains("id=\"btn-print\""));
|
||||
assert!(page.contains("id=\"btn-search\""));
|
||||
assert!(!page.contains("id=\"btn-search\""));
|
||||
assert!(page.contains("window.ipc.postMessage('open')"));
|
||||
assert!(page.contains("window.__mdPreviewOpenFile = openFile"));
|
||||
assert!(page.contains("window.__mdPreviewShowFind = showFind"));
|
||||
assert!(page.contains("window.__mdPreviewToggleEdit"));
|
||||
assert!(page.contains("Cmd/Ctrl+F"));
|
||||
assert!(page
|
||||
.contains("if (inEdit()) return;\n\t e.preventDefault();\n\t showFind();"));
|
||||
assert!(page.contains("body.editing #btn-search"));
|
||||
assert!(page.contains("id=\"hljs-code\""));
|
||||
assert!(page.contains("#preview pre { background: #1e1e1e;"));
|
||||
assert!(!page.contains("hljs-light"));
|
||||
assert!(page.contains("ta.focus({ preventScroll: true })"));
|
||||
assert!(page.contains("window.__setEmptyPreview"));
|
||||
assert!(page.contains("id=\"tabbar\""));
|
||||
|
||||
Reference in New Issue
Block a user