11import { ok as assert } from "assert" ;
22import * as shiki from "shiki" ;
3- import { Highlighter } from "shiki/dist/highlighter" ;
43import { unique } from "./array" ;
54
6- export type ShikiTheme = Parameters < typeof import ( "shiki" ) [ "getTheme" ] > [ 0 ] ;
7-
85// This is needed because Shiki includes some "fake" languages
96// ts / js are expected by users to be equivalent to typescript / javascript
107
@@ -22,13 +19,11 @@ const supportedLanguages = unique([
2219 ...shiki . BUNDLED_LANGUAGES . map ( ( lang ) => lang . id ) ,
2320] ) . sort ( ) ;
2421
25- let highlighter : Highlighter | undefined ;
22+ let highlighter : shiki . Highlighter | undefined ;
2623
27- export async function loadHighlighter ( theme : ShikiTheme ) {
24+ export async function loadHighlighter ( theme : shiki . Theme ) {
2825 if ( highlighter ) return ;
29- highlighter = await shiki . getHighlighter ( {
30- theme,
31- } ) ;
26+ highlighter = await shiki . getHighlighter ( { theme } ) ;
3227}
3328
3429export function isSupportedLanguage ( lang : string ) {
@@ -39,7 +34,11 @@ export function getSupportedLanguages(): string[] {
3934 return supportedLanguages ;
4035}
4136
42- export function highlight ( code : string , lang : string ) : string {
37+ export function highlight (
38+ code : string ,
39+ lang : string ,
40+ theme : shiki . Theme
41+ ) : string {
4342 assert ( highlighter , "Tried to highlight with an uninitialized highlighter" ) ;
4443 if ( ! isSupportedLanguage ( lang ) ) {
4544 return code ;
@@ -52,7 +51,7 @@ export function highlight(code: string, lang: string): string {
5251 lang = aliases . get ( lang ) ?? lang ;
5352
5453 const result : string [ ] = [ ] ;
55- for ( const line of highlighter . codeToThemedTokens ( code , lang , {
54+ for ( const line of highlighter . codeToThemedTokens ( code , lang , theme , {
5655 includeExplanation : false ,
5756 } ) ) {
5857 for ( const token of line ) {
0 commit comments