Skip to content

Commit 2a9b633

Browse files
authored
Improve code block color theming (ggml-org#16325)
* feat: Improve code block theming * chore: update webui build output * chore: Update webui static build
1 parent 1104ca1 commit 2a9b633

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

tools/server/public/index.html.gz

383 Bytes
Binary file not shown.

tools/server/webui/src/app.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
--sidebar-accent-foreground: oklch(0.205 0 0);
3838
--sidebar-border: oklch(0.922 0 0);
3939
--sidebar-ring: oklch(0.708 0 0);
40-
--code-background: oklch(0.225 0 0);
41-
--code-foreground: oklch(0.875 0 0);
40+
--code-background: oklch(0.975 0 0);
41+
--code-foreground: oklch(0.145 0 0);
4242
--layer-popover: 1000000;
4343
}
4444

@@ -74,6 +74,8 @@
7474
--sidebar-accent-foreground: oklch(0.985 0 0);
7575
--sidebar-border: oklch(1 0 0 / 10%);
7676
--sidebar-ring: oklch(0.556 0 0);
77+
--code-background: oklch(0.225 0 0);
78+
--code-foreground: oklch(0.875 0 0);
7779
}
7880

7981
@theme inline {

tools/server/webui/src/lib/components/app/misc/MarkdownContent.svelte

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import rehypeKatex from 'rehype-katex';
99
import rehypeStringify from 'rehype-stringify';
1010
import { copyCodeToClipboard } from '$lib/utils/copy';
11-
import 'highlight.js/styles/github-dark.css';
11+
import { browser } from '$app/environment';
1212
import 'katex/dist/katex.min.css';
1313
14+
import githubDarkCss from 'highlight.js/styles/github-dark.css?inline';
15+
import githubLightCss from 'highlight.js/styles/github.css?inline';
16+
import { mode } from 'mode-watcher';
17+
1418
interface Props {
1519
content: string;
1620
class?: string;
@@ -21,6 +25,26 @@
2125
let containerRef = $state<HTMLDivElement>();
2226
let processedHtml = $state('');
2327
28+
function loadHighlightTheme(isDark: boolean) {
29+
if (!browser) return;
30+
31+
const existingThemes = document.querySelectorAll('style[data-highlight-theme]');
32+
existingThemes.forEach((style) => style.remove());
33+
34+
const style = document.createElement('style');
35+
style.setAttribute('data-highlight-theme', 'true');
36+
style.textContent = isDark ? githubDarkCss : githubLightCss;
37+
38+
document.head.appendChild(style);
39+
}
40+
41+
$effect(() => {
42+
const currentMode = mode.current;
43+
const isDark = currentMode === 'dark';
44+
45+
loadHighlightTheme(isDark);
46+
});
47+
2448
let processor = $derived(() => {
2549
return remark()
2650
.use(remarkGfm) // GitHub Flavored Markdown

0 commit comments

Comments
 (0)