@@ -19,31 +19,42 @@ export interface ShikiMagicMoveProps {
19
19
}
20
20
21
21
export function ShikiMagicMove ( props : ShikiMagicMoveProps ) {
22
- const codeToTokens = ( code : string , lineNumbers ?: boolean ) =>
23
- codeToKeyedTokens (
24
- props . highlighter ,
25
- code ,
26
- {
27
- lang : props . lang ,
28
- theme : props . theme ,
29
- } ,
30
- lineNumbers ,
31
- )
22
+ const codeToTokens = createMemo ( ( ) => {
23
+ return ( code : string , lineNumbers ?: boolean ) =>
24
+ codeToKeyedTokens (
25
+ props . highlighter ,
26
+ code ,
27
+ {
28
+ lang : props . lang ,
29
+ theme : props . theme ,
30
+ } ,
31
+ lineNumbers ,
32
+ )
33
+ } )
32
34
33
- const machine = createMagicMoveMachine ( ( code , lineNumbers ) => codeToTokens ( code , lineNumbers ) )
35
+ const machine = createMemo ( ( ) => {
36
+ const newCodeToTokens = codeToTokens ( )
37
+ return createMagicMoveMachine ( ( code , lineNumbers ) =>
38
+ newCodeToTokens ( code , lineNumbers ) ,
39
+ )
40
+ } )
34
41
35
42
const result = createMemo ( ( ) => {
36
43
const lineNumbers = props . options ?. lineNumbers ?? false
37
44
if (
38
- props . code === machine . current . code &&
39
- props . theme === machine . current . themeName &&
40
- props . lang === machine . current . lang &&
41
- lineNumbers === machine . current . lineNumbers
45
+ props . code === machine ( ) . current . code &&
46
+ props . theme === machine ( ) . current . themeName &&
47
+ props . lang === machine ( ) . current . lang &&
48
+ lineNumbers === machine ( ) . current . lineNumbers
42
49
) {
43
- return machine
50
+ return machine ( )
51
+ }
52
+ try {
53
+ return machine ( ) . commit ( props . code , props . options )
54
+ // eslint-disable-next-line unused-imports/no-unused-vars
55
+ } catch ( e ) {
56
+ return machine ( )
44
57
}
45
-
46
- return machine . commit ( props . code , props . options )
47
58
} )
48
59
49
60
return (
0 commit comments