File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed
Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change 77import { createOnigurumaEngine } from 'shiki/engine/oniguruma' ;
88import angularTs from '@shikijs/langs/angular-ts' ;
99import githubLight from '@shikijs/themes/github-light' ;
10+ import githubDark from '@shikijs/themes/github-dark' ;
1011
1112@Injectable ( { providedIn : 'root' } )
1213export 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 } ) ;
Original file line number Diff line number Diff line change 99} from '@angular/core' ;
1010import { SafeHtml } from '@angular/platform-browser' ;
1111import { 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} )
4243export 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 } ) ;
You can’t perform that action at this time.
0 commit comments