Skip to content

Commit 85bccdf

Browse files
committed
fix:demo page fix
1 parent beb904e commit 85bccdf

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

docs/demo/demo.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ header {
2323
box-sizing: border-box;
2424
border-bottom: 1px solid #E5E7EB;
2525
gap: 16px;
26+
/* Reserve space for GitHub corner so it doesn't overlap the toggle */
27+
padding-right: 96px;
2628
}
2729

2830
header .logo-link {
@@ -74,6 +76,8 @@ header h1 {
7476
font-size: 14px;
7577
font-weight: 500;
7678
transition: background-color 0.2s ease, color 0.2s ease;
79+
position: relative;
80+
z-index: 1;
7781
}
7882

7983
.theme-toggle:hover {
@@ -279,3 +283,10 @@ body.dark .loadingError {
279283
body.dark #loading {
280284
color: #9CA3AF;
281285
}
286+
287+
/* Responsive: when GitHub corner is hidden, remove extra right padding */
288+
@media (max-width: 768px) {
289+
header {
290+
padding-right: 24px;
291+
}
292+
}

docs/demo/demo.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ $optionsElem.addEventListener('keydown', handleInput, false);
5151
$clearElem.addEventListener('click', handleClearClick, false);
5252

5353
// --- Theme Toggle Setup ---
54-
const $themeToggle = document.getElementById('theme-toggle');
54+
const $themeToggle = document.getElementById('demo-theme-toggle');
5555

5656
function applyTheme(theme) {
5757
if (theme === 'dark') {
5858
document.body.classList.add('dark');
59+
// Also set on <html> to keep in sync with prepaint class
60+
document.documentElement.classList.add('dark');
5961
} else {
6062
document.body.classList.remove('dark');
63+
document.documentElement.classList.remove('dark');
6164
}
6265
}
6366

@@ -80,6 +83,13 @@ function getPreferredTheme() {
8083
const initialTheme = getPreferredTheme();
8184
applyTheme(initialTheme);
8285

86+
// Keep in sync if another script/tab changes the theme key
87+
window.addEventListener('storage', function(e) {
88+
if (e.key === 'theme') {
89+
applyTheme(e.newValue || getPreferredTheme());
90+
}
91+
});
92+
8393
if ($themeToggle) {
8494
$themeToggle.addEventListener('click', function() {
8595
const currentTheme = document.body.classList.contains('dark')

docs/demo/index.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
<title>Marked Demo</title>
66
<meta charset="utf-8" />
77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<!-- Prevent white flash: apply dark mode before first paint -->
9+
<script>
10+
(function () {
11+
try {
12+
var theme = localStorage.getItem('theme');
13+
var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
14+
if (theme === 'dark' || (!theme && prefersDark)) {
15+
// Use html.dark so we can style prepaint while body isn't parsed yet
16+
document.documentElement.classList.add('dark');
17+
}
18+
} catch (e) {}
19+
})();
20+
</script>
21+
<style>
22+
/* Minimal prepaint fallback to avoid flash before demo.css loads */
23+
html.dark, html.dark body { background-color: #111827; color: #F9FAFB; }
24+
@media (prefers-color-scheme: dark) { html { background-color: #111827; } }
25+
</style>
826
<link rel="stylesheet" href="./demo.css" type="text/css" />
927
<link rel="stylesheet" href="../css/shared.css" type="text/css" />
1028
<link rel="stylesheet" href="../css/style.css" type="text/css" />
@@ -39,7 +57,7 @@ <h1>Marked Demo</h1>
3957
<span class="separator">·</span>
4058
<a href="https://daringfireball.net/projects/markdown/dingus">Daring Fireball Demo</a>
4159
</div>
42-
<button id="theme-toggle" class="theme-toggle" aria-label="Toggle dark mode">
60+
<button id="demo-theme-toggle" class="theme-toggle" aria-label="Toggle dark mode">
4361
<span class="material-icons light-icon">dark_mode</span>
4462
<span class="text light-text">Dark Mode</span>
4563
<span class="material-icons dark-icon">light_mode</span>

docs/demo/preview.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
<head>
55
<meta charset="utf-8">
66
<title>marked.js preview</title>
7+
<!-- Prevent white flash in iframe: set dark before paint using same key -->
8+
<script>
9+
(function () {
10+
try {
11+
var theme = localStorage.getItem('theme');
12+
var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
13+
if (theme === 'dark' || (!theme && prefersDark)) {
14+
document.documentElement.classList.add('dark');
15+
// Ensure body reflects dark once available
16+
document.addEventListener('DOMContentLoaded', function () {
17+
document.body && document.body.classList.add('dark');
18+
});
19+
}
20+
} catch (e) {}
21+
})();
22+
</script>
723
<link rel="stylesheet" href="./demo.css" />
824
<link rel="stylesheet" href="../css/style.css" />
925
<link rel="stylesheet" href="../css/hljs-github.css" />

0 commit comments

Comments
 (0)