Skip to content

Commit fcc4775

Browse files
committed
fix: match code highlighter theme to app theme
Fixes that we were always using a light theme, even if the app is in dark mode.
1 parent 2ef9d23 commit fcc4775

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

report-app/src/app/services/code-highligher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { createOnigurumaEngine } from 'shiki/engine/oniguruma';
88
import angularTs from '@shikijs/langs/angular-ts';
99
import githubLight from '@shikijs/themes/github-light';
10+
import githubDark from '@shikijs/themes/github-dark';
1011

1112
@Injectable({ providedIn: 'root' })
1213
export class CodeHighligher implements OnDestroy {
@@ -25,7 +26,7 @@ export class CodeHighligher implements OnDestroy {
2526
if (!this.cachedHighligher) {
2627
const engine = await createOnigurumaEngine(import('shiki/wasm'));
2728
this.cachedHighligher = createHighlighterCoreSync({
28-
themes: [githubLight],
29+
themes: [githubLight, githubDark],
2930
langs: [angularTs],
3031
engine,
3132
});

report-app/src/app/shared/code-viewer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@angular/core';
1010
import { SafeHtml } from '@angular/platform-browser';
1111
import { CodeHighligher } from '../services/code-highligher';
12+
import { AppColorMode } from '../services/app-color-mode';
1213

1314
@Component({
1415
selector: 'app-code-viewer',
@@ -41,6 +42,7 @@ import { CodeHighligher } from '../services/code-highligher';
4142
})
4243
export class CodeViewer {
4344
private highlighter = inject(CodeHighligher);
45+
private colorService = inject(AppColorMode);
4446
protected formatedCode = signal<SafeHtml>('');
4547

4648
code = input.required<string>();
@@ -49,9 +51,10 @@ export class CodeViewer {
4951
const elementRef = inject(ElementRef);
5052

5153
afterRenderEffect(async () => {
54+
const colorMode = this.colorService.colorMode();
5255
const highlightedString = await this.highlighter.codeToHtml(this.code(), {
5356
lang: 'angular-ts',
54-
theme: 'github-light',
57+
theme: colorMode === 'dark' ? 'github-dark' : 'github-light',
5558
});
5659
elementRef.nativeElement.innerHTML = highlightedString;
5760
});

0 commit comments

Comments
 (0)