1
- import { getHighlighter } from "shiki" ;
1
+ import { createHighlighter } from "shiki" ;
2
2
3
3
import { processAST , type SyntaxLine } from "./processAST" ;
4
4
@@ -10,20 +10,21 @@ export type DiffAST = DePromise<ReturnType<typeof codeToHast>>;
10
10
11
11
export type DiffHighlighter = {
12
12
name : string ;
13
+ type : "class" | "style" | string ;
13
14
maxLineToIgnoreSyntax : number ;
14
15
setMaxLineToIgnoreSyntax : ( v : number ) => void ;
15
16
ignoreSyntaxHighlightList : ( string | RegExp ) [ ] ;
16
17
setIgnoreSyntaxHighlightList : ( v : ( string | RegExp ) [ ] ) => void ;
17
18
getAST : ( raw : string , fileName ?: string , lang ?: string , theme ?: "light" | "dark" ) => DiffAST ;
18
19
processAST : ( ast : DiffAST ) => { syntaxFileObject : Record < number , SyntaxLine > ; syntaxFileLineNumber : number } ;
19
20
hasRegisteredCurrentLang : ( lang : string ) => boolean ;
20
- getHighlighterEngine : ( ) => DePromise < ReturnType < typeof getHighlighter > > | null ;
21
+ getHighlighterEngine : ( ) => DePromise < ReturnType < typeof createHighlighter > > | null ;
21
22
} ;
22
23
23
- let internal : DePromise < ReturnType < typeof getHighlighter > > | null = null ;
24
+ let internal : DePromise < ReturnType < typeof createHighlighter > > | null = null ;
24
25
25
26
const getDefaultHighlighter = async ( ) =>
26
- await getHighlighter ( {
27
+ await createHighlighter ( {
27
28
themes : [ "github-light" , "github-dark" ] ,
28
29
langs : [
29
30
"cpp" ,
@@ -92,7 +93,7 @@ Object.defineProperty(instance, "setIgnoreSyntaxHighlightList", {
92
93
} ) ;
93
94
94
95
Object . defineProperty ( instance , "getAST" , {
95
- value : ( raw : string , fileName ?: string , lang ?: string , theme ?: "light" | "dark" ) => {
96
+ value : ( raw : string , fileName ?: string , lang ?: string ) => {
96
97
if (
97
98
fileName &&
98
99
highlighter . ignoreSyntaxHighlightList . some ( ( item ) =>
@@ -109,7 +110,12 @@ Object.defineProperty(instance, "getAST", {
109
110
try {
110
111
return internal ?. codeToHast ( raw , {
111
112
lang : lang ,
112
- theme : theme === "dark" ? "github-dark" : "github-light" ,
113
+ themes : {
114
+ dark : "github-dark" ,
115
+ light : "github-light" ,
116
+ } ,
117
+ cssVariablePrefix : "--diff-view-" ,
118
+ defaultColor : false ,
113
119
mergeWhitespaces : false ,
114
120
} ) ;
115
121
} catch ( e ) {
@@ -141,6 +147,8 @@ Object.defineProperty(instance, "getHighlighterEngine", {
141
147
} ,
142
148
} ) ;
143
149
150
+ Object . defineProperty ( instance , "type" , { value : "class" } ) ;
151
+
144
152
const highlighter : DiffHighlighter = instance as DiffHighlighter ;
145
153
146
154
export const highlighterReady = new Promise < DiffHighlighter > ( ( r ) => {
0 commit comments